Using field catalog in OOALV

+ -
Requirement: Display material no, material type, industry sector, material group and base unit of mesure of list of materials in grid format using Object Oriented techniques.

Step 1: Data deceleration's for ALV, custom container and internal table for MARA(User defined types).

Step 2: Create Screen.

Step 3: Insert Custom container UI element into the screen.

Step 4: Create Modules PBO and PAO, add logic.

Step 5: Build field catalog.

Step 6: Display ALV.

Step 1: Data deceleration's for ALV, Custom Container and user defined types of MARA.

Add data deceleration's for ALV grid, custom container UI element and for MARA internal table.Add select-options for material number.
DATA : LO_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Custom Container 
DATA : LO_ALV TYPE REF TO CL_GUI_ALV_GRID. "ALV Grid
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
       WA_MARA TYPE TY_MARA.
TABLES: MARA.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

Step 2: Create Screen

Create Screen in start of selection by using key work CALL SCREEN .
START-OF-SELECTION.
**Here 100 is the screen number which we are going to create, you can create any like: 200, 300 etc
CALL SCREEN 100. "double click on 100 to create a screen

After calling screen, double click on 100, click create.

Object Oriented ALV with field catalogue

Provide short description, click on layout, layout designer will open(If you use it first it will take some time, wait till it comes, if you face any issue while opening contact BASIS, there might be configuration missing. ).

Object Oriented ABAP ALV

Step 3: Insert Custom Container UI element

Drag and drop custom container UI element, double click and provide a name and save, activate and close layout designer.

Object Oriented ALV ABAP

Object Oriented ABAP ALV

Step 4:Create Modules

Click on flow logic, uncomment MODULES, double click on each one(one at one time), click yes and select main program.

ALV Object Oriented ABAP

OOALV Development

Step 5, 6: Build Field Catalog.

Field Catalog: It is a structure which is used to specify out put structure with field names, field positions, descriptions and additional properties.To see the list of properties of OOALV field catalog, go to se11 and check the structure LVC_S_FCAT.

Building of field catalog is give below.

**Declare field catalog table and structure as per class method
DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT,
       WA_FIELDCATALOG TYPE LVC_S_FCAT.
***Build Field Catalogue
  WA_FIELDCATALOG-COL_POS = '1'. "Set column1
  WA_FIELDCATALOG-FIELDNAME = 'MATNR'. "set field
  WA_FIELDCATALOG-TABNAME = 'MARA'. "set table
  WA_FIELDCATALOG-SCRTEXT_M = 'Material No'. "set column description
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG. "append to table
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '2'. "set column2
  WA_FIELDCATALOG-FIELDNAME = 'MTART'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Material Type'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '3'. "set column 3
  WA_FIELDCATALOG-FIELDNAME = 'MBRSH'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Industry Sector'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '4'. "set column 4
  WA_FIELDCATALOG-FIELDNAME = 'MATKL'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Material Group'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '5'. "set column 5
  WA_FIELDCATALOG-FIELDNAME = 'MEINS'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Unit Of Measure'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
**End field catalogue
MODULE STATUS_0100 OUTPUT.
**Create object for Custom container
  CREATE OBJECT LO_CONT
    EXPORTING
*     PARENT         =
      CONTAINER_NAME = 'CC_ALV' "container name whcih we have created
.
**Create Object for ALV Grid
  CREATE OBJECT LO_ALV
    EXPORTING
      I_PARENT = LO_CONT "Object of custom container
.
**Get data from MARA for user input
  SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA
    INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.

**Display ALV data using structure
  CALL METHOD LO_ALV->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
*     I_BUFFER_ACTIVE  =
*     I_BYPASSING_BUFFER            =
*     I_CONSISTENCY_CHECK           =
*     I_STRUCTURE_NAME = 'MARA'
*     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_MARA
      IT_FIELDCATALOG = IT_FIELDCATALOG
*     IT_SORT          =
*     IT_FILTER        =
*  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

Final and Modularized code will be

REPORT ZSAN_OOALV_FCAT.
TABLES: MARA.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
       WA_MARA TYPE TY_MARA.
DATA : LO_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "custom container
DATA : LO_ALV TYPE REF TO CL_GUI_ALV_GRID. "alv grid
DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT,
       WA_FIELDCATALOG TYPE LVC_S_FCAT.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
CALL SCREEN 100. "double click to create
MODULE STATUS_0100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
  CREATE OBJECT LO_CONT
    EXPORTING
*     PARENT         =
      CONTAINER_NAME = 'CC_ALV'.
  CREATE OBJECT LO_ALV
    EXPORTING
      I_PARENT = LO_CONT.
***Build Field Catalogue
  WA_FIELDCATALOG-COL_POS = '1'. "Set column1
  WA_FIELDCATALOG-FIELDNAME = 'MATNR'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Material No'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '2'. "set column2
  WA_FIELDCATALOG-FIELDNAME = 'MTART'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Material Type'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '3'. "set column 3
  WA_FIELDCATALOG-FIELDNAME = 'MBRSH'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Industry Sector'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '4'. "set column 4
  WA_FIELDCATALOG-FIELDNAME = 'MATKL'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SCRTEXT_M = 'Material Group'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
  WA_FIELDCATALOG-COL_POS = '5'. "set column 5
  WA_FIELDCATALOG-FIELDNAME = 'MEINS'.
  WA_FIELDCATALOG-TABNAME = 'MARA'.
  WA_FIELDCATALOG-SELTEXT = 'Unit Of Measure'.
  APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
  CLEAR : WA_FIELDCATALOG.
**End field catalogue
  SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA
    INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.

  CALL METHOD LO_ALV->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_MARA
      IT_FIELDCATALOG = IT_FIELDCATALOG
*     IT_SORT         =
*     IT_FILTER       =
*  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.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

Execute and test the program .

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 18 People out of 20 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Lesson → ALV Factory Method with OOABAP