Showing posts with label Colours. Show all posts
Showing posts with label Colours. Show all posts

Tuesday, 16 May 2023

Defining colours for a report header column/2 - the easy method

Some time after writing yesterday's extravaganza, I wondered whether it would be possible to define the background colour of a report header column by using the 'design report' functionality. Assuming that a report (or the procedure calling it) appears on a menu, one right clicks on the appropriate option and chooses the 'design report' option from the pop-up menu. A document design will be created if the report/procedure does not have a previously created design.

One then clicks on the appropriate report and then right clicks on the appropriate column. From the pop-up menu, one chooses the title attributes option. A dialog box appears where one can choose various options: one clicks on the 'paint can' button, causing another dialog box to open, from which one can choose the desired colour. One repeats this process for all the fields whose background colour one wishes to choose.

This is the user's method, whereas yesterday I documented the programmer's method.

Monday, 15 May 2023

Defining colours for a report header column

It is possible to define the background colour of a report header column, as shown below.



In order to achieve this, one has to enter the 'report columns - HTML design' sub-form for each field; in the field 'title design', one enters D, and in the 'column title - HTML design' sub-form of this form, one defines the desired colour.


This is very easy to do - at least, when one knows the technique. From what I have seen, this technique works with stand-alone reports, reports that are invoked by a regular procedure and reports that are invoked as part of an HTML document.

Shown below is a procedure that I wrote to update all the visible column titles (but not of columns that appear in a header) of any given report.

:PAR1 = '$'; :EXEC = 0; LINK EXEC TO :$.EXE; ERRMSG 1 WHERE :RETVAL <= 0; SELECT EXEC, ENAME INTO :EXEC, :ENAME FROM EXEC WHERE EXEC > 0 AND TYPE = 'R'; UNLINK EXEC; ERRMSG 2 WHERE :EXEC = 0; LINK HTMLCOLORS TO :$.COL; ERRMSG 1 WHERE :RETVAL <= 0; SELECT COLOR INTO :COLOR FROM HTMLCOLORS WHERE COLOR > 0; UNLINK HTMLCOLORS ; DECLARE CUR CURSOR FOR SELECT POS FROM REPCLMNS WHERE EXEC = :EXEC AND RSELECT <> 'N' /* not hidden */ AND FGROUP < 100 /* not a header */ AND POS > 0; OPEN CUR; GOTO 300 WHERE :RETVAL <= 0; LINK GENERALLOAD TO :$.GEN; ERRMSG 1 WHERE :RETVAL <= 0; :LINE = 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT13) VALUES (1, '1', :ENAME); LABEL 100; FETCH CUR INTO :POS; GOTO 200 WHERE :RETVAL <= 0; :LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, INT1) VALUES (:LINE, '2', :POS); :LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, CHAR1) VALUES (:LINE, '3', 'D'); :LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, INT1) VALUES (:LINE, '4', :COLOR); LOOP 100; LABEL 200; CLOSE CUR; EXECUTE INTERFACE '$', SQL.TMPFILE, '-L', :$.GEN; GOTO 250 WHERE NOT EXISTS (SELECT 1 FROM ERRMSGS WHERE USER = SQL.USER AND TYPE = 'i'); EXECUTE BACKGROUND WINACTIV '-R', 'INTERFACEERR'; LABEL 250; UNLINK GENERALLOAD; LABEL 300;
The interface called has the same name as the procedure (that's the dollar sign) and is defined as follows:
Screen nameidentifiercolumn namefield name
EREP1ENAMETEXT13
REPCLMNS2POSINT1
REPCLMNSHTML3ADDTITLECHAR1
REPCLMNSTITLEHTML4BGCOLORINT1

Thursday, 20 April 2023

Colouring fields in reports

As usual, the SDK mentions the possibility of showing report fields in colour, but doesn't give the full explanation. You can change the font and/or font color of a specific report column, as well as determine its background color. This can be defined directly in the report, or indirectly, by designating another report column whose value determines the font or color. For example, use the Font Color Def. Column to specify the Col. Number of the report column whose value sets the font color. If the designated report column is hidden, that column must have a value in the Sort Priority column. 

This is about 90% of the story. Ignoring the final sentence for a moment, the way that I discovered how to use colours was to define a column that checks a condition and returns a value (e.g. ORDERS.CURDATE < SQL.DATE8 ? 0 : 3) then one uses this column as written above. With regard to the returned value, 0 is 'no colour' and 3 is red. The table HTMLCOLORS lists the various colour available and one can add more if necessary. One quickly discovers that hiding this column causes the target column not to be coloured. So I was taught that one displays the column in the report then creates a display format (right click on the menu option for the report) that hides the column. Not perfect, but it works.

I discovered an easier way to achieve the desired result; this may not work in versions prior to 21. One defines the condition column as before and assigns it a value in the Sort Priority column (normally 9 or 99). One runs the report: the column that is to appear coloured does so, but the condition column also appears. Now hide the condition column and run the report: the first column is still coloured whilst the condition column does not appear. There is no need to create a display format then hide the condition column.

The value of the sort priority is irrelevant (although it has to be higher than anything in the report otherwise it is liable to affect the display order of the lines) but it has to be there. As far as I can see, having a sort priority is a type of 'escape clause' for the report generator; it knows that it has to perform some magic if there is a sort priority and the column number appears somewhere in the HTML definitions sub-form.