05-09-2006 10:00 AM
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
05-09-2006 10:15 AM
loop at itab3.
at first.
write: matnr.
endat.
write: field2.
endloop.
Check will this helps or not
05-09-2006 10:15 AM
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.
05-09-2006 10:18 AM
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.
05-09-2006 10:25 AM
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.
05-09-2006 10:27 AM
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
05-09-2006 11:02 AM
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.