Saturday, August 19, 2017

ALV List & Grid Display with Checkbox & Stripped Zebra Lines

The ALV (ABAP List Viewer) is a flexible tool in SAP ABAP that enables developers to generate customized reports with various features. One such feature is displaying checkboxes and stripped zebra lines in the ALV list and grid display.

To display checkboxes in the ALV list and grid display, developers can create a custom field in the field catalog and specify it as a checkbox field using the checkbox option available in the 'Output Options' tab of the field catalog maintenance screen. After defining the checkbox field, developers can add it to the ALV layout and include it in the report.

Likewise, developers can activate stripped zebra lines in the ALV list and grid display by configuring the appropriate properties in the layout object. They can use the 'Set_table_for_first_display' method of the ALV object to achieve this. By specifying the 'zebra' parameter as 'X', they can enable the stripped zebra lines.

Sample Report 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,
       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.

SELECTION-SCREEN BEGIN OF BLOCK ABC WITH FRAME TITLE TEXT-001.

 PARAMETERS : R1 RADIOBUTTON GROUP RG1 USER-COMMAND UC DEFAULT 'X',
              R2 RADIOBUTTON GROUP RG1 .

SELECTION-SCREEN END OF BLOCK ABC.

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.

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_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'.

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-EDIT = 'X'.
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.


ELSEIF R2 = 'X'.

WA_LAYOUT-BOX_FIELDNAME = 'CHECK'.
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_FCAT-COL_POS = '2'.
WA_FCAT-TABNAME = 'IT_FINAL'.
WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-INPUT = 'X'.
WA_FCAT-EDIT = 'X'.
WA_FCAT-SELTEXT_M = 'MATERIAL NUMBER'.
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-EDIT = '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-EDIT = 'X'.
WA_FCAT-SELTEXT_M = 'MTERIAL DESCRIPTION'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

CALL FUNCTION 'REUSE_ALV_GRID_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_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
   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
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* 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.
ENDIF.


In summary, the ALV list and grid display with checkboxes and stripped zebra lines is a useful way to present data to users. The checkboxes allow users to select and manipulate data easily, while the stripped zebra lines provide a clear visual differentiation between rows, making the data easier to read and comprehend.





No comments:

Post a Comment