Displaying ALV with the automatic fieldcatalog creation:
Displaying ALV with manual Fieldcatalog creation:
*&---------------------------------------------------------------------* *& *& SIMPLE ALV DISPLAY WITH VARIOUS METHODS *&---------------------------------------------------------------------* REPORT zdemo1. START-OF-SELECTION. ********************************************************************** * DISPLAYING ALV WITH AUTOMATIC GENERATION OF FIELD CATALOG ********************************************************************** DATA: lt_tab TYPE TABLE OF ekko, lt_fcat TYPE slis_t_fieldcat_alv, ls_fcat TYPE slis_fieldcat_alv, ls_layout TYPE slis_layout_alv. CLEAR: ls_fcat, ls_layout. REFRESH: lt_tab, lt_fcat. SELECT * FROM ekko INTO TABLE lt_tab. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' "AUTOMATIC CREATION OF FIELDCATALOG EXPORTING i_program_name = sy-repid i_structure_name = 'EKKO' CHANGING ct_fieldcat = lt_fcat EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ls_layout-colwidth_optimize = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "FM TO SHOW ALV EXPORTING i_callback_program = sy-repid is_layout = ls_layout it_fieldcat = lt_fcat TABLES t_outtab = lt_tab EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF.
Displaying ALV with manual Fieldcatalog creation:
*&---------------------------------------------------------------------* *& *& SIMPLE ALV DISPLAY WITH VARIOUS METHODS *&---------------------------------------------------------------------* REPORT zdemo1. START-OF-SELECTION. ********************************************************************** * DISPLAYING ALV WITH MANUAL FIELDCATALOG CREATION ********************************************************************** DATA: lt_fcat TYPE slis_t_fieldcat_alv, ls_fcat TYPE slis_fieldcat_alv, ls_layout TYPE slis_layout_alv, lv_count TYPE i VALUE 1, lt_tab TYPE TABLE OF ekko . CLEAR: ls_fcat, ls_layout. REFRESH: lt_fcat, lt_tab. SELECT ebeln bukrs bstyp bsart bsakz FROM ekko INTO TABLE lt_tab. ********************* MANUAL FIELDCATALOG CREATION ********************************* ls_fcat-fieldname = 'EBELN'. "FIELDNAME THAT IS TO BE MAPPED ls_fcat-seltext_m = 'Purchasing Document Number'. "FIELD DESCRIPTION IN THE ALV GRID ls_fcat-col_pos = lv_count. "COLUMN POSITION IN THE ALV GRID APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BUKRS'. ls_fcat-seltext_m = 'Company Code'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BSTYP'. ls_fcat-seltext_m = 'Purchasing Document Category'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BSART'. ls_fcat-seltext_m = 'Purchasing Document Type'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BSAKZ'. ls_fcat-seltext_m = 'Control indicator for purchasing document type'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ********************* #END MANUAL FIELDCATALOG CREATION ********************************* ls_layout-colwidth_optimize = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid is_layout = ls_layout it_fieldcat = lt_fcat TABLES t_outtab = lt_tab EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF.
Displaying ALV with OO approach:
For displaying ALV with OO approach:
1. A new screen has to be created first
2. Activate the PAI and PBO include of the screen
3. Copy the standard ALV status (how to?)
Then refer to the below program:
*&---------------------------------------------------------------------* *& *& SIMPLE ALV DISPLAY WITH VARIOUS METHODS *&---------------------------------------------------------------------* REPORT zdemo1. START-OF-SELECTION. ********************************************************************** * DISPLAY ALV WTIH OO APPROACH ********************************************************************** DATA: lo_grid TYPE REF TO cl_gui_alv_grid, lo_container TYPE REF TO cl_gui_docking_container, lt_fcat TYPE lvc_t_fcat, ls_fcat TYPE lvc_s_fcat, lv_count TYPE i VALUE 1, lt_tab TYPE TABLE OF ekko. CLEAR: ls_fcat. REFRESH: lt_fcat, lt_tab. SELECT ebeln bukrs bstyp bsart bsakz FROM ekko INTO TABLE lt_tab. CALL SCREEN 0100. *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * PBO EVENT *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'PF_STATUS'. *********************** FIELDCATALOG CREATION ************************ ls_fcat-fieldname = 'EBELN'. "FIELDNAME THAT IS TO BE MAPPED ls_fcat-scrtext_m = 'Purchasing Document Number'. "FIELD DESCRIPTION IN THE ALV GRID ls_fcat-col_pos = lv_count. "COLUMN POSITION IN THE ALV GRID APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BUKRS'. ls_fcat-scrtext_m = 'Company Code'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BSTYP'. ls_fcat-scrtext_m = 'Purchasing Document Category'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BSART'. ls_fcat-scrtext_m = 'Purchasing Document Type'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ls_fcat-fieldname = 'BSAKZ'. ls_fcat-scrtext_m = 'Control indicator for purchasing document type'. ls_fcat-col_pos = lv_count. APPEND ls_fcat TO lt_fcat. lv_count = lv_count + 1. CLEAR: ls_fcat. ********************** #FIELDCATALOG CREATION ************************ CREATE OBJECT lo_container EXPORTING ratio = '95'. CREATE OBJECT lo_grid EXPORTING i_parent = lo_container. CALL METHOD lo_grid->set_table_for_first_display CHANGING it_outtab = lt_tab it_fieldcatalog = lt_fcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDMODULE. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * PAI EVENT - USER COMMAND HANDLER *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE sy-ucomm. WHEN '&F03' OR '&F15' OR '&F12'. LEAVE PROGRAM. ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT
Awesome post! Keep up the great work! :)
ReplyDelete