04-04-2008 10:36 PM
Hi Experts,
I want to convert rows into coloumns in final internal table.
How to do that one. Can any one help me its very urgent.
Regards,
PBS.
04-04-2008 11:07 PM
Check this example, is more dynamic.
TYPES: BEGIN OF ty_1,
first,
second,
third,
END OF ty_1.
TYPES: BEGIN OF ty_2,
first,
second,
third,
END OF ty_2.
FIELD-SYMBOLS: <fs> TYPE ANY,
<fs2> TYPE ANY.
DATA: itab1 TYPE TABLE OF ty_1 WITH HEADER LINE,
itab2 TYPE TABLE OF ty_1 WITH HEADER LINE,
curr_line TYPE sy-tabix.
itab1-first = 'a'.
itab1-second = 'a'.
itab1-third = 'a'.
APPEND itab1.
itab1-first = 'b'.
itab1-second = 'b'.
itab1-third = 'b'.
APPEND itab1.
itab1-first = 'c'.
itab1-second = 'c'.
itab1-third = 'c'.
APPEND itab1.
LOOP AT itab1.
CLEAR itab2.
ASSIGN COMPONENT sy-tabix OF STRUCTURE itab2 TO <fs>.
curr_line = sy-tabix.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE itab1 TO <fs2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF curr_line = 1.
<fs> = <fs2>.
APPEND itab2.
ELSE.
READ TABLE itab2 INDEX sy-index.
<fs> = <fs2>.
MODIFY itab2 INDEX sy-index.
ENDIF.
ENDDO.
ENDLOOP.
04-04-2008 10:59 PM
hi,
Find the below code for changing rows into colums.
data: begin of itab1 occurs 0,
fld,
end of itab1.
data: begin of itab2 occurs 0,
fld1,
fld2,
fld3,
end of itab2.
itab1-fld = 1.
append itab1.
itab1-fld = 2.
append itab1.
itab1-fld = 3.
append itab1.
read table itab1 index 1.
if sy-subrc eq 0.
itab2-fld1 = itab1-fld.
endif.
read table itab1 index 2.
if sy-subrc eq 0.
itab2-fld2 = itab1-fld.
endif.
read table itab1 index 3.
if sy-subrc eq 0.
itab2-fld3 = itab1-fld.
endif.
append itab2.
loop at itab1.
write:/ itab1.
endloop.
loop at itab2.
write:/ itab2.
endloop.
refer the below link for further information
04-04-2008 11:07 PM
Check this example, is more dynamic.
TYPES: BEGIN OF ty_1,
first,
second,
third,
END OF ty_1.
TYPES: BEGIN OF ty_2,
first,
second,
third,
END OF ty_2.
FIELD-SYMBOLS: <fs> TYPE ANY,
<fs2> TYPE ANY.
DATA: itab1 TYPE TABLE OF ty_1 WITH HEADER LINE,
itab2 TYPE TABLE OF ty_1 WITH HEADER LINE,
curr_line TYPE sy-tabix.
itab1-first = 'a'.
itab1-second = 'a'.
itab1-third = 'a'.
APPEND itab1.
itab1-first = 'b'.
itab1-second = 'b'.
itab1-third = 'b'.
APPEND itab1.
itab1-first = 'c'.
itab1-second = 'c'.
itab1-third = 'c'.
APPEND itab1.
LOOP AT itab1.
CLEAR itab2.
ASSIGN COMPONENT sy-tabix OF STRUCTURE itab2 TO <fs>.
curr_line = sy-tabix.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE itab1 TO <fs2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF curr_line = 1.
<fs> = <fs2>.
APPEND itab2.
ELSE.
READ TABLE itab2 INDEX sy-index.
<fs> = <fs2>.
MODIFY itab2 INDEX sy-index.
ENDIF.
ENDDO.
ENDLOOP.