Hi SAPgurus,
Please go through this and give your valuble suggestions on this issue.
Thanks in advance......
Selection Screen
Date Range : Select options : S_date like vbrk-fkdat.
Sales Organization : Select Options : S_vkorg like vbrk-vkorg default value 1000
Distribution Channel : Parameter : p_vtweg like vbrk-vtweg default value 00
Division : Parameter : P_spart like vbrk-spart default value 00.
Process :
Read the Table KNVP with condition PARVW = PE,P1 Or P2 (Sales Man #1,Sales Man #2 and Sales Man #3.) and get the PERNR (Sales Man) and KUNNR (Customer No).
Read VBRK table for the selection criteria entered on the selection Screen with condition KUNAG = KNVP-KUNNR and select VBELN
Read table VBRP with condition VBELN = VBRK-VBELN and select MATNR, NETWR, WAVWR, MATKL, WERKS and PRODH fields.
Read table VBFA with condition VBELN = VBRK-VBELN and VBTYP_V = J and select field VBELV to get the delivery number
Read table VBAP with condition vbeln = vbrk-vbeln and select the PERNR
For this I have writter the following logic, check this code and advise me If I am doing wrong.
SELECT avbeln afkart afkdat abzirk
bmatnr bnetwr bwavwr bmatkl bwerks bprodh
cvbelv cvbtyp_v
d~pernr INTO
(tab_slsmnbycust-vbeln,
tab_slsmnbycust-fkart,
tab_slsmnbycust-fkdat,
tab_slsmnbycust-bzirk,
tab_slsmnbycust-matnr,
tab_slsmnbycust-netwr,
tab_slsmnbycust-wavwr,
tab_slsmnbycust-matkl,
tab_slsmnbycust-werks,
tab_slsmnbycust-prodh,
tab_slsmnbycust-vbelv,
tab_slsmnbycust-vbtyp_v,
tab_slsmnbycust-pernr)
FROM vbrk AS a
INNER JOIN vbrp AS b ON avbeln = bvbeln
INNER JOIN vbfa AS c ON bvbeln = cvbeln
INNER JOIN vbpa AS d ON avbeln = dvbeln
WHERE a~kunag = tab_kunnr_mult_kunnr-kunnr AND
cvbtyp_v = 'J' AND afkdat BETWEEN date1-low AND date1-high
AND afkart IN r_fkart AND avkorg IN s_vkorg
AND avtweg = p_vtweg AND aspart = p_spart
AND d~parvw IN r_parvw.
Please see the internal table data below
VBELN FKART FKDAT BZIRK MATNR NETWR WAVWR PERNR VBELV DATE
90000003 F2 20050602 2 10000030 50 4.67 1 80000011 200506
90000004 F2 20050602 2 10000030 50 4.67 1 80000012 200506
90000005 F2 20050603 2 10000030 50 4.67 1 80000014 200506
90000006 F2 20050617 2 10000030 400 109.29 1 80000019 200506
90000007 F2 20050627 2 10000030 100 13.86 1 80000016 200506
90000009 F2 20050627 2 10000030 4 2.77 1 80000040 200506
90000022 F2 20050719 2 10000030 10 1.39 2 80000052 200507
90000023 F2 20050719 2 10000030 10 1.39 1 80000053 200507
90000024 F2 20050719 2 10000030 10 1.39 1 80000054 200507
90000025 F2 20050726 2 10000030 25.2 1.4 2 80000061 200507
90000026 F2 20050726 2 10000030 25.2 1.4 2 80000062 200507
90000027 F2 20050726 2 10000030 0 0 2 80000063 200507
90000028 F2 20050801 2 10000030 252 14 2 80000067 200508
90000029 F2 20050803 2 10000030 0 0 2 80000069 200508
90000029 F2 20050803 2 10000030 120 15.4 2 80000069 200508
90000029 F2 20050803 2 10000030 0 0 2 80000069 200508
90000029 F2 20050803 2 10000030 120 15.4 2 80000069 200508
90000040 F2 20050829 2 10000030 25.2 1.4 2 80000084 200508
90000046 F2 20050902 6 91 150 77.5 2 80000086 200509
90000047 F2 20050906 2 91 47.25 1.55 2 80000087 200509
90000048 F2 20050906 6 91 29.5 1.55 2 80000088 200509
90000049 S1 20050906 6 91 29.5 1.55 2 80000088 200509
90000050 F2 20050906 6 91 29.5 1.55 2 80000088 200509
90000051 F2 20050906 2 91 57.5 1.55 2 80000089 200509
90000080 F2 20050928 AK 1 70 21.89 2 80000106 200509
90000084 F2 20051006 AK 400030 30 10 2 80000110 200510
90000084 F2 20051006 AK 1 35 10.94 2 80000110 200510
90000084 F2 20051006 AK 400030 30 10 2 80000110 200510
90000084 F2 20051006 AK 1 35 10.94 2 80000110 200510
90000085 F2 20051006 13 400030 400 20 2 80000111 200510
90000085 F2 20051006 13 1 350 109.44 2 80000111 200510
90000085 F2 20051006 13 400030 400 20 2 80000111 200510
90000085 F2 20051006 13 1 350 109.44 2 80000111 200510
90000087 G2 20051006 13 1 3.5 1.09 2 80000111 200510
90000087 G2 20051006 13 400030 40 2 2 80000111 200510
90000087 G2 20051006 13 1 3.5 1.09 2 80000111 200510
90000087 G2 20051006 13 400030 40 2 2 80000111 200510
90000088 F2 20051006 2 91 10500 310 2 80000112 200510
90000092 F2 20051011 AK 91 250 15.5 2 80000115 200510
90000093 F2 20051022 2 10000043 1.1 1 2 80000117 200510
90000094 F2 20051019 6 91 250 15.5 2 80000118 200510
90000099 F2 20051027 13 400030 600 70 2 80000124 200510
90000099 F2 20051027 13 400030 0 0 2 80000124 200510
90000099 F2 20051027 13 400030 600 70 2 80000124 200510
90000099 F2 20051027 13 400030 0 0 2 80000124 200510
90000100 F2 20051028 6 1234567 300 200 2 80000126 200510
Now I have to group by PERNR,BZIRK and DATE Fields and corresponding NETWR and WAVWR fields should be sum up and show the values. But here one issue we have to take care i.e
This internal table Field FKART already contains both Positive Billing Documents(F2,L2,IV,S2) and Negative Billing Documents (S1,G2,RE,IG).
Inside we have to calculate the Sales$ and Cost$ values.
Sales$ = VBRP-NETWR(Positive Billing Docs) VBRP-NETWR ( Negative Billing Docs)
Cost$ = VBRP-WAVWR(Positive Billing Docs) VBRP-WAVWR (Negative Billing Docs)
This value I have to move it to output table.
Output should follow like this.
Salesmen District date total (sales$)
1 2 200506 100.00
1 2 200507 45.00
2 2 200507 80.00
2 2 200508 70.00
Like so on ..
Regards,
Sivaram