Regarding summary Query...!

Hi,
i need a solution to this query.....
i have a table which looks like this
bot_ccy sold_ccy bot_amount sold_amount
USD AED 120000 150000
AED INR 5000 6000
INR GBP 80000 70000
GBP USD 7000 2000
USD GBP 220000 2000
Now i need a summary for each currency like this:
i need to show bot_ccy and sold_ccy in a single column
and then sum up all bot_amounts for each currency
and sum up all sold_amounts for each currency and then net it.
i am facing problem in writing this query...
suggestions required.....
currency bot_amount sold_amount net_amount
USD 340000 150000 190000

Hi ravi,
I may be missing something but how did you manage to produce this result?
currency bot_amount sold_amount net_amount
USD 340000 150000 190000
However, if I understood you right, you need something like this:
SQL> create table curr
  2   (bot_ccy varchar2(3),
  3    sold_ccy varchar2(3),
  4    bot_amount number,
  5    sold_amount number);
Table created.
SQL> begin
  2    insert into curr values('USD', 'AED', 120000, 150000);
  3    insert into curr values('AED', 'INR', 5000, 6000);
  4    insert into curr values('INR', 'GBP', 80000, 70000);
  5    insert into curr values('GBP', 'USD', 7000, 2000);
  6    insert into curr values('USD', 'GBP', 220000, 2000);
  7  end;
  8  /
PL/SQL procedure successfully completed.
SQL> select currency,
  2         sum(bot_amount) bot_amount,
  3         sum(sold_amount) sold_amount,
  4         sum(bot_amount) - sum(sold_amount) net_amount
  5    from (select bot_ccy currency, bot_amount, 0 sold_amount
  6            from curr
  7           union all
  8          select sold_ccy, 0, sold_amount
  9            from curr)
10   group by currency;
CUR BOT_AMOUNT SOLD_AMOUNT NET_AMOUNT
AED       5000      150000    -145000
GBP       7000       72000     -65000
INR      80000        6000      74000
USD     340000        2000     338000Does it answer your question?
Cheers.

Similar Messages

  • Regarding a query that gives a count of a certain combination of characters

    Hi all,
           I had a query to be created that gives a count of a certain combination of characteristics from a cube.
    Say a cube has 4 characteristics , Say A, B, C, D.
    Now amongst all the records that occured in the Cube I need a report of the following A, B and be able to see the count of the number of times a combination of A B occured i.e. variations of C and D for a certain A and B.
    For example say in the cube the A B C D has the following contents
    a1,b1,c1,d1
    a1,b1,c1,d2
    a1,b1,c1,d3
    a1,b1,c2,d1
    a1,b2,c1,d1
    a1,b2,c1,d2
    a1,b2,c2,d1
    a1,b2,c2,d2
    a2,b1,c1,d1.
    the report should show
    a1,b1,4 ,where 4 is the number of combination of a1 & b1.
    a1,b2,4 ,where 4 is the number of combination of a1 & b2.
    a2,b1,1 ,where 1 is the number of combination of a2 & b1.
    i want a help from all regarding this query.
    Thanking you in advance

    If you are in BW 3.5 or SEM I'd do this with a BPS-Exit that fills a key figure 'Combination Count' with 1 for each combination. If you need any details programming a BPS exit function feel free to ask.
    If you are in BW 3.0 or 3.1 without BPS-functions or you don't want to do BPS-setup just to create a user exit I'd suggest the following.
    1. Create an ODS CCOUNT that contains A,B,C,D and a key figure COUNT.
    2. Create an export data source for your cube.
    3. Create uodate rules from your cube to the ODS and set the key figure to constant 1 (with overwrite).
    4. Load your cube data into the ODS object.
    5. Load the ODS values back into the cube.
    This could lead to problems if you have other InfoObjects in your cube like time or version where you want to filter.
    Final method would be a virtual key figure but I'd try it this way first.
    B est regards
       Dirk

  • Regarding ABAP Query authorization group

    Hi Team,
    This is regarding ABAP Query!
    I have created one authorization group, for testing i have assigned my id in authorization group.
    After creation of ABAP query,standard program got generated. Now i have created one transaction code at the last for the ABAP Query.
    Now the isse is even though i have deleted my id from the authorization group. I am able to execute the query from SQ01 and with the Transaction code .
    It should not happen...i want who soever id is mapped to the transaction code ...that member should only be able to run that query, otherwise there is no use of authorization group.
    Please help me out in this case.
    Thanks & Regards,
    Anil Kumar Sahni

    Are you sure that you don't have access to that authorisation group? Execute report RSUSR002. In the 'Authorization Object 1' block inform  S_TABU_DIS in 'Auth.Object' and accept. Then inform Activity=03 and Auth.Gruop= your group.
    You will get a list of all the users which, theoretically, will be able to execute the query. If you press 'Roles' or 'Profiles' in the toolbar of the listing you will get to know why you have authorisation. May be you have the SAP_ALL profile.
    Also, one more thing to take into account: how have you created your transaction? Is it referring directly to the generated report? Then it is an error, you should execute program SAP_QUERY_CALL. Read this post: [Relate transaction to query;

  • Regarding Bex Query

    Hi All
    There is an issue....when i am trying to run my query in Bex Analyzer then its giving some error regarding Read Mode... and asking to go to Query Monitor (transaction RSRT1) here i am finding these two errors...
    Invalid read mode
    Error when generating dataProvider
    Any suggestion would be highly helpful.
    Thank you .
    Regards
    Shivanjali

    OSS note: 432596
    Summary
    Symptom
    Invalid read mode. For repair: RSRT (OK code =RMRP)
    Additional key words
    Cause and prerequisites
    Longtext of this message:
    A number of querues often have by mistake the read mode "Read all at once". In many cases, this causes performance problems. To avoid this type of error, the above warning message appears when you execute a query that has been generated with this read mode.
    Solution
    Change the read mode before you execute the query: You can change the read mode of a specific query using transaction RSRT. Choose Query -> Read mode to set the read mode for a selected query. If this warning message is displayed when you call up a query, you have to change the default read mode for new InfoCube queries in Customizing for BW (Tools > Business Engineer > BW Customizing > SAP Reference IMG ). The default read mode is under the node "BW Customizing Implmentation Guide > Business Information Warehouse > Reporting-Relevant Settings > Set Read Mode for InfoCube
    You can also change the read mode for all queries and the default read mode for all InfoCubes using transaction RSRT. Choose Environment -> Repair read mode. This is where you can change all non-allowed read modi to "Subsequenlty read by navigation".
    cheers
    Sunil

  • Regarding SELECT query

    Dear experts,
    Is there a way for the following SELECT query to be improved?
    The problem that I'm seeing here is that the same table (l_item_tab) is being queried twice in the SELECT query (due to the "table joins", a and b). How can I improve the data retrieval here? And I also can't change the SELECT query to be out of the loop - ledger is a select-option and multiple values are possible.
    * Get Ledger
      SELECT * FROM t881 INTO TABLE lt_t881
        WHERE rldnr IN s_rldnr.
      LOOP AT lt_t881.
    *   Get FI-SL user-defined item table based on ledger
        PERFORM get_sl_item_tab USING lt_t881-rldnr CHANGING l_item_tab.
      " L_ITEM_TAB is populated here
    *   Get SL line items
        SELECT * APPENDING CORRESPONDING FIELDS OF TABLE gt_glu1
        FROM (l_item_tab) AS a
        WHERE
            rldnr         IN s_rldnr             " Ledger
        AND rbukrs        IN s_bukrs             " Company code
        AND ryyrkeg_wwsub IN s_wwsub             " Subsystem
        AND racct         IN s_racct             " Account no
        AND ryymac        IN s_yymac             " Management area
        AND rtcur         IN s_rtcur             " Trx currency
        AND docnr         IN s_docnr             " Doc. number
        AND docty         IN s_docty             " Doc. type
        AND docct         EQ c_docct_l           " Doc. category (L = Local)
        AND ryear         IN s_ryear             " Fiscal year
        AND budat         IN s_budat             " Posting date
        AND yystodt       IN s_stodt             " Reversal date
        AND yystgrd       IN s_stgrd             " Reversal reason
        AND yyintref      IN s_intref            " Interface ID
        AND NOT exists
          ( SELECT * FROM (l_item_tab) AS b
             WHERE
                 b~rldnr    = a~rldnr     AND
                 b~docnr    = a~docnr     AND
                 b~rbukrs   = a~rbukrs    AND
           ( ( ( b~docct    = c_docct_y
              OR b~docct    = c_docct_x ) AND
                 b~refryear = a~ryear )   OR
             ( ( b~docct    = c_docct_u
              OR b~docct    = c_docct_t ) AND
                 b~ryear    = a~ryear ) )
      ENDLOOP.
    Edited by: Rob Burbank on Jun 23, 2010 12:33 PM

    >
    Siegfried Boes wrote:
    > > Will certainly try this out too..
    > maybe you should think twice .... The usage of a subselect is that the result set is not transferred to the application server it is only needed
    > during the selection.
    >
    > You should anser the following questions:
    > + who wrote the code? you or? I get the impression that you don't know what is intended.
    > + SQL Trace, what are the numbers for repeated executions, (go to summary by SQL statement), duration, execution, records
    > + how many different tables are accessed, l_item_tab is dynamic
    > + what knid of tables are accessed?
    >
    > Siegfried
    Hi Siegfried,
    - The codes are currently existing ones and they were not written by me too. I just do know that the first / main SELECT statement in the query is for retrieving FI special ledger line item data records, while the second / sub SELECT statement is to ensure that the line item data records are not already reversed, and not a reversal.
    - In the summarized SQL trace of a sample test run: executions = 1, identical executions = 0, duration = 700247324 (almost 100% of the total processing durations), records = 0 (there should be more records returned in an actual production run)
    - Only one table, ZZGLV4A (custom) is accessed based on the selection screen variant. ZZGLV4A is an FI special ledger line item table and its data volume: 455 mil. data records. Note: The codes are written for a report that runs in the background, and the selection screen variant is used for the executions too. The table accessed (l_item_tab is ZZGLV4A in this case) depends on the ledger inputted here - only one ledger is specified for the current selection screen variant.
    - Table accessed - FI special ledger line item data.
    I tried tuning the query a little further by just properly specifying the WHERE fields - only a minimal improvement is observed, an average of about 6% of runtime improvement only (tested via SE30 in the development box for ZZGLV4A but its table volume is 4 mil. data records here only). This obviously works only for the table ZZGLV4A for now, I'm afraid.
    Any other ideas on how such subqueries can be improved generally (maybe secondary indexes)? The subquery is certainly re-hitting the same table at least twice.
    Thanks for the inputs once again!

  • Need clarification regarding select query

    Hi,
    I need a little clarification regrding a Select senario
    I want to select data from table which have been minupulated between a certian date like between 1-DEC-10 to 31-DEC-10 and note that table does not have any time/date column. I've applied the following query to do this.
    select * from TABLE_NAME where sysdate between to_date('01-DEC-10') AND to_date('31-DEC-10');
    Would it work fine because I've tried it against a table and it returned me nothing however DML occur between time period.
    Regards,
    Abbasi

    Abbasi wrote:
    Hi,
    I need a little clarification regrding a Select senario
    I want to select data from table which have been minupulated between a certian date like between 1-DEC-10 to 31-DEC-10 and note that table does not have any time/date column. I've applied the following query to do this.
    select * from TABLE_NAME where sysdate between to_date('01-DEC-10') AND to_date('31-DEC-10');
    Would it work fine because I've tried it against a table and it returned me nothing however DML occur between time period.
    Regards,
    AbbasiAFAIK without log mining and auditing this is not possible.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/logminer.htm

  • Regarding select query Issue

    Hi ABAPERS,
          I had written one written one 'select single' query to retrieve the data from PRPS table.
    but what the data was selecting for OBJNR (Object number)field based on PSPNR(WBS element) .
    That OBJNR values in the report is totally different from the database table OBJNR  values.How its possible
    I am not getting.So can anyone please help me regarding this...
    Thanks and Regards
    Deepa

    Hi deepa,
    Pass the values to the select query where clause as you can see the values in SE16 display.(This is external format)
    If a table field as conversion routine, then SAP dosplay some thing on screen and store some thing else in data base.
    To check conversion exit go to domain of that field. Here you can see the routine used.
    For example you can check domain MATNR. Externally it display with leading zeros. But internally it stores with out zeros.
    Thanks,
    Vinod.

  • Regarding "select query" on performance basis..

    Hi Experts,
    I am creating an ALV report,so that i have to collect all data in 1 internal table.
    I have to collect data from 3 standard tables i.e.T157E,MSEG,MKPF.
    For all entries of T157E, i have to fetch data from MSEG.
    But in where condition i have to give POSTING DATE n this field is in MKPF.
    Also Database performance analysis is around 98%.
    How can i give better performance, please help..
    Below is my coding...
    (second select query is taking too much time,how can i rectify)
    SELECT BWART
                 GRUND
        FROM T157D
        INTO CORRESPONDING FIELDS OF TABLE IT_MOV_TYPE.
    SELECT MATNR
             MJAHR
             MBLNR
             BWART
             WERKS
             LGORT
             CHARG
             GRUND
             MENGE
             MEINS
        FROM MSEG
        INTO CORRESPONDING FIELDS OF TABLE IT_MSEG
        FOR ALL ENTRIES IN IT_MOV_TYPE
       WHERE GRUND = IT_MOV_TYPE-GRUND
         AND BWART = IT_MOV_TYPE-BWART
         AND WERKS = PLANT
         AND LGORT IN ST_L.
      SORT IT_MSEG BY MBLNR.
      LOOP AT IT_MSEG.
        AT NEW MBLNR.
          SELECT SINGLE BUDAT
                   FROM MKPF
                   INTO V_BUDAT
                  WHERE MBLNR = IT_MSEG-MBLNR
                    AND MJAHR = IT_MSEG-MJAHR.
          SELECT SINGLE MAKTX
                   FROM MAKT
                   INTO V_MAKTX
                  WHERE MATNR = IT_MSEG-MATNR.
          SELECT SINGLE GRTXT
                   FROM T157E
                   INTO V_GRTXT
                  WHERE GRUND = IT_MSEG-GRUND.
        ENDAT.
        IT_MSEG-BUDAT = V_BUDAT.
        IT_MSEG-MAKTX = V_MAKTX.
        IT_MSEG-GRTXT = V_GRTXT.
        MODIFY IT_MSEG.
      ENDLOOP.
    Regards,
    Ankur

    Before you use
    FOR ALL ENTRIES IN
    Do the following :
    1. Sort the Internal table used in the 'FOR ALL ENTRIES IN' clause.
    2. Make sure they do not contain duplicates.
    3. Last and most importantly include a primary key field(Unique entry) in the select list. The reason, the system gets unique field records based on the where condition. It summarizes the data based on the Data type and field list in the target internal table.
    One should be sure the internal table, used in the FOR ALL ENTRIES clause is not empty. If the table is empty, ALL ENTRIES will be selected. (Actually, all WHERE clauses are neglected). Of course, you should also be sure you select on INDEX fields. Otherwise the use of FOR ALL ENTRIES increases the runtime instead of improving it.

  • Daily Invoice Posting Summary Query

    Hello --
    Question about this Query below:
    SELECT T1.RefDate, SUM(T0.Debit - T0.Credit) as 'Net Balance'
    from JDT1 T0
    Inner Join OJDT T1 ON T1.TransId = T0.TransID and
    (T1.TransType = '13' or T1.TransType = '14')
    Inner Join OCRD T2 ON T2.CardCode = T0.ShortName
    Where T1.RefDate Between '[%0]' and '[%1]' and T2.CardType = 'C'
    Group by T1.RefDate
    Order By T1.RefDate
    This Query allows us to view a summary of the invoices and credit memo's posted for a specified time frame.
    I noticed that in the initial pop up window when we select this Query, it allows us to select the date range.  Today the date range ended with 10/1 -- today's date.
    However, after we select this range, the results show only up to 9/30 as the last date. 
    The results page is correct as the Invoices we have processed only apply up to 9/30 -- we have not invoiced for 10/1 yet.  Why does the selection period show up to 10/1 and not 9/30?
    Thanks!!
    Mike

    Mike,
    As I wrote to you in my earlier reply....what you see on the list of dates for selection is what is on the OJDT table.
    9/30 - 569 records for this date
    10/1 - 199 records for this date
    10/2 - 72 records for this date
    It does not mean that the 72 records that are found in OJDT match your criteria on belong to the document you are filtering on.
    OJDT contains journal entries from every possible document in Business One.....
    There are two things that happens when you select the date range 9/30 - 10/2
    In your query the WHERE clause is what does the filtering and qualification of the results...in the below WHERE clause.....
    Where T1.RefDate Between '[%0\]' and '[%1\]' is only one part...if you substitute them with the date...
    Where T1.RefDate Between '09/30/08' and '10/02/08'...the total records returned would be 840 (total of the above date range)...then come the T2.CardType = 'C' filteration...in which no records from 10/02/08 qualify... and only those which qualify show in the result.
    Where T1.RefDate Between '[%0\]' and '[%1\]' and T2.CardType = 'C'
    Group by T1.RefDate
    Order By T1.RefDate
    I think this is the best one can explain.........

  • Urgent: regarding insert query problem

    i have a one table say "item_master_old" its structure is like
    item_master_old (item_name, item_rate, item_qty, item_desc)
    second table say "item_master" its structure is like
    item_master(id, item_name, item_rate, item_qty, item_desc)
    i want to insert item_master_old values in item_master using the following insert query :
    insert into item_master ( (select nvl( max(id), 0) + 1 from item_master ),
    item_name,
    item_rate,
    item_qty,
    item_desc
    from
    item_master_old)
    but i update the id column with 1 in all column but i want the max(id) + 1
    how it can be possible ?
    Regards
    s

    try this!
    insert into item_master
    select (select nvl(max(id),0) from item_master)+rownum,
    item_name,  item_rate, item_qty, item_desc
    from item_master_old;
    "Not tested"Message was edited by:
    Jameel

  • Regarding ABAP query layout changes

    In 46C system, we have addon transaction ZXX created thru ABAP query displaying in ALV report
    layout fields in order A,B,C,D. But after upgrade to ECC5.0 we found the layout is changed to fields D,B,C,A.
    why its changed? Is it Patch problem or its SAP problem.
    However after upgrade we could manualy drag and drop the fields as per the 46C existing report layout
    it works fine.
    But we would like to know the reason why its happenning.?
    Could somebody give me suggestion.
    Regards
    Ambichan

    Hi Ambikumar,
    The ALV output layout is dependent on user settings.
    THe order of layout fields is changed bcz user has saved the new layout.
    In the output, check the ALV toolbar for CHANGE LAYOUT button. Click on it & check if anyone has saved any new layout. Delete the layout & you would alwyz get the fields in the same order as specified in the query.
    No need to modify the query using SQ01/SQ02.
    Simply execute the query & click button CHANGE LAYOUT.
    Best regards,
    Prashant

  • Question regarding SAP query (SQ01& SQ02)

    Hello everyone,
    I have been assigned a task of creating a SAP query in SQ01. The report requires me to incorporate a drill down functionality.
    i.e. when I double click on a material I should be able to see the components of that material.
    My question is "Is it possible to incorporate a drill down functionality in a Query through SQ01".
    If yes then how.
    Please provide me with some documentations or example codes for this.
    Regards,
    Deepti Jain.

    Deepti,
    There are 2 ways to get the output  From SAP query.
    1.Under record processing :
          if you don't write any code in Start of selection event for output
         (WRITE statements)  we can not have any control on that.
    2. Under start of selection event :
         If you write any code in START OF SELECTION event like
         get the data in internal table and loop the internal table
         In loop WRITE statement to display with format and try to use
        Interactive report commands Here. I think it will work fine.

  • Regarding ABAP Query related

    Hi,
      Can any body tell me how to keep query related data in
    internal table?
    Regards,
    Suresh Kumar.

    Do you mean that you are running a SQ01 query and you want to get the data from it into your report program?
    If this is the case, the normal way that we pass internal tables and stuff from program to program, is thru IMPORT/EXPORT statements.  But since you are talking about a query this may be a problem in adding the EXPORT statement to it.
    Regards,
    RIch Heilman

  • Regarding the Query Creation Date

    Dear All,
    How Can I find the creation date of querries which I have done in query designer. Is there any Infoobject keeping track of this data (SAP DEFINED). Pls post msg as soon as possible.

    Welcome on SDN!!
    In Bex analizer, open the query in modify mode, than choose properties and you will find creation date.
    Hope it helps.
    Regards
    PS: assign points if helpfull

  • Query regarding Inline Query and a Join.Please see

    I have a query regarding Inline Queries
    I have 2 tables
    TRADE and POSTING
    TRADE has Primary Key:id_trade_ref and POSTING has Foriegn.Key: id_trade_ref
    id_trade_ref 5V973781B has 5 records in POSTINGS
    If i need to join these 2 tables,I use
    1) Select t.id_entity,t.id_trade_ref,p.am_stock
       from trade t,posting p
       where t.id_trade_ref = '5V973781B'
       and   p.id_trade_ref = '5V973781B'
    2) Now I can use the same as an Inline Query:
       select
       t.id_entity,
       t.id_trade_ref,
       (  select p1.am_stock 
          from posting p1
          where p1.id_entity =  t.id_entity
          and   p1.id_trade_ref= t.id_trade_ref
          and   p1.id_posting_type in ( 'NEW', 'CAN')
    from
    trade t
    where t.id_entity = 'DBL'
    and   t.id_trade_ref = '5V973781B'
    My Query:
    Of the two,which is a better option to use.?
    Is Inline a better option or a normal join?

    I would rewrite the first one to:
    Select t.id_entity,t.id_trade_ref,p.am_stock
    from trade t,posting p
    where t.id_trade_ref = '5V973781B'
    and p.id_trade_ref = t.id_trade_ref
    This way, you really make the join between the table.
    I think the join is better because it uses less code. I do not think you will notice much performance win between one or the other, especially because it concerns only a few rows.

Maybe you are looking for

  • Multiple persistence units and OneToMany associations

    Hi, I have an EAR with two persistence units and corresponding entities. Each is contained within a separate library jar file. Some of the entities in one of the jars refer to entities in the other jar. If I refer to just a single entity (i.e., a One

  • They tell you Lies and there is nothing can be done

    I've been a loyal customer for over 9yrs with Verizon with 5 lines of service and up until this year I raved about their service.I even referred all my family and friends to them that was until now ! First let me say I HAVE NEVER BEEN TREATED SO UNFA

  • CHARM Roles in Satellite System

    Hi, Can anybody tell me  exactly on CHARM roles in Solman 7.0 EHP1. I am totally confused which roles i have to assign to Change Manager, IT operator, Tester, Developer & Requester. In Solman which roles I have to assign & in Satellite system R/3 whi

  • How do i install photoshop in my new computer without a cd

    i got a new laptop and it doesn't have a slot for a cd. How do i install my photoshop top my new computer?

  • Cystal Reports to Business Objects

    I have couple of reports designed in crystal reports and trying to import them into BO xi.  But these two are in different locations.  Having problem importing them.  BO is on Soalris, Cystal is running on Windows.  Can any body help?  You might need