Thursday, May 10, 2012

Object Oriented ALV

Example:
*Global data for ALV display
DATA: splitter_1  TYPE REF TO cl_gui_splitter_container,
      container   TYPE REF TO cl_gui_custom_container,
      container_1 TYPE REF TO cl_gui_container,
      container_2 TYPE REF TO cl_gui_container,
      container_3 TYPE REF TO cl_gui_container,
      container_4 TYPE REF TO cl_gui_container,
      grid1       TYPE REF TO cl_gui_alv_grid,
      grid2       TYPE REF TO cl_gui_alv_grid,
      grid3       TYPE REF TO cl_gui_alv_grid,
      grid4       TYPE REF TO cl_gui_alv_grid,
      ok_code     TYPE sy-ucomm,
      loyo        TYPE lvc_s_layo.
*----------------------------------------------------------------------*
*           FOR FIELD CATALOG
*----------------------------------------------------------------------*
DATA: gt_fieldcatalogue TYPE lvc_t_fcat,
      gs_fieldcatalogue TYPE lvc_s_fcat.
DATA: g_container      TYPE scrfname.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'ZALV'.
  SET TITLEBAR 'ZTITLE'.
*creating object reference for container
  CREATE OBJECT container
    EXPORTING
      container_name = g_container."Pass name of container created in Screen no 9010
*splitting the main container into 3 rows
  CREATE OBJECT splitter_1
    EXPORTING
      parent  = container
      rows    = 4
      columns = 1.
*getting the reference for the splited container (row 1 & col 1 container)
  CALL METHOD splitter_1->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = container_1.
*getting the reference for the splited container (row 2 & col 1 container)
  CALL METHOD splitter_1->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = container_2.
*getting the reference for the splited container (row 3 & col 1 container)
  CALL METHOD splitter_1->get_container
    EXPORTING
      row       = 3
      column    = 1
    RECEIVING
      container = container_3.
*populating first internal table to the container
  CREATE OBJECT container
    EXPORTING
      container_name = g_container.
  CREATE OBJECT grid1
    EXPORTING
      i_parent = container_1.
* FOR LAYOUT
  loyo-zebra = c_x.
  loyo-cwidth_opt = c_x.
  loyo-grid_title = 'This is actually grid title'.
*  loyo-stylefname = c_sfn100.
  PERFORM create_fieldcatalog USING c_grid1.
  CALL METHOD grid1->set_table_for_first_display
    EXPORTING
      is_layout       = loyo
    CHANGING
      it_fieldcatalog = gt_fieldcatalogue
      it_outtab       = gt_table1.
*populating second internal table
  CREATE OBJECT container
    EXPORTING
      container_name = g_container.
  CREATE OBJECT grid2
    EXPORTING
      i_parent = container_2.
* FOR LAYOUT
  loyo-grid_title = text-020.
  PERFORM create_fieldcatalog USING c_grid2.
  CALL METHOD grid2->set_table_for_first_display
    EXPORTING
      is_layout       = loyo
    CHANGING
      it_fieldcatalog = gt_fieldcatalogue
      it_outtab       = gt_table2.
*populating third internal table
  CREATE OBJECT container
    EXPORTING
      container_name = g_container.
  CREATE OBJECT grid3
    EXPORTING
      i_parent = container_3.
* FOR LAYOUT
  loyo-grid_title = 'Title 3'.
  PERFORM create_fieldcatalog USING c_grid3.
  CALL METHOD grid3->set_table_for_first_display
  EXPORTING
     is_layout        = loyo
  CHANGING
    it_fieldcatalog = gt_fieldcatalogue
     it_outtab      = gt_table3.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'CANCEL'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT                                                        *
*&---------------------------------------------------------------------*
MODULE exit INPUT.
*free the container memory when exit
  CALL METHOD container->free.
  LEAVE PROGRAM.
ENDMODULE.  "EXIT INPUT


 

No comments:

Post a Comment