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: 

itab 3 lines to 1

Former Member
0 Kudos

thanks for the answer but it seems that you did not understand me

itab 3 lines to 1

Posted: May 9, 2006 4:07 AM Reply E-mail this post

i have table itab3 (with 1000 rows) with

matnr min max avg

2222 2

2222 10

2222 8

i want to make it to 1 row in new table

matnr min max avg

2222 2 10 8

i want all the 3 lines become 1 line i tried your example and it;s not works

6 REPLIES 6

Former Member
0 Kudos

loop at itab3.

at first.

write: matnr.

endat.

write: field2.

endloop.

Check will this helps or not

Former Member
0 Kudos

What I understood from your problem is that..

U have an internal table whose data is spread in 3 rows and you want to merge them into a single record..

For ex:

Internal table contents:

matnr min max avg

2222 2

2222 10

2222 8

3333 1

3333 5

3333 3

Desired output :

2222 2 10 8

3333 1 5 3

if what I understood is right, you can follow the given code and get the value into itab in the desired manner

data: itab_copy like itab occurs 0 with header line.

itab_copy[] = itab[].

delete adjacent duplicates from itab comparing matnr.

loop at itab.

loop at itab_copy where matnr = itab-matnr.

if sy-tabix = 1.

continue.

endif.

if sy-tabix = 2.

itab-max = itab_copy-min.

endif.

if sy-tabix = 3.

itab-avg = itab_copy-min.

endif.

endloop.

modify itab.

endloop.

Former Member
0 Kudos

hi rani,

Please check this below code

sort itab3 by matnr.

loop at itab3.

at new matnr.

loop at itab3 where matnr = itab3-matnr.

case itab3-field.

when 'MAX'.

move itab3-value to itab-max.

when 'MIN'.

.......

endcase.

endloop.

endat.

move: itab3-matnr to itab-matnr.

append itab.

endloop.

sbhutani1
Contributor
0 Kudos

Hi rani,

Try this code

SORT ITAB3 BY MATNR.

LOOP AT ITAB3.

AT NEW MATNR.

ITAB3-MATNR TO ITAB-MATNR.

LOOP AT ITAB3 WHERE MATNR = ITAB3-MATNR.

CASE WTAB3-VALUE.

WHEN 'MIN'.

MOVE ITAB3-VALUE TO ITAB-MAX.

WHEN 'MAX'.

MOVE ITAB3-VALUE TO ITAB-MIN.

WHEN 'AVG'.

MOVE ITAB3-AVG TO ITAB-AVG.

ENDCASE.

ENDLOOP.

ENDAT.

ENDLOOP.

Former Member
0 Kudos

Hai Rani

Try with the following Code

tables : mara.

data : begin of it_mara occurs 0,

matnr like mara-matnr,

mbrsh like mara-mbrsh,

mtart like mara-mtart,

meins like mara-meins,

end of it_mara.

start-of-selection.

perform upload_data.

&----


*& Form upload_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload_data .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\mat_bdc.txt'

FILETYPE = 'ASC'

TABLES

DATA_TAB = it_mara.

IF SY-SUBRC = 0.

SORT IT_MARA BY MATNR MBRSH MTART MEINS.

ENDIF.

loop at it_mara.

at new matnr.

write 😕 it_mara-matnr.

endat.

at new mbrsh.

write : it_mara-mbrsh.

endat.

at new mtart.

write : it_mara-mtart.

endat.

at new meins.

write : it_mara-meins.

endat.

endloop.

ENDFORM. " upload_data

Thanks & regards

Sreenivasulu P

Former Member
0 Kudos

Hello Rani,

just copy this code and run it. You will get the desired output.

<b>tables : mara.

data : begin of itab occurs 0,

matnr type mara-matnr,

min type i,

max type i,

avg type i,

end of itab.

data itab3 like standard table of itab with header line initial size

0.

itab-matnr = '2222'.

itab-min = 2.

append itab.

clear itab.

itab-matnr = '2222'.

itab-min = 10.

append itab.

clear itab.

itab-matnr = '2222'.

itab-min = 8.

append itab.

clear itab.

loop at itab.

itab3-matnr = itab-matnr.

itab3-min = itab-min.

itab3-max = itab-max.

itab3-avg = itab-avg.

append itab3.

endloop.

sort itab by matnr.

delete adjacent duplicates from itab comparing matnr.

loop at itab.

loop at itab3 where matnr = itab-matnr.

case sy-tabix.

when 2.

itab-max = itab3-min.

when 3.

itab-avg = itab3-min.

endcase.

endloop.

modify itab.

endloop.

loop at itab.

write : / itab-matnr , itab-min, itab-max, itab-avg.

endloop.</b>

Regards,

Kunal.