A good challenge for the experts!!!!

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
shireeshm

A good challenge for the experts!!!!

Post by shireeshm » Mon Mar 24, 2003 6:34 am

I am trying to arrange vertical data from one internal table into another table horizontally...meaning....lets say itab1 has 5 entries

matnr1
matnr2
matnr3
matnr4
matnr5

I want them arranged into itab2 as 1 rec having 5 fields

it should look like:

field1 field2 field3 field4 field5
*********************************
matnr1 matnr2 matnr3 matnr4 matnr5
**********************************

I had done this long back using field-symbols..but i dont have the ref code with me now...and now i am wasting too much time on it...can somebody help me out quick?

Thanks,
Shireesh

Jumanji
Posts: 23
Joined: Wed Feb 19, 2003 12:48 am
Location: Hyderabad, India

Post by Jumanji » Mon Mar 24, 2003 7:21 am

Yea even i did this using fieldsymbols before.
I dont remember the exact code but i can help u with pseudocode.
it goes like this
data:begin of itab2 occurs 0,
matnr1 like mara-matnr,
matnr2.......so on till matnr5 end of itab.

loop at itab1.
counter = counter + 1.
concatenate 'itab2-matnr' 'counter' into name.
assign (name) to <fs>.
<fs> = itab1-matnr.
if counter = 5.
append itab2.
clear counter.
endif.
endloop.

i think u got the picture.
get back if any doubts
bye

kumar
Posts: 2012
Joined: Tue Oct 22, 2002 12:51 pm
Location: Basel, Switzerland
Contact:

Post by kumar » Mon Mar 24, 2003 10:35 am

Something like this

Code: Select all


DATA : BEGIN OF ITAB1 OCCURS 0,
           MATNR LIKE ...
           *etc
           END OF ITAB1,
           BEGIN OF ITAB2 OCCURS 0,
           F1 LIKE ...
           F2 LIKE ...
           F3 LIKE ....
           F4 LIKE ...
           F5 LIKE ....
           END OF ITAB2,
           CNT TYPE N,
           NAME(8)
*Fill ITAB1

LOOP AT ITAB1.
CNT = SY-TABIX.
CONCATEANTE 'ITAB2-F' CNT INTO NAME.
ASSIGN (NAME) TO <FS>.

<FS> = ITAB1-MATNR.

ENDLOOP.

APPEND ITAB2.


If your ITAB1 has more than 5 fields you have to change ITAB2, CNT and NAME Accordingly.

KRK

Guest

Post by Guest » Mon Mar 24, 2003 1:50 pm

Dear Shireeshm:
What if you have six entries in your table but only five fields? I mean, you can easily exceed the fields, unless you know for sure you have only up to a certain number.

Try DO ... 5 TIMES VARYING. (F1 on DO) It requires the fields to be spaced apart evenly, e.g., declared one after another.

Regards,
Wolfgang

Post Reply