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

Similar Messages

  • How to do parallel processing with dynamic internal table

    Hi All,
    I need to implement parallel processing that involves dynamically created internal tables. I tried doing so using RFC function modules (using starting new task and other such methods) but didn't get success this requires RFC enabled function modules and at the same time RFC enabled function modules do not allow generic data type (STANDARD TABLE) which is needed for passing dynamic internal tables. My exact requirement is as follows:
    1. I've large chunk of data in two internal tables, one of them is formed dynamically and hence it's structure is not known at the time of coding.
    2. This data has to be processed together to generate another internal table, whose structure is pre-defined. But this data processing is taking very long time as the number of records are close to a million.
    3. I need to divide the dynamic internal table into (say) 1000 records each and pass to a function module and submit it to run in another task. Many such tasks will be executed in parallel.
    4. The function module running in parallel can insert the processed data into a database table and the main program can access it from there.
    Unfortunately, due to the limitation of not allowing generic data types in RFC, I'm unable to do this. Does anyone has any idea how to implement parallel processing using dynamic internal tables in these type of conditions.
    Any help will be highly appreciated.
    Thanks and regards,
    Ashin

    try the below code...
      DATA: w_subrc TYPE sy-subrc.
      DATA: w_infty(5) TYPE  c.
      data: w_string type string.
      FIELD-SYMBOLS: <f1> TYPE table.
      FIELD-SYMBOLS: <f1_wa> TYPE ANY.
      DATA: ref_tab TYPE REF TO data.
      CONCATENATE 'P' infty INTO w_infty.
      CREATE DATA ref_tab TYPE STANDARD TABLE OF (w_infty).
      ASSIGN ref_tab->* TO <f1>.
    * Create dynamic work area
      CREATE DATA ref_tab TYPE (w_infty).
      ASSIGN ref_tab->* TO <f1_wa>.
      IF begda IS INITIAL.
        begda = '18000101'.
      ENDIF.
      IF endda IS INITIAL.
        endda = '99991231'.
      ENDIF.
      CALL FUNCTION 'HR_READ_INFOTYPE'
        EXPORTING
          pernr           = pernr
          infty           = infty
          begda           = '18000101'
          endda           = '99991231'
        IMPORTING
          subrc           = w_subrc
        TABLES
          infty_tab       = <f1>
        EXCEPTIONS
          infty_not_found = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        subrc = w_subrc.
      ELSE.
      ENDIF.

  • 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

  • Declare dynamic internal table during runtime error

    Hi Gurus,
    I have encounter a problem here. I would like to have several block of alv list output; for each customer open items details. Thus, i need to create dynamic internal table duirng runtime as i do not know how many customers that should be output before user enter from the selection screen field for customer code.
    I tried to search in the forums and found this website [Runtime Declaration of Internal Table;.
    But when i tried to execute it, i have an error. The field symbols that i passed into the call function REUSE_ALV_BLOCK_LIST_APPEND for parameter t_outtab does not match. May i know how do i go about it?
    Or are there any other solutions to display this kind of reports? I ever think of using hierarchy list alv. But it does not match the requirement. I would like to display the total amount for each customer. Can hierarchy list able to do so? Or it can only display as the grand total at the end of the report? I think it would be best to display as alv block output.
    Your help will be much appreciated. <offer removed by moderator>
    Thanks
    Edited by: Thomas Zloch on Oct 22, 2010 11:23 AM

    the problem comes up, when there are fields in the table which represent numbers with decimals (type p). Best is to reference the field directly what comes from SAP. Replace the LOOP At idetails ... ENDLOOP with:
    LOOP AT idetails INTO xdetails.
        CLEAR xfc.
        xfc-fieldname = xfc-ref_field = xdetails-name .
        xfc-ref_table   = p_table.
    *    xfc-datatype = xdetails-type_kind.
    *    xfc-inttype = xdetails-type_kind.
    *    xfc-intlen = xdetails-length.
    *    xfc-decimals = xdetails-decimals.
        APPEND xfc TO ifc.
      ENDLOOP.

  • Need to make the internal table structure dynamic

    Hi ,
    I need to upload data from an excel file, the columns in the excel keep on varying
    E.g the number of columns in one excel file can be 10, in the second excel file it can be 15.
    So in order to upload the data into an internal table the structre of internal table needs to be dynamic and change according to the number of fields in the input file .
    Is it possible by using field symbols or is there any other method to do the same
    Thanks.
    Nishant
    Edited by: nishant patel on Sep 17, 2009 10:48 AM

    Hi Nishant,
    According to ur requirement, dynamic internal table can be created like below. But database table name has to passed dynacimally.
        DATA: ftab TYPE STANDARD TABLE OF ddfield,
              ftab_wa TYPE ddfield,
              fcat_itab TYPE lvc_t_fcat,
              fcat_wa TYPE lvc_s_fcat,
              poi_itab TYPE REF TO data.
    FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
        CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
          EXPORTING
            tabname  = p_table  " Pass database table name dynamically
          TABLES
            ddfields = ftab.
        LOOP AT ftab INTO ftab_wa.
          fcat_wa-fieldname = ftab_wa-fieldname.
          fcat_wa-ref_field = ftab_wa-fieldname.
          fcat_wa-ref_table = p_table.
          APPEND fcat_wa TO fcat_itab.
        ENDLOOP.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog           = fcat_itab
          IMPORTING
            ep_table                  = poi_itab
          EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.
        ASSIGN poi_itab->* TO <itab>.  " <itab> is dynamic internal table
    Might help u.
    Thanks.
    Edited by: Sap Fan on Sep 17, 2009 1:19 PM

  • Need urgent help on dynamic internal table.

    Hi experts,
    I got an editable dynamic internal table. When the value in 1 of the editable field has been changed, I will fire the the DATA_CHANGED event. In this event, I can get the row ID where the changes occur, but the problem is, how can I select back the data from the dynamic internal table using the row ID since index is not permitted to be used? I need to get the rest of the records form the ROW and then perform a database update accordingly. How can I select from the dynamic internal table given the row ID? THanks in advance.

    Hi
    I suppose it depends on the kind of internal table assigned to fieldsymbol, this sample works fine:
    FIELD-SYMBOLS: <FS> TYPE TABLE,
                   <WA> TYPE ANY.
    DATA: BEGIN OF ITAB OCCURS 0,
            FIELD,
          END   OF ITAB.
    DO 10 TIMES.
      ITAB-FIELD = 'a'.
      APPEND ITAB.
    ENDDO.
    ASSIGN ITAB[] TO <FS>.
    READ TABLE <FS> ASSIGNING <WA> INDEX 1.
    WRITE <WA>.
    It can't use the index with internal table of kind HASHED.
    Max

  • Need ALV LIST for displaying Dynamic Internal Tables

    Hi Guys,
                     I have some thing like 2 Dynamic internal tables.
    Say 1st Internal table will be filled based on some condition.
    say 2nd table will be filled based on some condition.
    When appending the 1st Internal table, if that internal table is filled it creates another internal table of same kind and continues so on until some condition.
    In the same way when appending the 2nd Internal table, if that internal table is filled it creates another internal table of same kind and continues so on until some condition.
    My requirement is I need to display all these Internal tables in the output.
    The output should look something like
    1st Internal Table
    some gap
    2nd Internal Table
    some gap
    so on...................
    Is there any standard ALV List, to display all these Internal Tables in such a way.
    Thanks,
    Prasad.

    Hi.
    One thing more here is code which get 10 records from 2 tables and then show them in ALV.
    first when u execute it will show data from ist table.
    when u go back (F3) then it will sow data from 2nd table.
    But if u want to show both ALV on the same screen then u will have to use screen programin and using class u will have to create container and then have to do it.
    But as i above mentioned. that sample code is as below.
    REPORT ztn_test LINE-COUNT 100.
      data: itab_ref type ref to data.
      data: hstr type lvc_title.
    data: tabname like DD02T-TABNAME.
       tabname = 'MARA'. " First Table
      create data itab_ref type standard table of (tabname).
      field-symbols: <itab> type standard table.
      assign itab_ref->* to <itab>.
      select * UP TO 10 ROWS from (tabname) into corresponding fields of table <itab>.
      perform showalv.
       tabname = 'KNA1'. " 2nd Table
      create data itab_ref type standard table of (tabname).
      "field-symbols: <itab> type standard table.
      assign itab_ref->* to <itab>.
      select * UP TO 10 ROWS from (tabname) into corresponding fields of table <itab>.
      perform showalv.
    form showalv.
    " to show that data in alv
      type-pools: slis.
      data: myalv type ref to cl_gui_alv_grid,    "ALV Grid
            fieldcat type slis_t_fieldcat_alv,    "Field Catalog Table
            ls_fcat type slis_fieldcat_alv,       "Line of Field catalog.
            ls_heading type slis_listheader,      "Line of Heading.
            layout type slis_layout_alv,          "layout of ALV for Heading and Logo.
            event type slis_t_event,              "Event Raising to Display Heading.
            event_str type slis_alv_event.        "Event String.
    type-pools: slis.
    data: heading type slis_t_listheader.       "List Heading.
      if heading[] is initial.
        ls_heading-typ = 'H'.
        ls_heading-info = 'HR: Master Data Change History'.
        append ls_heading to heading.
      endif.
    *  ls_heading-typ = 'A'.
    *  ls_heading-info = ''.
    *  APPEND ls_heading TO heading.
    *                          ALV DISPLAY                        *
    *******Making Layout of ALV
      layout-zebra = 'X'.
      layout-colwidth_optimize = 'X'.
    *Calling function to raise event to display heading and icon above ALV
      call function 'REUSE_ALV_EVENTS_GET'
       exporting
         i_list_type           = 0
       importing
         et_events             = event[]
    * EXCEPTIONS
    *   LIST_TYPE_WRONG       = 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.
    ******calling TOP_OF_PAGE Event
      read table event with key name = 'TOP_OF_PAGE' into event_str.
      if sy-subrc = 0.
        move: 'TOP_OF_PAGE' to event_str-form.
        modify event from event_str index sy-tabix.
      endif.
    **** Now use this Fuction to display ALV without any Screen Programming.
      call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
    *   I_INTERFACE_CHECK                 = ' '
    *   I_BYPASSING_BUFFER                = ' '
    *   I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = 'SAPLZFSL_HR_UTILS' "sy-cprog
    *   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                  = tabname
    *   I_BACKGROUND_ID                   = ' '
         i_grid_title                      = hstr   "Heading of ALV Grid.
    *   I_GRID_SETTINGS                   =
         is_layout                         = layout
    *   it_fieldcat                       = fieldcat[]
    *   IT_EXCLUDING                      =
    *   IT_SPECIAL_GROUPS                 =
    *   IT_SORT                           =
    *   IT_FILTER                         =
    *   IS_SEL_HIDE                       =
         i_default                         = 'X'
         i_save                            = 'X'
    *   IS_VARIANT                        =
         it_events                         = event[]
    *   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                          = <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.
    endform.

  • SET_TABLE_FOR_DISPLAY - Edited value from dynamic internal table need to be captured

    Hi all,
    I have created  2 tabstrip screns which contain ALV GRID DISPLAY  in a container with dynamic internal table and editable columns .I want to capture the edited value from this ALV GRID display.I have used SET_TABLE_FOR_DISPLAY  and for this dynamc internal table is passed which is Field symbol and editable columns have to be captured for further updation into another ztable.
    When i used check_changed_data  i am getting dump as field symbol not assigned.
    Below is the code :  How can i get edited column value from below code
    call method alv_list->set_table_for_first_display
        exporting
                is_layout                     = gs_layout
        changing
          it_outtab                     = <fs_dynamic_table>
          it_fieldcatalog               = it_fieldcat[]
        exceptions
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          others                        = 4.
      if sy-subrc <> 0.
    * Implement suitable error handling here
      endif.
    Kindly help me to solve this.
    With Thanks,
    Dina.

    please provide more info about the dump to try to help you
    as max said, it could be because the field symbol is not global and if its global maybe you are not refering well to the column
    i assume that you are using "ASSIGN COMPONENT comp OF STRUCTURE struc TO <fs>" to capture the value changed
    validate always the sy-subrc after the assignment.
    but the check changed data have parameters that have the old and new values
    please provide more info...
    Regards

  • Populate Final internal table from Dynamic internal table

    Hello,
    I have ti display data in ALV grid whose structure is fixed. I am dynamically selecting data iin an internal table.
    Now from this dynamic internal table, i need to populate my final internal table whose structurte is fixed.
    Please help.
    Rgds,
    Himanshu

    Hello Himanshu,
    When you say dynamic internal table there are two things one is the actual structure and other one is field table that holds information for all the fields used to create dynamic internal table.
    No if you want to move data from dynamic table to fixed internal table then you can try as follows:
    1.
    field-symbols <field_name> TYPE C.
    field-symbols <field_value> TYPE C.
    Now you either use
    LOOP AT fields_itab.
    ASSIGN fields_itab-fieldname to <field_name>.
    ASSIGN COMPONENT <field_name> OF STRUCTURE <structure_name> TO <field_value>
    Now you move value from <field_value> to required field in fixed internal table.
    i.e.
    itab-fieldname = <field_value>.
    Other way to do this:
    If you fields order is constant then you can also use index in assign component statement.
    do <no_of_fields> times.
        ASSIGN COMPONENT sy-index OF STRUCTURE <structure_name> TO <field_value>.
    rest is same as first method.
    Hope this help!
    I have given sudo code and you need to work on it little.
    Thanks,
    Augustin.

  • How to populate data in dynamic internal table

    Hi Expert,
    fyi. My dynamic internal table field is created base on data selected. Eg. select table qpcd has 5 records.  These 5 recods will become fieldname to my dynamic internal table. My dynamic internal table will be
    ...itab
          01
          02
          03
          04
          05
    The 5 records from qpcd is populated in another table call viqmel.  I need to find the occurance of each code in viqmel and populate the number of occurance in itab in each of column.  The final dynamic itab will be like this
    table itab
    01       02     03    04     05   -
    > field name
    2         0        1     0       1    -
    > data
    my source code like below
    Report ZPLYGRND2.
    TABLES: mara, makt.
    TYPE-POOLS: slis, sydes.
    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.
    types : begin of t_qpcd,
             codegruppe like qpcd-codegruppe,
             code like qpcd-code,
            end of t_qpcd.
    data:wa_qpcd type t_qpcd,
         i_qpcd type standard table of t_qpcd initial size 0.
    FIELD-SYMBOLS: <l_table> TYPE table,
                   <l_line> TYPE ANY,
                   <l_field> TYPE ANY.
    select * into corresponding fields of wa_qpcd from qpcd
    where katalogart = 'D'
    and   codegruppe = 'OOT01'.
    append wa_qpcd to i_qpcd.
    endselect.
    loop at i_qpcd into wa_qpcd.
      is_fcat-fieldname = wa_qpcd-code.
      APPEND is_fcat TO it_fcat.
    endloop.
    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.
    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.
    if sy-subrc = 0.
    endif.
    *... 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>.
    LOOP AT <l_table> INTO <l_line>.
    ENDLOOP.

    hello dear i m giving u a code in this a dynamic table is made on the basis of table in database , and u can download this data correct it , see it, or even change it....and upload in tht table help full if u dont know the table name...in advance.
    also the code to populate data in dynamic table is in this code like:
    SELECT * FROM (MTABLE_N)
    INTO CORRESPONDING FIELDS OF TABLE <FS_ITAB> .
    look at the whole program .hope this solve ur problem thanks.
    REPORT ZTESTA  MESSAGE-ID ZIMM    .
    TYPES : DATA_OBJECT TYPE REF TO DATA.
    DATA : MITAB TYPE REF TO DATA .
    TYPE-POOLS : SLIS .
    DATA : IT_FIELDCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV
    WITH HEADER LINE .
    DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT .
    DATA : WA_FIELDCATALOG TYPE LVC_S_FCAT .
    DATA : I_STRUCTURE_NAME LIKE DD02L-TABNAME .
    DATA : I_CALLBACK_PROGRAM LIKE SY-REPID .
    DATA : DYN_LINE TYPE DATA_OBJECT .
    FIELD-SYMBOLS : <FS_ITAB> TYPE STANDARD TABLE .
    DATA : TABLE_NAME_IS_VALID TYPE C .
    DATA : DYNAMIC_IT_INSTANTIATED TYPE C .
    CONSTANTS BUTTONSELECTED TYPE C VALUE 'X' .
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_TABL.
    PARAMETERS : MTABLE_N LIKE RSRD1-TBMA_VAL
    MATCHCODE OBJECT DD_DBTB_16 OBLIGATORY .
    DATA CHECKTABLED.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_FILE.
    PARAMETERS : MFILENAM LIKE RLGRAP-FILENAME .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_DOWN.
    PARAMETERS : P_DOWNLD RADIOBUTTON GROUP GRP1
    USER-COMMAND M_UCOMM .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_CHKF.
    PARAMETERS : P_CHKFIL RADIOBUTTON GROUP GRP1 .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_UPLD.
    PARAMETERS : P_UPLOAD RADIOBUTTON GROUP GRP1 .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_SHOW.
    PARAMETERS : P_SHOW_T RADIOBUTTON GROUP GRP1 .
    SELECTION-SCREEN END OF LINE.
    AT SELECTION-SCREEN OUTPUT .
      PERFORM CHECK_FILENAME .
    AT SELECTION-SCREEN.
      IF SY-UCOMM = 'ONLI'.
        CHECKTABLED = MTABLE_N+0(1).
        IF CHECKTABLED NE 'Z'.
          MESSAGE I017.
          LEAVE TO SCREEN 1000.
        ENDIF.
        IF SY-UNAME NE 'KAMESH.K'.
          MESSAGE I023 WITH SY-UNAME.
          LEAVE TO SCREEN 1000.
        ENDIF.
      ENDIF.
      IF SY-UCOMM = 'PRIN'.
        CHECKTABLED = MTABLE_N+0(1).
        IF CHECKTABLED NE 'Z'.
          MESSAGE I017.
          LEAVE TO SCREEN 1000.
        ENDIF.
        IF SY-UNAME NE 'KAMESH.K'.
          MESSAGE I023 WITH SY-UNAME.
          LEAVE TO SCREEN 1000.
        ENDIF.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR MFILENAM .
      PERFORM F4_FOR_FILENAME .
    INITIALIZATION .
      T_TABL = 'Table Name' .
      T_FILE = 'File Name' .
      T_DOWN = 'Download Table' .
      T_CHKF = 'Check File to Upload' .
      T_UPLD = 'Upload File' .
      T_SHOW = 'Show Table Contents' .
    START-OF-SELECTION .
      PERFORM CHECK_TABLE_NAME_IS_VALID .
    END-OF-SELECTION .
      IF TABLE_NAME_IS_VALID EQ ' ' .
        MESSAGE I398(00) WITH 'INVALID TABLE NAME' .
      ELSE .
        PERFORM INSTANTIATE_DYNAMIC_INTERNAL_T .
        CHECK DYNAMIC_IT_INSTANTIATED = 'X' .
        CASE BUTTONSELECTED .
          WHEN P_DOWNLD .
            PERFORM SELECT_AND_DOWNLOAD .
          WHEN P_CHKFIL .
            PERFORM CHECK_FILE_TO_UPLOAD .
          WHEN P_UPLOAD .
            PERFORM UPLOAD_FROM_FILE .
          WHEN P_SHOW_T .
            PERFORM SHOW_CONTENTS .
        ENDCASE .
      ENDIF .
    FORM CHECK_TABLE_NAME_IS_VALID.
      DATA MCOUNT TYPE I .
      TABLES DD02L .
      CLEAR TABLE_NAME_IS_VALID .
      SELECT COUNT(*) INTO MCOUNT FROM TADIR
      WHERE PGMID = 'R3TR'
      AND OBJECT = 'TABL'
      AND OBJ_NAME = MTABLE_N .
      IF MCOUNT EQ 1 .
        CLEAR DD02L .
        SELECT SINGLE * FROM DD02L WHERE TABNAME = MTABLE_N .
        IF SY-SUBRC EQ 0.
          IF DD02L-TABCLASS = 'TRANSP' .
            TABLE_NAME_IS_VALID = 'X' .
          ENDIF .
        ENDIF.
      ENDIF .
    ENDFORM. " CHECK_TABLE_NAME_IS_VALID
    FORM SELECT_AND_DOWNLOAD.
      CLEAR : <FS_ITAB> .
      SELECT * FROM (MTABLE_N)
      INTO CORRESPONDING FIELDS OF TABLE <FS_ITAB> .
      PERFORM CHECK_FILENAME.
      CALL FUNCTION 'WS_DOWNLOAD'
           EXPORTING
                FILENAME                = MFILENAM
                FILETYPE                = 'DAT'
           TABLES
                DATA_TAB                = <FS_ITAB>
           EXCEPTIONS
                FILE_OPEN_ERROR         = 1
                FILE_WRITE_ERROR        = 2
                INVALID_FILESIZE        = 3
                INVALID_TYPE            = 4
                NO_BATCH                = 5
                UNKNOWN_ERROR           = 6
                INVALID_TABLE_WIDTH     = 7
                GUI_REFUSE_FILETRANSFER = 8
                CUSTOMER_ERROR          = 9
                OTHERS                  = 10.
      IF SY-SUBRC EQ 0.
        MESSAGE I398(00) WITH 'Table' MTABLE_N
        'successfully downloaded to '
        MFILENAM .
      ENDIF.
    ENDFORM. " SELECT_AND_DOWNLOAD
    FORM UPLOAD_FROM_FILE.
      DATA : ANS TYPE C .
      DATA : LINES_OF_ITAB TYPE I .
      DATA : MSY_SUBRC TYPE I .
      CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
           EXPORTING
                TEXTLINE1 = 'Are you sure you wish to upload'
                TEXTLINE2 = 'data from ASCII File to DB table '
                TITEL     = 'Confirmation of Data Upload'
           IMPORTING
                ANSWER    = ANS.
      IF ANS = 'J' .
        PERFORM CHECK_FILENAME.
        CLEAR MSY_SUBRC .
        CALL FUNCTION 'WS_UPLOAD'
             EXPORTING
                  FILENAME                = MFILENAM
                  FILETYPE                = 'DAT'
             TABLES
                  DATA_TAB                = <FS_ITAB>
             EXCEPTIONS
                  CONVERSION_ERROR        = 1
                  FILE_OPEN_ERROR         = 2
                  FILE_READ_ERROR         = 3
                  INVALID_TYPE            = 4
                  NO_BATCH                = 5
                  UNKNOWN_ERROR           = 6
                  INVALID_TABLE_WIDTH     = 7
                  GUI_REFUSE_FILETRANSFER = 8
                  CUSTOMER_ERROR          = 9
                  OTHERS                  = 10.
        MSY_SUBRC = MSY_SUBRC + SY-SUBRC .
        IF SY-SUBRC EQ 0.
          DESCRIBE TABLE <FS_ITAB> LINES LINES_OF_ITAB .
          IF LINES_OF_ITAB GT 0 .
            MODIFY (MTABLE_N) FROM TABLE <FS_ITAB> .
            MSY_SUBRC = MSY_SUBRC + SY-SUBRC .
          ENDIF .
        ENDIF.
        IF MSY_SUBRC EQ 0 .
          MESSAGE I398(00) WITH LINES_OF_ITAB
          'Record(s) inserted in table'
          MTABLE_N .
        ELSE .
          MESSAGE I398(00) WITH
          'Errors occurred No Records inserted in table'
          MTABLE_N .
        ENDIF .
      ENDIF .
    ENDFORM. " UPLOAD_FROM_FILE
    FORM F4_FOR_FILENAME.
      CALL FUNCTION 'WS_FILENAME_GET'
           EXPORTING
                DEF_PATH         = 'C:\'
                MASK             = ',.,..'
                MODE             = '0'
           IMPORTING
                FILENAME         = MFILENAM
           EXCEPTIONS
                INV_WINSYS       = 1
                NO_BATCH         = 2
                SELECTION_CANCEL = 3
                SELECTION_ERROR  = 4
                OTHERS           = 5.
    ENDFORM. " F4_FOR_FILENAME
    FORM CHECK_FILENAME.
      IF MFILENAM IS INITIAL
      AND NOT ( MTABLE_N IS INITIAL )
      AND P_SHOW_T NE BUTTONSELECTED.
        CONCATENATE 'C:\'
        MTABLE_N '.TXT' INTO MFILENAM.
      ENDIF .
    ENDFORM. " CHECK_FILENAME
    FORM INSTANTIATE_DYNAMIC_INTERNAL_T.
      CLEAR DYNAMIC_IT_INSTANTIATED .
      I_STRUCTURE_NAME = MTABLE_N .
      CLEAR IT_FIELDCAT[] .
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
           EXPORTING
                I_STRUCTURE_NAME       = I_STRUCTURE_NAME
           CHANGING
                CT_FIELDCAT            = IT_FIELDCAT[]
           EXCEPTIONS
                INCONSISTENT_INTERFACE = 1
                PROGRAM_ERROR          = 2
                OTHERS                 = 3.
      IF SY-SUBRC EQ 0.
        LOOP AT IT_FIELDCAT .
          CLEAR WA_FIELDCATALOG .
          MOVE-CORRESPONDING IT_FIELDCAT TO WA_FIELDCATALOG .
          WA_FIELDCATALOG-REF_FIELD = IT_FIELDCAT-FIELDNAME .
          WA_FIELDCATALOG-REF_TABLE = MTABLE_N .
          APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG .
        ENDLOOP .
        CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
        IT_FIELDCATALOG = IT_FIELDCATALOG
        IMPORTING
        EP_TABLE = MITAB .
        ASSIGN MITAB->* TO <FS_ITAB> .
        DYNAMIC_IT_INSTANTIATED = 'X' .
      ENDIF.
    ENDFORM. " INSTANTIATE_DYNAMIC_INTERNAL_T
    FORM SHOW_CONTENTS.
      CLEAR : <FS_ITAB> .
      SELECT * FROM (MTABLE_N)
      INTO CORRESPONDING FIELDS OF TABLE <FS_ITAB> .
      I_CALLBACK_PROGRAM = SY-REPID .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM = I_CALLBACK_PROGRAM
                IT_FIELDCAT        = IT_FIELDCAT[]
           TABLES
                T_OUTTAB           = <FS_ITAB>
           EXCEPTIONS
                PROGRAM_ERROR      = 1
                OTHERS             = 2.
    ENDFORM. " SHOW_CONTENTS
    FORM CHECK_FILE_TO_UPLOAD.
      PERFORM CHECK_FILENAME.
      CALL FUNCTION 'WS_UPLOAD'
           EXPORTING
                FILENAME                = MFILENAM
                FILETYPE                = 'DAT'
           TABLES
                DATA_TAB                = <FS_ITAB>
           EXCEPTIONS
                CONVERSION_ERROR        = 1
                FILE_OPEN_ERROR         = 2
                FILE_READ_ERROR         = 3
                INVALID_TYPE            = 4
                NO_BATCH                = 5
                UNKNOWN_ERROR           = 6
                INVALID_TABLE_WIDTH     = 7
                GUI_REFUSE_FILETRANSFER = 8
                CUSTOMER_ERROR          = 9
                OTHERS                  = 10.
      IF SY-SUBRC EQ 0.
        I_CALLBACK_PROGRAM = SY-REPID .
        CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
             EXPORTING
                  I_CALLBACK_PROGRAM = I_CALLBACK_PROGRAM
                  IT_FIELDCAT        = IT_FIELDCAT[]
             TABLES
                  T_OUTTAB           = <FS_ITAB>
             EXCEPTIONS
                  PROGRAM_ERROR      = 1
                  OTHERS             = 2.
      ENDIF .
    ENDFORM. " CHECK_FILE_TO_UPLOAD
    Message was edited by:
            SAURABH SINGH
            SENIOR EXECUTIVE
            SAMSUNG INDIA ELECTRONICS LTD.,NOIDA

  • Logic for retreiving the values from a dynamic internal table

    Hi all,
    I have an issue with the logic to fetch data from a dynamic internal table into fields. let me give you guys an example the sy-tfill = 9 (subject to vary). I need to populate the fields.
    Regards,
    Sukumar

    Hi,
    this is for printing out the info in a dynamic table,
    it will work likewise to insert data.
    PARAMETERS:
      p_tabnam TYPE tabname DEFAULT 'DB_TABLE_NAME'.
    DATA:
      lv_dref TYPE REF TO data,
      ls_dd03l LIKE dd03l,
      lt_fieldname TYPE TABLE OF fieldname,
      ls_fieldname TYPE fieldname.
    FIELD-SYMBOLS:
      <fs> TYPE STANDARD TABLE,
      <wa_comp> TYPE fieldname,
      <wa_data> TYPE ANY,
      <wa_field> TYPE ANY.
    REFRESH lt_fieldname.
    SELECT * FROM dd03l INTO ls_dd03l
                       WHERE as4local = 'A'
                         AND as4vers  = '0000'
                         AND tabname  = p_tabnam
                       ORDER BY position.
      ls_fieldname = ls_dd03l-fieldname.
      APPEND ls_fieldname TO lt_fieldname.
    ENDSELECT.
    IF NOT ( lt_fieldname[] IS INITIAL ).
      CREATE DATA lv_dref TYPE TABLE OF (p_tabnam).
      ASSIGN lv_dref->* TO <fs>.
      SELECT * FROM (p_tabnam) INTO TABLE <fs>.
      WRITE:
        / 'CONTENTS OF TABLE', p_tabnam.
      LOOP AT <fs> ASSIGNING <wa_data>.
        SKIP.
        WRITE:
          / 'LINE', sy-tabix.
        ULINE.
        LOOP AT lt_fieldname ASSIGNING <wa_comp>.
          ASSIGN COMPONENT sy-tabix OF STRUCTURE <wa_data> TO <wa_field>.
          WRITE:
            / <wa_comp>, <wa_field>.
        ENDLOOP.
      ENDLOOP.
    ENDIF.
    grtz
    Koen

  • How to delete data from dynamic internal table

    Hi,
    I have dynamic internal table and I have some slection screen fields , using these selection screen fields
    (select -options), I have to filter the data? assigning will work with READ , but I have select options not the parametre,
    and also delete will not work for dynamic table..
    as we cannot use assigning with delete..
    So how to do this?
    and one more thing is , I cannot filter the data while selection( in select, I cannot filter the data-> as it's not coming directly from table, it's coming from buffer),
    so now after selection of data, I need to filter the data from dynamic table.
    Is there any way to do this?
    Regards,
    Mrunal

    Hi matt,
    I tried with below code as  you said. But I am getting dump. can you help?
    here is my piece of code.
    FIELD-SYMBOLS: <LS_DATA> type any,
                               <LT_DATA> TYPE table,
                                <L_FIELD> type any.
        ASSIGN <l_buffer_entry>-dataptr->* TO <LS_DATA>.
        ASSIGN <l_buffer_entry>-dataptr->* TO <LT_DATA>.
    LOOP AT <LT_DATA> ASSIGNING <LS_DATA>.
    ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <LS_DATA> TO <L_FIELD>.
    IF <L_FIELD> NOT IN SO_BUKRS.
    DELETE <LT_DATA>.
    ENDIF.
    UNASSIGN <L_FIELD>.
    ASSIGN COMPONENT 'BELNR' OF STRUCTURE <LS_DATA> TO <L_FIELD>.
    IF <L_FIELD> NOT IN SO_BELNR.
    DELETE <LT_DATA>.
    ENDIF.
    UNASSIGN <L_FIELD>.
    ENDLOOP.
    and here is the description of my dump:->>>
    You attempted to access an unassigned field symbol
    (data segment 32772).
    This error may occur for any of the following reasons:
    - You address a typed field symbol before it is set using ASSIGN
    - You address a field symbol that points to a line in an internal table
      that has been deleted
    - You address a field symbol that had previously been reset using
      UNASSIGN, or that pointed to a local field that no longer exists
    - You address a global function interface parameter, even
      though the relevant function module is not active,
      that is it is not in the list of active calls. You can get the list
      of active calls from the this short dump.

  • Create a deep structure for dynamic internal table

    Hi All,
    I am creating a dynamic table using method cl_alv_table_create=>create_dynamic_table.
    The normal structure gets created. but now I want to creat a Deep structure for having information of colors also for each column. So I want to add a COLTAB type LVC_T_SCOL for colors information .
    How should I create this using above method?
    Rgds,
    Madhuri

    I created a zcelltab structure as below. But while creating dynamic internal table, I received the error  with
    'Type "ZCELLTAB" is unknown 68 ZCELLTAB-CELLTAB
    Here is the code.
    DATA: BEGIN OF ZCELLTAB,
             CELLTAB LIKE LVC_S_STYL,
         END OF ZCELLTAB.
    FIELD-SYMBOLS <T_CELLTAB> TYPE LVC_T_STYL.
    DATA : LT_CELLTAB TYPE LVC_T_STYL.
    DATA:  WA_CELLTAB TYPE LINE OF LVC_T_STYL.
    DATA: GT_FCAT1 TYPE LVC_T_FCAT,
               GW_FCAT1 TYPE LVC_S_FCAT,
                GT_FCAT2 TYPE LVC_T_FCAT,
                GW_FCAT2  TYPE LVC_S_FCAT.
    After filling the FCAT1, I added the field in FCAT2  like below
      GT_FCAT2[ ] = GT_FCAT1[ ].
      G_TABIX = G_TABIX + 1.
      GW_FCAT2-INTTYPE = 'C'.
      MOVE G_TABIX TO GW_FCAT2-COL_POS.
      GW_FCAT2-OUTPUTLEN = '10'.
      GW_FCAT2-FIELDNAME = 'T_CELLTAB'.
      GW_FCAT2-TABNAME = 'ZCELLTAB'.
      GW_FCAT2-REF_FIELD = 'CELLTAB'.
      GW_FCAT2-REF_TABLE = 'ZCELLTAB'.
      APPEND GW_FCAT2 TO GT_FCAT2
      CLEAR GW_FCAT2.
    While calling the below method, the error with
    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
         EXPORTING
          IT_FIELDCATALOG = GT_FCAT2
        IMPORTING
          EP_TABLE        = GT_REQ.
      ASSIGN GT_REQ->* TO <F_TAB>.
      CREATE DATA GWA_REQ LIKE LINE OF <F_TAB>.
      ASSIGN GWA_REQ->* TO <F_WA>.
    LOOP AT ITAB.
    ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <F_WA> TO <F_VAL>
    <F_VAL> = ITAB-MATNR.
    IF ITAB-MATNR IS INITIAL.
    ASSIGN COMPONENT 'T_CELLTAB' OF STRUCTURE <F_WA> TO <T_CELLTAB>
            CLEAR WA_CELLTAB.
            WA_CELLTAB-FIELDNAME = 'MATNR'.
            WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
            INSERT WA_CELLTAB INTO TABLE <T_CELLTAB>.
    ENDIF.
    APPEND <F_WA> TO <F_TAB>
    ENDLOOP.
    CALL METHOD GR_GRID->SET_TABLE_FOR_FIRST_DISPLAY
            EXPORTING
              I_CONSISTENCY_CHECK  = G_CONSISTENCY_CHECK
              IT_TOOLBAR_EXCLUDING = G_EXCLUDE
              I_SAVE               = G_SAVE
           I_DEFAULT            = 'X'
              IS_LAYOUT            = G_LAYOUT
            CHANGING
              IT_OUTTAB            = <F_TAB>
              IT_FIELDCATALOG      = F_CAT1.
    Please let me know where I was wrong.
    Should I remove the T_CELLTAB as the field name is not mentioned in the structure 'ZCELLTAB'.
    Thanks,
    Kumar.
    Edited by: venn e on May 7, 2010 4:10 PM

  • 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.

  • How to populate dynamic internal table fields with data??

    Hi Folks,
    How to assign a particular internal table field to a dynamically assigned internal table?
    I have an excel sheet, and i upload the excel sheet data into an internal IT_EXLOAD table using FM ALSM_EXCEL_TO_INTERNAL_TABLE
    Now i created a dynamic internal table which has the same column as in my DB table.
    I have to fill the dynamically created Internal table with the IT_EXLOAD data dynamically.
    Suppose in future if i add some field in DB table and for that field if i add some column in excel sheet there is no need to change in the program.
    Looking for reply...
    Best Regards,
    Sayak

    hi,
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                filename                = p_path
                i_begin_col             = '1'
                i_begin_row             = '2'
                i_end_col               = '2'
                i_end_row               = '1000'
           TABLES
                intern                  = intern
           EXCEPTIONS
                inconsistent_parameters = 1
                upload_ole              = 2
                OTHERS                  = 3.
    *declare intern_tmp as internal table tb_data in wich you want the data
    *and declare a field symbol <fs_123>
    LOOP AT intern.
        ASSIGN COMPONENT intern-col OF STRUCTURE
        intern_tmp TO <fs_123>.
        IF NOT <fs_123> IS ASSIGNED.
          CLEAR intern.
          CLEAR intern_tmp.
          CONTINUE.
        ENDIF.
        <fs_123> = intern-value.
        AT END OF row.
          CLEAR tb_data.
          MOVE-CORRESPONDING: intern_tmp TO tb_data.
          APPEND tb_data.
          CLEAR intern_tmp.
        ENDAT.
        CLEAR intern.
      ENDLOOP.
    **paste this code and you can see the data in ur tables dynamically.
    Thanks
    Nitin Sachdeva

Maybe you are looking for