"How to sum FKIMG in VBRK and VBRP Table with sample output

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
345 with material number mat1=7, mat2=7
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.
kzwi1,kzwi2,kzwi3 is also been sum up
Sir the output is something like this
Sales Ord# Material Qty KWIZ1 KWIZ2 KWIZ3 MGVR1 VBELN
1234       Mat1     24  23.2  22    12           LastInvoice#
1234       Mat2     12  20.0  21    15           LastInvoice#  
1234       Mat3     37  22.0  22    16           LastInvoice#
5432       Mat1     30  25.0  23    15           LastInvoice#
5432       Mat2     24  22.0  24    23           LastInvoice#
5432       Mat3     20  18.0  20    12           LastInvoice#
Hope you can help me as i cant hardy sleep thinking of this ...
I will really appreciate your great help..
Thanks !
I will really appreciate your great help..
Thanks !
Moderator message: duplicate post locked.
Edited by: Thomas Zloch on Sep 20, 2011 3:05 PM

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

Similar Messages

  • How to update the VBFA table without entries in VBRK and VBRP tables

    Hello,
    I have a requirement , where the sales order , delivery happens in one SAP system say X system and billing document wil happens in other sap system say Y.
    Now in this particular case , if the user want to know the billing document number in X system. what would be the solution.
    Is there any possibility to update the VBFA table with invoice number of Y system (without updating the VBRK and VBRP tables).
    User want to see the billing doc number from sales order in the form of document flow in X system
    Thanks in advance
    Pradeep

    Hii
    Without updating VBRK/VBRP table and updating VBFA is not possible, So you have to play with work arround to create one Z TABLE, so whenever system Y will create billing document with the reference of System X data you have to update Ztable with Invoice number created in System Y, The primary key will be in Z TABLE is Delivery document number to track one to one with billing doc.
    Thanks and Regards
    Shambhu Sarkar

  • Vbrk and Vbrp tables performance problem

    Hi all,
    The below query is taking lot of time in QAS i need to decrease the time without affecting the logic.....
      SELECT vbrk~kunag
           vbkd~bstkd
           vbkd~bstdk
           INTO TABLE c_tab_po FROM vbrp
           INNER JOIN vbrk ON vbrkmandt = vbrpmandt AND vbrk~vbeln =
           vbrp~vbeln
           INNER JOIN vbkd ON vbkdmandt = vbrpmandt AND vbkd~vbeln =
           vbrp~aubel
                              AND vbkd~posnr = con_zposnr
           WHERE vbrp~vbeln EQ nast-objky.
      DELETE ADJACENT DUPLICATES FROM c_tab_po COMPARING ALL FIELDS.
    *Getting the other Invoices based on the customer PO number
      IF c_tab_po[] IS NOT INITIAL.
        SELECT
        vbrk~kunag
        vbkd~bstkd
        vbkd~bstdk
        vbkdposex_e vbrkvkorg
        vbrpvbeln vbrpposnr vbrp~erdat
               vbpakunnr vbrpaubel vbrpaupos vbakerdat
               vbrpmatnr vbrkmwsbk vbrp~netwr
               vbrkvaldt vbrkzterm vbrk~vbtyp
                INTO TABLE g_tab_invoice FROM vbrp
                INNER JOIN vbrk ON vbrkmandt = vbrpmandt AND vbrk~vbeln =
                vbrp~vbeln
                INNER JOIN vbkd ON vbkdmandt = vbrpmandt AND vbkd~vbeln =
                vbrp~aubel
                               AND vbkd~posnr = con_zposnr
                INNER JOIN vbpa ON vbpamandt = vbrpmandt AND vbpa~vbeln =
                vbrp~aubel
                               AND vbpaposnr = con_zposnr AND vbpaparvw =
                               con_parvw
                INNER JOIN vbak ON vbakmandt = vbakmandt AND vbak~vbeln =
                vbrp~aubel
                FOR ALL entries IN c_tab_po
                    WHERE vbrk~kunag EQ c_tab_po-kunag AND
                    vbkd~bstkd EQ c_tab_po-bstkd AND
                    vbkd~bstdk EQ c_tab_po-bstdk.
      ENDIF.

    Hi Younus,
    First join seems to be oku2026
    But you are querying Db tables multiple times to avoid this.
    Fetch the fields
    vbkdposex_e vbrkvkorg
    vbrpvbeln vbrpposnr vbrp~erdat
    vbrpaubel vbrpaupos
    vbrpmatnr vbrkmwsbk vbrp~netwr
    vbrkvaldt vbrkzterm vbrk~vbtyp
    in the first join itself.
    SELECT vbrk~kunag
    vbkd~bstkd
    vbkd~bstdk
    vbkd~posex_e vbrk~vkorg
    vbrp~vbeln vbrp~posnr vbrp~erdat
    vbrp~aubel vbrp~aupos
    vbrp~matnr vbrk~mwsbk vbrp~netwr
    vbrk~valdt vbrk~zterm vbrk~vbtyp
    INTO TABLE c_tab_po FROM vbrp
    INNER JOIN vbrk ON vbrk~mandt = vbrp~mandt AND vbrk~vbeln =
    vbrp~vbeln
    INNER JOIN vbkd ON vbkd~mandt = vbrp~mandt AND vbkd~vbeln =
    vbrp~aubel
    AND vbkd~posnr = con_zposnr
    WHERE vbrp~vbeln EQ nast-objky.
    then Just join VBPA & VBAK and get required data.
    Thanks,
    Sudha

  • How to get invoice data(VBRK and VBRP)

    Hi, guru:
    Would like to ask one thing:
    customer system will pass ECC invoice id, and base on that do we have any SAP standard BAPI or function module which can get all the details for that invoice(header and items both).
    I tried BAPI_billingdoc_getdetail, however I can only get data for header(VARK)
    Thanks heaps!
    Eric

    is ECC a legal number maintained in the J*** transaction. then you can fetch if from there.

  • Select from vbak, vbrk and vbrp

    Hi experts,
    In one of my programs i hve to select the data from tables <b>VBAK, VBRK</b> and <b>VBRP.</b>
    The requirement is:
    <b>parameters: p_matnr like vbrp-matnr,
                p_charg like vbrp-charg.
    select-options: audat for vbak-audat.</b>
    upon entering the values on selection-screen,
    i need to select <b>FKDAT, FKIMG</b> from tables VBRK and VBRP respectively.
    Please help me in writing the selection.
    Any help is appreciated.
    Thanks a lot.

    Hi,
    Hope this will give u some idea..
    select avbeln bfkdat into table itab from vbak as a inner join
                                  vbrk as b on
                                  avbeln = bvbeln where
                                  a~audat in s_audat.
    if not itab[] is initial.
    select fkimg into corresponding fields of table itab_final
                  from vbrp for all entries in itab
                  where vbeln = itab-vbeln and
                        matnr = p_matnr and
                        charg = p_charg.
    endif.
    Cheer,
    Vikram
    Pls reward fopr helpful replies!!

  • HT201363 My iPhone, iPad and iPod are all associated with the same Apple ID.  How can I remove the iPod and associate it with a new Apple ID without affecting the data on the other devices (note: there is no data on the iPod I want to keep)?

    My iPhone, iPad and iPod are all associated with the same Apple ID.  How can I remove the iPod and associate it with a new Apple ID without affecting the data on the other devices (note: there is no data on the iPod I want to keep)?

    Very simple.  Turn off Find my iDevice, then  Tap Settings, General, Erase, Erase all content and settings.

  • How to create a matrix with constant values and multiply it with the output of adc

    How to create a matrix with constant values and multiply it with the output of adc 

    nitinkajay wrote:
    How to create a matrix with constant values and multiply it with the output of adc 
    Place array constant on diagram, drag a double to it, r-click "add dimension". There, a constant 2D double array, a matrix.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How to load data to dimensions and fact table is it simialr to sql server

    How to load data to dimensions and fact table in a data ware house environment, is it simialr to sql server, oracle?
    Never migrated or loaded data to datawarehouse server.
    I have an interview and am really confused if they ask anything related to the dataware house side elements.
    Coudl you please if you don't mind provide me some steps and dimension and fact table info, an example only.
    Atleast for my knowledge.
    Thank you very much for the helpful info.

    Some discussions in previous forums should help you
    http://forums.sdn.sap.com/thread.jspa?threadID=2019448
    http://forums.sdn.sap.com/thread.jspa?threadID=1908902
    In the SAP tutorial, you can see a sample example of making fact tables.
    http://help.sap.com/businessobject/product_guides/boexir32SP1/en/xi321_ds_tutorial_en.pdf
    Arun

  • VBRK and KONA tables data (Agreements)

    hi experts,
    i have created view based on VBRK and KONA tables, but why some of the agreements are missing in VBRK??
    i not able to find the solutions, as i am ABAP developer.
    please tell me the reason why some of the agreements missed in VBRK?
    regards
    venuscm

    Hi
    Normally the rebate agreement is updated in KONA table. The rebate is created for a specific combination of customer and material or customer and rebate group etc. The rebate agreement appears in VBRK only if the combination in the invoice is same as that maintained  in the rebate. This means that for the invoice the rebate is accrued or provision is kept aside if the conditions of the invoice are similar to that of the rebate. To describe it through an example. Lets say customer has a rebate agreement for material Cadbury Dairy Milk and the rebate agreement is based on that. So if customer buys Cadbury 5-star and the rebate is not on that the acrrual would not be possible and hence VBRK would have no entry as it did not satisfy the condition of the rebate. If VBRK had customer and the material as Cadbury Dairy milk.
    Hope this explains.
    Thanks
    Indranil Ain

  • Once made a selection in photoshop how do you export in Illustrator and use it with a cutting plotte

    once made a selection in photoshop how do you export in Illustrator and use it with a cutting plotter?

    Plotters require continuous paths. Convert the selection to a path and clean it up suitably. Copy&paste it to Illustrator and use it as a clipping mask on your artwork or whatever. You may also need to create a duplicate layer/ separate PDF file file. Talk to the people doing the plotting.
    Mylenium

  • How do i share i tunes and i cloud with 2 iphones

    how do i share i tunes and i cloud with 2 iphones, like when i buy music it will go to my husbands phone or vice versa!

    Sharing an Apple ID for iTunes and App store purchases is not a problem.  Just enter the same Apple ID in Settings>Store>Apple ID.  You can turn on Automatic Downloads here as well.  However, don't share the same iCloud account unless you want to have merged calendars and contacts.  To maintain separation it's best to have separate iCloud accounts with different Apple IDs.  (The Apple ID you use for iCloud does not have to be the same as the one you use for purchases in Settings>Store.)  This article may be of interest: http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/.

  • How can I share my music and some apps with my children's devices, but not share iMessage

    How can I share my music and some apps with my children's devices, but not share iMessage

    Then only set up your account in "Settings > iTunes & App Stores" and don't give them your password .

  • How you can sync your contact and your mail with iTunes 11 as it's not there anymore ?

    How you can sync your contact and your mail with iTunes 11 as it's not there anymore ?

    ~ means your Home directory. Using the command above takes you to the Home directory on the boot drive.  Your backup files are now on another drive in a directory that used to be your Home but is now a subfolder of Users so you have to specify that drive after the /Volumes, then the user name, then the rest to go there
    I use OSX 10.4.11 and on it the libraries are still visible.  There's two at least.  One general one at the top level of the boot drive and another for each user (the one with the ~).  I think they made at least one of them invisible with newer OS versions.

  • How-to create dependent list boxes in a table -Frank Sample

    hi everyone i would like to ask a suggestion about Frank's example on How-to create dependent list boxes in a table -Frank Sample ...
    i want to extend this example for 3 dependent lists... including locations, departaments and employes....
    this the ListboxBean java that Frank is using in his example.... and this is only for locations and departaments tables and it works ok... i want to add the third list for employers wich is dependent only from departaments list.... as i am not good in java i would like to ask u a suggestion on how to develop the third list in this java class ...
    public class ListboxBean {
    private SelectItem[] locationsSelectItems = null;
    private SelectItem[] departmentsSelectItems = null;
    public SelectItem[] getLocationsSelectItems() {
    if (locationsSelectItems == null){
    FacesContext fctx = FacesContext.getCurrentInstance();
    ValueBinding vbinding = fctx.getApplication().createValueBinding("#{bindings.LocationsView1Iterator}");
    DCIteratorBinding locationsIterBinding = (DCIteratorBinding) vbinding.getValue(fctx);
    locationsIterBinding.executeQuery();
    Row[] locRowsArray = locationsIterBinding.getAllRowsInRange();
    // define select items
    locationsSelectItems = new SelectItem[locRowsArray.length];
    for (int indx = 0; indx < locRowsArray.length; indx++) {
    SelectItem addItem = new SelectItem();
    addItem.setLabel((String)locRowsArray[indx].getAttribute("City"));
    addItem.setValue(locRowsArray[indx].getAttribute("LocationId"));
    locationsSelectItems[indx] = addItem;
    return locationsSelectItems;
    return locationsSelectItems;
    public SelectItem[] getDepartmentsSelectItems() {
    FacesContext fctx = FacesContext.getCurrentInstance();
    ValueBinding vbinding = fctx.getApplication().createValueBinding("#{row}");
    JUCtrlValueBindingRef rwJUCtrlValueBinding = (JUCtrlValueBindingRef) vbinding.getValue(fctx);
    Row rw = rwJUCtrlValueBinding.getRow();
    if (rw.getAttribute(6) != null){
    OperationBinding oBinding = (OperationBinding) fctx.getApplication().createValueBinding("#{bindings.ExecuteWithParams}").getValue(fctx);
    oBinding.getParamsMap().put("locId",rw.getAttribute(6).toString());
    oBinding.execute();
    ValueBinding vbinding2 = fctx.getApplication().createValueBinding("#{bindings.DepartmentsView2Iterator}");
    DCIteratorBinding departmentsIterBinding = (DCIteratorBinding) vbinding2.getValue(fctx);
    departmentsIterBinding.executeQuery();
    Row[] depRowsArray = departmentsIterBinding.getAllRowsInRange();
    // define select items
    departmentsSelectItems = new SelectItem[depRowsArray.length];
    for (int indx = 0; indx < depRowsArray.length; indx++) {
    SelectItem addItem = new SelectItem();
    addItem.setLabel((String)depRowsArray[indx].getAttribute("DepartmentName"));
    addItem.setValue(depRowsArray[indx].getAttribute("DepartmentId"));
    departmentsSelectItems[indx] = addItem;
    return departmentsSelectItems;
    public void setLocationsSelectItems(SelectItem[] locationsSelectItems) {
    this.locationsSelectItems = locationsSelectItems;
    public void setDepartmentsSelectItems(SelectItem[] departmentsSelectItems) {
    this.departmentsSelectItems = departmentsSelectItems;
    Thanks in advance :0

    Hi,
    I think that all you need to do is to look at how I implemented the dependent detail for querying the Employees select items
    Then you make sure the DepartmentsVO and the EmployeesVO have bind variable to query them according to the pre-selected value in their respective master list
    Frank

  • No Update FMIOI and KBLP tables with purchase order

    Hello,
    We have un serious problem : No Update FMIOI and KBLP tables with purchase order
    System :  SAP ERP 6.0 /7.0 - EHP 4
    Note 965633 was read.
    1) First case: The purchase order 4510000673 does not reduce the funds reservation.
    Purchase order 4510000673 should consume the funds reservation 1200000193 because all post of the PO charge the funds reservation 1200000193.But the consumption history of the funds reservation 1200000193 donu2019t show this consumption.
    In table FMIOI, we do not have lines with amount type 0200 (reduction) but whe have the lines with the post of PO with amount type (0100).  The Purchase order 4510000673 should consume the funds reservation 1200000193.
    In table KBLP, the fields are :
    Total amount (LC) - HWGES  = 53.409,40
    Amount used u2013 WTABB = 0,00
    Reduction amount u2013 HWABB = 0,00
    Open amount u2013 CWTFREE =    53.409,40
    Reduced amount u2013 WTABG = 0,00
    Reduced amount u2013HWABG = 0,00
    To solve the problem, we executed the transactions : FM4N et FMN5 and the program RFFMRC20 but no result.
    2) Second case : Delete a item of a purchase order does not release the budget
    The single item of the purchase order 4510000597 is deleted but in the display of consumption History of the funds reservation 1200000137, the amount of the purchase order is not to zero.
    To solve the problem, we executed the transactions : FM4N et FMN5 and the program RFFMRC20 but no result.
    Somebody already had a similar problem ?
    Thank you
    Fabian

    Hello Fabian
    There are two known notes dealing with missing update on reference Earmarked Funds, I am listing them for future references:
    1376800  Earmarked funds: Incorrect open amount         
    1438487  RFFMRC20: Missing KBLE records are ignored     
    These notes correct some errors within the Standard.
    However, in your scenario, problem has to do with an incorrect execution of a Commit work inside a customer user-exit. After elimination of this commit work, new Po's are working correctly.
    Remaining task is the correction of old PO's. Manual correction via small changes with ME22N (for instance, adding a '.' to the line item text/s) will force the correct update and fix your database
    If you agree, we can close this thread (?)
    Kind regards
    Mar

Maybe you are looking for

  • Navigation Bar - No Rollover

    www.crystalhoyt.com I made the navigation bar by using the navigation bar tool. Although it says "rollover" image, none comes up. It is loaded because I use it for the "selected" image too for different web pages. Please advise.

  • My Mac Mini is running on iOS 10.6.8 can it be loaded with 7.0 or higher?

    My Mac Mini is running on iOS 10.6.8 can it be loaded with 7.0 or higher?

  • Catalyst Control Center.

    Catalyst Control Center On My  HP Pavilion dv7-6c50ei Crashes On Start Up, Any Solutions To Get It Running Again?. Thank You, Your Help Would be Much Appreciated.

  • Apple TV - iTunes Performance - Thumbails Generation slowing everything dow

    Hello all, I've been wondering if I am the only one with an issue that has been completely diminishing my end-user experience regarding my Apple TV. Whenever I hit the 'Movies' tab when browsing my Apple TV, iTunes will completely freeze for about 4-

  • Coding in iChat

    Hi. I'm from Russia. I have very big problems with coding in iChat. I can send messages, on other side my friends can read it, but I cannot read their messages... Help me please!!!! P.S.: My friends work on Windows with Rambler ICQ or QIP.