2005 May 19 8:15 AM
hi all,
some logic problem,i have data in internal table,i have diff values of matkl,now i want all the count of each matkl values.how can i do that.plz give me some code.
i will give some brief explanation.
for example matkl is having values 10,10,10,10,20,30,40,50,50.than what i want from this is
10 - 4,
20 - 1,
30 - 1,
40 - 1,
50 - 2.
like this i need the count of the diff matkl values,plz help me with some code.
2005 May 19 8:21 AM
Hi Anil,
You can try out something like this -
data count type i.
sort itab by matkl.
loop at itab.
at end of matkl.
count = sy-tabix - count.
write : / itab-matkl , count.
endat.
endloop.
Regards,
Anand Mandalika.
2005 May 19 8:34 AM
I'm sorry, the above logic doesn't work quite right. Try this one instead -
data: count1 type i,
count2 type i.
loop at itab.
at new matnr.
count1 = sy-tabix.
endat.
at end of matnr.
count2 = sy-tabix - count1 + 1.
write : / itab-matnr , count2.
endat.
endloop.
Regards,
Anand Mandalika.
2005 May 19 8:46 AM
2005 May 19 8:50 AM
Hi Anil,
In my test program I have used MATNR instead of MATKL. Please change the code accordingly if you have not done that.
If you think your code is correct, then paste it here.
Regards,
Anand Mandalika.
2005 May 27 8:19 AM
hi,
plz solve my issue.i'm doing a report where i'm extracting the material group afer some selections into an internal table.now my prob isif i leave the material group in selectin screen empty it is showing correct value.if i give any value in the selection screen for material group it is not showing me the exact value.i'm pasting my code plz give me the correct code.
Tables : VBAP,VBEP,VBFA,v023.
selection-screen begin of block prod with frame.
selection-screen skip 1.
select-options: Date for vbfa-erdat.
selection-screen skip 1.
select-options:MATGROUP for VBAP-MATKL.
selection-screen end of block prod.
data iVO23 like V023 occurs 0 with header Line.
DATA : Begin of ZVBFA occurs 0,
POSNV like VBFA-POSNV,
VBELV like VBFA-VBELV,
ERDAT LIKE VBFA-ERDAT,
RFMNG LIKE VBFA-RFMNG,
RFWRT LIKE VBFA-RFWRT,
End of ZVBFA.
TYPES: A TYPE I.
DATA : Begin of ZVBeP occurs 0,
vbeln like vbap-vbeln,
matkl like vbap-matkl,
EDATU like VBeP-EDATU,
POSNR like VBeP-POSNR,
bmeng like vbep-bmeng,
End of ZVBeP.
data: begin of edate occurs 0,
edatu1 like vbep-edatu,
end of edate.
data: tcount type i.
DATA : Begin of ZVBFA1 occurs 0,
POSNV1 like VBFA-POSNV,
VBELV1 like VBFA-VBELV,
ERDAT1 LIKE VBFA-ERDAT,
edatu1 like vbep-edatu,
bmeng like vbep-bmeng,
matkl like vbap-matkl,
End of ZVBFA1.
data: begin of total occurs 0,
matkl like vbap-matkl,
end of total.
data : begin of total1 occurs 0,
matkl1 like vbap-matkl,
bmeng like vbep-bmeng,
end of total1.
data :begin of sum1 occurs 0,
matkl like vbap-matkl,
bmeng like vbep-bmeng,
end of sum1.
data: begin of out occurs 0,
a like vbap-matkl,
b type i,
c type i,
d type i,
per type p decimals 2,
per1 type p decimals 2,
bmeng like vbep-bmeng,
end of out.
data: begin of out1 occurs 0,
a like vbap-matkl,
b type i,
end of out1.
data: begin of out2 occurs 0,
a like vbap-matkl,
b type i,
bmeng like vbep-bmeng,
end of out2.
data mtl like vbap-matkl.
top-of-page.
skip to line 6.
write:/40'SHIPPMENT REPORT FOR SCHEDULE LINE ITEMS'.
WRITE:/40'----
'.
start-OF-SELECTION.
select VBELV POSNV ERDAT RFMNG RFWRT into corresponding fields of
ZVBFA from VBFA where VBTYP_N = 'R' and erdat in date.
append zvbfa.
endselect.
select avbeln amatkl bposnr bedatu b~bmeng into
corresponding fields of table zvbep from
vbap as a inner join vbep as b
on avbeln = bvbeln
and aposnr = bposnr
where MATKL in MATGROUP and bmeng GE '1'.
if sy-subrc ne 0.
FORMAT COLOR COL_NEGATIVE INVERSE.
SKIP TO LINE 14.
write:/ ' NO DATA EXITS FOR SELECTED CRITERIA.'.
FORMAT RESET.
ENDIF.
loop at zvbep.
read table zvbfa with key vbelv = zvbep-vbeln
posnv = zvbep-posnr
binary search.
if sy-subrc EQ 0.
move: zvbfa-vbelv to zvbfa1-vbelv1,
zvbfa-posnv to zvbfa1-posnv1,
zvbfa-erdat to zvbfa1-erdat1,
zvbep-edatu to edate-edatu1,
zvbep-bmeng to zvbfa1-bmeng,
zvbep-matkl to zvbfa1-matkl.
append zvbfa1.
append edate.
endif.
endloop.
loop at zvbfa1.
read table edate with key edatu1 = zvbfa1-erdat1 binary search.
if sy-subrc EQ 0.
move: zvbfa1-matkl to total-matkl.
append total.
else.
move: zvbfa1-matkl to total1-matkl1,
zvbfa1-bmeng to total1-bmeng.
append total1.
endif.
endloop.
SORT total BY MATKL.
sort total1 by matkl1.
data: count1 type i,
count2 type i.
LOOP AT total.
at new matkl.
count1 = sy-tabix.
endat.
at end of matkl.
count2 = sy-tabix - count1 + 1.
out1-b = count2.
out1-a = total-matkl.
append out1.
clear total.
endat.
endloop.
loop at total1.
at new matkl1.
count1 = sy-tabix.
endat.
at end of matkl1.
count2 = sy-tabix - count1 + 1.
out2-b = count2.
out2-a = total1-matkl1.
sum.
out2-bmeng = total1-bmeng.
append out2.
clear total1.
endat.
endloop.
loop at out2.
read table out1 with key a = out2-a binary search.
move: out2-bmeng to out-bmeng.
if sy-subrc = 0.
move : out1-a to out-a,
out1-b to out-b,
out2-b to out-c.
out-d = out-b + out-c.
out-per = ( out-b * 100 / out-d ).
out-per1 = ( out-c * 100 / out-d ).
append out.
endif.
endloop.
skip to line 9.
write:/ sy-Uline(115).
write:/ sy-vline,
12 sy-vline,
28 'ON-TIME' ,
43 sy-vline,
65'LATE SHIP',
93 sy-vline,
95 'TOTAL',
110 sy-vline.
format color col_positive inverse.
write:/ sy-Uline(115).
write:/ sy-vline,
'Mat.Group',
12 sy-vline,
14 'Sch.Line',
23 sy-vline,
29 'Per (%)',
43 sy-vline,
45 'Sch.Line',
55 sy-vline,
60 'TOT.QTY',
73 sy-vline,
82 'Per (%)',
93 sy-vline,
110 sy-vline.
format reset.
write:/ sy-Uline(110).
loop at out where a in matgroup.
write 😕 sy-vline,
out-a,
12 sy-vline,
13 out-b,
23 sy-vline,
24 out-per,'%',
43 sy-vline,
44 out-c,
55 sy-vline,
57 out-bmeng,
73 sy-vline,
74 out-per1,'%',
93 sy-vline,
94 out-d,
110 sy-vline,
/ sy-uline(110).
endloop.
2005 May 19 8:21 AM
Hi,
You can achieve that with an aggregate select, as in
<b>SELECT count(MATKL) FROM ... GROUP BY MATKL.</b>
If you have to work with the internal table, you can use the <b>AT END OF ... ENDAT</b> command, as in the following pseudo-code:
LOOP AT itab INTO wa.
AT END OF MATKL.
ADD 1 to wa-count.
MODIFY itab FROM wa.
ENDAT.
ENDLOOP.
Note: I haven't actually tested this code, so you should check for syntax errors and look at the online help etc.
Hope that helps (please reward me if it does),
Joerg
2005 May 19 8:24 AM
Hi anil,
collect is the command you need (->F1)
data: begin of mtab occurs 0,
matkl type mara-matkl,
cnt type p decimals 0,
end of mtab.
*
loop at itab.
move itab-matkl to mtab-matkl.
mtab-cnt = 1.
collect mtab.
clear mtab.
endloop.
regards Andreas
2005 May 19 9:22 AM
Hi,
As u need to count at new maktl or at end of maktl, first sort the internal table.
ws_count = 0.
SORT itab.
LOOP AT ITAB into w_itab.
<b>ws_count = ws_count + 1.</b>
<b>AT end of maktl.</b>
outtab-count = ws_count.
append outtab.
<b>clear ws_count.</b>
ENDAT.
ENDLOOP.
Try this one. This will work
Thanks & Regards,
Judith.
Message was edited by: Judith Jessie Selvi
2005 May 19 9:55 AM
2005 May 19 10:19 AM
hi anil try this it will work out for you.
data count type i,
temp like mara-matkl.
sort itab by matkl.
loop at itab.
at first.
move itab-matkl to temp.
count = 0.
endat.
if temp = itab-matkl.
count = count + 1.
else.
write:/ temp , 'is' , count , ' times'.
count = 1.
move itab-matkl to temp.
endif.
endloop.
Thankx & Regards,
Raghu
2005 May 19 12:20 PM
Hi,
I have just now tried with a sample program, this works fine
REPORT ZZZTEST_3 .
TYPES: BEGIN OF ty_out,
number TYPE i,
name(10) TYPE c,
count TYPE i,
END OF ty_out.
DATA: ws_count TYPE i,
i_out TYPE STANDARD TABLE OF ty_out,
i_output TYPE STANDARD TABLE OF ty_out,
w_out TYPE ty_out.
ws_count = 0.
w_out-number = 1. w_out-name = 'John'.
APPEND w_out TO i_out.
w_out-number = 2. w_out-name = 'Paul'.
APPEND w_out TO i_out.
w_out-number = 2. w_out-name = 'Paul1'.
APPEND w_out TO i_out.
w_out-number = 3. w_out-name = 'Ringo'.
APPEND w_out TO i_out.
w_out-number = 4. w_out-name = 'George'.
APPEND w_out TO i_out.
<b>LOOP AT i_out INTO w_out. </b>
ws_count = ws_count + 1.
<b>AT END of number</b>.
w_out-count = ws_count.
Append w_out to i_output.
clear ws_count.
<b> ENDAT.
ENDLOOP.</b>
The i_output table will have that column count as u need.
Try this one and let me know.
Thanks & Regards,
Judith.