2013 Jan 22 6:41 AM
Hi All,
I got an issue while working with internal tables.
I am trying to create an output table from input table based on the customized mapping table. Mapping table records will be like this
inputfld outputfld
COL1 COL3
COL4 COL1
COL3 COL2
here, From my input table(itab1) COL1 data should map to output Table ( Itab2) COL3, similarly for itab1-COL4 should map to itab2-COL1.
Mapping should be based on customized mapping table ZMAP.
Is there any Idea to achive this.
Please help .
Thanks,
Vishnu
2013 Jan 22 7:09 AM
Hi,
I have tried with using field symbols for mapping table & reading the COL1 number from ZMAP.
and assigning to output table is not happening....
2013 Jan 22 6:54 AM
This looks to me as Requirement Dumping which is against Forum Rules.
Please show what research you have done before posting. So, we could continue answering to the post.
Please Read the Rules of Engagement
Hope this helps.
2013 Jan 22 7:09 AM
Hi,
I have tried with using field symbols for mapping table & reading the COL1 number from ZMAP.
and assigning to output table is not happening....
2013 Jan 22 9:22 AM
2013 Jan 22 9:43 AM
Ok , Sure we are here to help.
Lets take the Example with FIELDS to avoid confusion.
ITAB1 ITAB2
----------- -------------
MATNR MATNR
COL1 COL3
COL4 COL1
COL3 COL2
so assuming your INPUT Table (ITAB1)
Now we prepare the OUTPUT Table (ITAB2)
When first point comes into Picture.. COL1 which is MATNR of ITAB1 will be placed at COL3(MATNR) in ITAB2. Is that what you want?
In That case what about the COL4 and COL1, before that you should have a field right..
Please explain clearly..
2013 Jan 22 9:45 AM
What is going wrong with ASSIGN COMPONENT comp OF STRUCTURE struc,
Loop at internal table 1 assigning a field symbol to the record (or use a work area), append an initial record to internal table 2 assigning an other field symbol. Then loop into your "customizing table", loaded in memory in an internal table, which should contain pair of field name and assign one field symbol to component name1 of internal table 1 field symbol and another field symbol to component name2 of internal table 2 field symbol and move the data from first field symbol to the second
Regards,
Raymond
2013 Jan 22 10:44 AM
Hi,
Will you please explain logic in detail.....becoz i have done some mistakes while assigning field symbols of customization table to internal table 2.
thanks!
2013 Jan 22 10:55 AM
Hi,
Instead of wasting time with the two liners , try to provide the code part which you have written.
2013 Jan 22 11:35 AM
Hi,
I have done the coding like this. Sorry if any mistakes i am learning use of field symbols.
LOOP AT ITAB1 ASSIGNING <FS_ITAB1>.
LOOP AT ZMAP INTO WA_ZMAP.
ASSIGN COMPONENT WA_ZMAP-SAPFLD OF STRUCTURE ZMAP TO <FS1>.
ASSIGN COMPONENT WA_ZMAP-OUTPUT OF STRUCTURE ZMAP TO <FS2>.
WA_ITAB2-<FS2> = <FS_ITAB1>-<FS1>. " Is this possible?
APPEND WA_ITAB2 TO ITAB2.
ENDLOOP.
ENDLOOP. .
Thanks!
2013 Jan 22 11:46 AM
2013 Jan 22 11:59 AM
Here is the thing that I noticed.
ASSIGN COMPONENT WA_ZMAP-SAPFLD OF STRUCTURE ZMAP TO <FS1>.
ASSIGN COMPONENT WA_ZMAP-OUTPUT OF STRUCTURE ZMAP TO <FS2>.
Did you declared ZMAP as Structure in your Program.
Because when you say Loop at ZMAP It should be a ITAB.
If you declare ZMAP with TABLEs Parameter then it wont suite in this requirement.
One more thing is that. Lets say WA_ZMAP-SAPFLD has the field Value as 'MATNR' then it should of which structure ? does ZMAP structure has MATNR in it.?
Please check the BOLD part the code
Hope this helps
2013 Jan 22 6:27 PM
Try
LOOP AT ITAB1 ASSIGNING <FS_ITAB1>.
LOOP AT ZMAP INTO WA_ZMAP.
TRY.
ASSIGN COMPONENT WA_ZMAP-SAPFLD OF STRUCTURE<FS_ITAB1> <FS1>.
ASSIGN COMPONENT WA_ZMAP-OUTPUT OF STRUCTURE WA_ITAB2 TO <FS2>.
<FS2> =<FS1>.
" Here try to CATCH mapping error
ENDTRY.
ENDLOOP.
APPEND WA_ITAB2 TO ITAB2.
ENDLOOP.
Regards,
Raymond
2013 Jan 22 6:41 PM
That is not possible
vishnu vishnu wrote:
Hi,
I have done the coding like this. Sorry if any mistakes i am learning use of field symbols.
LOOP AT ITAB1 ASSIGNING <FS_ITAB1>.
LOOP AT ZMAP INTO WA_ZMAP.
ASSIGN COMPONENT WA_ZMAP-SAPFLD OF STRUCTURE ZMAP TO <FS1>.
ASSIGN COMPONENT WA_ZMAP-OUTPUT OF STRUCTURE ZMAP TO <FS2>.
WA_ITAB2-<FS2> = <FS_ITAB1>-<FS1>. " Is this possible?
APPEND WA_ITAB2 TO ITAB2.
ENDLOOP.
ENDLOOP. .
Thanks!
The line:
wa_itab2-<FS2> = <FS_ITAB1>-<FS1> .
That is not possible.
When you assign a component, of a structure to a field symbol, you can use the field symbol directly as if it were the field.
<fs2> = <fs1> .
Additionally, it is always a good idea to ensure assignment of a field symbol was successful.
Usually a IF ASSIGNED statement will work, in this case:
IF <fs2> IS ASSIGNED .
IF <fs1> IS ASSIGNED .
<fs2> = <fs1> .
ELSE .
" Handle what to do if <FS1> IS not assigned
ENDIF .
ELSE .
" Handle what to do if <FS2> is not assigned.
ENDIF .
That should work for actually carrying out the data transfer.
ZMAP stores the maps, correct? ITAB1 and ITAB2 store data to be moved?
Your ASSIGN statements should be changed as follow I believe:
ASSIGN COMPONENT wa_zmap-sapfld OF STRUCTURE <fs_itab1> TO <fs1> .
ASSIGN COMPONENT wa_zmap-output OF STRUCTURE wa_itab2 TO <fs2> .
Edit - Raymond already answered.
2013 Jan 23 9:32 AM
Hi Raymond,
Thanks for valuable reply.
I Have tried like this but i need to move ITAB1-COL1 data to ITAB2-COL3. IF suppose ITAB1-COL contains data as "123", with first ASSIGN component statement I am able to get "123" into <FS1>.
After 2nd ASSIGN Component statement I am moving <FS1> to <FS2>.
Now my issue is how to move the data "123" to ITAB2-COL3.?
here is my code.
FIELD-SYMBOLS : <FS_ITAB1> TYPE TY_ITAB1,
<FS1>,<FS2>.
ASSIGN WA_ITAB2 TO <FS2>.
LOOP AT IT_ITAB1 ASSIGNING <FS_ITAB1>.
LOOP AT IT_ZMAP INTO WA_ZMAP.
ASSIGN COMPONENT WA_ZMAP-SAPFIELD OF STRUCTURE <FS_ITAB1> TO <FS1>.
ASSIGN COMPONENT WA_ZMAP-OPTCOL OF STRUCTURE WA_ITAB2 TO <FS2>.
<FS2> = <FS1>. "here value <FS2> is containing value"123" but i need to assign this to
"WA_ITAB2-COL3.then I will append the same to ITAB2.
ENDLOOP.
APPEND <FS2> TO IT_NEW.
ENDLOOP..
Please suggest......
2013 Jan 23 9:39 AM