Moving values from one Itab to another Itab(Resolved)

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
Gladiator
Posts: 797
Joined: Wed Dec 18, 2002 5:55 am
Location: Hyderabad, India

Moving values from one Itab to another Itab(Resolved)

Post by Gladiator » Tue Feb 24, 2009 3:10 pm

Hi,

However I tried, I could not find a solution ( if there is one ) and I am not at all strong in using Field Symbols.

Below is the scanario.
ITAB1

Fields: Field1 Field2 Field3
Values (1) MATNR QTY AMNT
(2) 0100785 3 25.45

ITAB2
Fields: MATNR QTY AMNT
Requirement: I need to move values from ITAB1 to ITAB2. Field names are different but first internal table has it's first row which are field names of the second itab.

Any pointers to me?

Thank you.
Last edited by Gladiator on Wed Feb 25, 2009 9:08 am, edited 1 time in total.
Gladiator.

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Re: Moving values from one Itab to another Itab

Post by Rich » Tue Feb 24, 2009 3:47 pm

Off the top of my head....

Code: Select all

Field-Symbols: <f_column>,
               <f_Source>,
               <f_Target>
*
Data: w_Fname  type FieldName,
      t_Fnames type standard table of w_FName.

Loop at itab1.
*
*    Get the field names
*
     If sy-tabix = 1.
        Do.
            Assign component sy-index of structure itab1 to <f_Column>.
            If sy-Subrc <> 0.
               Exit.
            Else.
               Append <f_Column> to t_FNames.
               UnAssign <f_Column>.
            EndIf.
        EndDo.
     Else.
*
*       Or field values
*
        Clear itab2
        Loop at t_FNames into w_Fname.
             Assign component sy-tabix of structure itab1 to <f_Source>.
             Assign component (w_FName) of structure itab2 to <f_target>.
             Move <F_Source> to <f_Target>.
             UnAssign: <f_Target>,
                       <f_Source>.
        EndLoop.
        Append Itab2.
     EndIf.
EndLoop.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Gladiator
Posts: 797
Joined: Wed Dec 18, 2002 5:55 am
Location: Hyderabad, India

Re: Moving values from one Itab to another Itab

Post by Gladiator » Wed Feb 25, 2009 9:06 am

Rich,

Works like charm! Thanks a lot, mate.
Gladiator.

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Re: Moving values from one Itab to another Itab(Resolved)

Post by Rich » Wed Feb 25, 2009 10:42 am

No Probs.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Post Reply