Pages

Sunday, 31 August 2014

ALV Grid Control Part 01 - Simple Report Using ALV Grid Control

My Learning Notes 01. 
This is a simple example step by step create report using cl_gui_alv_grid.
Sample program is copying from  BCALV_GRID_DEMO.

1. Create new executable program. For Example : Z_OOALV_01.
2. Create a new screen. For Example here I Create Screen 9000.
3. Click Layout to display Screen Painter, add custom control with name : CC_CONTAINER.
Add Custom Container.


 
4. Create New GUI_STATUS with name : ST_9000.

5. Back to main program. Declare reference variable for ALV grid control.
DATA: OK_CODE LIKE SY-UCOMM,
      GT_SFLIGHT TYPE TABLE OF SFLIGHT,
      G_CONTAINER TYPE SCRFNAME VALUE 'CC_CONTAINER',
      GRID1  TYPE REF TO CL_GUI_ALV_GRID,
      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
 6. After declaring variable, ddd script for retrieve data from flight table and call screen 9000.
SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT.
CALL SCREEN 9000.

 7. Double Click in Screen 9000. Create new module in PBO and PAI.


8. Fill the module PBO & PAI with this code :
MODULE pbo OUTPUT.
  SET PF-STATUS 'ST_9000'.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
      EXPORTING
        container_name = g_container.
    CREATE OBJECT grid1
      EXPORTING
        i_parent = g_custom_container.
    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_structure_name = 'SFLIGHT'
      CHANGING
        it_outtab        = gt_sflight.
  ENDIF.
ENDMODULE.                 " PBO  OUTPUT 

MODULE pai INPUT.
*   to react on oi_custom_events:
  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN '&EXIT'.
      LEAVE PROGRAM.
    WHEN OTHERS.
*     do nothing
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                 " PAI  INPUT

9. Right click on main program and activate.
10. Run the program.

No comments:

Post a Comment