Find total quantity from vbrk and vbrp

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

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

Similar Messages

  • 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!!

  • Find out the relation from vbrk and ekpo

    hi
    i want the relation field from vbrk and ekko or ekpo apart from kunnr and lifnr.
    ple give me the field

    Check ThisLink
    Relation between the tables ekko and vbrk
    Ranga

  • 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

  • Is there a way I can have my form calculate a total time from beginning and ending time?

    Is there a way I can have my form calculate a total time from beginning and ending time?

    Sorry, but Formscentral doesn't support either a timer function or any kind of calculation. You might be able to do this if created your form in PDF. For help with PDF form creation in Acrobat I suggest you repost your question to the Acrobat Forum.
    Andrew

  • 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 add Total Quantity in Inbound and Outbound Delivery screen

    Hi,
    I want to add Total quantity field in Inbound and Outbound Delivery screens.
    In document flow i can see the line item quantities in ALV Format, but if i select Display the totals above the entry check box
    in Change Layout--> Display, i didn't see any totals displayed.
    Please help me on this?
    Regards
    Bhuvana

    Hi
    If the field is a customer field, see BADI 'LE_SHP_TAB_CUST_HEAD'
    Regards
    Eduardo

  • How to find onhand quantity from backend

    Hi,
    Somebody please tell me how to find onhand quantity for a particular item for particular subinventory.
    Please provide the query.
    Thanks in advance.

    mtl_onhand_quantities view contains the details of onhand.
    You can sum up transaction_quantities and group by item_id, org_id and subinventory code.
    Hope this helps,
    Sandeep Gandhi

  • RRB- Quantity from Project and rate from sales order

    Hi All,
    I got scenerio in my project where project is having resource related billing. Now ap per the client requirement, we have a sals order and projects. All prjects are software projects. Now my requirement is client is looking for a system there billing can be done at projet and resource level. which means if project is having 50 confirmed hours. In - dp91 one debit memo requiet should be created with 50 hours and rate should come sales order.
    Means if on a project 50 hours has been confirmes than in debit memo  request 50 hours should come from the prject and rate to be billed should come from sales order.
    Kindly suggest.
    Regards
    Abhishek Sinha

    Dear Virendra,Abhinay & Gokul,
    Thanks a lot for giving guidance. As per conversation above i can feel that we can overwrite the rates from project to condition records in SD. Is there any specific condition type made for RRB as my SD consultant never worked on RRB scnerios. Again reconfirming, in my current system at the time of debit memo request sytsem is taking all cost from project for billing but i want that system should take the confirm actual hours from proect and rates to bill them from SD.
    Once again thank a lot for showing interest. Sorry for replying late because of different time zone.
    Regards
    Abhishek Sinha

  • "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

  • Amount is different in VBRK and VBRP

    For currency USD, why the amount posted to NETWR in VBRK is correct and amount posted to NETWR in VBRP is with 2 decimal places. Example, total of 226.472,0000 USD but posted as 22.647.200,00.

    Hi,
    1> Please check the decimal notation settings under default tab for the user under transaction SU3.
    2> If your condition rate currency is different than document currency, exchange rate will be applied during the condition value calculation.  Exch rate * TCURF-FFACT  = VBRK-KURRF (In case of billing doc).   So plz check the TCURF table FFACT value whether is 1 or 100.  It should be 100 for no decimal currencies (Such as JPY, TWD)
    Regards,
    P Gomatheeswaran

  • Join Problem LIKP,LIPS,VBRK and VBRP

    Hi,
    i am working on the SAP Query report. But having problem in creating joins between the following tables
    LIKP
    LIPS
    VBRK
    VBRP
    please guide me
    regard
    khurram

    LIKP
    LIPS
    VBRK
    VBRP
    select a~ b~ c~ d~ into corresponding fields of table itab from likp as a inner join
    LIPS as b on a~VBELN = b~VBELN
    VBRK as c~VBELN = a~VBELN
    VBRP as d~VBELN = a~~VBELN.
    also check the first condition  a~VBELN = b~(KDAUF,VBELV,VGBEL,WKTNR)
    second condition a~VBELN = c~SFAKN
    third condition a~VBELN = d~(AUBEL,VBELV,VGBEL,VGBEL_EX)
    hope it solves...

  • TS2755 I am trying to find a message from 2012 and when I load previous messages it only goes back so far then the program quits and sends me to the home ( main) screen. How can I find the message and get around this?

    I am trying to access a message from early 2012. When I load previous messages It will only go back to oct 2012 and then the program stops and kicks my to the home page. Anyone know how I can get to the message? Thanks.

    Try Spotlight Search
    1. From any Home screen page of iPad, drag your finger down anywhere on the center of Home screen.
    2. Spotlight search will now appear and you can search for apps, texts, or any other content you'd like just as you did on previous versions of iOS.

  • 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.

  • Problem in fetching invoice data from VBRK table.

    Hi guys,
              I am developing an ABAP program where I have to fetch the invoice data from VBRK and VBRP  based on the PO data or SO data in table LIPS. But I am not been able to link the two tables. Can anyone please suggest what are the PO and SO fields in VBRK or how to get the invoice data from VBRK and VBRP based on the Sales Order or Purchase Order number from LIPS. Thanks in advance.

    example:-
    VBRK &  VBRP
    select b~vbeln
             b~posnr
             a~fkdat
             a~spart
             a~kunag
             a~vkorg
             a~rfbsk
             a~fkart
             a~vtweg
             a~bzirk
             a~kurrf
             a~waerk
             a~knumv  
             b~fkimg    
             b~netwr 
             b~mwsbp 
             b~matnr
             b~arktx 
             b~prodh 
             b~vkgrp 
             b~ktgrm 
             b~aubel 
             b~matnr 
      into corresponding fields of table itab
      from vbrk as a inner join  vbrp as b
    on avbeln = bvbeln
      where a~kunrg in p_cust and
            a~fkdat in p_date and
            a~spart in p_dev and
            a~vkorg in p_vkorg and
            a~vtweg in p_vtweg and
            a~rfbsk in p_rfbsk and
            a~regio in p_regio and
            a~fkart in p_type and
            b~werks in s_werks and
            b~matnr in matnr.

Maybe you are looking for

  • Taking long time to execute views

    Hi All, my query is taking long time to execute(i am using standard views in my query) XLA_INV_AEL_GL_V , XLA_WIP_AEL_GL_V -----these standard views itself taking long time to execute ,but i need the info from this views WHERE gjh.je_batch_id = gjb.j

  • Loss of control file

    Hi My database is running on solaris 10. database verrison is 10.2.0.3.0 when connecting ot db after databases get started. it throws error ORA-00205: error in identifying control file, check alert log for more info and when I checked in alert log fi

  • Password required for Apple ID....but email address changed since created. Password forgotten.

    MY mum was just browsing the web when a message popped up saying....sing in to iCloud. enter the Apple ID password for (her email address). The problem is that she has changed her email address since creating her iCloud account.  She can't remember t

  • 6300 all-in-one BLACK ink

    I only want to print in BLACK ink. How do I turn off the color?  THANX

  • Transporting XI object

    Hi Gurus, I need to know about Transporting XI object. What object we can transport and what objects we cannot. If we can transport complete senarion what is use of software product and component.