Application Development and Automation 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: 
Read only

Issue with internal table columns

Former Member
0 Likes
1,700

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,661

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....

14 REPLIES 14
Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,661

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.

Read only

Former Member
0 Likes
1,662

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....

Read only

0 Likes
1,661

Hello,

  please suggest any idea...

Thanks!

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,661

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..

Read only

0 Likes
1,661

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

Read only

0 Likes
1,661

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!

Read only

0 Likes
1,661

Hi,

Instead of wasting time with the two liners , try to provide the code part which you have written.

Read only

0 Likes
1,661

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!

Read only

0 Likes
1,661

Hi,

any idea..

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,661

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

Read only

0 Likes
1,661

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

Read only

0 Likes
1,661

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.

Read only

0 Likes
1,661

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......

Read only

0 Likes
1,661

Many Thanks Raymond......got it......!!