Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Field catalog:
Field catalog is a format description of the display area.

There are three procedures to build a FIELD CATALOG.
1. Automatic field catalog.
2. Semi-automatic field catalog.
3. Manual field catalog.

1. Automatic field catalog.

If the list structure has the same line type as the dictionary structure, then the proxy instance
will automatically create the field catalog.
To do this, just pass the name of the dictionary structure to form using the parameter
'I_STRUCTURE_NAME'.

Example:

REPORT  zalv.

DATA: t_sflight TYPE TABLE OF sflight, " INTERNAL TABLE FOR SFLIGHT
      fs_sflight TYPE sflight.         " WORK AREA FOR SFLIGHT
DATA: r_container TYPE REF TO cl_gui_custom_container,
      r_grid TYPE REF TO cl_gui_alv_grid.

SELECT * FROM sflight INTO TABLE t_sflight.

CALL SCREEN 100.
*&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'SCREEN1'.
  SET TITLEBAR 'TITLE1'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE. " STATUS_0100 INPUT
*&---------------------------------------------------------------------
*& Module HANDLER OUTPUT
*&---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
MODULE handler OUTPUT.
  CREATE OBJECT r_container
    EXPORTING
      container_name = 'CONTAINER'.
  CREATE OBJECT r_grid
    EXPORTING
      i_parent = r_container.
  CALL METHOD r_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = 'SFLIGHT'
    CHANGING
      it_outtab        = t_sflight.
ENDMODULE.                    "USER_COMMAND_0100 INPUT

2. Semi-automatic field catalog.
All fields of the global structure type appears in the data table with the same name.
Now the requirement is to make changes to the dictionary structure or the additional columns
are to be displayed.

In this case we can call a function module (LVC_FIELDCATALOG_MERGE) that returns the field catalog
of the dictionary structure to a table of type lvc_t_fcat.
Now we can loop it and can make whatever changes we want.

Example:

Report zalv. 
DATA: t_fcat TYPE lvc_t_fcat. " INTERNAL TABLE
FIELD-SYMBOLS: <fs_fcat> TYPE lvc_s_fcat.
.
.
.
.
.
.
.
.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'SFLIGHT'
    CHANGING
      ct_fieldcat            = t_fcat
    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.

  LOOP AT t_fcat ASSIGNING <fs_fcat>.
    CASE <fs_fcat>-fieldname .
      WHEN 'PLANETYPE'.
        <fs_fcat>-coltext = 'PLANE'.
      WHEN 'SEATSMAX'.
        <fs_fcat>-no_out = 'X'.
    ENDCASE.
  ENDLOOP.
.
.
.
.
.

Now you can pass this field catalog to the method SET_TABLE_FOR_FIRST_DISPLAY.
3. Manual field catalog.

If the data table's line type does not contains the dictionary references or it only contains references to individual
global structure fields, you have to create the field catalog manually.
For this you have to create an internal table of type LVC_T_FACT and populate it manually.

Example :

REPORT zalv.
TYPES:
  BEGIN OF stu,
    carrid TYPE sflight-carrid,
    connid TYPE sflight-connid,
    fldate TYPE sflight-fldate,
    w_check,
  END OF stu.
DATA:
fs_itab TYPE stu,                 " INTERNAL TABLE
t_itab LIKE TABLE OF fs_itab.     " WORK AREA
DATA:
r_grid TYPE REF TO cl_gui_alv_grid,
r_container TYPE REF TO cl_gui_custom_container.
DATA:
t_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat.
SELECT carrid connid fldate FROM
sflight INTO CORRESPONDING FIELDS OF TABLE t_itab.
CALL SCREEN 100.
*&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'SCREEN'.
  SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
*text
*--------------------------------------------------------------------
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
*& Module SET_HANDLER OUTPUT
*&-------------------------------------------------------------------
*text
*----------------------------------------------------------------------
MODULE set_handler OUTPUT.
  CREATE OBJECT r_container
    EXPORTING
      container_name = 'CONTAINER'.
  CREATE OBJECT r_grid
    EXPORTING
      i_parent = r_container.
*POPULATING THE FIELD CATALOG.
  wa_fcat-fieldname = 'W_CHECK'.
  wa_fcat-coltext = 'CHECK'.
  wa_fcat-checkbox = 'X'.
  wa_fcat-edit = 'X'.
  wa_fcat-col_pos = 1.
  APPEND wa_fcat TO t_fcat.
  CLEAR wa_fcat.
  wa_fcat-fieldname = 'CARRID'.
  wa_fcat-ref_table = 'SFLIGHT'.
  wa_fcat-ref_field = 'CARRID'.
  wa_fcat-col_pos = 2.
  APPEND wa_fcat TO t_fcat.
  CLEAR wa_fcat.
  wa_fcat-fieldname = 'CONNID'.
  wa_fcat-ref_table = 'SFLIGHT'.
  wa_fcat-ref_field = 'CONNID'.
  wa_fcat-col_pos = 3.
  APPEND wa_fcat TO t_fcat.
  CLEAR wa_fcat.
  CALL METHOD r_grid->set_table_for_first_display
    CHANGING
      it_fieldcatalog = t_fcat
      it_outtab       = t_itab.
ENDMODULE. " SET_HANDLER OUTPUT