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: 

dynamically changing reference / assignment

Former Member
0 Kudos

hi i am trying to do a transpose

i got 2 internal tables in my program.

source - key: a , b & data 1 , 2, 3

target - key: a , b ,<generated key value> & data 1.

i am trying to merge all data values of 1 2 and 3 from source into single data component 1 of target. to keep values seperate i am generating a key value in target.

in my abap code i am looping 3 times and then tyring to append copies of source to target while varying data references.

but i dont know how to vary the rerences between comonents 1 2 and 3

whats should i be using.. field symbols or reference...and how?

thanks

sharan

1 ACCEPTED SOLUTION

former_member186741
Active Contributor
0 Kudos

assuming all your 'data' columns are identical you could use something like this. Show us your table definitions if it's more complicated than this. The 'index' field is not essential but just differentiates the multiple entries with identical a and b values.

data w_data(5).

data: begin of t1 occurs 0,

a(3),

b(3),

d1(5),

d2(5),

d3(5),

end of t1.

data: begin of t2 occurs 0,

a(3),

b(3),

index type sy-tabix,

data(5),

end of t2.

loop at t1.

move-corresponding t1 to t2.

do 3 times varying w_data from t1-d1 next t1-d2.

t2-index = sy-index.

t2-data = w_data.

append t2.

enddo.

endloop.

7 REPLIES 7

guillaume-hrc
Active Contributor
0 Kudos

Hi,

Not sure I understood your question completely...

Did you use ASSIGN COMPONENT ... OF STRUCTURE... ASSIGNING <fs> to vary reference ?

Best regards,

Guillaume

Former Member
0 Kudos

i am not a full time abap programmer so i do not know what solution best fits this situation.

i am currently trying to use a field symbol as you described but not working out very well as i do not know how to increament to next component in the structure.

thanks for replying.

sharan

0 Kudos

Hi,

Here is the syntax of ASSIGN COMPOENENT taken from the Help :

 DATA: BEGIN OF STR, 
          A VALUE 'a', 
          B VALUE 'b', 
          C VALUE 'c', 
          D VALUE 'd', 
        END   OF STR, 
        CN(5) VALUE 'D'. 
  FIELD-SYMBOLS <FS> TYPE ANY. 
  DO 3 TIMES. 
    ASSIGN COMPONENT SY-INDEX OF 
           STRUCTURE STR TO <FS>. 
    IF SY-SUBRC <> 0. EXIT. ENDIF. 
    WRITE <FS>. 
  ENDDO. 
  ASSIGN COMPONENT CN OF STRUCTURE STR TO <FS>. 
  WRITE <FS>.

Basically, this code allows to pass from one field of a structure to another easily. <i>Another way is to specify the name of the field instead of sy-index</i>.

Could you post some of your code so that we can see clearly what is going on ?

Thanks.

Best regards,

Guillaume

Message was edited by: Guillaume Garcia

former_member186741
Active Contributor
0 Kudos

assuming all your 'data' columns are identical you could use something like this. Show us your table definitions if it's more complicated than this. The 'index' field is not essential but just differentiates the multiple entries with identical a and b values.

data w_data(5).

data: begin of t1 occurs 0,

a(3),

b(3),

d1(5),

d2(5),

d3(5),

end of t1.

data: begin of t2 occurs 0,

a(3),

b(3),

index type sy-tabix,

data(5),

end of t2.

loop at t1.

move-corresponding t1 to t2.

do 3 times varying w_data from t1-d1 next t1-d2.

t2-index = sy-index.

t2-data = w_data.

append t2.

enddo.

endloop.

Former Member
0 Kudos

thanks guys... impressive response...will implement the methods and assign points soon.

0 Kudos

i was able to verify that neils code works. i am able to switch between data columns but as he himself points out it has some issues with data types of the columns. i was able to find a interm solution but not much luck yet.

looks like vary statements work with only N X and C. i am dealing with a float here...

any suggestions?

thanks

sharan

0 Kudos

actually solved it!!

thanks

sharan