Home > Default > Inserting data into dynamic internal tables

Inserting data into dynamic internal tables

November 30Hits:0
Advertisement
Hello everyone, i need some suggestions on the following problem:
I have created a dynamic table that consist of storage locations(SL) belonging to a plant. Each record in the internal table would need to display all the SL on the same line. I have succesfully created it and displayed it on an ALV, the problem now is how to insert data for the dynamically created storage locations:
EXAMPLE: Created dynamic itab
colA | colB | SL1 | SL2 | ... | SLn | colC | <--header
data | data | 100 | 120 | ... | 200 | data | <--record
I would like to insert data from the fields of another itab into SL1 to SLn. How can i go about doing it?
Data from ColA to ColC has been filled through:
<i>loop at itab into w_itab.
move-corresponding w_itab to <dyn_tab>.
endloop.</i>
I cannot do the same to the SLs as the fields is dynamically created during runtime and the fieldname is different from the data that i am to insert in into.
Any ideas?

Answers

Hi,
  I have the following code in my BADI:
ct_value_list is defined in the parameters of the method as a type standard table.
Create values list reference
CREATE DATA lv_value_list_ref LIKE LINE OF ct_value_list.
ASSIGN lv_value_list_ref->* TO <lfs_value_list>.
  IF CT_VALUE_LIST IS INITIAL.
    lv_tabix = sy-tabix.
    IF NOT LT_DATA[] IS INITIAL.
      LOOP AT lt_data assigning <lfs_data>.
        assign <lfs_data> to <lfs_value_list>.
      assign <lfs_value_list> to <lv_value_list>.
        ASSIGN COMPONENT lc_prvar OF STRUCTURE <lfs_value_list>
        TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
Get the material id
        READ TABLE it_matkey_tab ASSIGNING <lfs_matkey>
          WITH KEY matnr = <lfs_attribute>.
        IF sy-subrc = 0.
          lv_matid = <lfs_matkey>-matid.
        ENDIF.
        ENDIF.
        ASSIGN COMPONENT lc_mktgr OF STRUCTURE <lfs_value_list>
          TO <lfs_attribute>.
        IF <lfs_value_list> IS ASSIGNED.
        READ TABLE it_loc ASSIGNING <lfs_loc>
          WITH KEY locno = <lfs_attribute>.
        IF sy-subrc = 0.
          lv_locid = <lfs_loc>-locid.
        ENDIF.
        READ TABLE it_matloc ASSIGNING <lfs_matloc_int>
          WITH KEY matid = lv_matid
                   locid = lv_locid.
       if sy-subrc = 0.
      MATLOC: Assignment of Values - START
          ASSIGN COMPONENT 'MATLOCID'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-matlocid.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
            INSERT <lfs_matloc_int> INTO TABLE <lv_value_list>.
          ENDIF.
          ASSIGN COMPONENT 'PLANNER_SNP'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-planner_snp.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
          ENDIF.
          ASSIGN COMPONENT 'AT101'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-at101.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
          ENDIF.
          ASSIGN COMPONENT 'AT102'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-at102.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
          ENDIF.
          ASSIGN COMPONENT 'AT103'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-at103.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
          ENDIF.
          ASSIGN COMPONENT 'AT104'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-at104.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
          ENDIF.
          ASSIGN COMPONENT 'AT105'
            OF STRUCTURE <lfs_matloc_int> TO <lfs_attribute>.
          IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_matloc_int>-at105.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
          ENDIF.
        endif.
       ENDIF.
        ASSIGN COMPONENT 'PRVAR'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-prvar.
           INSERT <lfs_value_list> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'PARPR'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-parpr.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'VARID'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-varid.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'VARCT'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-varct.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'VARTX'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-vartx.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'DMOAP'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-dmoap.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'PRDID'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-prdid.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'BRFAM'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-brfam.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MATKL'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-matkl.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'BRDIF'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-brdif.
           INSERT <lfs_attribute> INTO TABLE ct_value_list.
        ENDIF.
        ASSIGN COMPONENT 'MEIND'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-meind.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MKLEN'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-mklen.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'PCKTY'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-pckty.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'ITPCK'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-itpck.
           INSERT <lfs_attribute> INTO TABLE ct_value_list.
        ENDIF.
        ASSIGN COMPONENT 'PMEIN'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-pmein.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MKTHK'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-mkthk.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'FLIND'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-flind.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'EDTID'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-edtid.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'BNDTY'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-bndty.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'ITBND'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-itbnd.
            INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'ITCSE'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-itcse.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'TPCOL'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-tpcol.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'SPFLV'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-spflv.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'PRSHP'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-prshp.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MKTGR'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-mktgr.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'SUBMK'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-submk.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'BOMHD'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-bomhd.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'BRDSC'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-brdsc.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MKSTR'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-mkstr.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'EDDSC'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-eddsc.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'EDCAT'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-edcat.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'CCIND'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-ccind.
         INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'CGSTY'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-cgsty.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'FLTTY'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-fltty.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'CPIND'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-cpind.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MBIND'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-mbind.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'USPRP'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-usprp.
         INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'EDDET'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-eddet.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'BRGEW'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-brgew.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'NTGEW'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-ntgew.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'GEWEI'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-gewei.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'VOLUM'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-volum.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'VOLEH'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-voleh.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'DMOAPP1'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-dmoapp1.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'MAKTX'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
           <lfs_attribute> = <lfs_value_list>-maktx.
           INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
        ASSIGN COMPONENT 'RPLVL'
            OF STRUCTURE <lfs_value_list> TO <lfs_attribute>.
        IF <lfs_attribute> IS ASSIGNED.
          <lfs_attribute> = <lfs_value_list>-rplvl.
          INSERT <lfs_attribute> INTO TABLE <lv_value_list>.
        ENDIF.
     ENDLOOP.
    ENDIF.
ENDIF.
I get a shortdump in the code for the above code. There are diff types of inserts that I am trying to do and each one gives a short dump.
Looking forward to your inputs.
Your program is not applicable in my case as I have ct_value_list passed as a changing parameter of type standard table in my APO BADI.
cheers
Aveek

Read other 3 answers

Tags:

Related Articles

  • Inserting data into dynamic internal tablesNovember 30

    Hello everyone, i need some suggestions on the following problem: I have created a dynamic table that consist of storage locations(SL) belonging to a plant. Each record in the internal table would need to display all the SL on the same line. I have s

  • How to insert  data from different internal  table  into a data base tableOctober 11

    hi all,          I want to insert a particular field in an internal table to a field in a data base table.Note that the fields in the internal table and database table are not of the same name since i need to insert data from different internal table

  • How to populate data in dynamic internal tableOctober 11

    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    

  • Popualting data into dynamic internal tableNovember 30

    Hi all,     I am working on Dynamic internal tables.I have created the structure of internal table but i am unable to populate data into it.Though i have seen some of the forums but those didn't help me. please provide me the solution. Here is my cod

  • How to delete data from dynamic internal tableOctober 11

    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

  • How to pass data from dynamic internal table to standard internal tableOctober 11

    hi experts, below is the piece of code which i have used in my requirement but the data is not moved. LOOP AT <tab> ASSIGNING <tab1>.   MOVE-CORRESPONDING <tab1> TO wa.   append wa TO  gt_outtab. ENDLOOP. here <tab> - dynamic inter

  • Populate data in dynamic internal tableOctober 11

    Hi ppl, I have a requirement where I need to display certain fields in the report output. The output contains 8 fixed fields (common for all rows in output) and some dynamic fields (number of column varies with rows) which will be determined at runti

  • How to upload data with dynamic internal tableOctober 11

    Hi, I have to upload the basic , sales, purchasing view data by using bapi depend on check box selected for views. i have filled fieldcatalog for selected views and pass the field catalog structure to dynamic int table and import it into the field sy

  • How to populate data into Dynamic Internal Table.October 11

    Hi Experts, I had created one Dynamic Internal table and one static internal table.I want to move data from Static Internal table to Dynamic interal table.And aslo the number of coloum of these two tables are not same. So please help me for solving t

  • Populate data from dynamic internal tableOctober 11

    Hi I have dynamic internal table <lt_paxxxx>. Iam fillling <lt_paxxxx> in the following way. select * into table <lt_paxxxx> from (infty-dbname). I have to pass data of <lt_paxxxx> to another internal table lt_final. 'lt_final' sho

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.661 s.