Is there anything we can do with reported data that has already been output ? What can be done with data that has already been prresented on a report ? It can be read and modified..
When retrieving data selected by an end user, it is often necessary to find out what type of report line has been selected. E.g. empty lines (uline, skip), top of page lines with column headings, the order header or order position. To distinguish them at runtime the following statements can be used:
SY-LISEL
holds the content of the (full) line, which can be used to determine which type of line was selected (double clicked on). To make your setup more reliable, you can use the HIDE
statement. The HIDE
will store the content of globally defined variables with the report line you are about to output. This means that when the line is double clicked on later, the HIDE
statement will place the values of these global variables back in the variables. A short example:
DATA: gv_LINETYPE. gv_LINETYPE = 'H'. "Type: header data WRITE: / 'Ordernumber: ', AUFK-AUFNR. HIDE gv_LINETYPE. ULINE. gv_LINETYPE = 'P'. "Type: position data WRITE: / 'Orderposition:', AFPO-POSNR. HIDE gv_LINETYPE. SKIP 2. WRITE: / 'Amount', POSITION_AMOUNT.
When the above report is output and the user double clicks on a line, the Abap can easily choose which processing to use
AT LINE-SELECTION. READ CURRENT LINE. CASE gv_LINETYPE. WHEN ' '. "Empty: no position or header selected MESSAGE 'Please select position or header' TYPE 'S'. WHEN 'H'. "Header data selected PERFORM DISPLAY_ORDER. WHEN 'P'. "Position data selected PERFORM DISPLAY_ORDERPOSITIE. ENDCASE.
Potentially the best way to determine which field contents was double clicked on is GET CURSOR FIELD
fieldname, which will return the field name when it was output to the report. Thus a report that would do a WRITE MARA-MATNR
. when double clicked on. Consider it's potential !
Reading back the written (reported) data can be done in several ways. A few related statements:
READ LINE lin. READ LINE lin OF CURRENT PAGE. READ LINE lin OF PAGE pag. READ CURRENT LINE.
Results of the READ
are in the field SY-LISEL
. If there are HIDE
fields, they will be filled in again. So the value of a given printed field, can be determined with:
READ CURRENT LINE FIELD VALUE fieldname INTO fieldvariable.
Or the much improved:
GET CURSOR FIELD fld VALUE val.
The whole idea of "refreshing" just part of a report is generally not the way to go. A full refresh of the report (and it's selection) is the more common way to change a report contents. But if you insist, here's some statements that would do it:
MODIFY LINE lin. MODIFY LINE lin OF CURRENT PAGE. MODIFY LINE lin OF PAGE pag. MODIFY CURRENT LINE.
Modifying is done in the field SY-LISEL
, or per field name with:
MODIFY LINE lin FIELD VALUE fieldname FROM fieldvalue.
Color changing
To change colors, you can:
MODIFY LINE lin FIELD FORMAT fieldname current_format new_format.
To change the the colors of a specified field
MODIFY LINE lin LINE FORMAT current_format new_format.
For further explanation and examples we refer to the help system of MODIFY
.
Unpleasant is that a line is completely rebuild when a field value (from a line or format) is altered. When you do not carefully prepare this, you will get an empty line that contains only the modified fields. Use READ LINE
before MODIFY LINE
.
Another unpleasantness: when determining at runtime what field name has to change its color, the following construction cannot be used:
fieldname = 'COLUMN_32'. MODIFY LINE 23 FIELD FORMAT (fieldname) COLOR 7 COLOR 3.
But there is a solution: using field symbols:
FIELD-SYMBOLS <fs>. fieldname = 'kolom_32'. ASSIGN (fieldname) TO <fs>. MODIFY LINE 23 FIELD FORMAT <fs> COLOR 7 COLOR 3.