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: 

Find total quantity from vbrk and vbrp

Former Member
0 Kudos

Hi frinds doing a report to display sales in 3 month 6 month snd past 12 months but didnt get logic to find out

here is my code

SELECT vbrk~vbeln

vbrk~fkdat

vbrp~fkimg

vbrp~matnr

vbrp~werks

INTO CORRESPONDING FIELDS OF TABLE iquan

FROM vbrk INNER JOIN

vbrp ON vbrkvbeln = vbrpvbeln

WHERE vbrk~fkdat >= w_date " w_date =past 12month

AND vbrp~matnr IN s_matnr " = imatr-matnr

AND vbrp~werks IN s_werks. " = imatr-werks

**now how to find the total sales quantity

i tried in this way its not working "iquan is same as iquan1 with added added sales field.

LOOP AT iquan.

READ TABLE iquan1 WITH KEY matnr = iquan-matnr

werks = iquan-werks.

IF sy-subrc = 0.

IF w_date3 LE iquan-fkdat.

w_tot3 = w_tot3 + iquan-fkimg.

ELSEIF

w_date2 LE iquan-fkdat.

w_tot2 = w_tot2 + iquan-fkimg.

ELSEIF

w_date1 LE iquan-fkdat.

w_tot1 = w_tot1 + iquan-fkimg.

ENDIF.

iquan-sale12 = w_tot1.

iquan-sale6 = w_tot2.

iquan-sale3 = w_tot3.

ENDIF.

MODIFY iquan.

ENDLOOP.

*PLs pls pls pls help me with code or suggestion

0ut put shpuld be

material plant sales 3months 6months 12 months

01 0040 130 00.00 120

regards

1 ACCEPTED SOLUTION

messier31
Active Contributor
0 Kudos

Hi Farukh,

The logic seems correct..but i dont understand following line in <b>LOOP AT IQUAN</b>

i.e

<b>READ TABLE iquan1 WITH KEY matnr = iquan-matnr

werks = iquan-werks.</b>

You are reading iquan1 and assigning iquan1-werks to werks...Can you check this out..?

Enjoy SAP.

Pankaj Singh

3 REPLIES 3

messier31
Active Contributor
0 Kudos

Hi Farukh,

The logic seems correct..but i dont understand following line in <b>LOOP AT IQUAN</b>

i.e

<b>READ TABLE iquan1 WITH KEY matnr = iquan-matnr

werks = iquan-werks.</b>

You are reading iquan1 and assigning iquan1-werks to werks...Can you check this out..?

Enjoy SAP.

Pankaj Singh

Former Member
0 Kudos

Hi Farukh,

Try this code. This will definitely help you.

************************************************

<b>REPORT ZTEST .</b>

<b>TABLES:</b> VBRK,

VBRP.

<b>SELECT-OPTIONS :</b>

s_matnr FOR VBRP-MATNR,

S_WERKS FOR VBRP-WERKS.

<b>DATA:</b> BEGIN OF STRUCT,

matnr LIKE vbrp-matnr,

werks LIKE vbrp-werks,

vbeln LIKE vbrk-vbeln,

fkdat LIKE vbrk-fkdat,

fkimg LIKE vbrp-fkimg,

sale6 LIKE vbrp-fkimg,

sale12 LIKE vbrp-fkimg,

sale3 LIKE vbrp-fkimg,

END OF STRUCT,

IQUAN LIKE TABLE OF STRUCT WITH HEADER LINE,

IQUAN1 LIKE TABLE OF IQUAN WITH HEADER LINE.

<b>DATA:</b> w_tot1 LIKE iquan-fkimg,

w_tot2 LIKE iquan-fkimg,

w_tot3 LIKE iquan-fkimg.

<b>DATA:</b> W_DATE1 LIKE SY-DATUM,

W_DATE2 LIKE SY-DATUM,

W_DATE3 LIKE SY-DATUM.

**assign dates

W_DATE1 = '20051107' .

W_DATE2 = '20060507' .

W_DATE3 = '20060807'.

<b>SELECT</b> vbrk~vbeln

vbrk~fkdat

vbrp~fkimg

vbrp~matnr

vbrp~werks

INTO CORRESPONDING FIELDS OF TABLE iquan

FROM vbrk INNER JOIN

vbrp ON vbrkvbeln = vbrpvbeln

WHERE vbrk~fkdat >= w_date1 " w_date1 =past 12month

AND vbrp~matnr IN s_matnr " = imatr-matnr

AND vbrp~werks IN s_werks. " = imatr-werks

<b>SORT</b> IQUAN BY MATNR WERKS.

IQUAN1[] = IQUAN[].

<b>LOOP AT iquan.</b>

READ TABLE iquan1 WITH KEY matnr = iquan-matnr

werks = iquan-werks.

IF sy-subrc = 0.

"w_date3 : PAST 3 MONTHS

IF w_date3 LE iquan-fkdat.

w_tot3 = w_tot3 + iquan-fkimg.

ELSEIF

"w_date2 : PAST 6 MONTHS

w_date2 LE iquan-fkdat.

w_tot2 = w_tot2 + iquan-fkimg.

ELSEIF

"w_date1 : PAST 12 MONTHS

w_date1 LE iquan-fkdat.

w_tot1 = w_tot1 + iquan-fkimg.

ENDIF.

iquan-SALE12 = w_tot1.

iquan-sale6 = w_tot2.

iquan-Sale3 = w_tot3.

ENDIF.

<b> MODIFY iquan.</b>

ENDLOOP.

<b>LOOP AT IQUAN.</b>

STRUCT = IQUAN.

<b>AT END OF WERKS.</b>

<b>WRITE:/</b>

STRUCT-matnr, ' ',

STRUCT-werks, ' ',

STRUCT-sale6, ' ',

STRUCT-sale12, ' ',

STRUCT-sale3.

ENDAT.

<b>ENDLOOP.</b>

<b>The output is:</b>

9767A002AA 3201 10,255.000 0.000 0.000

C9138-60001 3201 10,255.000 2,000.000 0.000

C9361-30001 3201 10,255.000 2,004.000 0.000

Hope this will solve your purpose.

Regards,

Pragya

Former Member
0 Kudos

Hi Farukh,

Do you still have any doubt?

Regards,

Pragya