Thursday, October 7, 2010

Create Fieldcatalog Dynamically

Using SLIS:

type-pools: slis.

data: begin of itab,
        vbeln like vbak-vbeln,
        erdat like vbak-erdat,
        vkorg like vbak-vkorg,
        end of itab.

data gt_fieldcat type slis_t_fieldcat_alv.
data wa_fieldcat type slis_fieldcat_alv.
* to create Fieldcatalog for dynamically for table SFLIGHT

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
 I_PROGRAM_NAME              = sy-repid
 I_STRUCTURE_NAME          = 'SFLIGHT'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER       =
* I_BUFFER_ACTIVE              =

CHANGING
ct_fieldcat                              = gt_fieldcat[].
* to create fieldcatalog for fields declared in INTERNAL TABLE
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
 I_PROGRAM_NAME              = sy-repid     " Program Name
  I_INTERNAL_TABNAME     = 'ITAB'        " Internal Table Name
  I_INCLNAME                        = sy-repid     " Include Name Where the Int. Table is Declared
CHANGING
   ct_fieldcat                              = gt_fieldcat[].
Note:
When Creating Fieldcatalog Using Internal Table
  -> Maximum Line length in Report should not exceed 72.
 ->  In Internal Table the fieldnames referring DB Table fields Should be Declared Using LIKE.

Using OOABAP:

data: it_fieldcat type lvc_t_fcat,
       w_fieldcat type lvc_s_fcat.

* to create field catalog dynamically for table SFLIGHT
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'SFLIGHT'
changing
ct_fieldcat = it_fieldcat[].

No comments: