Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Populating Field catalog with an internal table using CL_ABAP_STRUCTDESCR class for ALV display (OOPS)

By Deepan Ignaatious, Kaavian systems

Scenario: In this example, I demonstrate on how to populate Field catalog using an internal table for ALV display without using structure in the LVC_FIELDCATALOG_MERGE.

Steps:

1.     Create a program to display a normal ALV using oops concept.

2.     After getting the data for the respective input selection criteria.

3.     Populate the field catalog.

4.     Pass the work area of the final ALV internal table to the P_WA_REPORT to determine the structure descriptions.

LOBJ_STDESC ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA ( P_WA_REPORT ).

5.     Then Check for if it as DDIC structure

IF LOBJ_STDESC->IS_DDIC_TYPE( ) IS NOT INITIAL.
    LV_STNAME = LOBJ_STDESC->GET_RELATIVE_NAME( ).

6.     Now the LV_STNAME (of type DD02L-TABNAME) is to be passed to the LVC_FIELDCATALOG_MERGE Function module I_STRUCTURE_NAME field.

7.     The structure fields are retrieved in the LT_FIELDS internal table.

LT_FIELDS = LOBJ_STDESC->GET_INCLUDED_VIEW ( ).

8.     After looping the LT_FIELDS and processing as shown in the source code below the LT_FCAT is populated which is then passed to the SET_TABLE_FOR_FIRST_DISPLAY method.

9.     The complete sample source code is given below the building field catalog process is in FORM BUILD_FIELDCATALOG subroutine.

Source code:

REPORT  ZD_ALV_OBJECT1.

DATA: LOBJ_STDESC TYPE REF TO CL_ABAP_STRUCTDESCR,
        LT_FIELDS   
TYPE CL_ABAP_STRUCTDESCR=>INCLUDED_VIEW,
        LW_FIELDS   
TYPE LINE OF CL_ABAP_STRUCTDESCR=>INCLUDED_VIEW,
        LW_DESC     
TYPE X030L,
        LW_FLDCAT   
TYPE LINE OF LVC_T_FCAT,
        LV_STNAME   
TYPE DD02L-TABNAME,
        IT_FCAT     
TYPE  LVC_T_FCAT.
DATA : BEGIN OF WA_ALV,
  VBELN 
TYPE VBELN_VA,
  POSNR 
TYPE POSNR_VA,
  MATNR 
TYPE MATNR,
  MATKL 
TYPE MATKL,
  NETWR 
TYPE NETWR_AP,
  KWMENG 
TYPE KWMENG,
  WERKS 
TYPE WERKS_EXT,
  NETPR 
TYPE NETPR,
END OF WA_ALV.
DATA IT_ALV LIKE TABLE OF WA_ALV.
DATA IT_ALV_CPY LIKE TABLE OF WA_ALV.
DATA OPTIONS TYPE VBAK-VBELN.
DATA: OBJ_ALV TYPE REF TO CL_GUI_ALV_GRID.
DATA: OBJ_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

SELECT-OPTIONS : SO_VBELN FOR OPTIONS.

START-
OF-SELECTION.
  
PERFORM SELECTION.
  
PERFORM BUILD_FIELDCATALOG USING WA_ALV.
  
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.

  
CREATE OBJECT OBJ_CONT
    
EXPORTING
      CONTAINER_NAME = 
'CUST'.
  
IF SY-SUBRC <> 0.
    
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  
ENDIF.
  
CREATE OBJECT OBJ_ALV
    
EXPORTING
      I_PARENT = OBJ_CONT.
  
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 OBJ_ALV->SET_TABLE_FOR_FIRST_DISPLAY
    
CHANGING
      IT_OUTTAB                     = IT_ALV
      IT_FIELDCATALOG               = IT_FCAT
    
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.
ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.

ENDMODULE.                 " USER_COMMAND_9000  INPUT

*&---------------------------------------------------------------------*
*&      Form  SELECTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SELECTION .
  
SELECT VBELN
         POSNR
         MATNR
         MATKL
         NETWR
         KWMENG
         WERKS
         NETPR
  
FROM VBAP INTO TABLE IT_ALV
      
WHERE VBELN IN SO_VBELN.
ENDFORM.                    "SELECTION

*&---------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_REPORT  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG  USING    P_WA_REPORT TYPE ANY.

* Determine structure descriptor
  
TRY.
      LOBJ_STDESC ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA( P_WA_REPORT ).
    
CATCH CX_ROOT.
      
RAISE NO_FIELD_CATALOG.
  
ENDTRY.
* If it is DDIC structure, determine field catalog using ALV FM
  
IF LOBJ_STDESC->IS_DDIC_TYPE( ) IS NOT INITIAL.
    LV_STNAME = LOBJ_STDESC->GET_RELATIVE_NAME( ).
    
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      
EXPORTING
        I_BUFFER_ACTIVE        = SPACE
        I_STRUCTURE_NAME       = LV_STNAME
        I_BYPASSING_BUFFER     = 
'X'
      
CHANGING
        CT_FIELDCAT            = IT_FCAT
      
EXCEPTIONS
        INCONSISTENT_INTERFACE = 
1
        PROGRAM_ERROR          = 
2
        
OTHERS                 = 3.
    
IF SY-SUBRC <> 0.
      
CLEAR IT_FCAT.
      
RAISE NO_FIELD_CATALOG.
    
ENDIF.
    
RETURN.
  
ENDIF.
* Get structure fields
  LT_FIELDS = LOBJ_STDESC->GET_INCLUDED_VIEW( ).
* Build field catalog
  
LOOP AT LT_FIELDS INTO LW_FIELDS.
    
CLEAR: LW_FLDCAT,
           LW_DESC.
    LW_FLDCAT-COL_POS   = SY-TABIX.
    LW_FLDCAT-FIELDNAME = LW_FIELDS-NAME.
    
IF LW_FIELDS-TYPE->IS_DDIC_TYPE( ) IS NOT INITIAL.
      LW_DESC            = LW_FIELDS-
TYPE->GET_DDIC_HEADER( ).
      LW_FLDCAT-ROLLNAME = LW_DESC-TABNAME.
    
ELSE.
      LW_FLDCAT-INTTYPE  = LW_FIELDS-
TYPE->TYPE_KIND.
      LW_FLDCAT-INTLEN   = LW_FIELDS-
TYPE->LENGTH.
      LW_FLDCAT-
DECIMALS = LW_FIELDS-TYPE->DECIMALS.
    
ENDIF.
    
APPEND LW_FLDCAT TO IT_FCAT.
  
ENDLOOP.
  
IF IT_FCAT IS INITIAL.
    
RAISE NO_FIELD_CATALOG.
  
ENDIF.
ENDFORM.                    " BUILD_FIELDCATALOG

Output:

The field catalog has been populated based on the internal table data elements

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image