SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Switch to ALV List from ALV Grid at runtime



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Tue Jan 15, 2008 2:06 pm    Post subject: Switch to ALV List from ALV Grid at runtime Reply with quote

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.

Code:
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 : <FS_FCAT> LIKE LINE OF T_FIELDCAT.
  READ TABLE T_FIELDCAT ASSIGNING <FS_FCAT> with key FIELDNAME = 'PRICE'.
  IF SY-SUBRC = 0.
    <FS_FCAT>-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 interface for the BADI Implementation
Code:
METHOD IF_EX_ALV_SWITCH_GRID_TO_LIST~IS_SWITCH_TO_LIST_REQUESTED.

  IF alv_layout-username eq 'XXXXX'.
    value = if_salv_cbool_sap=>true.
  ELSE.
    value = if_salv_cbool_sap=>false.
  ENDIF.
ENDMETHOD.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.