In my previous article, we have learned about Classical Reports of SAP. There are various occasions where we need to color code our result in output. In this article I will provide some quick source code that you can use for color coding.
The following colors are the approximate HTML rendering of an ABAP list when the SAPGUI theme uses this background color:
[COLOR {{{color [ON]}|OFF}|{= numericvariable}}]
[INTENSIFIED [{ON|OFF}|{= flag}]]
[INVERSE [{ON|OFF}|{= flag}]]
where color may be either a constant (COL_BACKGROUND, COL_HEADING, COL_NORMAL, COL_TOTAL, COL_KEY, COL_POSITIVE, COL_NEGATIVE, COL_GROUP) or a numeric value (respectively 0 to 7).
Below is the source code that you can use
REPORT ZBILL_REPORT. *TABLES: ZBILL. DATA : WA_BILL TYPE ZBILL. " WORK AREA OR STRUCTURE DATA : IT_BILL TYPE ZBILL OCCURS 0. " INTERNAL TABLE DATA: V_REPID TYPE SY-REPID, V_USER TYPE SY-UNAME, V_DATE TYPE SY-DATUM, V_TIME TYPE SY-UZEIT. INITIALIZATION. V_REPID = SY-REPID. V_USER = SY-UNAME. V_DATE = SY-DATUM. V_TIME = SY-UZEIT. START-OF-SELECTION. " for selection of data from database. PERFORM GET_BILLS. END-OF-SELECTION. " this event signals that event of what has been initiated by start of selection event. PERFORM SHOW_BILLS. TOP-OF-PAGE. " Display header messages on all pages i.e. page header. WRITE: / 'Report :', 12 V_REPID, / 'Date :', 12 V_DATE dd/mm/yyyy, / 'User :', 12 V_USER, / 'Time :', 12 V_TIME. ULINE. END-OF-PAGE. WRITE: /40 'Page No.-', sy-pagno. FORM GET_BILLS. SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_BILL FROM ZBILL ORDER BY DOC_ID. " SELECT DATA FROM DATABASE TABLE AND PUT INTO INTERNAL TABLE. ENDFORM. FORM SHOW_BILLS. LOOP AT IT_BILL INTO WA_BILL. " LOOP START AT FIRST. "---CONTROL BREAK STATEMENT, DISPLAY ONLY ONE TIME, BREAK THE LOOP FOR COLUMN HEADING. * FORMAT COLOR COL_BACKGROUND INTENSIFIED OFF. FORMAT COLOR COL_BACKGROUND INTENSIFIED ON. FORMAT COLOR 1 INTENSIFIED ON. WRITE: /3 'Document Id', 20 'Bill Number', 35 'Description', 70 'Date', 90 'Quantity', 110 'Amount (RS.)'. ULINE. " FOR UNDERLINE ENDAT. FORMAT COLOR 2 INTENSIFIED ON. * FORMAT COLOR 7 INTENSIFIED OFF. * FORMAT COLOR 7 INVERSE ON. WRITE: /3 WA_BILL-DOC_ID, 20 WA_BILL-BILNO, 35 WA_BILL-BILDESC, 70 WA_BILL-BILDATE, 80 WA_BILL-QUANTITY, 100 WA_BILL-AMOUNT. AT LAST. "---CONTROL BREAK STATEMENT, DISPLAY ONLY ONE TIME SKIP. "FOR BLANK LINE. WRITE: /40 '~~~~~~~ End Of Bills Display ~~~~~~~'. ENDAT. ENDLOOP. ENDFORM.
Output: