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: 

How to sum FKIMG in VBRK and VBRP Table

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

Below is my Sample Codes:

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,

s_erdate type d,

scr_erdat type d,

s_erdate = scr_erdat.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = 1 " Negative to subtract from old date, positive to add

olddate = s_erdate

IMPORTING

newdate = new_date.

""" This is another way manual adding by days

  • CALL FUNCTION 'CALCULATE_DATE'

  • EXPORTING

  • days = +30

  • start_date = s_erdate

  • IMPORTING

  • result_date = new_date.

  • result_date = ddate.

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'

AND ( vbrperdat GE s_erdate OR vbrperdat LE new_date OR vbrp~erdat IN s_erdat ) " + JP 09 19 2011 Additional Optimization

  • ORDER BY aubel aupos .

ORDER BY aubel aupos matnr.

"""" This where i need your help Sir\Mam\Gurus

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

it3_vbrp_details = it_vbrp_details.

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

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.

COLLECT ls_vbrp_details INTO itfinal1_vbrp_details.

APPEND ls_vbrp_details TO it_vbrp_details.

ENDLOOP.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Hope you can help me as i cant hardy sleep thinking of this ...

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:21 PM

1 REPLY 1

Former Member
0 Kudos

Hi,

How you want to display the output?..

If you want to display the output as mentioned below, then you have to use nested loop & dynamic field assignments to get result.

Output column

sales order Mat1 Mat2 Mat3 ......

1234 24 12 37

Kindly let me know, if you have any questions

Regards,

S.Senthilkumar