01-29-2008 5:41 AM
hi experts
i have a problem plse help me.
iam fetching data from the DB tables to the internal table.now i want to find the no of rows for the perticular field, not the entire internal table .
ex: eatch material have many packaging types , for eatch packing type there will be multiple components.
i want to find the no of components in the internal table , i.e .field wise records.
if the no of records are 1 need not to do the sum,if no of records are more than 1 then i have to do the sum for the quantity.
plse help me.....
with regards
aaryaa
01-29-2008 6:03 AM
Hi,
Set counter at AT NEW/AT END statements.
like:
LOOP AT itab result ...
[AT FIRST.
...
ENDAT.]
[AT NEW comp1.
...
ENDAT.
[AT NEW comp2.
...
ENDAT.
AT END OF comp2.
...
ENDAT.]
AT END OF comp1.
...
ENDAT.]
[AT LAST.
...
ENDAT.]
ENDLOOP.
the above given is the general syntax... u may write it according to ur requirement.
Regards,
Renjith Michael.
Edited by: Renjith Michael on Jan 29, 2008 11:33 AM
01-29-2008 6:03 AM
Hi,
Set counter at AT NEW/AT END statements.
like:
LOOP AT itab result ...
[AT FIRST.
...
ENDAT.]
[AT NEW comp1.
...
ENDAT.
[AT NEW comp2.
...
ENDAT.
AT END OF comp2.
...
ENDAT.]
AT END OF comp1.
...
ENDAT.]
[AT LAST.
...
ENDAT.]
ENDLOOP.
the above given is the general syntax... u may write it according to ur requirement.
Regards,
Renjith Michael.
Edited by: Renjith Michael on Jan 29, 2008 11:33 AM
01-29-2008 6:45 AM
hi Renjith Michael
the logic developed by me is :
SORT itab BY matnr atwrt.
LOOP AT itab INTO wa_itab.
at new matnr
WRITE: /05 wa_itab-matnr,
/25 wa_itab-maktx,
/ .
endat.
at new atwrt.
WRITE: /05 wa_itab-atwrt,
25 wa_itab-ojtxp,
45 wa_itab-factor.
endat.
AT END OF atwrt.
SUM.
WRITE: /05 sy-uline(134),
/05 'total',
65 wa_itab-factor.
endat.
clear:itab,
wa_itab.
here i want to control the total(sum), like if internal table field ojtxp records are more than 1 then i have to perform sum else i have to skip the sum portion.
it its not happening here. i mean if we use at new , similar fileds suold not be repeate. it is fine with matnr but not with atwrt.
plse help me
with regards
aaryaa
01-29-2008 6:52 AM
Hi,
Instead of using SUM, better sum it outside AT END OF.
SORT itab BY matnr atwrt.
LOOP AT itab INTO wa_itab.
at new matnr
WRITE: /05 wa_itab-matnr,
/25 wa_itab-maktx,
/ .
endat.
at new atwrt.
WRITE: /05 wa_itab-atwrt,
25 wa_itab-ojtxp,
45 wa_itab-factor.
endat.
sum = sum + wa_itab-factor.
AT END OF atwrt.
WRITE: /05 sy-uline(134),
/05 'total',
65 sum.
sum = 0.
endat.
clear:itab,
wa_itab.