Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ALV - Field Catalog

Guys,

I need your help in making me understand the ALV grid with Field catalog concepts.I understand that 3 possible cases for field catalog exist.They are

1)Automatic

2)Semi Automatic

3)Manual.

There is a small piece of code that I had taken from the internet however I am unable to understand the concept with the example.I am here with sharing the piece of code with you.I humbly request your help in making me understand the 3 cases of Field Catalog by using the code that I had shared here.You may make changes accordingly for Automatic,Semi and Manual with the piece of code that I had shared.Please separate all the 3 types while replying.

Regards,

Krish

REPORT  ZALVGRID.
TYPE-POOLS: SLIS.
TABLES     : VBAK,                 
             VBAP.                 
TYPES: BEGIN OF ST_OUTPUTDATA,
        VBELN LIKE Vbak-vbeln,
        POSNR LIKE Vbap-posnr,
        MATNR LIKE Vbap-matnr,
        VBTYP LIKE Vbak-vbtyp,
        VKORG LIKE Vbak-vkorg,
        VOREF LIKE Vbap-VOREF,
      END OF ST_OUTPUTDATA.

DATA: t_OUTPUTDATA TYPE ST_OUTPUTDATA OCCURS 0 WITH HEADER LINE.
DATA: v_repid LIKE sy-repid.
DATA:
    t_FIELDCATELOG TYPE SLIS_T_FIELDCAT_ALV,
      t_LISTHEADER TYPE SLIS_T_LISTHEADER.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
  SELECT-OPTIONS SO_VBELN FOR Vbak-vbeln OBLIGATORY.
  SELECT-OPTIONS SO_ERDAT FOR Vbak-erdat.
  SELECT-OPTIONS SO_ERNAM FOR Vbak-ernam.
  SELECT-OPTIONS SO_VBTYP FOR Vbak-vbtyp.
  SELECT-OPTIONS SO_VKORG FOR Vbak-vkorg.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
  PARAMETERS R_LIST RADIOBUTTON GROUP G1.
  PARAMETERS R_GRID RADIOBUTTON GROUP G1.
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN.
  SELECT SINGLE * FROM VBAK WHERE VBELN = SO_VBELN-LOW.
  IF SY-SUBRC NE 0.
    SET CURSOR FIELD 'SO_VBELN-LOW'.
    MESSAGE 'Enter valid Sales Document Number.' TYPE 'E'.
  ENDIF.
  SELECT SINGLE * FROM VBAK WHERE VBELN = SO_VBELN-HIGH.
  IF SY-SUBRC NE 0.
    SET CURSOR FIELD 'SO_VBELN-HIGH'.
    MESSAGE 'Enter valid Sales Document Number.' TYPE 'E'.
  ENDIF.

AT SELECTION-SCREEN OUTPUT.
  MODIFY SCREEN.
INITIALIZATION.
  v_repid = SY-REPID.

END-OF-SELECTION.

PERFORM BUILD_OUTPUTDATA.

PERFORM BUILD_FIELDCATELOG.

PERFORM BUILD_LISTHEADER.

IF R_LIST = 'X'.

PERFORM DISPLAY_LISTREPORT.

ELSEIF R_GRID = 'X'.

PERFORM DISPLAY_GRIDREPORT.

ENDIF.

FORM BUILD_OUTPUTDATA.

SELECT

VBAK~VBELN

VBAP~POSNR

VBAP~MATNR

VBAK~VBTYP

VBAK~VKORG

INTO CORRESPONDING FIELDS OF TABLE t_OUTPUTDATA

FROM VBAK INNER JOIN VBAP ON VBAKVBELN = VBAPVBELN

WHERE VBAK~VBELN IN SO_VBELN AND

VBAK~ERDAT IN SO_ERDAT AND

VBAK~ERNAM IN SO_ERNAM AND

VBAK~VBTYP IN SO_VBTYP AND

VBAK~VKORG IN SO_VKORG.

LOOP AT t_OUTPUTDATA.

ENDLOOP.

ENDFORM.

FORM BUILD_FIELDCATELOG.

DATA: ls_FIELDCAT TYPE slis_fieldcat_alv.

CLEAR ls_FIELDCAT.

ls_FIELDCAT-COL_POS = 1.

ls_FIELDCAT-FIELDNAME = 'VBELN'.

ls_FIELDCAT-TABNAME = 'T_OUTPUTDATA'.

ls_FIELDCAT-SELTEXT_M = 'Sales Doc No'.

APPEND ls_FIELDCAT TO t_FIELDCATELOG.

CLEAR ls_FIELDCAT.

ls_FIELDCAT-COL_POS = 2.

ls_FIELDCAT-FIELDNAME = 'POSNR'.

ls_FIELDCAT-TABNAME = 'T_OUTPUTDATA'.

ls_FIELDCAT-SELTEXT_M = 'Sales Doc Item'.

APPEND ls_FIELDCAT TO t_FIELDCATELOG.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = v_repid

I_INTERNAL_TABNAME = 't_OUTPUTDATA'

I_STRUCTURE_NAME = 'ST_OUTPUTDATA'

I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = v_repid

CHANGING

ct_fieldcat = t_FIELDCATELOG[].

IF sy-subrc <> 0.

ENDIF.

ENDFORM.

FORM BUILD_LISTHEADER.

DATA: ls_line TYPE slis_listheader.

***Header

CLEAR ls_line.

ls_line-typ = 'H'.

ls_line-info = 'Sales Order Data'.

APPEND ls_line TO t_LISTHEADER.

ENDFORM.

FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_LISTHEADER

I_LOGO = 'ENJOYSAP_LOGO'.

ENDFORM.

FORM DISPLAY_LISTREPORT.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = v_repid

I_STRUCTURE_NAME = 'ST_OUTPUTDATA'

IT_FIELDCAT = t_FIELDCATELOG[]

TABLES

t_outtab = t_OUTPUTDATA

ENDFORM.

FORM DISPLAY_GRIDREPORT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = v_repid

I_STRUCTURE_NAME = 'ST_OUTPUTDATA'

IT_FIELDCAT = t_FIELDCATELOG[]

TABLES

t_outtab = t_OUTPUTDATA.

IF sy-subrc <> 0.

ENDIF.

ENDFORM.

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question