Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

You have developed a ALV GRID report using REUSE_ALV_GRID_DISPLAY function and the report has come out really well. However, some users want to see a ALV list than the grid. Or you have a existing ALV GRID report and the user want to have a ALV List report.

SAP has provided a BADI just for this purpose. The name of the BADI is

ALV_SWITCH_GRID_LIST

. Now create a implementation for this BADI.

For a given user or specific to a report, you can switch on the flag to produce a ALV list.

Here is the simple code for the report

REPORT  Y_RAVI_REUSE_ALV.

TYPE-POOLS : SLIS.

DATA : T_DATA TYPE TABLE OF ALV_T_T2,

      T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

START-OF-SELECTION.

  SELECT * FROM ALV_T_T2 INTO TABLE T_DATA UP TO 30 ROWS.

END-OF-SELECTION.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

  •     I_PROGRAM_NAME               =

  •     I_INTERNAL_TABNAME           =

      I_STRUCTURE_NAME             = 'ALV_T_T2'

  •     I_CLIENT_NEVER_DISPLAY       = 'X'

  •     I_INCLNAME                   =

  •     I_BYPASSING_BUFFER           =

  •     I_BUFFER_ACTIVE              =

    CHANGING

      CT_FIELDCAT                  = T_FIELDCAT

  •   EXCEPTIONS

  •     INCONSISTENT_INTERFACE       = 1

  •     PROGRAM_ERROR                = 2

  •     OTHERS                       = 3

            .

  IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  •         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

  FIELD-SYMBOLS : -DO_SUM = 'C'.

  ENDIF.

  DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

  WA_LAYOUT-allow_switch_to_list = 'X'.

  DATA : WA_VARIANT TYPE DISVARIANT.

  WA_VARIANT-USERNAME = SY-UNAME.

  WA_VARIANT-REPORT = SY-REPID.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

  •     I_INTERFACE_CHECK                 = ' '

  •     I_BYPASSING_BUFFER                = ' '

  •     I_BUFFER_ACTIVE                   = ' '

  •     I_CALLBACK_PROGRAM                = ' '

  •     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                       = T_FIELDCAT

  •     IT_EXCLUDING                      =

  •     IT_SPECIAL_GROUPS                 =

  •     IT_SORT                           =

  •     IT_FILTER                         =

  •     IS_SEL_HIDE                       =

  •     I_DEFAULT                         = 'X'

  •     I_SAVE                            = ' '

      IS_VARIANT                        = WA_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                          = T_DATA

  •   EXCEPTIONS

  •     PROGRAM_ERROR                     = 1

  •     OTHERS                            = 2

            .

  IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  •         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.



Here if you have noticed, there are couple of important parameters that need to be passed. Those are

IS_VARAINT

and

IS_LAYOUT

. You have to set this field

allow_switch_to_list

to 'X' and also pass the username and report name in the IS_VARIANT field if you want to switch to the list based on the conditions.

Here is the normal output of the grid.

Here is the implementation of the BADI.

Here is the interface for the BADI Implementation

Here is the code

Finally here is the output.

3 Comments