How to Sum in a SAP Query

Folks,
I have given up....Really need some advice....
I need a report example: Order Number, Order Type, Order Date, Customer number, Net Price, Total order cost
I can get all I need from file VBAK, EXCEPT total order cost, which is at the line level (VBAP).  Now I need to show one line per order and sum the cost field (VBAP/WAVWR)...
How can I accomplish this in SAP Query?  IS this even possible?

Hi,
I am sure about SAP Query...
But check this program which might satisfy your requirement..
Declarations.
TYPE-POOLS: slis.
DATA: BEGIN OF wa_data,
        vbeln LIKE vbak-vbeln,
        auart LIKE vbak-auart,
        audat LIKE vbak-audat,
        kunnr LIKE vbak-kunnr,
        netwr LIKE vbak-netwr,
        wavwr LIKE vbap-wavwr,
        waerk LIKE vbak-waerk,
        posnr LIKE vbap-posnr,
      END OF wa_data.
DATA: itab LIKE wa_data OCCURS 0 WITH HEADER LINE.
DATA: itab_final LIKE wa_data OCCURS 0 WITH HEADER LINE.
DATA: v_tabix TYPE sytabix.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv.
Selection-screen.
PARAMETERS: p_erdat LIKE vbak-erdat OBLIGATORY.
START-OF-SELECTION.
Get the data
  SELECT avbeln aauart
         aaudat akunnr
         anetwr bwavwr
         awaerk bposnr
         INTO TABLE itab
         FROM vbak AS a INNER JOIN vbap AS b
         ON avbeln = bvbeln
         WHERE a~erdat = p_erdat.
  IF sy-subrc <> 0.
    MESSAGE s208(00) WITH 'No data found'.
    LEAVE LIST-PROCESSING.
  ENDIF.
  SORT itab BY vbeln.
Sum the cost.
  LOOP AT itab.
Store the tabix.
    v_tabix = sy-tabix.
    wa_data = itab.
    AT END OF vbeln.
      SUM.
modify the cost.
      MOVE wa_data TO itab_final.
      MOVE itab-wavwr TO itab_final-wavwr.
      APPEND itab_final.
      CLEAR itab_final.
    ENDAT.
  ENDLOOP.
SHow the report.
  DATA: v_repid TYPE syrepid.
  v_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name     = v_repid
            i_internal_tabname = 'WA_DATA'
            i_inclname         = v_repid
       CHANGING
            ct_fieldcat        = t_fieldcat.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            i_callback_program = v_repid
            it_fieldcat        = t_fieldcat
       TABLES
            t_outtab           = itab_final.
Thanks,
Naren

Similar Messages

  • How show the Extractor's Sap query

    Hi masters,
    I have a custom extractor in R/3 created with SAP Query method.
    By RSA2, if I try to double click on Extractor name it does not succeed nothing!
    How can I see the Sap Query created behind The Extractor?
    Thanks so much!

    Hi Martina,
    if you want see the infoset in the extractor use sq02.
    Bye

  • How to change code in SAP Query

    Hi Experts !!
    In SAP QUERY I am getting the  PO  with  all delivey dates & deliveried Qty  but I have to select only  single PO with latest delivery date  & qty. If there r more than one record for latest delivery date than deliveried QTY must be sum of  all QTY (for the  latest delivery date). for example :
    this is coming
    Po                delivery date                 qty
    10001         30.06.2009                   4
    10001         30.06.2009                   5
    10001         01.05.2009                   4
    we want
    Po                delivery date                 qty
    10001          30.06.2009                   9
    Thanks in advance.
    Thanks & Regards
    Navneet Singhal

    >
    navneet singhal wrote:
    > There is an internal table  %G00 in  query generated program (AQCSZPCWMM======Z_PCW_ORDER_V2) when I use this table in Code section (END-OF-SELECTION ) system thro msg %G00 is not defined . if I define this table in DATA  section than  run the query , It gives the  DUMP  with error %G00 is already decleared.
    >
    > How can I use %G00 internal table  in my code section.
    I have the same problem as the OP. I need to get rid of the duplicates and have all sumarized in just one row. I was thinking about this same solution, but when I add code to the END-OF-SELECTION event, this doesn't appears anywhere (but if I add code to any calculated field, yes).
    And the problem of the quoted message. I tried using field-symbols but I have errors saying that it's nos a valid table, etc...
    Any ideas???
    Thanks!!!

  • How to remove duplicates in SAP Query

    Dear Frns,
    I created a simple SAP query with quickviewer by table join option.
    tables are MAST & STPO.
    Link is only STLNR.
    I am getting a duplicate extra line with same data.
    Can anyone suggest me how it happened.
    Is there anyway to remove these duplicate lines.
    pl suggest

    Hi,
    You can sort the internal table and then delete the duplicate entries.
    sort itab ascending by STLNR.
    delete adjacent duplicates from itab comparing STLNR.
    Reward points for useful answers.

  • How to Substr field in SAP Query.

    Dear Developer,
    How to substr any field in SAP Query ?
    Regards,
    Ujed.

    Hi Ujed,
    if SUBSTR stands for substring, then possibly your question may be how to get the substr method as konown in languages like php in ABAP.  If SAP Query points to a SAP query as created in transaction SQ01, then you should explain what you want to achieve.
    Note: Better ask a specific question and get am answer you can or which is already generalized.
    If I need a substr function, I'd create a functional method for that:
    method substr
      importing
        anyfield type any
        offset type i
        length type i
      returning substring type string.
      try.
        substring = anyfield+offset(length).
      catch cx_root.
    * handle error
      endtry.
    endmethod.
    Regards,
    Clemens

  • SAP Query: How to filter records from SAP Query output before display

    Hi Friends,
      Can I delete records from an SAP query basic list before it is displayed?
    For example I want to delte all the orders whose system status is "RELEASED" before the basic list of that SAP query is displayed.
    I have gone through SAP help and found out that we can write some code in <b>END code</b> section which will execute before the basic list of the query is displayed. But I could not figure out how the code this...following is an excerpt form SAP help.
    <b>"The END-OF-SELECTION code consists of two parts (Before list output and After list output). The first part is processed before the list is output and the second part afterwards."</b>
    Can anybody help me?
    Regards,
    Bharat.
    Message was edited by:
            Bharat Reddy V

    Try this simple procedure. <b>Hope</b> this should work for you.
    You do the slection of the status in the List-Processing. say your final field of status flag is GF_STATUS.
    Immediatly after that use this within the List-Processing.
    CHECK GF_STATUS EQ '<RELEASED STATUS>'
    How it works:
    SELECT  <>       "<-------Query processing(system code).
    *< Your code put in the List processing
    CHECK GF_STATUS EQ '<RELEASED STATUS>'   "< --only released records passed.
    *>
    ENDSELECT      "<-----Query endselect(system code).
    Please let me know the result.
    Regards,
    A.Singh
    Message was edited by:
            Amarjit Singh

  • How to edit a standard SAP Query

    I need to do authority check for satndard SAP Query....How to do it

    If you put code similar the following in the Infoset ---> Extras -> Code -> Start of Selection it should work
    CALL FUNCTION 'SD_ORGDATA_AUTHORITY_CHECK'
    EXPORTING
       I_VKORG            = P_VKORG
    *   I_VTWEG            =
    *   I_SPART            =
        I_ACTVT            = '01'
    EXCEPTIONS
       NO_AUTHORITY       = 1
       OTHERS             = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    So, if the user does not have the proper authorization, it will exit the program.  You will need to check with your Security administrator to verify what value to use for the Activity Code.

  • How to Create Specific SAP Query for Sales BOM

    Dear All Salute !!
    How I can create a SAP Query which provide information from the Sales Order-Line Item, this specific material is having any BOM or not?
    Suppose, user want Input,
    Sales Order No., Product Category, Duration of Sales Order Release.
    want Output,
    Sales Order No., Customer No., Customer Description, Sales Order Line Item, Material No., Material Description, Delivery Date, Quantity, Sales Order release Date
    Users requirement is, List of All Line Items for which BOM is yet to be Uploaded in the System.
    Please provide complete detail with Table & field by using SAP Query.
    Rgds
    Srivastav
    +91-9973504950

    If I am correct, in table KDST, you can see the details of Sales BOM with sale order.  Since right now, I dont have access to SAP, I am unable to confirm this.  You have to consider this table and develop on your own logic with the help of ABAPer.
    thanks
    G. Lakshmipathi

  • SAP Query: InfoSet Filter

    Hey experts,
    I have an Infoset that contains the JEST table (status of object) and TJ02T (text of the status).
    In my query result I only want records in 1 language.
    I know I can make a selection criteria on language with a default value.
    But now I want to hide the field in the selection criteria.
    How can I do this?
    I don't find an option to hide selection criteria. And I don't want to make an additional variant.
    Is it possible to delete the records in the infoset with some coding?
    Thanks
    Steven

    I found the solution in post Re: SAP Query: How to filter records from SAP Query output before display

  • Debugging in SQ02 (Sap Query Report)

    Hi All ;
    I want to learn that ,how can I debug a sap query report.I added some fields to the query with code.
    How can I reach that code by debugging ?Thanks for your reply.
    Regards.
    Fırtına.

    Hi Yigit,
    Every Query generated one program like  AQZZ/FSCMA/IS===CDM_10_Q1=====
    Go To your QuerySQ01 , run your query and From selection screen, check your program name  after that you can search your added code. what you added in infoset but your breakpoint  and debug your query code.
    Regards,
    Prasenjit

  • Debugging a SAP Query

    Hi,
    I have created a SAP query using the tcodes sq01,sq02 and sq03.
    Have added an additional field to retrieve some text and wrote the code also inside the query.
    Now i want to debugg the query.
    How do i degubb a sap query?
    Thanks in Advance,
    Regards,
    mani

    find out program name with:
    SQ01 - query - more functions - display report name
    (example : AQZZ/GRC/APPL===FI_AP_20_Q1===)
    -> search for your add. coding / field in this report and set break-points
    hope that helps
    Andreas

  • Urgent........SAP Query..

    Hi,
    Cany anyone tell me how to find when a SAP query is created/changed?
    Is there any table to store all these details about the query..
    plz..its urgent one..
    Thanks in advance.
    Srinivas.

    Hi
    Check the query related tables
    AQGDB
    AQGTB
    AQGTQ
    AQGDBBG
    AQGTS
    AQGQCAT
    Also check the table TADIR with object type AQQU
    for query related info
    Reward points for useful Answers
    Regards
    Anji
    Message was edited by:
            Anji Reddy Vangala

  • Question on SAP query

    i am working on sap query,
    my requirement is:
    there is already a sap query, where MARA tabel and MARC are mapped and are working fine.
    i need to drag in one more table AEOI for the purpose of finding latest revision level.
    in ususal report program we can find the revision level by sending matnr as OBJKT, objtyp as 41,
    and out of the list we get, we sort in descending order of date to get the latest levesion level.
    can some one suggest me how to do this in SAP query.
    is there a place where i can simply put in my code to call the AEOI table and sort the out put.
    please help.

    Hi Sanjana,
    Its better not to touch the standard sap generated program for the query, better choice would be copy the program to Z program and then make the changes what ever you require.
    Then create the tcode for that zreport and execute it and you can transport it to other environments.
    you can directly give the tcode to the process folks.

  • Caller Program name after SUBMIT or Call Tran (SAP-Query drill as ex)

    Hi ,  there is real simple situation
    I have SAP Query and do Drill Down to my Report or  Transaction.
    So I have two questions but as I believe they are equal:
    1) How I can get Caller SAP Query name from my Report ?
    2) How can we get  Caller Program name after SUBMIT or CALL TRANSACTION operator (in new started report for example )?

    Hi,
    there is a system variable sy-cprog ...check if u can use it...
    else from the caller prog move its name to SAP memory and retrive it in called prog..
    in caller prog
    data caller_prog type SYCPROG.
    move sy-repid to caller_prog.
    set parameter id 'ZCPROG' field caller_prog.
    submit <called_prog> and return.
    in called prog
    data caller_prog type SYCPROG.
    get parameter id 'ZCPROG' field caller_prog.
    write caller_prog.
    write / sy-repid.
    Cheers,
    jose.

  • RSBBS: Jump From BW Query to SAP Query

    Hi
    I have a cost center analysis report in BW which has an option to jump to R/3. When I type the transaction RSBBS and give the name of the query, the Receiver application is 'QU' (Sap Query) and the receiver object is 'GZ_BW_INTGRTYZISQ_CCA_Q01' which I am presuming is the query to which the Cost Center analysis report in BW is jumping to.
    How do I view this SAP query and if necessary change it. I have tried tcodes SQ01, SQ02, SQ03 and none of these recognise the above mentioned receiver object
    Kindly advise.
    Regards
    Sheily

    the best way to figure out is to ask ur functional guy the Tcode to get there. it could be anything.

Maybe you are looking for

  • How to Call  fnd_submit.submit_program  in a custom Form ?

    Hi, Im creating a custom form based on TEMPLATE.fmb in Oracle EBS R12. I want to call a concurrent program (called: RVCTP) through trigger WHEN_WINDOW_CLOSED or WHEN_BOTTON_PRESSED whatever.. I'm using this function: fnd_submit.submit_program How i c

  • "Errors in Task Sequence" dialog after replicating DS

    I'm trying to replicate some scripts in the \Scripts folder from a Server 2008 R2 machine running MDT 2012 (update nothing) at our main office out to other servers running the same version of Windows and MDT at our remote sites.  I've found that afte

  • Mac Pro no longer supporting my 2 displays?

    I have a 4 year old Mac Pro with the Dual-Core Intel Xeon Processors and 6GB of ram. I seems to have 4 NVIDIA GeForce GT display cards as well. I have been using this system with two 22" Apple cinema displays for 4 years with no problem what-so-ever.

  • Trouble turning on my ipad mini wifi.

    Battery was low, it turn off by it self. An it had been a week I can't turn it on.

  • PI Integration between SAP NW MDM and APO

    Hi SDners, This is a Parts Master Data Solution for one of the Largest Auto Manufacturer where SAP MDM will be the central hub of all the Global and Local attributes of Parts . The subscribing system is SAP SCM APO  . Please advice if there is any po