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: 

CREATION OF DYNAMIC TABLE

Former Member
0 Kudos

Hi experts,

I used the method CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE.

to create an internal table by passing the field catalog.

I got the output with the structure where the field length of the fields is 10 for all the fields.

ie. For Matnr length = 10 instead of 18.

Could you please let me know how can get the correct length

1 REPLY 1

uwe_schieferstein
Active Contributor
0 Kudos

Hello Somenath

Most likely your fieldcatalog data are <i>incomplete</i>. The following sample report shows how to create a dynamic itab where the fields have the correct data elements.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_DYNAMIC_ITAB_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_dynamic_itab_create.




DATA:
  gs_fcat       TYPE lvc_s_fcat,
  gt_fcat       TYPE lvc_t_fcat,
  gdo_data      TYPE REF TO data.


FIELD-SYMBOLS:
  <gt_itab>     TYPE table.



START-OF-SELECTION.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'MARA'
    CHANGING
      ct_fieldcat            = gt_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.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'KNB1'
    CHANGING
      ct_fieldcat            = gt_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.

  DELETE gt_fcat WHERE NOT ( fieldname = 'MATNR'  OR
                             fieldname = 'KUNNR'  OR
                             fieldname = 'BUKRS' ).

  LOOP AT gt_fcat INTO gs_fcat.
    gs_fcat-col_pos = syst-tabix.
    MODIFY gt_fcat FROM gs_fcat INDEX syst-tabix.
  ENDLOOP.




  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
*      I_STYLE_TABLE             =
      it_fieldcatalog           = gt_fcat
*      I_LENGTH_IN_BYTE          =
    IMPORTING
      ep_table                  = gdo_data
*      E_STYLE_FNAME             =
    EXCEPTIONS
      generate_subpool_dir_full = 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.


  ASSIGN gdo_data->* TO <gt_itab>.
  APPEND INITIAL LINE TO <gt_itab>.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      it_fieldcat_lvc = gt_fcat
    TABLES
      t_outtab        = <gt_itab>
    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.



END-OF-SELECTION.

Regards

Uwe