ABAP/4 Example Code: ALV Grid Control by applying object CL_GUI_ALV_GRID
Create ZPROGRAM and create normal screen no. 100 under this program. And in screen 100, please create custom control name ’CUSTOM1’.
Example
*** ZPROGRAM CODING ***
DATA: save_ok LIKE sy-ucomm,
ok_code LIKE sy-ucomm,
it_spfli TYPE TABLE OF spfli WITH HEADER LINE.
DATA: G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GRID1 TYPE REF TO CL_GUI_ALV_GRID,
it_cat TYPE LVC_T_FCAT,
wa_cat TYPE LVC_S_FCAT.
START-OF-SELECTION.
SELECT * FROM spfli
INTO TABLE it_spfli.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS ’100’.
SET TITLEBAR ’100’.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
save_ok = ok_code.
clear ok_code.
CASE save_ok.
WHEN ’BACK’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module INITIAL_GRID OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE INITIAL_GRID OUTPUT.
PERFORM create_field_catalog.
PERFORM create_grid_control.
ENDMODULE. " INITIAL_GRID OUTPUT
*&---------------------------------------------------------------------*
*& Form create_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_field_catalog .
IF it_cat[] is initial.
clear wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = ’CARRID’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-reptext = ’Airline Code’.
wa_cat-coltext = ’Airline Code’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 2.
wa_cat-fieldname = ’CONNID’.
wa_cat-datatype = ’NUMC’.
wa_cat-inttype = ’N’.
wa_cat-intlen = 4.
wa_cat-reptext = ’Flight Conn. No’.
wa_cat-coltext = ’Flight Conn. No’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 3.
wa_cat-fieldname = ’CITYFROM’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 20.
wa_cat-reptext = ’Dep. city’.
wa_cat-coltext = ’Dep. city’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 4.
wa_cat-fieldname = ’AIRPFROM’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-reptext = ’Dep. airport’.
wa_cat-coltext = ’Dep. airport’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 5.
wa_cat-fieldname = ’CITYTO’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 20.
wa_cat-reptext = ’Arrival city’.
wa_cat-coltext = ’Arrival city’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 6.
wa_cat-fieldname = ’AIRPTO’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-reptext = ’Dest. airport’.
wa_cat-coltext = ’Dest. airport’.
append wa_cat to it_cat.
ENDIF.
ENDFORM. " create_field_catalog
*&---------------------------------------------------------------------*
*& Form create_grid_control
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_grid_control .
IF G_CUSTOM_CONTAINER1 is initial .
CREATE OBJECT G_CUSTOM_CONTAINER1
EXPORTING CONTAINER_NAME = ’CUSTOM1’.
CREATE OBJECT GRID1
EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.
CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
* EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = ’X’
* IS_LAYOUT =
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = it_spfli[]
IT_FIELDCATALOG = it_cat[]
* IT_SORT =
* IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM. " create_grid_control*** FLOW LOGIC ON SCREEN 100 ***
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE INITIAL_GRID.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
The output is:
- thitima's blog
- 12031 reads
Post new comment