Saturday, August 19, 2017

Use of ALV Layout- Displaying Traffic Light


The ALV layout is a feature of SAP ABAP that enables users to personalize the appearance of their ALV reports. One of the functions that can be included in an ALV layout is the display of traffic lights.

The traffic light display can be used to indicate the state of information in a report. For instance, if a report contains information on a manufacturing process, the traffic light display can be utilized to show whether the process is progressing smoothly or has encountered issues.

To add the traffic light display to an ALV layout, users must first specify the traffic light icons in the ABAP Dictionary. This entails defining a new data element and setting the traffic light icons to be used for each status. Afterward, the traffic light display can be incorporated into the ALV layout by setting the corresponding field in the layout to use the traffic light icons.

Apart from the traffic light display, the ALV layout also allows users to customize other aspects of the report, such as column headers, column widths, and color schemes. This customization can be accomplished through various ALV events and options that are available in the ALV framework.

In summary, the utilization of the ALV layout in displaying traffic lights is an effective way to visualize data in an ALV report and can provide a quick overview of the status of the information being presented.

Sample Program for Reference - 

REPORT  ZAVI_FEVER1.

TYPE-POOLS: SLIS.
TYPES: BEGIN OF ST_MAKT,
       MATNR TYPE MATNR,
       SPRAS  TYPE SPRAS,
       MAKTX  TYPE MAKTX,
       END OF ST_MAKT.

DATA: IT_MAKT TYPE STANDARD TABLE OF ST_MAKT,
      WA_MAKT TYPE ST_MAKT.

TYPES: BEGIN OF ST_FINAL,
        LIGHT(1),
        CHECK(1),
        MATNR TYPE MATNR,
        SPRAS  TYPE SPRAS,
        MAKTX  TYPE MAKTX,
        END OF ST_FINAL.

DATA: IT_FINAL TYPE STANDARD TABLE OF ST_FINAL,
      WA_FINAL TYPE ST_FINAL.

DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT TYPE SLIS_FIELDCAT_ALV.

DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV.



START-OF-SELECTION.

       SELECT MATNR
              SPRAS
              MAKTX
              FROM MAKT INTO TABLE IT_MAKT WHERE SPRAS = 'SY-LANGU'.

       IF SY-SUBRC = 0.
         SORT IT_MAKT BY MATNR.
       ENDIF.

END-OF-SELECTION.

       LOOP AT IT_MAKT INTO WA_MAKT.
         WA_FINAL-MATNR = WA_MAKT-MATNR.
         WA_FINAL-SPRAS = WA_MAKT-SPRAS.
         WA_FINAL-MAKTX = WA_MAKT-MAKTX.
         APPEND WA_FINAL TO IT_FINAL.
         CLEAR: WA_FINAL,WA_MAKT.
         ENDLOOP.


         LOOP AT IT_FINAL INTO WA_FINAL.
           IF SY-TABIX < 5.
WA_FINAL-light = 1.
ELSEIF sy-tabix > 5 AND sy-tabix LE 15.
WA_FINAL-light = 2. 
ELSE.
WA_FINAL-light = 3. 
ENDIF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING light.
ENDLOOP.


IF R1 = 'X'.

WA_FCAT-COL_POS = '1'.
WA_FCAT-TABNAME = 'IT_FINAL'.
WA_FCAT-FIELDNAME = 'CHECK'.
WA_FCAT-CHECKBOX = 'X'.
WA_FCAT-EDIT = 'X'.
WA_FCAT-SELTEXT_M = 'CHECKBOX'.
WA_FCAT-INPUT = 'X'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

WA_LAYOUT-LIGHTS_FIELDNAME = 'LIGHT'.
WA_FCAT-COL_POS = '2'.
WA_FCAT-TABNAME = 'IT_FINAL'.
WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-INPUT = 'X'.
WA_FCAT-SELTEXT_M = 'MATERIAL NUMBER'.
WA_LAYOUT-ZEBRA = 'X'.
*WA_LAYOUT-NO_COLHEAD = 'X'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

WA_FCAT-COL_POS = '3'.
WA_FCAT-TABNAME = 'IT_FINAL'.
WA_FCAT-FIELDNAME = 'SPRAS'.
WA_FCAT-INPUT = 'X'.
WA_FCAT-SELTEXT_M = 'LANGUAGE'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

WA_FCAT-COL_POS = '4'.
WA_FCAT-TABNAME = 'IT_FINAL'.
WA_FCAT-FIELDNAME = 'MAKTX'.

WA_FCAT-SELTEXT_M = 'MTERIAL DESCRIPTION'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK              = ' '
*   I_BYPASSING_BUFFER             =
*   I_BUFFER_ACTIVE                = ' '
   I_CALLBACK_PROGRAM             = 'SY-REPID'
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   I_STRUCTURE_NAME               =
   IS_LAYOUT                      = WA_LAYOUT
   IT_FIELDCAT                    = IT_FCAT
*   IT_EXCLUDING                   =
*   IT_SPECIAL_GROUPS              =
*   IT_SORT                        =
*   IT_FILTER                      =
*   IS_SEL_HIDE                    =
*   I_DEFAULT                      = 'X'
*   I_SAVE                         = ' '
*   IS_VARIANT                     =
*   IT_EVENTS                      =
*   IT_EVENT_EXIT                  =
*   IS_PRINT                       =
*   IS_REPREP_ID                   =
*   I_SCREEN_START_COLUMN          = 0
*   I_SCREEN_START_LINE            = 0
*   I_SCREEN_END_COLUMN            = 0
*   I_SCREEN_END_LINE              = 0
*   IR_SALV_LIST_ADAPTER           =
*   IT_EXCEPT_QINFO                =
*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER        =
*   ES_EXIT_CAUSED_BY_USER         =
  TABLES
    t_outtab                       = IT_FINAL
 EXCEPTIONS
   PROGRAM_ERROR                  = 1
   OTHERS                         = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


No comments:

Post a Comment