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: 

SUM of FKIMG joining VBRP and VBRK

Former Member
0 Kudos

Sir\Mam\Gurus ;

I hardly found it difficult in resolving my program in getting the sum of FKIMG inside the VBRP and VBRK tables

The scenario is that i have one Sales Order with multiple invoices . What i need to do is to sum up the fkimg or the quanitity of specific material regardless of how many invoices the material have in a particular SO

Example I have Sales Order number 35678952 with

3 invoices

Invoice # 123 with material number mat1=12, mat2=5 , mat3=7

  1. 345 with material number mat1=7, mat2=7

  2. 678 with material number mat1=5, mat3=10

Output shoud be

salesorder# 35678952

mat1 = 24

mat2 = 12

mat3 = 17

I will really appreciate your great help..

Thanks !

Moderator message : Duplicate post locked. Continue with original thread.

Edited by: Vinod Kumar on Sep 20, 2011 1:23 PM

2 REPLIES 2

former_member320332
Contributor
0 Kudos

After retriving the required data you can have a internal table with salesorder no and material no as key fields and the third field would be quantity. Then loop your internal table used for retrieving VBRP and VBRK values and move the corresponding fields in the second internal table and use COLLECT statement.

Thanks,

Pawan

0 Kudos

Thanks Pawan for your reply ;

Will you kindly take a look at my codes because it took a long time to process the data...

TYPES: BEGIN OF wa_vbrp_details,

matnr TYPE vbrp-matnr,

aubel TYPE vbrp-aubel,

aupos TYPE vbrp-aupos,

vbeln TYPE vbrp-vbeln,

kzwi1 TYPE vbrp-kzwi1,

kzwi2 TYPE vbrp-kzwi2,

kzwi3 TYPE vbrp-kzwi3,

kzwi4 TYPE vbrp-kzwi4,

kzwi5 TYPE vbrp-kzwi5,

kzwi6 TYPE vbrp-kzwi6,

mvgr1 TYPE vbrp-mvgr1,

mvgr2 TYPE vbrp-mvgr2,

mvgr3 TYPE vbrp-mvgr3,

mvgr4 TYPE vbrp-mvgr4,

mvgr5 TYPE vbrp-mvgr5,

knuma_pi TYPE vbrp-knuma_pi,

knuma_ag TYPE vbrp-knuma_ag,

mwsbp TYPE vbrp-mwsbp,

vkaus TYPE vbrp-vkaus,

fkimg TYPE vbrp-fkimg,

  • vbeln TYPE vbrk-vbeln,

fkart TYPE vbrk-fkart,

belnr TYPE vbrk-belnr,

xblnr TYPE vbrk-xblnr,

vbtyp TYPE vbrk-vbtyp,

kunag TYPE vbrk-kunag,

fksto TYPE vbrk-fksto,

  • fkart TYPE vbrk-fkart,

  • belnr TYPE vbrk-belnr,

  • xblnr TYPE vbrk-xblnr,

  • fksto TYPE vbrk-fksto,

  • vbtyp TYPE vbrk-vbtyp,

  • posnr TYPE vbap-posnr,

END OF wa_vbrp_details.

DATA : it_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,

ls_vbrp_details TYPE wa_vbrp_details,

ls_vbrp_details1 TYPE wa_vbrp_details,

lsfinal_vbrp_details TYPE wa_vbrp_details,

it2_vbrp_details TYPE STANDARD TABLE OF wa2_vbrp_details,

ls2_vbrp_details TYPE wa2_vbrp_details,

it3_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,

itfinal1_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,

itfinal2_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,

itfinal3_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,

ls3_vbrp_details TYPE wa_vbrp_details,

rtime1 TYPE i,

rtime2 TYPE i,

rtime3 TYPE i.

REFRESH: IT_vbrp_details.

SELECT

vbrp~matnr

vbrp~aubel

vbrp~aupos

vbrp~vbeln

vbrp~kzwi1

vbrp~kzwi2

vbrp~kzwi3

vbrp~kzwi4

vbrp~kzwi5

vbrp~kzwi6

vbrp~mvgr1

vbrp~mvgr2

vbrp~mvgr3

vbrp~mvgr4

vbrp~mvgr5

vbrp~knuma_pi

vbrp~knuma_ag

vbrp~mwsbp

vbrp~vkaus

vbrp~fkimg

  • vbrk~vbeln

vbrk~fkart

vbrk~belnr

vbrk~xblnr

vbrk~vbtyp

vbrk~kunag

vbrk~fksto

  • vbap~posnr

INTO TABLE IT_vbrp_details

FROM vbrp INNER JOIN vbrk ON vbrkvbeln EQ vbrpvbeln

  • where vbeln eq gt_data-vbeln

  • where vbrpaubel eq vbapvbeln

WHERE vbrp~posnr GE ''

AND vbrk~vbtyp EQ 'M'

AND vbrk~fksto NE 'X'

  • ORDER BY aubel aupos .

ORDER BY aubel aupos matnr.

IT3_vbrp_details = IT_vbrp_details.

SORT IT3_vbrp_details BY aubel matnr vbeln fkimg kzwi1 kzwi2 kzwi3 kzwi4 kzwi5 kzwi6 aupos

mvgr1 mvgr2 mvgr3 mvgr4 mvgr5 knuma_pi knuma_ag mwsbp vkaus fkart belnr vbtyp kunag fksto.

LOOP AT IT3_vbrp_details INTO LS_VBRP_DETAILS.

LS_vbrp_details1 = LS_vbrp_details.

  • COUNT = COUNT + 1.

AT END OF VBELN.

SUM.

LS_VBRP_DETAILS1-fkimg = LS_vbrp_details-fkimg.

LS_VBRP_DETAILS1-kzwi1 = LS_vbrp_details-kzwi1.

LS_VBRP_DETAILS1-kzwi2 = LS_vbrp_details-kzwi2.

LS_VBRP_DETAILS1-kzwi3 = LS_vbrp_details-kzwi3.

LS_VBRP_DETAILS1-kzwi4 = LS_vbrp_details-kzwi4.

LS_VBRP_DETAILS1-kzwi5 = LS_vbrp_details-kzwi5.

LS_VBRP_DETAILS1-kzwi6 = LS_vbrp_details-kzwi6.

APPEND LS_vbrp_details1 TO IT3_vbrp_details.

CLEAR LS_vbrp_details1.

ENDAT.

ENDLOOP.

Thanks ! Very much appreciated your reply!

God Bless!