on 06-28-2018 12:45 PM
I have 2 tables; my Local table with 300 fields, and the Customer table with 300 fields, and a mapping table which maps the fields from the Local table to the Customer table. In my Local table are approximately 10000 entries which now have to be copied to the Customer table based on the Mapping table.
The mapping table could be changed from time to time so the solution must be dynamic.
The field names are completely different in both files and look something like this:
LOC_TAB (fields)
CUST_TAB (fields)
MAPPING_TAB
So, for example the value in field 'userid' must be passed to the field 'usrid' in the Customer table. I can do something like:
LOOP at LOC_TAB into local_workarea.
LOOP at MAPPING_TAB into map_workarea.
append CUST_TAB????
ENDLOOP.
ENDLOOP.
Problem is that the above solution would mean looping on my mapping table for every single entry and Loop on the Local file. I cannot think of a better way.:(
All help greatly appreciated!
LOOP AT source_tab ASSIGNING <source_row>.
APPEND INITIAL LINE TO target_tab ASSIGNING <target_row>.
LOOP AT mapping_table INTO map.
ASSIGN COMPONENT (map-source) OF STRUCTURE <source_row> TO <source_field>.
ASSIGN COMPONENT (map-target) OF STRUCTURE <target_row> TO <target_field>.
<target_field> = <source_field>.
ENDLOOP.
ENDLOOP.
Not tested or syntax verified, but should give you the basic idea.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think this should work:
SELECT source_col, target_col
FROM MAPPING_TAB
INTO TABLE @DATA(lt_mab).
LOOP AT lt_mab INTO DATA(ls_mab).
IF lv_sel IS INITIAL.
lv_sel = |{ ls_mab-source_col } AS { ls_mab-target_col }|.
ELSE.
lv_sel = |{ lv_sel } , { ls_mab-source_col } AS { ls_mab-target_col }|.
ENDIF.
ENDLOOP.
SELECT ( LV_SEL ) FROM LOC_TAB INTO TABLE @DATA(lt_target).
UPDATE CUST_TAB FROM lt_target.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the CORRESPONDING operator with MAPPING or use CL_ABAP_CORRESPONDING?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually Warren but i use pseudoname here because i am ashamed that i am not clever and ask stupid questions.
I think there is nothing to be ashamed of, we're all learning something and nobody can be an expert at everything. The way the question is asked says a lot more about the person than the content. I found your questions generally well thought out and well described, and would count very much in your favor if I were researching an interview candidate.
Thank you for your kind words, and also for your solution which worked! 🙂
There are no stupid questions. Though there are many inquisitive idiots, I don't think you're one of them. Well constructed non-FAQ basic questions are welcomed by me.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.