Skip to end of metadata
Go to start of metadata

Author: Jayanthi Jayaraman

Submitted: 15.06.07
Related Links:

This document describes how to create an ALV using OOPS method in few steps. It will help the beginners to start with.

Procedure

Step 1: Create a container. There are 2 containers. They are docking and custom.

For eg.. Create docking container.

Go to SE38.Create a program. Use Pattern button to create object for docking container. Click ABAP Object Pattern radio button.

  

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CREATE OBJECT O_DOCKING
  EXPORTING
*    PARENT                      =
*    REPID                       =
*    DYNNR                       =
*    SIDE                        = DOCK_AT_LEFT
*    EXTENSION                   = 50
*    STYLE                       =
*    LIFETIME                    = lifetime_default
*    CAPTION                     =
*    METRIC                      = 0
     RATIO                       = '95'
*    NO_AUTODEF_PROGID_DYNNR     =
*    NAME                        =
*  EXCEPTIONS
*    CNTL_ERROR                  = 1
*    CNTL_SYSTEM_ERROR           = 2
*    CREATE_ERROR                = 3
*    LIFETIME_ERROR              = 4
*    LIFETIME_DYNPRO_DYNPRO_LINK = 5
*    others                      = 6
    .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Step 2: Create a grid inside the container.

Use Pattern button to create the same. Make the parent of grid as container.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CREATE OBJECT O_GRID
  EXPORTING
*    I_SHELLSTYLE      = 0
*    I_LIFETIME        =
    I_PARENT          =  O_DOCKING
*    I_APPL_EVENTS     = space
*    I_PARENTDBG       =
*    I_APPLOGPARENT    =
*    I_GRAPHICSPARENT  =
*    I_NAME            =
*  EXCEPTIONS
*    ERROR_CNTL_CREATE = 1
*    ERROR_CNTL_INIT   = 2
*    ERROR_CNTL_LINK   = 3
*    ERROR_DP_CREATE   = 4
*    others            = 5
    .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 

 

Step 3: Call the function LVC_FIELDCATALOG_MERGE to get the fieldcatalog.

Pass the structure name.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
 EXPORTING
*   I_BUFFER_ACTIVE              =
    I_STRUCTURE_NAME             = 'MARA'
*   I_CLIENT_NEVER_DISPLAY       = 'X'
*   I_BYPASSING_BUFFER           =
*   I_INTERNAL_TABNAME           =
  CHANGING
    CT_FIELDCAT                  = I_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.

Step 4: Call the method of grid set_table_for_first_display to display the output.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
W_VARIANT-REPORT = SY-REPID.
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
  EXPORTING
*      I_BUFFER_ACTIVE               =
*      I_BYPASSING_BUFFER            =
*      I_CONSISTENCY_CHECK           =
*      I_STRUCTURE_NAME              =
     IS_VARIANT                    = W_VARIANT
     I_SAVE                        = 'A'
*      I_DEFAULT                     = 'X'
*      IS_LAYOUT                     =
*      IS_PRINT                      =
*      IT_SPECIAL_GROUPS             =
*      IT_TOOLBAR_EXCLUDING          =
*      IT_HYPERLINK                  =
*      IT_ALV_GRAPHICS               =
*      IT_EXCEPT_QINFO               =
  CHANGING
    IT_OUTTAB                     = ITAB
    IT_FIELDCATALOG               = I_FIELDCAT
*      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.


 

Step 5: Fill the internal table itab with values by using logic.

select * from mara into table itab up to 100 rows.

call screen 9000.

Create a screen by double clicking 9000 in the above line. Fill the description for the screen.  In the flow logic, uncomment the PBO and PAI module and create those in main program (for simplicity).

Step 6: Create GUI status as below. Create GUI Title if required.

Step 7: Free the memory occupied once the 'BACK, EXIT' or 'CANCEL' button is clicked. Use Pattern button to call the method 'FREE' of cl_gui_alv_grid.

Complete Code

 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA : ITAB TYPE STANDARD TABLE OF MARA,"Output Internal table
       I_FIELDCAT TYPE STANDARD TABLE OF LVC_S_FCAT,"Field catalog
       WA TYPE MARA,
       W_VARIANT TYPE DISVARIANT,
       O_DOCKING TYPE REF TO CL_GUI_DOCKING_CONTAINER,"Docking Container
       O_GRID TYPE REF TO CL_GUI_ALV_GRID."Grid
SELECT * FROM MARA INTO TABLE ITAB UP TO 100 ROWS.
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
  IF O_DOCKING IS INITIAL.
    SET PF-STATUS 'ZSTATUS'. "GUI Status
    SET TITLEBAR 'ZTITLE'.   "Title
* Creating Docking Container
    CREATE OBJECT O_DOCKING
           EXPORTING
             RATIO                       = '95'.
    IF SY-SUBRC EQ 0.
* Creating Grid
      CREATE OBJECT O_GRID
          EXPORTING
             I_PARENT          = O_DOCKING.
    ENDIF.
* Filling the fieldcatalog table
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        I_STRUCTURE_NAME       = 'MARA'
      CHANGING
        CT_FIELDCAT            = I_FIELDCAT
      EXCEPTIONS
        INCONSISTENT_INTERFACE = 1
        PROGRAM_ERROR          = 2
        OTHERS                 = 3.
    W_VARIANT-REPORT = SY-REPID.
* Displaying the output
    CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        IS_VARIANT                    = W_VARIANT
        I_SAVE                        = 'A'
      CHANGING
        IT_OUTTAB                     = ITAB
        IT_FIELDCATALOG               = I_FIELDCAT
      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.
ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       PAI
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
  DATA LV_UCOMM TYPE SY-UCOMM.
  LV_UCOMM = SY-UCOMM.
  CASE LV_UCOMM.
    WHEN 'CANCEl' OR 'EXIT'.
      PERFORM FREE_OBJECTS.
      LEAVE PROGRAM.
    WHEN 'BACK'.
      PERFORM FREE_OBJECTS.
      SET SCREEN '0'.
      LEAVE SCREEN.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  free_objects
*&---------------------------------------------------------------------*
*       Free Objects
*----------------------------------------------------------------------*
FORM FREE_OBJECTS .
  CALL METHOD O_GRID->FREE
    EXCEPTIONS
      CNTL_ERROR        = 1
      CNTL_SYSTEM_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.
  CALL METHOD O_DOCKING->FREE
    EXCEPTIONS
      CNTL_ERROR        = 1
      CNTL_SYSTEM_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.
ENDFORM.                    " free_objects