Monday, 7 January 2013

Dynamicall Read Field names and values


REPORT DYNAMICALLY_READ_TABLE_FIELDS_AND_VALUES.

PARAMETERStab TYPE dd02l-tabname.

FIELD-SYMBOLS<fs_table> TYPE STANDARD TABLE,
               <fs_wa>,
               <fs_field>.

"data: t_sflight type table of SFLIGHT.

DATAt_fcat TYPE lvc_t_fcat,
      fs_fcat LIKE LINE OF t_fcat,
      dyn_table    TYPE REF TO data,
      fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
*   I_BUFFER_ACTIVE        =          " I_STRUCTURE_NAME             = 'SFLIGHT' " here pass the structure of ur internal table.
    i_structure_name       tab "TAB' " here pass the structure of ur internal table.
*   I_CLIENT_NEVER_DISPLAY = 'X'
*   I_BYPASSING_BUFFER     =
*   I_INTERNAL_TABNAME     =
  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 INTO fs_fcat.
  WRITE:/ fs_fcat-fieldname.
ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog t_fcat
  IMPORTING
    ep_table        dyn_table.
ASSIGN dyn_table->TO <fs_table>.

SELECT INTO CORRESPONDING FIELDS OF TABLE  <fs_table> FROM (tab).


DATAit_fcat  TYPE slis_t_fieldcat_alv.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  EXPORTING
    i_structure_name       tab
  CHANGING
    ct_fieldcat            it_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.

*  fieldcatalog[] =  it_fcat[].



CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  = TAB
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
   it_fieldcat                       it_fcat[]
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          =  <fs_table>
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.




 

No comments:

Post a Comment