Query giving wrong output

I am trying to look for sub programs that use the synonyms in the schema.I wrote the following query.But its giving strange output.
  select usy.synonym_name, us.text, us.name, us.type
  from user_synonyms usy, user_source us
where upper(us.text) like ('%' || usy.synonym_name || '%')
   and usy.synonym_name in
       (select synonym_name
          from user_synonyms us
         where us.synonym_name <> us.table_name
           and table_owner = 'XYZ')
order by usy.synonym_nameOutput
synonym_name text
txn_deposit select pir_detail_txn.instrument_amnt
I wonder why txn.instrument is taken same as txn_instrument which is the synonym name??

where name like 'txn_instrument'
give all outputs like
txn_instrument
txn.instrument
txn1instrument
txn2instrument .......
but
where name like 'txn\_instrument' escape '\'
gives only txn_instrument
~Praveen

Similar Messages

  • Query giving wrong values in portal but correct through RSRT

    Hi,
    Users are running a query through portal which is giving wrong figures. But when we are running the query through RSRT it is showing correct values. The quesry is built on top of an InfoCube which is regularly updated and data in it is matching with R/3.
    This is an Inventory Valuation Query.
    Please suggest what could be the possible issue.
    BR,
    Sayan

    Hi,
    Make sure cache is deleted for the particular query. While the report is executed through portal it refers the cache and if the data in the backend is not changed then the cache for a particular query selection is active and referred each time the query is run.
    on other hand while running RSRT we have an option of not using cache and thus it refers the infoprovider and fetches the correct result. In this case cache could be invalid.
    Try deleting the cache.
    Regards,
    Amit

  • Report is giving wrong output while running in Background ?

    Hi,
    We have a report program which gives the correct output while running it in forground(or manually) but when we run it in backgroud it gives the wrong output. (The printout goes to the wrong printer.)
    I've read in a SAP doc that:
    NEW-PAGE PRINT ON  even gives unpredictable
    results when the print parameters are incomplete; and it suggested to use FM 'GET_PRINT_PARAMETERS to validate the print parameters before NEW-PAGE PRINT ON event . I tried the same but still our report is sending the printout to the wrong printer while running it in background.
    Other events used in the program are AT NEW and AT LAST .
    Can anyone confirm me NEW-PAGE PRINT ON, AT NEW and AT LAST  events work correctly in background mode also.
    Thanks,
    Bhavana

    hi
    good
    NEW-PAGE PRINT ON should be work in the background also,check your syntax with the below syntax,if still it is going to the different printer in the background than check with the configuration setting of printer for the particular report that you r printing,sometime it happens that even in the foreground the correct printer ideanfies but in the background that same printer didnt identify.
    NEW-PAGE PRINT ON
        NEW-SECTION
        PARAMETERS pripar
        ARCHIVE PARAMETERS arcpar
        NO DIALOG.
      DO 440 TIMES.
        WRITE (3) sy-index.
      ENDDO.
      NEW-PAGE PRINT OFF.
    ENDFORM.
    thanks
    mrutyun^

  • Query giving wrong results

    Below is the query thats giving me wrong results ...can anyone help me figure where i am going wrong :(
    SQL> select count(*) from t where source='LP1.1';
      COUNT(*)
            69
    SQL> select count(*) from tblspring where line_a='LP1.1';
      COUNT(*)
           233now when i join these two table ...the total counts exceeds the expected records that i want
    SQL> select count(*) from t , tblspring where t.source=tblspring.line_a and t.source='LP1.1';
      COUNT(*)
         16077

    the thing is i want to filter only those records from table t where the column named  - source is equal to the column named line_a from table tblspring from the query in table t i get 69 records ....
    now when i match the it table tblspring with the condition
    i want the number of records should be less than or equal to 69 but not more than 69
    Edited by: Suhail Faraaz on Mar 5, 2011 7:31 AM

  • Query giving wrong result

    Hi
    Could anybody tell me why this query is giving the wrong result? The column 'Spend for Selected Period' is showing as far too much (ie exactly 11 times too much!!!) when totalling the 37 invoices involved
    SELECT T0.[CardCode], T0.[CardName],T0.[MailCity] AS 'Town', T2.[SlpName] AS 'Rep',
    SUM(T1.DocTotal - T1.VatSum)  AS 'Spend for Selected Period', MAX(T3.CreateDate) AS 'Last Visit Date'
    FROM OCRD T0  left JOIN OINV T1 ON T0.CardCode = T1.CardCode LEFT JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode LEFT JOIN OSCL T3 ON T0.CardCode = T3.Customer
    where  T0.[CardCode] = 'wyk027/34' AND T1.DocDate BETWEEN '20090101' AND '20091231'
    GROUP BY T0.[CardCode], T0.[CardName],T0.[MailCity], T2.[SlpName]
    Thanks
    Steve

    Hi ,
    It seems like it is duplicated by the number of service calls.
    Try this one:
    SELECT T0.CardCode, T0.CardName,T0.MailCity AS 'Town', T2.SlpName AS 'Rep',
    SUM(T1.DocTotal - T1.VatSum) AS 'Spend for Selected Period', (select MAX(T3.CreateDate) from OSCL T3 where T0.CardCode = T3.Customer) AS 'Last Visit Date'
    FROM OCRD T0 inner JOIN OINV T1 ON T0.CardCode = T1.CardCode inner JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode
    where T0.CardCode = '10001' AND T1.DocDate BETWEEN '20090101' AND '20091231'
    GROUP BY T0.CardCode, T0.CardName,T0.MailCity, T2.SlpName
    Best regards,
    Maya

  • Oralce query giving wrong data

    Hi all oracle experts :
    in oracle backend ( LOV ) user is selecting 'long text' instead of 'short text' and as a result user is getting wrong data Ship_To_Adress ( column ). here what i need is :
    Upon data is coming from Long_Text table - it should not bring the wrong data Ship_To address.. It should give no value on the report.
    feasibility of modifying query to maintain two Scenarios - Irrespective of Long or Short text - User should not give wrong 'Ship To' address on the pick ticket.
    please go through the following query and make necessary changes. thanks in advance for your precious time valuable advice
    looking the feasibility of modifying query to maintain two Scenarios - Irrespective of Long or Short text - User should not give wrong 'Ship To' address on the pick ticket.
    Thanks in advance
    Shiva
    SELECT
         wpsv.pick_slip_number          "Pick Slip #",
         wdd.source_header_number          "Sales Order #" ,
         wdd.source_line_number          "Sales Order Line #" ,
    nvl(round(ool.unit_selling_price,2),0) "unitsell price" ,
    (nvl(round(ool.unit_selling_price,2),0))*nvl(wpsv.primary_qty,0) "Extended sell rice",
         '*'||wpsv.transaction_id||'*'          "Task ID" ,
         wpsv.transaction_id               "Task ID#" ,
         msi.segment1               "Item",
         msi.description               "Item Description",
         msi.segment1 || ' - ' ||msi.description               "Item - Description",
         wdd.requested_quantity_uom          "UOM",
         wdd.serial_number               "Serial #",
         wnd.delivery_id               "Delivery#",
         wpsv.from_subinventory          "Pick from Sub-inventory",
         wpsv.from_subinventory          || ' - ' ||
              SELECT
                   segment1||'.'||segment2||'.'||segment3||'.'||segment4
              FROM
                   INV.MTL_ITEM_LOCATIONS
              WHERE
                   inventory_location_id     = DECODE(msi.reservable_type,2,wdd.locator_id,wpsv.from_locator_id)
         ) "Pick From",
              SELECT
                   segment1||'.'||segment2||'.'||segment3||'.'||segment4
              FROM
                   INV.MTL_ITEM_LOCATIONS
              WHERE
                   inventory_location_id     = DECODE(msi.reservable_type,2,wdd.locator_id,wpsv.from_locator_id)
         )                    "Pick from Location",
         wpsv.to_subinventory "Deliver to Sub-inventory",
              select
                   segment1||'.'||segment2||'.'||segment3||'.'||segment4
              from
                   inv.mtl_item_locations
              where
                   inventory_location_id     = wpsv.to_locator_id
         )                    "Deliver to Location",
         wpsv.primary_qty          "Quantity to be Picked",
         party.party_name||CHR(10)||
         DECODE(ship_loc.address1, NULL, '',ship_loc.address1||CHR(10))||
         DECODE(ship_loc.address2, NULL, '',ship_loc.address2||CHR(10))||
         DECODE(ship_loc.address3, NULL, '',ship_loc.address3||CHR(10))||
         DECODE(ship_loc.address4, NULL, '',ship_loc.address4||CHR(10))||
         DECODE(ship_loc.city, NULL, NULL, ship_loc.city || ', ') || DECODE(ship_loc.state, NULL, NULL, ship_loc.state || ', ') || DECODE(ship_loc.postal_code, NULL, NULL,      ship_loc.postal_code || ', ') || DECODE(ship_loc.country, NULL, NULL, ship_loc.country) SHIP_TO_ADDRESS,
         NVL(h.shipping_instructions, '-') shipping_instructions,
         NVL(h.shipment_priority_code,'-') shipment_priority_code,
    NVL(OL.MEANING,'-') "Freight Terms",
         NVL(FLV.meaning, '-') shipping_method,
         NVL(QQA.quote_attachment, '-'),
         RSA.name,
         NVL(h.packing_instructions, '-') packing_instructions,
         NVL(H.CUST_PO_NUMBER,'-') customer_po#
    FROM
    apps.oe_order_lines_all ool,
         APPS.WSH_PICK_SLIP_V               WPSV,
         WSH.WSH_DELIVERY_DETAILS          WDD,
         INV.MTL_SYSTEM_ITEMS_B          MSI,
         WSH.WSH_DELIVERY_ASSIGNMENTS     WDA,
         WSH.WSH_NEW_DELIVERIES          WND,
         APPS.ORG_ORGANIZATION_DEFINITIONS     ORG,
         WMS.WMS_DISPATCHED_TASKS          WDT,
         APPS.OE_ORDER_HEADERS_ALL          H,
         APPS.HZ_CUST_SITE_USES_ALL          SHIP_SU,
         APPS.HZ_PARTY_SITES               SHIP_PS,
         APPS.HZ_LOCATIONS               SHIP_LOC,
         APPS.HZ_CUST_ACCT_SITES_ALL          SHIP_CAS,
         APPS.HZ_PARTIES                PARTY,
         APPS.FND_LOOKUP_VALUES          FLV,
    APPS.OE_LOOKUPS OL,
              SELECT
                   OOH.header_id,
                   MAX(DECODE(rownum,1, FDST.short_text, ''))||CHR(10)||CHR(10)||MAX(DECODE(rownum,2, FDST.short_text, ''))||MAX(DECODE(rownum,3, FDST.short_text, ''))||CHR(10)||CHR(10)||MAX(DECODE(rownum,4, FDST.short_text, '')) quote_attachment
              FROM
                   APPS.FND_ATTACHED_DOCUMENTS     FAD
                   , APPS.FND_DOCUMENTS_TL          FDT
                   , APPS.FND_DOCUMENTS_SHORT_TEXT     FDST
                   , APPS.FND_DOCUMENTS               FD
                   , APPS.FND_DOCUMENT_CATEGORIES_TL     FDC
                   , APPS.OE_ORDER_HEADERS_ALL          OOH
                   , APPS.ORG_ORGANIZATION_DEFINITIONS OOD
              WHERE
                   OOD.organization_id =?Organization ? AND
                   OOH.ORDER_NUMBER = ?SO#? AND
                   OOH.org_id = OOD.operating_unit AND
                   TO_CHAR(OOH.header_id) = FAD.pk1_value AND
                   FAD.document_id = FDT.document_id AND
                   FAD.entity_name = 'OE_ORDER_HEADERS' AND
                   FDT.media_id = FDST.media_id AND
                   FDT.language = 'US' AND
                   FAD.document_id = FD.document_id AND
                   FD.category_id = FDC.category_id AND
                   FDC.language = 'US' AND
                   FDC.user_name ='APS_Pack/AR Invoice/CI/SO Ack Printing'
              GROUP BY
                   OOH.header_id
         ) QQA
         , APPS.RA_SALESREPS_ALL RSA
    WHERE
         wpsv.move_order_line_id     =wdd.move_order_line_id          AND
         (wdd.source_header_number = ?SO#? )                    AND
         wdd.inventory_item_id     = msi.inventory_item_id(+)          AND
         wdd.organization_id          = msi.organization_id(+)          AND
         wdd.delivery_detail_id     = wda.delivery_detail_id          AND
         wda.delivery_id          = wnd.delivery_id(+)               AND
         wdd.organization_id = org.organization_id               AND
         wdt.TRANSACTION_TEMP_ID(+)=wpsv.transaction_id          AND
         wdt.organization_id (+)      =?Organization ?               AND
         wdd.organization_id          =?Organization ?               AND
         wdd.source_header_number      = h.order_number               AND
         h.salesrep_id = RSA.salesrep_id(+) AND
         h.org_id = RSA.org_id(+) AND
         h.org_id                = org.operating_unit               AND
         SHIP_PS.party_id          = PARTY.party_id(+)           AND
         H.ship_to_org_id          = SHIP_SU.site_use_id(+)           AND
         SHIP_SU.cust_acct_site_id     = SHIP_CAS.cust_acct_site_id(+)      AND
         SHIP_CAS.party_site_id     = SHIP_PS.party_site_id(+)           AND
         SHIP_LOC.location_id(+)     = SHIP_PS.location_id           AND
         H.shipping_method_code     = FLV.lookup_code(+)          AND
         FLV.lookup_type(+)          = 'SHIP_METHOD'               AND
         FLV.language(+)          = 'US'                    AND
         QQA.header_id(+)           = TO_CHAR(H.header_id)           AND
         wpsv.line_status          = 'UNPICKED'               AND
    H.FREIGHT_TERMS_CODE=OL.LOOKUP_CODE(+)
    AND OL.LOOKUP_TYPE(+) ='FREIGHT_TERMS' AND
    OOL.header_id = wdd.source_header_id(+) AND
    OOL.line_id = wdd.source_line_id(+) AND
         EXISTS(
              SELECT
                   'Y'
              FROM
                   INV.MTL_ONHAND_QUANTITIES_DETAIL OHQ
              WHERE
                   WDD.inventory_item_id     = OHQ.inventory_item_id     AND
                   WDD.organization_id     = OHQ.organization_id     AND
                   WPSV.from_subinventory = OHQ.subinventory_code
              GROUP BY
                   'Y'
              HAVING
                   SUM(transaction_quantity) >0
    ORDER BY
         2, 11, 12, 6, 3

    Thank you very much indeed for your reply - yes youre right. in oracle backend there are dropdown selections : 1) short text and 2) long text. as per the table user has to select short text so that he will get the correct output , but if by mistake user selects long text then the table is pulling wrong data. so here we need the query to be changed if user selects long text report shouldnt show any data..
    i am not sure but as per my little knowledge in oracle i believe that the problem is lying in the folloiwng query line.. please help me out in this regard. i have a screen shots of oralce backend where user is selecting long text / short text but here theres no option of inserting the files...
    DECODE(ship_loc.address1, NULL, '',ship_loc.address1||CHR(10))||
    DECODE(ship_loc.address2, NULL, '',ship_loc.address2||CHR(10))||
    DECODE(ship_loc.address3, NULL, '',ship_loc.address3||CHR(10))||
    DECODE(ship_loc.address4, NULL, '',ship_loc.address4||CHR(10))||
    DECODE(ship_loc.city, NULL, NULL, ship_loc.city || ', ') || DECODE(ship_loc.state, NULL, NULL, ship_loc.state || ', ') || DECODE(ship_loc.postal_code, NULL, NULL, ship_loc.postal_code || ', ') || DECODE(ship_loc.country, NULL, NULL, ship_loc.country) SHIP_TO_ADDRESS,
    Thank you very much once again
    Shiva

  • Isnumeric function is giving wrong output

    please check the code below.
    before converting I am validating the value is isnumeric or not. The Logic is giving isnumeric = 1 and when i am trying to convert to numeric it is giving me the error.
    declare @CustPhone varchar(max)
    set @CustPhone = '30927600,'
    select isnumeric(@CustPhone)
    select CONVERT(NUMERIC(15),ISNULL(@CustPhone,0))
    Gani.p

    Hi deve_gona
    Yes, we are getting the value with the comma. When there is  not comma it is working fine. But when there was a comma it is giving error.
    Gani.p
    then do a replace and then do cast
    isnumeric will return 1 for few other characters also like , $ etc so its not fully reliable
    see
    http://beyondrelational.com/modules/2/blogs/70/posts/10803/enhanced-isnumeric-function.aspx
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Concurrent generating wrong output format with TEXT as output type

    Hi,
    I have create a custom rdf and set TEXT as its output type.
    I want the text output to be specific format but the concurrent is not generating the exact expected output.
    Expected Output:
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE labels SYSTEM "label.dtd">
    <labels FORMAT="E:WIPMATX.ZPL" _QUANTITY="1" _PRINTERNAME="Printer
    1" _JOBNAME="LBL101">
    <label>
    <variable name="$$WIP_ENTITY_NAME$$">BLFTOP</variable>
    <variable name="$$WIP_ENTITY_NAME$$">BLFTOP14</variable>
    <variable name="COM">19AWG</variable>
    <variable name="LOT_NUMBER"></variable>
    <variable name="ASSEMBLY">A05A0084-1</variable>
    <variable name="QUANTITY_ISSUED">0</variable>
    </label>
    </labels>
    *Wrong Output:*
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE labels SYSTEM "label.dtd">
    <labels _FORMAT="E:WIPMAT_X.ZPL" _QUANTITY="1" _PRINTERNAME="Printer
    1" _JOBNAME="LBL101">
    <label>
    <variable name="$$WIP_ENTITY_NAME$$"> BLFTOP </vari
    </variable>
    <variable name="$$WIP_ENTITY_NAME$$"> BLFTOP
    BLFTOP14</variable>
    <variable name="COM">19AWG</variable>
    <variable name="LOT_NUMBER"></variable>
    <variable name="ASSEMBLY">A05A0084-1</variable>
    <variable name="QUANTITY_ISSUED">0</variable>
    </label>
    </labels>
    And Actually i am trying to generate this output format type because , wer are using Zebra Printer to print lable and it is a XML enabled bprinter and understand this specifice XML DTD type. We found when set Output type to XML, it was not generating XML in accordance with DTD which Zebra printer understand Hence we are tring to use TEXT output.
    Please suggest.
    Edited by: user5499188 on Oct 3, 2011 12:12 AM
    Edited by: user5499188 on Oct 3, 2011 12:13 AM
    Edited by: user5499188 on Oct 3, 2011 12:14 AM
    Edited by: user5499188 on Oct 3, 2011 12:23 AM

    I get the solution for this issue.
    The solution is to use XML Publisher etext temaplate.
    Etext is used to get text output in any format.
    Regards, :)

  • Query displaying wrong results

    Hi
    I have developed a query, in dev and transported to quality.
    everything worked fine in dev, after transport to quality, the query output is displaying data incorrectly
    for one particular infoobject. value is fourtimes the original value in the cube.
    Ex. cube has output for x field as 2.5
    query has the output as 15.0. This behaviour is observed only in quality after transport.
    Dev query is still working fine.
    I think even retransport would not solve the issue, since Dev is fine.
    Plz suggest,
    Regards

    Dear Sanju,
    Iu2019m going to try helping you regarding your question,
    Something, when you usually transport a query, something lose a variable, or structure, or calculate key figure, or restrict key figure. I suggest you; check all of component of query in development and quality system, through BEx Query Designer.
    Be sure, that the data that you try to display isnu2019t impact be reporting authorization.
    Compare the date in InfoProviders in both system development and quality system, through Tcode LISTCUBE.
    Try to execute the query through Tcode RSUDO for check some authorization behavior, see the log through Tcode RSECPROT.
    I hope this suggestion can help you to answer your question,
    Luis

  • Query SQL and output to text file then loop through list to execute

    It seems there's no obvious way to do what I want to below as everyone has their own take on querying SQL server with Powershell!
    I need to use PowerShell to connect to ServerA and query a test database and select Name from it.  The Name results of that query need to output to C:\names.txt and then I need a ForEach loop to go through that file line by line and execute some text
    against each Name from the list.
    Any ideas how I can achieve this?
    Thanks!

    I can't even output SQl to a table at the moment, the text file has a column header and about 50 empty rows in the file.
    $dataSource = "DEMO"
    $database = "TESTDB"
    $connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=True;"
    $query = "SELECT name FROM dbo.names"
    $connection = New-Object System.Data.SqlClient.SqlConnection
    $connection.ConnectionString = $connectionString
    $connection.Open()
    $command = $connection.CreateCommand()
    $command.CommandText  = $query
    $result = $command.ExecuteReader()
    $table = new-object "System.Data.DataTable"
    $table.Load($result)
    $format = @{Expression={$_.Id};Label="Name";width=25}
    $table | format-table $format | Out-File C:\export\servers.txt
    $connection.Close()

  • Create SP that returns value and at the same time displays query result in output window

    I would like create an SP which will return the records from the table and also return value to my c# client application.
    For Example:
    Select * from employee returns all the query results in output window.
    Now I want to create an SP
    Create procedure Test
    As
    Declare @ret int,
    Select * from employee
    set @ret = Select count(*) from employee
    if @ret > 0
    return 1
    else
    return 0
    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Can u pls help in this regard.

    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Why?  and No!
    Why?  Your procedure generates a resultset of some number of rows.  You check the resultset for the presence of rows to determine if "anything is there".  You don't need a separate value to tell you this.  Note that it helps
    to post tsql that is syntactically correct.   While we're at it, if you just need to know that rows exist there is no need to count them since that does more work than required.  Simply test for existence using the appropriately-named function
    "exists".  E.g., if exists (select * from dbo.employee). 
    No!  A stored procedure does not display anything anywhere.  The application which executes the procedures is responsible for the consumption of the resultset; it chooses what to do and what to display. 
    Lastly, do not get into the lazy habit of using the asterisk in your tsql code.  That is not best practice.  Along with that, you should also get into the following best practice habits:
    schema-qualify your objects (i.e., dbo.employee)
    terminate every statement - it will eventually be required.

  • WRONG OUTPUT

    Hi all,
    i am getting wrong output when executing the below code
    i.e the output is coming regard less of the order number  in select statement.
    Kindly please help me.
    REPORT  ZTEMP2.
    TYPES: BEGIN OF TY_BKPF,
           MONAT TYPE MONAT,
           BUDAT TYPE BUDAT,
           BELNR TYPE BELNR_D,
           GJAHR TYPE GJAHR,
           BUKRS TYPE BUKRS,
    END OF TY_BKPF.
    TYPES: BEGIN OF TY_BSEG,
           BUKRS TYPE BUKRS,
           BELNR TYPE BELNR_D,
           GJAHR TYPE GJAHR,
           HKONT TYPE HKONT,
           WRBTR TYPE WRBTR,
           SGTXT TYPE SGTXT,
           AUFNR TYPE AUFNR,
    END OF TY_BSEG.
    TYPES: BEGIN OF TY_COLL,
           MONAT TYPE MONAT,
           BUDAT TYPE BUDAT,
           BELNR TYPE BELNR_D,
           WRBTR TYPE WRBTR,
           SGTXT TYPE SGTXT,
    END OF TY_COLL.
    DATA: TOT LIKE BSEG-WRBTR.
    DATA: IT_BKPF TYPE TABLE OF TY_BKPF,
          WA_BKPF TYPE TY_BKPF,
          IT_BSEG TYPE TABLE OF TY_BSEG,
          WA_BSEG TYPE TY_BSEG,
          IT_COLL TYPE TABLE OF TY_COLL,
          WA_COLL TYPE TY_COLL.
    SELECTION-SCREEN: BEGIN OF BLOCK B1.
    SELECT-OPTIONS: S_HKONT FOR WA_BSEG-HKONT memory id one,
                    S_AUFNR FOR WA_BSEG-AUFNR memory id twq,
                    S_BELNR FOR WA_BKPF-BELNR memory id twe,
                    S_BUDAT FOR WA_BKPF-BUDAT memory id two.
    SELECTION-SCREEN: END OF BLOCK B1.
    START-OF-SELECTION.
    SELECT MONAT
           BUDAT
           BELNR
           GJAHR
           BUKRS FROM BKPF
           INTO TABLE IT_BKPF
           WHERE BELNR IN S_BELNR
           AND  BUDAT IN S_BUDAT.
    IF NOT IT_BKPF[] IS INITIAL.
      SELECT BUKRS
             BELNR
             GJAHR
             HKONT
             WRBTR
             SGTXT
             AUFNR FROM BSEG
             INTO TABLE IT_BSEG
             FOR ALL ENTRIES IN IT_BKPF
             WHERE HKONT IN S_HKONT
             AND AUFNR IN S_AUFNR
             AND BELNR IN S_BELNR
             AND GJAHR = IT_BKPF-GJAHR
             AND BUKRS = IT_BKPF-BUKRS.
    ENDIF.
    END-OF-SELECTION.
    SORT IT_BKPF BY MONAT.
    SORT IT_BSEG BY HKONT.
    LOOP AT IT_BKPF INTO WA_BKPF.
    Read table IT_BSEG INTO WA_BSEG WITH KEY BUKRS = WA_BKPF-BUKRS
                                             BELNR = WA_BKPF-BELNR
                                             GJAHR = WA_BKPF-GJAHR BINARY SEARCH.
    WA_COLL-BELNR = WA_BKPF-BELNR.
    WA_COLL-BUDAT = WA_BKPF-BUDAT.
    WA_COLL-WRBTR = WA_BSEG-WRBTR.
    WA_COLL-SGTXT = WA_BSEG-SGTXT.
    WA_COLL-MONAT = WA_BKPF-MONAT.
    COLLECT WA_COLL INTO IT_COLL.
    CLEAR: WA_BKPF, WA_BSEG.
    ENDLOOP.
    SORT IT_COLL BY MONAT.
    LOOP AT IT_COLL INTO WA_COLL.
        WRITE:/06 WA_COLL-BELNR,
               22 WA_COLL-BUDAT,
               32 WA_COLL-WRBTR,
               54 WA_COLL-SGTXT.
        AT end of MONAT.
          SUM.
          WRITE:/ WA_COLL-MONAT.
          WRITE:32 WA_COLL-WRBTR.
        ENDAT.
    ENDLOOP.
    Thanks in advance,
    ben2012.

    Hi,
    I tried this way to calculcate opening balance,
    but it is not working kindly suggest me.
    REPORT  ZTEMP1.
    " Types Declaration part
    TYPES: BEGIN OF TY_COLL,
           MONAT TYPE MONAT,
           BUDAT TYPE BUDAT,
           BELNR TYPE BELNR_D,
           WRBTR TYPE WRBTR,
           SGTXT TYPE SGTXT,
           TOT TYPE WRBTR,
    END OF TY_COLL.
    DATA: TOT LIKE BSEG-WRBTR.
    DATA: IT_BKPF TYPE TABLE OF TY_BKPF,
          WA_BKPF TYPE TY_BKPF,
          IT_BSEG TYPE TABLE OF TY_BSEG,
          WA_BSEG TYPE TY_BSEG,
          IT_BKPF1 TYPE TABLE OF TY_BKPF1,
          WA_BKPF1 TYPE TY_BKPF1,
          IT_BSEG1 TYPE TABLE OF TY_BSEG1,
          WA_BSEG1 TYPE TY_BSEG1,
          IT_COLL TYPE TABLE OF TY_COLL,
          WA_COLL TYPE TY_COLL.
    SELECTION-SCREEN: BEGIN OF BLOCK B1.
    SELECT-OPTIONS: S_HKONT FOR WA_BSEG-HKONT memory id one,
                    S_AUFNR FOR WA_BSEG-AUFNR memory id twq,
                    S_BELNR FOR WA_BKPF-BELNR memory id twe,
                    S_BUDAT FOR WA_BKPF-BUDAT memory id two.
    SELECTION-SCREEN: END OF BLOCK B1.
    START-OF-SELECTION.
    PERFORM SELECT1.
    PERFORM OPB.
    END-OF-SELECTION.
    PERFORM P_SELECT1.
    PERFORM P_OPB.
    PERFORM P_COLL.
    *&      Form  SELECT1
    FORM SELECT1 .
    SELECT MONAT
           BUDAT
           BELNR
           GJAHR
           BUKRS FROM BKPF
           INTO TABLE IT_BKPF
           WHERE BELNR IN S_BELNR
           AND  BUDAT IN S_BUDAT.
    IF NOT IT_BKPF[] IS INITIAL.
      SELECT BUKRS
             BELNR
             GJAHR
             HKONT
             WRBTR
             SGTXT
             AUFNR FROM BSEG
             INTO TABLE IT_BSEG
             FOR ALL ENTRIES IN IT_BKPF
             WHERE HKONT IN S_HKONT
             AND AUFNR IN S_AUFNR
             AND BELNR = IT_BKPF-BELNR
             AND GJAHR = IT_BKPF-GJAHR
             AND BUKRS = IT_BKPF-BUKRS.
    ENDIF.
    ENDFORM.                    " SELECT1
    *&      Form  OPB
    FORM OPB .
    SELECT MONAT
           BUDAT
           BELNR
           GJAHR
           BUKRS FROM BKPF
           INTO TABLE IT_BKPF1
           WHERE BELNR IN S_BELNR
           AND  BUDAT < S_BUDAT+3(8).
    IF NOT IT_BKPF1[] IS INITIAL.
      SELECT BUKRS
             BELNR
             GJAHR
             HKONT
             WRBTR
             SGTXT
             AUFNR FROM BSEG
             INTO TABLE IT_BSEG1
             FOR ALL ENTRIES IN IT_BKPF1
             WHERE HKONT IN S_HKONT
             AND AUFNR IN S_AUFNR
             AND BELNR = IT_BKPF1-BELNR
             AND GJAHR = IT_BKPF1-GJAHR
             AND BUKRS = IT_BKPF1-BUKRS.
    ENDIF.
    ENDFORM.                    " OPB
    *&      Form  P_SELECT1
    FORM P_SELECT1 .
    SORT IT_BKPF BY MONAT.
    SORT IT_BSEG BY HKONT.
    LOOP AT IT_BSEG INTO WA_BSEG.
      READ TABLE IT_BKPF INTO WA_BKPF WITH KEY BUKRS = WA_BSEG-BUKRS
                                               BELNR = WA_BSEG-BELNR
                                               GJAHR = WA_BSEG-GJAHR BINARY SEARCH.
    IF sy-subrc EQ 0.
    WA_COLL-BELNR = WA_BKPF-BELNR.
    WA_COLL-BUDAT = WA_BKPF-BUDAT.
    WA_COLL-WRBTR = WA_BSEG-WRBTR.
    WA_COLL-SGTXT = WA_BSEG-SGTXT.
    WA_COLL-MONAT = WA_BKPF-MONAT.
    COLLECT WA_COLL INTO IT_COLL.
    endif.
    CLEAR: WA_BKPF, WA_BSEG.
    ENDLOOP.
    ENDFORM.                    " P_SELECT1
    *&      Form  P_OPB
    FORM P_OPB .
    SORT IT_BKPF1 BY MONAT.
    SORT IT_BSEG1 BY HKONT.
    LOOP AT IT_BSEG1 INTO WA_BSEG1.
      READ TABLE IT_BKPF1 INTO WA_BKPF1 WITH KEY BUKRS = WA_BSEG1-BUKRS
                                                 BELNR = WA_BSEG1-BELNR
                                                 GJAHR = WA_BSEG1-GJAHR BINARY SEARCH.
    IF sy-subrc EQ 0.
    WA_COLL-TOT = WA_BSEG1-WRBTR.
    COLLECT WA_COLL INTO IT_COLL.
    endif.
    CLEAR: WA_BKPF1, WA_BSEG1.
    ENDLOOP.
    ENDFORM.                    " P_OPB
    *&      Form  P_COLL
    FORM P_COLL .
    SORT IT_COLL BY MONAT.
    LOOP AT IT_COLL INTO WA_COLL.
        WRITE:/06 WA_COLL-BELNR,
               22 WA_COLL-BUDAT,
               32 WA_COLL-WRBTR,
               54 WA_COLL-SGTXT.
        AT end of MONAT.
          SUM.
          WRITE:/ WA_COLL-MONAT.
          WRITE:32 WA_COLL-WRBTR.
          WRITE: WA_COLL-TOT.  " getting value 0
        ENDAT.
    ENDLOOP.
    ENDFORM.                    " P_COLL

  • Report painter is giving wrong figures

    Hi All,
       After year-end activities my report painter is giving wrong figures for detors, we have implemented special purpose ledger also, is there any year-end activity for SP ledger, or , what could be the reason this report painter is giving wrong figures. for december it is giving correct figures, after Y-End activities it is giving wrong figures
    Suresh patipati.

    Hi All,
       should we do balance carry forward for special purpose ledger also in GVTR, if so in which cases.. my report painter is giving wrong figures for january( after year end activities), but without doing GVTR quality server is giving correct figures ( in QAS also we did year end activities) ... what could be the reason...
    Suresh patipatil.
    Edited by: suresh patipati on Aug 19, 2011 11:42 AM

  • Rows to columns/Transpose the records Query and Display output

    hi ,
    can anyone help me query this and transpose it to this format?
    i am still a beginner in sql.
    thanks for help!
    Rows to columns/Transpose the records Query and Display output
    id     startdate     endate                    
    1111     1/2/2001     11/3/2001                    
    1111     2/5/2002     4/3/2002                    
    1111     2/6/2000     2/5/2001                    
    3333     5/2/2003     11/3/2003                    
    3333     6/2/2003     12/3/2003                    
    3333     2/6/2005     2/5/2005                    
    desired output     
    id     startdate1     endate1     startdate2     endate2     startdate3     endate3
    1111     1/2/2001     11/3/2001     2/5/2002     4/3/2002     2/6/2000     2/5/2001
    3333     5/2/2003     11/3/2003     6/2/2003     12/3/2003     2/6/2005     2/5/2005

    Have you only 3 dates for each id ?
    So, try :
    SQL> l
      1  with tbl as
      2  (select 1111 as id, to_date('01/02/2001','DD/MM/YYYY') startdate, to_date('11/03/2001','DD/MM/YYYY') enddate from dual union all
      3  select 1111 as id, to_date('02/05/2002','DD/MM/YYYY') startdate, to_date('04/03/2002','DD/MM/YYYY') enddate from dual union all
      4  select 1111 as id, to_date('02/06/2000','DD/MM/YYYY') startdate, to_date('02/05/2001','DD/MM/YYYY') enddate from dual union all
      5  select 3333 as id, to_date('05/02/2003','DD/MM/YYYY') startdate, to_date('11/03/2003','DD/MM/YYYY') enddate from dual union all
      6  select 3333 as id, to_date('06/02/2003','DD/MM/YYYY') startdate, to_date('12/03/2003','DD/MM/YYYY') enddate from dual union all
      7  select 3333 as id, to_date('02/06/2005','DD/MM/YYYY') startdate, to_date('02/05/2005','DD/MM/YYYY') enddate from dual )
      8  select id, max(decode(dr,1,startdate)) start1,
      9             max(decode(dr,1,enddate)) end1,
    10             max(decode(dr,2,startdate)) start2,
    11             max(decode(dr,2,enddate)) end2,
    12             max(decode(dr,3,startdate)) start3,
    13             max(decode(dr,3,enddate)) end3
    14  from (select id, startdate,enddate, dense_rank() over (partition by id order by startdate) dr from tbl)
    15* group by id
    SQL> /
                                                    ID START1   END1     START2   END2     START3   END3
                                                  1111 02/06/00 02/05/01 01/02/01 11/03/01 02/05/02 04/03/02
                                                  3333 05/02/03 11/03/03 06/02/03 12/03/03 02/06/05 02/05/05
    SQL> HTH,
    Nicolas.

  • Need a query to merge output in a single row?

    Hi All,
    I need a query to merge output in a single row.
    Query :
    Select dname from dept.
    Actual output is :
    Dname
    EDP
    ACCOUNT
    GR
    Desired Output is:
    Dname
    EDP ACCOUNT GR
    Please provide me the solution
    Thanks
    Amit

    select max(sys_connect_by_path (t.name,' '))  from  ( select id,
                            name,
                            group_id,
                            row_number() over (partition by group_id order by id) rn
                       from ( select 1 id, 'test'  name, 1 group_id from dual
                              union
                              select 2 id, 'test1' name, 1 group_id from dual
                              union
                              select 3 id, 'test2' name, 1 group_id from dual
                              union
                              select 4 id, 'test3' name, 1 group_id from dual)  ) t
    start with t.rn = 1 and id = 1
    connect by t.rn = prior t.rn + 1
    group by t.group_id

Maybe you are looking for

  • I photo problems.... each time I open it

    Why do I get this question every time I open iPhoto in my macro, "Updating Thumbnails, alert: The photo "P1010145.JPG" could not be opened, because the original item cannot be found."

  • How can I send and receive a message from  a queue using standalone program

    Hi, I want to write a standalone Java program which has to post a message to a queue and receive a message from a queue thats specified as a replyto queue.I want to have my application to be completely standalone without the need of a Application ser

  • Save form values as HTML file needed

    Hi, I need to export a Customer form values to an HTML file. I need it a the base file for a fusion with a Word document. How can I do it? thanks.

  • Removing a Child Object

    I have a web site that creates a page by calling another class object. When I return from that page to the Main page I want the old page removed. I have done it like this but I am getting errors. Two vars in GlobalVarsContainer: public static var rem

  • X201 Touchpad drivers (for Windows XP)

    I recently got a new X201 with Windows XP installed (from work). While the touchpad works fine, I noticed that I can't scroll (up/down, left/right) using it. I went to the control panel in search of settings, but all I see under "Mouse" are the stand