Dynamic Internal Table creation in SAP version 4.5B

Hi All,
Can anybody please let me know if it is possible to create dynamic internal table in SAP version 4.5 B.
If yes will be of great help if somebody can give the method of doing it or any sample code to follow.
Thanks in advance!!!

Hi
Refer this wiki  [http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]
Regards
Raj

Similar Messages

  • Dynamic Internal Table creation and population

    Hi gurus !
    my issue refers to the slide 10 provided in this slideshow : https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae
    My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.
    Letu2019s use only EKPO, and only field MENGE.
    For this, I use Classes cl_abap_elemdescr, cl_sql_result_set and the Data Ref for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.
    Here it comes:
    DATA: element_ref             TYPE REF TO cl_abap_elemdescr,
          vl_fieldname               TYPE string,
                 tl_components         TYPE abap_component_tab,
                 sl_components         LIKE LINE OF tl_components_alv,
    linetype_lcl               TYPE REF TO cl_abap_structdescr,
    ty_table_type            TYPE REF TO cl_abap_tabledescr,
    g_resultset             TYPE REF TO cl_sql_result_set
    u2026
    CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
    * sg_columns-table_name contains 'EKPO'
    * sg_columns-column_name contains 'MENGE'
    * getting the element as a component
    element_ref ?= cl_abap_elemdescr=>describe_by_name( vl_fieldname ).
    sl_components-name  = sg_columns-column_name.
    sl_components-type ?= element_ref.
    APPEND sl_components TO tl_components.
    * dynamic creation of internal table
    linetype_lcl = cl_abap_structdescr=>create( tl_components ).
    ty_table_type = cl_abap_tabledescr=>create(
                      p_line_type = linetype_lcl ).
    u2026
    * Then I will create my field symbol table and line. Code has been cut here.
    CREATE DATA dy_line LIKE LINE OF <dyn_table>.
    u2026
    * Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
      g_resultset = g_stmt_ref->execute_query( stmt_str ).
    * Then structure for the Resultset is set
      CALL METHOD g_resultset->set_param_struct
        EXPORTING
          struct_ref = dy_line.
    * Fetching the lines of the resultset  => Dumpu2026
      WHILE g_resultset->next( ) > 0.
        ASSIGN dy_line->* TO <dyn_wa>.
        APPEND <dyn_wa> TO <dyn_table>.
      ENDWHILE.
    Anyone has any clue to how prevent my Dump ??
    The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that !

    Hello
    I have expanded your sample coding for selecting three fields out of EKPO:
    *& Report  ZUS_SDN_SQL_RESULT_SET
    *& Thread: Dynamic Internal Table creation and population
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1375510"></a>
    *& NOTE: Coding for dynamic structure / itab creation taken from:
    *& Creating Flat and Complex Internal Tables Dynamically using RTTI
    *& https://wiki.sdn.sap.com/wiki/display/Snippets/Creating+Flat+and+
    *& Complex+Internal+Tables+Dynamically+using+RTTI
    REPORT  zus_sdn_sql_result_set.
    TYPE-POOLS: abap.
    DATA:
    go_sql_stmt       TYPE REF TO cl_sql_statement,
    go_resultset      TYPE REF TO cl_sql_result_set,
    gd_sql_clause     TYPE string.
    DATA:
      gd_tabfield      TYPE string,
      go_table         TYPE REF TO cl_salv_table,
      go_sdescr_new    TYPE REF TO cl_abap_structdescr,
      go_tdescr        TYPE REF TO cl_abap_tabledescr,
      gdo_handle       TYPE REF TO data,
      gdo_record       TYPE REF TO data,
      gs_comp          TYPE abap_componentdescr,
      gt_components    TYPE abap_component_tab.
    FIELD-SYMBOLS:
      <gs_record>   TYPE ANY,
      <gt_itab>     TYPE STANDARD TABLE.
    START-OF-SELECTION.
    continued.

  • DYNAMIC INTERNAL TABLE CREATION BASED ON THE CONTENT OF ANOTHER INTERNAL TA

    Hi All
    I need to create an internal table at runtime.
    I have a selection screen parameter which is specific to country, Which can take values below
    eg:- IT_AREA for Italy(IT)
    FR_AREA for France(FR)
    IE_AREA for Ireland(IE).....And similary for other countries
    Based on the Above parameter, I need to create Internal Table as below
    DATA: itab TYPE italy_data Occurs 0.
    If I declare as above, Then itab has fields from italy_data. And this internal table i will be sending it to Function Module to get data into it.
    My Requirement is to Create the Internal table itab during runtime for tables italy_data OR france_data OR ireland_data based on selection screen parameter. Tables on Country may have different number of fields in it.
    Can anyone help me on this??

    Hi,
    Here is a sample code to create a dynamic internal table.
    REPORT ytrab03.
    TABLES: mara, makt.
    TYPE-POOLS: slis.
    DATA: it_fcat TYPE slis_t_fieldcat_alv,
    is_fcat LIKE LINE OF it_fcat,
    ls_layout TYPE slis_layout_alv.
    DATA: it_fieldcat TYPE lvc_t_fcat,
    is_fieldcat LIKE LINE OF it_fieldcat.
    DATA: new_table TYPE REF TO data,
    new_line TYPE REF TO data,
    ob_cont_alv TYPE REF TO cl_gui_custom_container,
    ob_alv TYPE REF TO cl_gui_alv_grid,
    vg_campos(255) TYPE c,
    i_campos LIKE TABLE OF vg_campos,
    vg_campo(30) TYPE c,
    vg_tables(60) TYPE c.
    DATA: e_params LIKE zutsvga_alv_01.
    FIELD-SYMBOLS: <l_table> TYPE table,
    <l_line> TYPE ANY,
    <l_field> TYPE ANY.
    PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    is_fcat-fieldname = 'COL01'.
    is_fcat-ref_fieldname = 'MATNR'.
    is_fcat-ref_tabname = 'MARA'.
    APPEND is_fcat TO it_fcat.
    is_fcat-fieldname = 'COL02'.
    is_fcat-ref_fieldname = 'MAKTX'.
    is_fcat-ref_tabname = 'MAKT'.
    APPEND is_fcat TO it_fcat.
    LOOP AT it_fcat INTO is_fcat.
    is_fieldcat-fieldname = is_fcat-fieldname.
    is_fieldcat-ref_field = is_fcat-ref_fieldname.
    is_fieldcat-ref_table = is_fcat-ref_tabname.
    APPEND is_fieldcat TO it_fieldcat.
    CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field
    INTO vg_campos SEPARATED BY '~'.
    APPEND vg_campos TO i_campos.
    ENDLOOP.
    *... Create the dynamic internal table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = it_fieldcat
    IMPORTING
    ep_table = new_table.
    *... Create a new line
    ASSIGN new_table->* TO <l_table>.
    CREATE DATA new_line LIKE LINE OF <l_table>.
    ASSIGN new_line->* TO <l_line>.
    SELECT (i_campos) FROM mara INNER JOIN makt
    ON mara~matnr = makt~matnr
    UP TO p_max ROWS
    INTO TABLE <l_table>.
    LOOP AT <l_table> INTO <l_line>.
    LOOP AT it_fcat INTO is_fcat.
    ASSIGN COMPONENT is_fcat-fieldname
    OF STRUCTURE <l_line> TO <l_field>.
    IF sy-tabix = 1.
    WRITE: /2 <l_field>.
    ELSE.
    WRITE: <l_field>.
    ENDIF.
    ENDLOOP.
    ENDLOOP.
    Regards,
    Karuna.

  • Question on Dynamic Internal Table creation

    Good day everyone.
    I would like to ask if it is possible to just add several fields to an existing internal table to make it dynamic? if possible, does anyone have a sample program? thanks a lot!

    Hi Christian,
    Refer the following code. It may help you.
    Reward points if it helps.
    REPORT ZDSAP .
    DATA: d_ref TYPE REF TO data,
    d_ref2 TYPE REF TO data ,
    i_alv_cat TYPE TABLE OF lvc_s_fcat,
    ls_alv_cat LIKE LINE OF i_alv_cat.
    TYPES tabname LIKE dcobjdef-name .
    parameter: p_tablen type tabname.
    data: begin of itab occurs 0.
    INCLUDE STRUCTURE dntab.
    data: end of itab.
    FIELD-SYMBOLS : <F_FS> TYPE table,
    <F_FS1> TYPE TABLE,
    <F_FS2> TYPE ANY,
    <F_FS3> TYPE TABLE.
    REFRESH itab.
    CALL FUNCTION 'NAMETAB_GET'
    EXPORTING
    langu = sy-langu
    tabname = p_tablen
    TABLES
    nametab = itab
    EXCEPTIONS
    no_texts_found = 1.
    LOOP AT itab .
    ls_alv_cat-fieldname = itab-fieldname.
    ls_alv_cat-ref_table = p_tablen.
    ls_alv_cat-ref_field = itab-fieldname.
    APPEND ls_alv_cat TO i_alv_cat.
    ENDLOOP.
    * internal table build
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING it_fieldcatalog = i_alv_cat
    IMPORTING ep_table = d_ref .
    ASSIGN d_ref->* TO <F_FS>.
    SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.
    LOOP AT <F_FS> ASSIGNING <F_FS2>.
    *your code goes here.
    ENDLOOP.

  • Dynamic internal table and dynamic field catalog

    hi
    i need to decide the number of fields of the internal table at runtime
    and then need to pass value to this internal table.
    then i need to create the field catalog for this internal table (so here
    field catalog is also dynamic) to display in alv.
    how to achieve this dynamic internal table creation and dyanmic field catalog generation

    Hi Ajay,
      U can use the below code to create a dynamic internal table.
    *adding the field names only once for the dynamic table     .
          MOVE 'PRCTR' TO gw_component-name.
          gw_component-type ?= cl_abap_elemdescr=>get_string( ).
          INSERT gw_component INTO TABLE gt_components.
          MOVE 'RCNTR' TO gw_component-name.
          gw_component-type ?= cl_abap_elemdescr=>get_string( ).
          INSERT gw_component INTO TABLE gt_components.
          MOVE 'RACCT' TO gw_component-name.
          gw_component-type ?= cl_abap_elemdescr=>get_string( ).
          INSERT gw_component INTO TABLE gt_components.
          MOVE 'RYEAR' TO gw_component-name.
          gw_component-type ?= cl_abap_elemdescr=>get_string( ).
          INSERT gw_component INTO TABLE gt_components.
          MOVE 'YTDBAL' TO gw_component-name.
          gw_component-type ?= cl_abap_elemdescr=>get_string( ).
          INSERT gw_component INTO TABLE gt_components.
          MOVE 'OBAL' TO gw_component-name.
          gw_component-type ?= cl_abap_elemdescr=>get_string( ).
          INSERT gw_component INTO TABLE gt_components.
    *get structure descriptor -> GR_STRUCTDESCR
              gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
    create work area of structure GR_STRUCTDESCR -> GR_WA
              CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
              ASSIGN gr_wa->* TO <gw_wa>.
    determine key components -> GT_KEYS
              MOVE lv_value1 TO gw_key-name.
              INSERT gw_key INTO TABLE gt_keys.
    create descriptor for internal table -> GR_TABLEDESCR
              gr_tabledescr ?= cl_abap_tabledescr=>create( p_line_type  = gr_structdescr
                                                           p_table_kind = cl_abap_tabledescr=>tablekind_hashed
                                                           p_unique     = abap_true
                                                           p_key        = gt_keys
                                                           p_key_kind   = cl_abap_tabledescr=>keydefkind_user ).
    create internal table -> GR_ITAB
              CREATE DATA gr_itab TYPE HANDLE gr_tabledescr.
              ASSIGN gr_itab->* TO <gt_itab>.
              CREATE DATA gr_itab LIKE STANDARD TABLE OF <gw_wa>.
              ASSIGN gr_itab->* TO <gt_sttab>.
    Now u r internal table named <gt_sttab> has been created with fields like RCNTR, PRCTR,RACCT, RYEAR etc whatever the field u need u can go ahead and create dynamically.
    then by using the table <gt_sttab> u can create u r field catalog.
    Regards,
    Rose.

  • Dynamic internal table with problem

    Hi,
    I have developed a program to update standard table. I am using dynamic internal table creation concept. But my dynamic internal table is having width only 1200 bytes. But many standard tables have more than that width. Do you have any input create dynamic internal table with more than 1200 bytes width..
    Have a look at the error.
    [http://3.bp.blogspot.com/_O5f8iAlgdNQ/SjYXTBpO92I/AAAAAAAAErI/Fs996_APHbE/s1600-h/error-792463.JPG|http://3.bp.blogspot.com/_O5f8iAlgdNQ/SjYXTBpO92I/AAAAAAAAErI/Fs996_APHbE/s1600-h/error-792463.JPG]
    Expecting reply
    Thanks
    Venkat

    Hi,
    DATA: IT_TABSTRUC     TYPE STANDARD TABLE OF DFIES INITIAL SIZE 0,
            V_REF        TYPE REF TO DATA,
              V_I_AVL_CAT  TYPE TABLE OF LVC_S_FCAT.
    FIELD-SYMBOLS : <F_FS_DATA>   TYPE STANDARD TABLE.
    SELECTION-SCREEN:BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001
    NO INTERVALS.
    PARAMETERS: P_TABNAM TYPE X_TABNAME.
    SELECTION-SCREEN:END OF BLOCK B1.
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          TABNAME        = p_tabnam
          LANGU          = SY-LANGU
        TABLES
          DFIES_TAB      = IT_TABSTRUC
        EXCEPTIONS
          NOT_FOUND      = 1
          INTERNAL_ERROR = 2
          OTHERS         = 3.
      LOOP AT IT_TABSTRUC .
        V_LS_AVL_CAT-FIELDNAME = IT_TABSTRUC -FIELDNAME.
        V_LS_AVL_CAT-REF_TABLE = P_TABNAM.
        V_LS_AVL_CAT-REF_FIELD = IT_TABSTRUC -FIELDNAME.
        APPEND V_LS_AVL_CAT TO V_I_AVL_CAT.
      ENDLOOP.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = V_I_AVL_CAT
        IMPORTING
          EP_TABLE        = V_REF.
      ASSIGN V_REF->* TO <F_FS_DATA>.
      FREE V_REF.
      SELECT * FROM (P_TABNAM) INTO CORRESPONDING
              FIELDS OF TABLE <F_FS_DATA> .
    Hope this resolves ur probs....

  • Dynamic internal table in SAP 3.1I version

    hi All,
    i am new to this form and have the following question.
    Currently i am working in SAP 3.1I version and i am required to create a dynamic internal table.
    Basically the table name will be entered by the user on the selection screen and the dynamic internal table has to be of this type (entered by user on the selection screen).
    Please let me know whether this is possible in 3.1I version and if its possible then how to achieve this.
    Note: this requirement has to be done in 3.1I version hence OO concept (ie)
         cl_alv_table_create=>create_dynamic_table doesn't work here.

    refer this demo code  -
    parameter p_table type tabname.
    field-symbols <tab> type table.
    field-symbols <tab1> type any.
    types: begin of itab,
          t_name type tabname,
          t_ref type ref to data,
          end of itab.
    data itab1 type table of itab with non-unique key t_name.
    perform fetch_data using p_table.
    perform print_table using p_table.
    *&      Form  fetch_data
          text
         -->P_P_TABLE  text
    FORM fetch_data  USING P_TABLE1 type tabname.
    data itab2 type itab.
    itab2-t_name = p_table1.
    create data itab2-t_ref type table of (itab2-t_name) .
    assign itab2-t_ref->* to <tab>.
    append itab2 to itab1.
    select * from (p_table1) up to 25 rows into corresponding fields of table <tab>.
    ENDFORM.                    " fetch_data
    *&      Form  print_table
          text
         -->P_P_TABLE  text
    FORM print_table  USING P_TABLE1 type tabname.
    DATA t_ref1 TYPE REF TO data.
    DATA itab2 TYPE itab.
    FIELD-SYMBOLS <field> TYPE ANY.
    READ TABLE itab1 INTO itab2 WITH KEY t_name = p_table1.
    ASSIGN itab2-t_ref->* TO <tab>.
    CREATE DATA t_ref1 LIKE LINE OF <tab>.
    ASSIGN t_ref1->* TO <tab1>.
    DO.
    *READ TABLE <tab> ASSIGNING <tab1> INDEX 1.
    READ TABLE <tab> ASSIGNING <tab1> INDEX SY-INDEX.
    *WRITE:/ p_table1.
    NEW-LINE.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE <tab1> TO <field>.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    WRITE: <field>,'    '.
    ENDDO.
    ENDDO.
    ENDFORM.                    " print_table

  • Creation of dynamic internal table is not synchronous

    In my code following lines are used to create a dynamic table.
    REFRESH : INCTABL .
      CLEAR INCTABL .
      INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.
      INCTABL-LINE =   'zpltnamec like zvendplt-zpltnamec,'. APPEND INCTABL.
      INCTABL-LINE =   'sourcing like zopsdwbom-sourcing,'. APPEND INCTABL.
    INCTABL-LINE =   'zmatgrp like zrmrpmaterial-zmatgrp,'. APPEND INCTABL.
      INCTABL-LINE =   'zcollection like zrmrpmaterial-zcollection,'.
      APPEND INCTABL.
      INCTABL-LINE =   'fiscintrodt like zrmrpmaterial-zfiscintrodt,'.
      APPEND INCTABL.
      INCTABL-LINE =   'bednr like ekpo-bednr,'. APPEND INCTABL.
      INCTABL-LINE =   'revlv like ekpo-revlv,'. APPEND INCTABL.
      INCTABL-LINE =   'ematn like ekpo-ematn,'. APPEND INCTABL.
      INCTABL-LINE =   'menge like mara-eannr,'. APPEND INCTABL.
      INCTABL-LINE =   'stprs like mara-eannr,'. APPEND INCTABL.
    *inctabl-line =   'kbetr like cdred-f_new,'. append inctabl.
      DATA : T_KBETR(72) .
      DATA :CNT(2).
      DO LIN TIMES .
        CNT = SY-INDEX .
        CONCATENATE 'kbetr' CNT ' like cdred-f_new,' INTO T_KBETR .
        CONDENSE T_KBETR .
        INCTABL-LINE =   T_KBETR . APPEND INCTABL.
      ENDDO .
      INCTABL-LINE = 'end of dyntab. '. APPEND INCTABL.
      INSERT REPORT 'zcrchangereport_3'(001) FROM INCTABL.
    but during run time it is using the previously created dynamic internal table structure and then creating currently required internal table.
    how to overcome this problem/
    Thanks.

    Hello,
    Instead of creating report, create subroutine pool. Like
    INCTABL-LINE = 'report ztest.'. APPEND INCTABL.
    INCTABL-LINE = 'form main'. APPEND INCTABL.
    INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.
    INCTABL-LINE = 'zpltnamec like zvendplt-zpltnamec.'. APPEND INCTABL.
    INCTABL-LINE = 'data: end of dyntab.'. APPEND INCTABL.
      CATCH SYSTEM-EXCEPTIONS GENERATE_SUBPOOL_DIR_FULL = 9.
        GENERATE SUBROUTINE POOL inctabl NAME l_name
                MESSAGE L_MESSAGE LINE L_LINE WORD L_WORD.
      ENDCATCH.
      IF L_MESSAGE IS INITIAL.
        PERFORM (L_FORM) IN PROGRAM (L_NAME).
      ELSE.
        WRITE : L_MESSAGE, L_LINE.
      ENDIF.
    You can get the message in L_message variable, if any error occurs.
    Regards,
    Naimesh

  • Reg: Creation of Dynamic Internal table

    Hi All,
    I got a requirement which should be handled by creating dynamic internal table.
    *Scenario: *
    1.First I will fetch data from one table into an internal table.
    Let suppose I am fetching the fieldnames of the table MAKT from DD03l. Then I will having following records in my internal table.
             MANDT
             MATNR
             SPRAS
             MAKTX
             MAKTG
    2.Now I need to download these fields into an excel file with same field names as headings as shown below
         |  MANDT  |  MATNR  |  SPRAS  |  MAKTX  |  MAKTG  |
    3.Later User will enter data for all those fields in the downloaded excel file and again upload the file. Here I need to create dynamic internal table because the table name is dynamic. Based on the table name, field names will be varying..
    Please provide me solution for the above..
    Thanks,
    Ravee

    Hi
    U can try something like this:
    TYPES: TY_LINE TYPE STRING.
    PARAMETERS: P_TABLE TYPE DDOBJNAME.
    DATA: DYN_TAB TYPE REF TO DATA.
    FIELD-SYMBOLS: <FS_TAB>   TYPE TABLE,
                   <FS_WA>    TYPE ANY,
                   <FS_FIELD> TYPE ANY.
    DATA: DFIES_TAB TYPE TABLE OF DFIES WITH HEADER LINE.
    DATA: W_LINE(10000) TYPE C.
    DATA: V_OFFSET TYPE I.
    DATA: LAST_FIELD.
    START-OF-SELECTION.
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          TABNAME        = P_TABLE
        TABLES
          DFIES_TAB      = DFIES_TAB
        EXCEPTIONS
          NOT_FOUND      = 1
          INTERNAL_ERROR = 2
          OTHERS         = 3.
      IF SY-SUBRC <> 0.
        MESSAGE I208(00) WITH 'No table'.
        STOP.
      ENDIF.
    * Create internal table
      CREATE DATA DYN_TAB TYPE TABLE OF (P_TABLE).
      ASSIGN DYN_TAB->* TO <FS_TAB>.
    * Create Header
      LOOP AT DFIES_TAB.
    * Insert field name
        MOVE DFIES_TAB-FIELDNAME TO W_LINE+V_OFFSET.
        V_OFFSET = V_OFFSET + 30.
        AT LAST.
          LAST_FIELD = 'X'.
        ENDAT.
        CHECK LAST_FIELD IS INITIAL.
    * Insert separator
        MOVE ';' TO W_LINE+V_OFFSET.
        V_OFFSET = V_OFFSET + 1.
      ENDLOOP.
      CONDENSE W_LINE NO-GAPS.
      WRITE W_LINE.
    * Get DATA
      SELECT * FROM (P_TABLE) INTO TABLE <FS_TAB>.
      LOOP AT <FS_TAB> ASSIGNING <FS_WA>.
        CLEAR LAST_FIELD.
        CLEAR V_OFFSET.
        CLEAR W_LINE.
        LOOP AT DFIES_TAB.
          AT LAST.
            LAST_FIELD = 'X'.
          ENDAT.
          ASSIGN COMPONENT DFIES_TAB-FIELDNAME
            OF STRUCTURE <FS_WA> TO <FS_FIELD>.
    * Insert value
          MOVE <FS_FIELD> TO W_LINE+V_OFFSET(DFIES_TAB-INTLEN).
          V_OFFSET = V_OFFSET + DFIES_TAB-INTLEN.
    * Insert separator
          MOVE ';' TO W_LINE+V_OFFSET.
          V_OFFSET = V_OFFSET + 1.
        ENDLOOP.
        CONDENSE W_LINE NO-GAPS.
        WRITE: / W_LINE.
      ENDLOOP.
    In your case u can append the workarea W_LINE to an internal table and then download it as CSV file.
    Max

  • Create object/structure like dynamic internal table

    Hi,
    We have created dynamic internal table with some fields.
    for the above how to create structure or internal table like dynamic internal table structure .
    Scenario: internal table itab1 ( with header line) have 5 fields.
    Based on some of the conditions in layout of the report.
    we have to create dynamic internal table.
    field-symbols: <FS> type standard table.
    we are able to create dynamic internal table with 3 fields
    with assignment <fs> = itab1[]
    the columns are not appearing but data appearing in next column.
    how to solve this one
    Thanks
    Ramesh

    Hi Ramesh,
      I hope this code works...
    report  yup_alv_datbase                         .
    *-Display Database table contents in ALV Grid Format
    >********************************************************************
    This report displays data from SAP tables, views (like SE16)        *
    FM : REUSE_ALV_GRID_DISPLAY                                         *
    tables:
      dd02l,                               " SAP tables
      dd03l.                               " Table Fields
    type-pools: slis.                      " ALV Global Types
    selection-screen :
    begin of line, comment 1(35) v_1 for field p_table.         "#EC NEEDED
    parameters p_table like dd03l-tabname obligatory memory id dtb.
    selection-screen end of line.
    selection-screen :
    begin of line, comment 1(35) v_2 for field p_max.           "#EC NEEDED
    parameters p_max(2) type n default '20' obligatory.
    selection-screen end of line.
    at selection-screen.
      select single * from dd02l where tabname  = p_table
                                   and as4local = 'A'
                                   and as4vers  = '0000'.
      if sy-subrc ne 0.
      Table & is not active in the Dictionary
        message e402(mo) with p_table.
      elseif dd02l-tabclass = 'INTTAB'.
      & is a structure, not a table
        message e403(mo) with p_table.
      endif.
    initialization.
      v_1 = 'Table'.
      v_2 = 'Maximum of records'.
    start-of-selection.
      perform f_display_data.
         Form  F_DISPLAY_DATA
    form f_display_data.
    Macro definition
      define m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-up = 'X'.
        append ls_sort to lt_sort.
      end-of-definition.
      data:
        l_long type i,
        lp_struct   type ref to data,
        lp_table    type ref to data,      " Pointer to dynamic table
        of_sdescr   type ref to cl_abap_structdescr,
        ls_lvc_cat  type lvc_s_fcat,
        lt_lvc_cat  type lvc_t_fcat,       " Field catalog
        ls_fieldcat type slis_fieldcat_alv,
        lt_fieldcat type slis_t_fieldcat_alv,  " Field catalog
        ls_layout   type slis_layout_alv,
        lt_sort     type slis_t_sortinfo_alv,  " Sort table
        ls_sort     type slis_sortinfo_alv.
      field-symbols :
        <fieldcat>   type slis_fieldcat_alv,
        <lt_data>    type table,           " Data to display
        <fs>         type any,
        <components> type abap_compdescr.
    Dynamic creation of a structure
      create data lp_struct type (p_table).
      assign lp_struct->* to <fs>.
    Fields Structure
      of_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
      loop at of_sdescr->components assigning <components>.
      Field MANDT not displayed
        if sy-tabix = 1 and <components>-name = 'MANDT'.
          continue.                        " Next loop
        endif.
      Build Fieldcatalog
        ls_lvc_cat-fieldname = <components>-name.
        ls_lvc_cat-ref_table = p_table.
        append ls_lvc_cat to lt_lvc_cat.
      Build Fieldcatalog
        ls_fieldcat-fieldname = <components>-name.
        ls_fieldcat-ref_tabname = p_table.
        append ls_fieldcat to lt_fieldcat.
      endloop.
    Create internal table
      call method cl_alv_table_create=>create_dynamic_table
        exporting it_fieldcatalog = lt_lvc_cat
        importing ep_table = lp_table.
      assign lp_table->* to <lt_data>.
    Read data
      select * from (p_table) up to p_max rows
        into corresponding fields of table <lt_data>
       order by primary key.
      if <lt_data>[] is initial.
      No table entries found for specified key
        message i429(mo).
        exit.
      endif.
    Read key field to Build Sort Table
      select * from dd03l where tabname  = p_table
                            and fieldname <> '.INCLUDE'
                            and as4vers  = '0000'
                            and as4local = 'A'
                          order by position.
        read table lt_fieldcat assigning <fieldcat>
                                with key fieldname = dd03l-fieldname.
        check sy-subrc eq 0.
        add dd03l-leng to l_long.
        if dd03l-keyflag = 'X'.
        Build Sort Table
          m_sort dd03l-fieldname.
          <fieldcat>-key = 'X'.
        elseif l_long > 150.
          <fieldcat>-tech = 'X'.
        endif.
      endselect.
      ls_layout-zebra = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           tables
                t_outtab    = <lt_data>.
    endform.                               " F_DISPLAY_DATA
    END OF PROGRAM Z_ALV_DYNAMIC_DATA *********************
    Regards,
    Sampath

  • How to use dynamic internal table when using gui_upload?

    Hi Experts,
    my scenario is like i have header data, item data and serial numbers.
    so with respect to the  quantity in unit of measure ,there will be number of serial numbers..
    i have declared the dynamic internal table,but i am not getting the logic to change the structure accordingly with respect to the flat file entries..
    is it possible to do or its not possible....any suggestion!!!!i have declared like this....
    TYPES: BEGIN OF ty_final,
          bldat TYPE string,      "Document Date
          budat TYPE string,      "Psting Date
          bktxt TYPE string,      "Document Header Text
          werks TYPE string,      "Plant
          lgort TYPE string,      "Storage Location
          matnr TYPE string,      "Material Number
          erfmg TYPE string,      "Quantity in Unit Of Entry
          anln1 TYPE string,      "Asset Number
          anln2 TYPE string,      "Asset Subnumber
          sernr TYPE string,      "serial Number
    END OF ty_final.
    DATA : it_final TYPE TABLE OF ty_final,
           wa_final TYPE ty_final.
    FIELD-SYMBOLS : <fs_final> TYPE table.
    ASSIGN it_final TO <fs_final>.
    after this i called gui upload and passed internal table it_final..
    but i have to change the internal table structure dynamically before the upload function.so that it will match with the flat file...
    Regards
    Karthick

    There are at least two approaches you can use to change/generate new dynamic-structured table. Either with [RTTI + RTTS|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI] or using [CL_ALV_TABLE_CREATE|http://www.sdn.sap.com/irj/scn/advancedsearch?query=cl_alv_table_create] . In this one just determine fieldcatalog of current table and change it accordingly, then regenarate table.
    There are plenty of examples in SCN for this. You should not face difficulties applying this.
    Regards
    Marcin

  • How to create Dynamic internal table with columns also created dynamically.

    Hi All,
    Any info on how to create a dynamic internal table along with columns(fields) also to be created dynamically.
    My requirement is ..On the selection screen I enter the number of fields to be in the internal table which gets created dynamically.
    I had gone thru some posts on dynamic table creation,but could'nt find any on the dynamic field creation.
    Any suggestions pls?
    Thanks
    Nara

    I don't understand ...
    something like that ?
    *   Form P_MODIFY_HEADER.                                              *
    form p_modify_header.
      data : is_fieldcatalog type lvc_s_fcat ,
             v_count(2)      type n ,
             v_date          type d ,
             v_buff(30).
    * Update the fieldcatalog.
      loop at it_fieldcatalog into is_fieldcatalog.
        check is_fieldcatalog-fieldname+0(3) eq 'ABS' or
              is_fieldcatalog-fieldname+0(3) eq 'VAL' .
        move : is_fieldcatalog-fieldname+3(2) to v_count ,
               p_perb2+5(2)                   to v_date+4(2) ,
               p_perb2+0(4)                   to v_date+0(4) ,
               '01'                           to v_date+6(2) .
        v_count = v_count - 1.
        call function 'RE_ADD_MONTH_TO_DATE'
            exporting
              months        = v_count
              olddate       = v_date
            importing
              newdate       = v_date.
        if is_fieldcatalog-fieldname+0(3) eq 'ABS'.
          concatenate 'Quantité 0'
                      v_date+4(2)
                      v_date+0(4)
                      into v_buff.
        else.
          concatenate 'Montant 0'
                      v_date+4(2)
                      v_date+0(4)
                      into v_buff.
        endif.
        move : v_buff to is_fieldcatalog-scrtext_s ,
               v_buff to is_fieldcatalog-scrtext_m ,
               v_buff to is_fieldcatalog-scrtext_l ,
               v_buff to is_fieldcatalog-reptext .
        modify it_fieldcatalog from is_fieldcatalog.
      endloop.
    * Modify the fieldcatalog.
      call method obj_grid->set_frontend_fieldcatalog
           exporting it_fieldcatalog = it_fieldcatalog.
    * Refresh the display of the grid.
      call method obj_grid->refresh_table_display.
    endform.                     " P_MODIFY_HEADER

  • How to create Dynamic Internal table in ALV?

    Hi all,
    I have to create a ALV report based on dynamic internal table. The requirement is that when I enter the months in my selection screen I should get the data relevant to those many months only. For eg if in selection I have given January to March, I should get an ALV output with columns from January to March only.
    Please help me with the coding part as I find it a bit confusing.
    Please reply immediately.
    Regards,
    Bhavani.

    Hi BHAVANI,
    first you have to prapare a field catalog [(see this)|http://help.sap.com/saphelp_470/helpdata/en/52/5f060de02d11d2b47d006094192fe3/frameset.htm]
    and than you can use a Method cl_alv_table_create=>create_dynamic_table
    I hope that help a little.
    Regards Bogdan

  • Error while creating a dynamic internal table refers to custom field

    Hi all,
    I am getting the exception TYPE_NOT_FOUND when I try to create a dynamic internal table using:-
    DATA: gr_desc TYPE REF TO cl_abap_typedescr.
    gr_desc = cl_abap_typedescr=>describe_by_name( p_field ).
    The field p_field is a Z-field inside a DB table, (e.g. a user added field in MARA). The statement fails at that point and gives a runtime exception. Any suggestions to how I may solve this problem? Or any alternatives for the same? I guess we face this issue for all custom fields..has SAP released a note for this??
    Thanks..

    that's just the wrong method, you should use DESCRIBE_BY_DATA
    gr_desc = cl_abap_typedescr=>describe_by_data( p_field ).
    Note: DESCRIBE_BY_NAME is to be used for referencing a DDIC type by its name. Example:
    gr_desc = cl_abap_typedescr=>describe_by_name( 'MARA-ZZFIELD' ).

  • Need information on Dynamic internal table

    Hi All,
    I need some information on dynamic internal table.
    I want what are the field names and the values in dynamic internal table.
    Is there any function module, which tells us the field names and values of corresponding fields from a dynamic internal table ?
    Thank you very much in advance.

    Hi,
    Program to display/edit database tables dynamically.
    REPORT  zdyn_table_display.
    PARAMETERS: p_table TYPE tabname OBLIGATORY,
                p_rows  TYPE I.
    * Creation of dynamic internal table
    DATA: lv_dref             TYPE REF TO data.
    FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE.
    DATA: lv_table  TYPE  string.
    START-OF-SELECTION.
    * Dynamic internal table.
      CREATE DATA lv_dref       TYPE TABLE OF (p_table).
      ASSIGN lv_dref->* TO <fs_table>.
      IF sy-subrc  EQ 0.
    *    EXIT.
      ENDIF.
    data i type i.
    * Get the data
      SELECT  *
            FROM (p_table)
            UP TO p_rows ROWS
            INTO TABLE <fs_table>.
      CONCATENATE 'Table contents : ' p_table INTO lv_table.
    * display the table control.
      CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
        EXPORTING
          header            = lv_table
          tabname           = p_table
          no_button         = space
        TABLES
          table             = <fs_table>
        EXCEPTIONS
          no_more_tables    = 1
          too_many_fields   = 2
          nametab_not_valid = 3
          handle_not_valid  = 4
          OTHERS            = 5.
      IF sy-subrc  EQ 0.
        EXIT.
      ENDIF.
    Getting internal table definition 
    Try this...
    DATA : l_descr_ref TYPE REF TO cl_abap_structdescr.
    l_descr_ref ?= cl_abap_typedescr=>describe_by_data( itab ).
    Now l_descr_ref->components holds the entire list of fields in itab.
    Thanks & Regards,
    ShreeMohan

Maybe you are looking for