1

Can someone explain the importance of having the code below? I'm new to ABAP and currently trying to create an ALV in a docking container. Thanks.

* Field Catalog

    wa_fieldcat   TYPE lvc_s_fcat.

http://saptechnical.com/Tutorials/ALV/Docking/Index.htm

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Michael
  • 37
  • 2
  • 7
  • Seems that `wa_fieldcat` is used as a helper structure for filling the fieldcatalog. Could you please try to explain your problem more precisely? –  Aug 02 '16 at 16:01

1 Answers1

2

The code in the example has this subroutine:

*&--------------------------------------------------------------*
*&      Form  FILL_FIELDCAT                                     *
*&--------------------------------------------------------------*
*       To Fill the Field Catalog                               *
*---------------------------------------------------------------*
*  Three Parameters are passed                                  *
*  pv_field   TYPE any for Field                                *
*  pv_tabname TYPE any for Table Name                           *
*  pv_coltext TYPE any for Header Text                          *
*---------------------------------------------------------------*
FORM fill_fieldcat  USING   pv_field   TYPE any
                            pv_tabname TYPE any
                            pv_coltext TYPE any .

  wa_fieldcat-fieldname  = pv_field.
  wa_fieldcat-tabname    = pv_tabname.
  wa_fieldcat-coltext    = pv_coltext.

  APPEND wa_fieldcat TO t_fieldcat.
  CLEAR  wa_fieldcat.
ENDFORM.                               " FILL_FIELDCAT   

The structure wa_fieldcat is used as a container for the information that is about to be added to t_fieldcat.

Since pv_field, pv_tabname, and pv_coltext are three disjoint variables, you cannot APPEND them to t_fieldcat before putting them in a central, unified structure.

That being said, I see no reason why the variable declaration you pointed out couldn't be placed inside of the subroutine FILL_FIELDCAT rather than being a global variable. Keeping the scope of variables only as large as they need to be is good coding practice.

gkubed
  • 1,849
  • 3
  • 32
  • 45