Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Internal table and Work area for a Field List

former_member229034
Participant
0 Kudos

Hi Team,

We have a data mapping scenario, where data is mapped from TABLE A to TABLE A. The SOURCE & TARGET fields that are to be populated respectively are maintained as a list of values in a custom table as shown below:

COLUMN 1

(Table A - Source Field)

COLUMN 2

(Table B - Target Field)

FIELD1FIELD1
FIELD2FIELD2
FIELD3FIELD3
FIELD4FIELD4
FIELD5FIELD5
FIELD....NFIELD....N

The above list of fields is subject to change frequently and the source and the target fields will be added/changed/removed.

We need to create dynamic internal table & work areas for both the above field lists. This helps the data can be taken from the respective source fields and be populated into the respective fields of the target table. Though I have worked on creating dynamic internal tables and work areas, this seems a bit different. Your inputs pls....

Thank you in Advance,

Chaitanya

1 ACCEPTED SOLUTION

former_member205763
Active Contributor
0 Kudos

you can loop on your ztable having these fields and use assign component to refer to fields of table A and table B and assign the values.

for ex:

Loop at itab into wa.

Assign component (wa-col1) OF structure WA_TABLEA assigning <FS_A>.

Assign component (wa-col2) OF structure WA_TABLEB assigning <FS_B>.

<FS_B> = <FS_A>.

A rough outline of what you can do, can you build your logic around this? I'm not able to see the need for dynamic internal table, may be u can elaborate?

8 REPLIES 8

Former Member
0 Kudos

Hi Chaitanya,

If only in table A and table B have a type and length column of related fields:

Column1 Type length

field1       C      4

field2       C      10.

....

fieldN       D      8.

then you can refer this link, http://wiki.scn.sap.com/wiki/display/Snippets/Example+-+create+a+dynamic+internal+table

regards,

Archer

former_member205763
Active Contributor
0 Kudos

you can loop on your ztable having these fields and use assign component to refer to fields of table A and table B and assign the values.

for ex:

Loop at itab into wa.

Assign component (wa-col1) OF structure WA_TABLEA assigning <FS_A>.

Assign component (wa-col2) OF structure WA_TABLEB assigning <FS_B>.

<FS_B> = <FS_A>.

A rough outline of what you can do, can you build your logic around this? I'm not able to see the need for dynamic internal table, may be u can elaborate?

alessandroieva
Active Participant
0 Kudos

Hi,

this is the code for create a dynamic table:

DATA: new_line             TYPE REF TO data.

FIELD-SYMBOLS: <fs_out>    TYPE REF TO data.

FIELD-SYMBOLS: <fs_tout>   TYPE table.

FIELD-SYMBOLS: <fs_wout>   TYPE ANY  .

PERFORM create_table.



FORM create_table .

   DATA: it_out                TYPE REF TO data.  

   ASSIGN it_out  TO <fs_out>.

   IF <fs_out> IS ASSIGNED.

     CALL METHOD cl_alv_table_create=>create_dynamic_table

       EXPORTING

         it_fieldcatalog           = it_catalog[]

       IMPORTING

         ep_table                  = <fs_out>

       EXCEPTIONS

         generate_subpool_dir_full = 1

         OTHERS                    = 2.

     ASSIGN <fs_out>->TO            <fs_tout>.

     CREATE DATA new_line LIKE LINE OF <fs_tout>.

     ASSIGN new_line->*   TO           <fs_wout>.

   ENDIF.

ENDFORM.                    " CREATE_TABLE



Let me know,


AI

former_member229034
Participant
0 Kudos

Dear All,

Thank you so much for the inputs !!

I tried the above suggestions but couldn't get it to work for this scenario.

We wont be knowing the name and length/characteristics of any of the fields; Also, the names of only some target fields may be same as source fields.

These fields will be maintained by the user. Hence we are trying to build a logic that works dynamically for any field.

The data source of the field list in COLUMN A is one custom table(DS1). The target for the field list in COLUMN B is another custom table(DT1). We need to fetch data for the field list in COLUMN A(from DS1) and populate the COLUMN B first. Then I will move the data to the respective Work area of COLUMN B and update the same(DT1). But how to make it dynamic ?

Thank you,

Chaitanya


0 Kudos

Hello Chaitanya,

      If suppose <fs_it1> table of type DS1, <fs_it2> table of type dt1..

      All field mapping details are avilable in a table called ZTABLE..

    So ..

Fetch ZTBALE first..

data : it type table of ZTABLE, wa type ZTBALE.

select * from table ztable into table it.

LOOP AT <FS_IT1> ASSIGNING <FS_WA1>.


   DO.

     READ TABLE IT INTO WA INDEX SY-INDEX.       " SY-TABIX

     IF SY-SUBRC <> 0.

       EXIT.

     ENDIF.

     ASSIGN COMPONENT  WA-COLUMN1 OF STRUCTURE <FS_WA1> TO <F1>.

     ASSIGN COMPONENT  WA_COLUMN2  OF STRUCTURE <FS_WA2> TO <F2>.

     <F2> = <F1>.

   ENDDO.

   append <fs_wa2> to <fs_it2>.

ENDLOOP.


make sure <f1>, <f2> are assigned properly.. clear the Field Symbols at appropriate positions..

Hope this works for you..


Regards,

Raghu

0 Kudos

Hello Chaitanya,

but which is the link between field in column A and fields in column B?

And, if i understood correctly, do you have to fill Column A and Column B dynamically given 2 input structure?

0 Kudos

I dont see a need for creating a dynamic table, if I understand correctly, you need to fill values from table A to table B based on the mapping in a third custom table right?

The code I gave about should work, it might hv nested loop but will work, can you let me know if it didnt behave in intended manner or if u r looking for something else?

former_member229034
Participant
0 Kudos

Dear All,

Just completed the code for this and it seems to be working fine in the debug mode and in the target table. Thank you Kartik Tarla

I am pasting the code below as a reference for our other folks in future !! correct this if needed....

Data objects:

1. wa_source_table - Work Area of the Source Table.

2. wa_target_table - Work Area of the Target Table.

3. LT_FIELDS --> Internal table of the type - Field to Field Mapping Table.

4. LW_FIELDS --> Work Area of the type -  Field to Field Mapping Table.

5. <field_symbol1> type any.

6. <field_symbol2> type any.

select column1 column2 from fieldlisttable into table lt_fields.

if sy-subrc = 0.

loop at lt_fields into lw_fields.

assign component lw_fields-column1 of structure wa_source_table to <field_symbol1>.

if <field_symbol1> is assigned.

assign component lw_fields-column2 of structure wa_target_table to <field_symbol2>.

**-- Assign value from one field symbol to the other
<field_symbol2> = <field_symbol2>.

**-- The above statement automatically assigns value into the wa_target_table.

endif.

clear: lw_fields.

endloop.

endif.

Thank you all so Much, Great Day Ahead !!

Best Regards,

Chaitanya