Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV - Field Catalog

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

hi krish,

please take help in sdn and you will get everying.

as of now for your basic understanding.

there are 3 ways to generate the fieldcat one is automatic,manual and semi automatic.

in automatic mode you call FM 'REUSE_ALV_FIELDCATALOG_MERGE' and your field cat will get filled up.

in manual mode you have to defind the fields you want to display in the output list manually and in semi automatic you will call the FM and also fill the fields manually.

find below the code for manual mode.


 g_repid = sy-repid.
  REFRESH i_fieldcat.
* fill the field catalog.
  wa_fieldcat-fieldname = 'EXIDV'.

  wa_fieldcat-seltext_l = text-001.
  wa_fieldcat-outputlen = 22.
  wa_fieldcat-col_pos     = 1.
  " wa_fieldcat-key         = c_x.
  "wa_fieldcat-no_zero     = c_x.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
  wa_fieldcat-fieldname = 'MOVED'.
  wa_fieldcat-seltext_l = text-002.
  wa_fieldcat-outputlen = 6.
  wa_fieldcat-col_pos     = 2.
  " wa_fieldcat-key         = c_x.
  "wa_fieldcat-no_zero     = c_x.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
  wa_fieldcat-fieldname = 'POSTED'.
  wa_fieldcat-seltext_l = text-003.
  wa_fieldcat-outputlen = 6.
  wa_fieldcat-col_pos     = 3.
  " wa_fieldcat-key         = c_x.
  "wa_fieldcat-no_zero     = c_x.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
  wa_fieldcat-fieldname = 'MESSAGE'.
  wa_fieldcat-seltext_l = text-004.
  wa_fieldcat-outputlen = 50.
  wa_fieldcat-col_pos     = 4.
  " wa_fieldcat-key         = c_x.
  "wa_fieldcat-no_zero     = c_x.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

* configuring layout before passing to FM
  g_layout-colwidth_optimize =  c_x.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      it_fieldcat        = i_fieldcat
      is_layout          = g_layout
    TABLES
      t_outtab           = i_out
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

hope this helps.

thanks

tanmaya

Former Member
0 Kudos

Thanks Tanmaya for the quick response.

I had gone thru the SDN site yesterday however I am still not clearwith the concept and hence request help in this regard.

I do not understand the role of cl_gui_custom_container and its references in ALV.Why do we create them?

In Field catalog,I understand that there are 3 ways of generating the Field catalog.Like you have explained earlier can u share the entire code for the ways of creating the field catalog so that I will be able to understand better.

Your help is very much appreciated.

Regards,

Krish

0 Kudos

This is the code I have for ALV.

1) Why do we need to pass thru a container control to see an report thru ALV?

2) Function of container control and what is does?

REPORT ZALV1.

DATA: ok_code LIKE sy-ucomm.

DATA: go_grid TYPE REF TO cl_gui_alv_grid,

go_custom_container TYPE REF TO cl_gui_custom_container.

START-OF-SELECTION.

SET SCREEN '100'.

MODULE user_command_0100 INPUT.

CASE ok_code.

WHEN 'EXIT'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

MODULE status_0100 OUTPUT.

IF go_custom_container IS INITIAL.

CREATE OBJECT go_custom_container

EXPORTING container_name = 'ALV_CONTAINER'.

CREATE OBJECT go_grid

EXPORTING

i_parent = go_custom_container.

PERFORM load_data_into_grid.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

FORM load_data_into_grid.

SELECT *

FROM sflight

INTO TABLE gi_sflight.

CALL METHOD go_grid->set_table_for_first_display

EXPORTING i_structure_name = 'SFLIGHT'

CHANGING it_outtab = gi_sflight.

ENDFORM. " load_data_into_grid

0 Kudos

Why don't you simply search by phrase like [why we use custom container|http://www.sdn.sap.com/irj/scn/advancedsearch?query=whyweusecustomcontainer] or similar.

This question is really basic and I believe you can find tens of threads/wikis/documents describing its use and reason behind it.

Regards

Marcin

ThomasZloch
Active Contributor
0 Kudos

The post is unreadable as well, please limit code parts to the necessary bits.

Thread locked.

Thomas