‎2013 Dec 18 1:12 PM
Hi Folks,
I am having an table with data like
X Y Z
10 20 30
50 60 70
I wanted to create an internal table as
1 X 10
1 Y 20
1 Z 30
2 X 50
2 Y 60
2 Z 70
Could you please give me some input on this.
Help is appreciated.
Thanks,
Smriti
‎2013 Dec 18 2:36 PM
Try below:
l_v_line = 0.
Loop at table_1 into wa_1.
l_v_line = l_v_line+1
wa_2-fld1 = l_v_line.
wa_2-fld2 = 'X'. "(Field_name1)
wa_2-fld3 = wa_1-fld1.
append wa_2 to table_2.
wa_2-fld2 = 'y'. "(Field_name2)
wa_2-fld3 = wa_1-fld2.
append wa_2 to table_2.
wa_2-fld2 = 'Z'. "(Field_name3)
wa_2-fld3 = wa_1-fld3.
append wa_2 to table_2.
clear wa_2.
Endloop.
‎2013 Dec 18 1:14 PM
‎2013 Dec 18 1:22 PM
yes always my table will have only these three fields only values will change.but internal table has to be the above format
thanks for ur instant reply.please provide your input
‎2013 Dec 18 1:31 PM
Check this code
types : begin of ty1 ,
x(2) ,
y(2),
z(2),
end of ty1.
types : begin of ty2 ,
no type i ,
key ,
value(2),
end of ty2.
data : itab1 type table of ty1, wa_itab1 type ty1,
itab2 type table of ty2, wa_itab2 type ty2.
wa_itab1-x = '10'.
wa_itab1-y = '20'.
wa_itab1-z = '30'.
append wa_itab1 to itab1.
wa_itab1-x = '40'.
wa_itab1-y = '10'.
wa_itab1-z = '20'.
append wa_itab1 to itab1.
wa_itab1-x = '60'.
wa_itab1-y = '40'.
wa_itab1-z = '20'.
append wa_itab1 to itab1.
data : lv_index type sy-tabix.
FIELD-SYMBOLS <fs1>.
loop at itab1 into wa_itab1.
lv_index = sy-tabix.
wa_itab2-no = lv_index.
wa_itab2-key = 'X'.
assign component 'X' of STRUCTURE wa_itab1 to <fs1>.
if <fs1> is ASSIGNED.
wa_itab2-value = <fs1>.
endif.
append wa_itab2 to itab2.
wa_itab2-key = 'Y'.
assign component 'Y' of STRUCTURE wa_itab1 to <fs1>.
if <fs1> is ASSIGNED.
wa_itab2-value = <fs1>.
endif.
append wa_itab2 to itab2.
wa_itab2-key = 'Z'.
assign component 'Z' of STRUCTURE wa_itab1 to <fs1>.
if <fs1> is ASSIGNED.
wa_itab2-value = <fs1>.
endif.
append wa_itab2 to itab2.
endloop.
loop at itab1 into wa_itab1.
write 😕 wa_itab1-x, 4 wa_itab1-y, 7 wa_itab1-z.
endloop.
loop at itab2 into wa_itab2.
write 😕 wa_itab2-no, wa_itab2-key, wa_itab2-value.
endloop.
‎2013 Dec 18 1:42 PM
Hi Smriti,
First create 2 internal table with same structure as shown by you.
move first index to 1 internal table and delete the first index from your old internal table.
then internal table shows like below.
new table
a b c
--------
X Y Z
old table
a b c
------------
10 20 30
50 60 70
then loop the old table and move the record to third internal table.
loop at old.
read table new
a = sy-tabix.
b = new-a
c = old-a
append to third
a = sy-tabix.
b = new-b
c = old-b
append to third
a = sy-tabix.
b = new-c
c = old-c
append to third
endloop.
This will solve your problem.
regards,
sumit
‎2013 Dec 18 1:49 PM
Hi Smriti,
Please find the code below.
TYPES: BEGIN OF TY_ITAB,
X(2) TYPE C,
Y(2) TYPE C,
Z(2) TYPE C,
END OF TY_ITAB.
DATA: ITAB TYPE STANDARD TABLE OF TY_ITAB,
WA_ITAB LIKE LINE OF ITAB,
IT_FINAL TYPE STANDARD TABLE OF TY_ITAB,
WA_FINAL LIKE LINE OF IT_FINAL.
WA_ITAB-X = '10'.
WA_ITAB-Y = '20'.
WA_ITAB-Z = '30'.
APPEND WA_ITAB TO ITAB.
CLEAR: WA_ITAB.
WA_ITAB-X = '50'.
WA_ITAB-Y = '60'.
WA_ITAB-Z = '70'.
APPEND WA_ITAB TO ITAB.
CLEAR: WA_ITAB.
LOOP AT ITAB INTO WA_ITAB.
WRITE: / WA_ITAB-X, WA_ITAB-Y, WA_ITAB-Z.
ENDLOOP.
DATA: COUNT TYPE I VALUE '0'.
LOOP AT ITAB INTO WA_ITAB.
ADD 1 TO COUNT.
MOVE COUNT TO WA_FINAL-X.
MOVE 'X' TO WA_FINAL-Y.
MOVE WA_ITAB-X TO WA_FINAL-Z.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL.
MOVE COUNT TO WA_FINAL-X.
MOVE 'Y' TO WA_FINAL-Y.
MOVE WA_ITAB-Y TO WA_FINAL-Z.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL.
MOVE COUNT TO WA_FINAL-X.
MOVE 'Z' TO WA_FINAL-Y.
MOVE WA_ITAB-Z TO WA_FINAL-Z.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL.
ENDLOOP.
LOOP AT IT_FINAL INTO WA_FINAL.
WRITE:/ WA_FINAL-X,6 WA_FINAL-Y,9 WA_FINAL-Z.
ENDLOOP.
Regards,
Philip.
‎2013 Dec 18 2:36 PM
Try below:
l_v_line = 0.
Loop at table_1 into wa_1.
l_v_line = l_v_line+1
wa_2-fld1 = l_v_line.
wa_2-fld2 = 'X'. "(Field_name1)
wa_2-fld3 = wa_1-fld1.
append wa_2 to table_2.
wa_2-fld2 = 'y'. "(Field_name2)
wa_2-fld3 = wa_1-fld2.
append wa_2 to table_2.
wa_2-fld2 = 'Z'. "(Field_name3)
wa_2-fld3 = wa_1-fld3.
append wa_2 to table_2.
clear wa_2.
Endloop.
‎2013 Dec 19 7:54 AM
HI Satish,
Thanks for your helpful answer it was correct i implemented the same logic.
But Iam not able to assign any points .
can anybody help me how can i assign points to this helpful answer.
Thanks,
smriti