Increase performance of the following SELECT statement.

Hi All,
I have the following select statement which I would want to fine tune.
  CHECK NOT LT_MARC IS INITIAL.
  SELECT RSNUM
         RSPOS
         RSART
         MATNR
         WERKS
         BDTER
         BDMNG FROM RESB
                      INTO TABLE GT_RESB 
                      FOR ALL ENTRIES IN LT_MARC
                      WHERE XLOEK EQ ' '
                      AND MATNR EQ LT_MARC-MATNR
                      AND WERKS EQ P_WERKS
                      AND BDTER IN S_PERIOD.
The following query is being run for a period of 1 year where the number of records returned will be approx 3 million. When the program is run in background the execution time is around 76 hours. When I run the same program dividing the selection period into smaller parts I am able to execute the same in about an hour.
After a previous posting I had changed the select statement to
  CHECK NOT LT_MARC IS INITIAL.
  SELECT RSNUM
         RSPOS
         RSART
         MATNR
         WERKS
         BDTER
         BDMNG FROM RESB
                      APPENDING TABLE GT_RESB  PACKAGE SIZE LV_SIZE
                      FOR ALL ENTRIES IN LT_MARC
                      WHERE XLOEK EQ ' '
                      AND MATNR EQ LT_MARC-MATNR
                      AND WERKS EQ P_WERKS
                      AND BDTER IN S_PERIOD.
  ENDSELECT.
But the performance improvement is very negligible.
Please suggest.
Regards,
Karthik

Hi Karthik,
<b>Do not use the appending statement</b>
Also you said if you reduce period then you get it quickly.
Why not try dividing your internal table LT_MARC into small internal tables having max 1000 entries.
You can read from index 1 - 1000 for first table. Use that in the select query and append the results
Then you can refresh that table and read table LT_MARC from 1001-2000 into the same table and then again execute the same query.
I know this sounds strange but you can bargain for better performance by increasing data base hits in this case.
Try this and let me know.
Regards
Nishant
> I have the following select statement which I would
> want to fine tune.
>
>   CHECK NOT LT_MARC IS INITIAL.
> SELECT RSNUM
>          RSPOS
> RSART
>          MATNR
> WERKS
>          BDTER
> BDMNG FROM RESB
>                       INTO TABLE GT_RESB 
> FOR ALL ENTRIES IN LT_MARC
>                       WHERE XLOEK EQ ' '
> AND MATNR EQ LT_MARC-MATNR
>                       AND WERKS EQ P_WERKS
> AND BDTER IN S_PERIOD.
>  
> e following query is being run for a period of 1 year
> where the number of records returned will be approx 3
> million. When the program is run in background the
> execution time is around 76 hours. When I run the
> same program dividing the selection period into
> smaller parts I am able to execute the same in about
> an hour.
>
> After a previous posting I had changed the select
> statement to
>
>   CHECK NOT LT_MARC IS INITIAL.
> SELECT RSNUM
>          RSPOS
> RSART
>          MATNR
> WERKS
>          BDTER
> BDMNG FROM RESB
> APPENDING TABLE GT_RESB
>   PACKAGE SIZE LV_SIZE
>                     FOR ALL ENTRIES IN LT_MARC
>   WHERE XLOEK EQ ' '
>                     AND MATNR EQ LT_MARC-MATNR
>   AND WERKS EQ P_WERKS
>                     AND BDTER IN S_PERIOD.
> the performance improvement is very negligible.
> Please suggest.
>
> Regards,
> Karthik
Hi Karthik,

Similar Messages

  • Change the default select statement in the execute_query function

    I want to list all records where c1 like '%ABD%'. So I set the following in the 'when_button_pressed' tigger:
    set_block_property ('block_name',DEFAULT_WHERE,'upper(c1) like '''||'%'||:block_name.blk_col_name||'%'||'''');
    execute_query;
    When I click on the button the :system.last_query holds the following select statement:
    select c1, c2, .. cn from t_n where upper(c1) like '%ABD%' and (upper(c1) = 'ABD' and (c1 like 'ab%' or c1 like 'aB%' or c1 like 'Ab%' or c1 like 'AB%')) order by c1
    Since the condition upper(c1) = 'ABD' is not satisfied oracle does not return any rows.
    My question is how to overcome this or is it possible to change the built-in select statement of execute_query.

    Have you tried this :
    'upper(c1) like upper('''||'%'||:block_name.blk_col_name||'%'||''''));

  • Help with a query using ISNULL and RTRIM in the same select statement

    What I'm trying to accomplish is to blend the following two statements together:
    ISNULL (EMail_Address, '') As Matrix_Member_Email
     AND
    RTRIM (EMail_Address) as Matrix_Member_EMail
    So that if the email address is NULL, it gets changed to blank and I still need to RTRIM the other entries and use the column header of Matrix_Member_Email.
    I've tried:
    ISNULL ((EMail_Address, '') (RTRIM (EMail_Address)) as Matrix_Member_EMail
    Any help would be greatly appreciated.
    Thank you,

    I'm sorry.  Here is the query:
    --Declare @EMail_Address nvarchar(100) = null
    Select SVAssociationID.R_ShortValue as MATRIX_AssociationID, Matrix_Modified_DT as Matrix_LastModified
      ,RTRIM (MLS_ID) As Matrix_MLS_ID
      , ISNULL(EMail_Address, '') AS MATRIX_member_Email
      ,RTRIM (EMail_Address) as Matrix_Member_EMail
      --,RTRIM( LTRIM(  ISNULL (@EMail_Address, '') ) ) as Matrix_Member_EMail 
      ,Last_Name AS MATRIX_LastName, Nickname AS MATRIX_NickName
      FROM    dbo.Agent_Roster_VIEW a
            LEFT JOIN dbo.select_values_VIEW SV ON a.Status_SEARCH = SV.ID
            LEFT JOIN dbo.select_values_VIEW BillType ON a.Bill_Type_Code_SEARCH = BillType.ID
      LEFT JOIN dbo.select_values_VIEW SVAssociationID ON A.Primary_Association_SEARCH = SVAssociationID.ID
    WHERE   Status_SEARCH IN (66,68) 
        Order by MLS_ID
    Results:
    MATRIX_AssociationID
    Matrix_LastModified
    Matrix_MLS_ID
    MATRIX_member_Email
    Matrix_Member_EMail
    MATRIX_LastName
    MATRIX_NickName
    STC
    09/02/14
    CCWILLI
    [email protected]
    [email protected]
    Williams                      
    Christine   
    STC
    09/12/14
    CCWORSL
    [email protected]
    [email protected]
    Worsley                       
    Charlie
    STC
    09/02/14
    CCYROBIN
    NULL
    Robinson       
    ECBR
    09/02/14
    CDABLACK
    [email protected]
    [email protected]
    Black                         
    Dale        
    STC
    09/02/14
    CDABRADY
    [email protected]
    [email protected]
    Brady                         
    David       
    Thank you,

  • Performance issue on a select statement

    Hi all @ SAPforums and thanks for your attention,
    the task is quite simple: given a Purchase Requisition number and position (banfn, bnfpo) I have to check if a contract with the same PR as source exists in the EKPO table.
    In order to check for it, I simply typed the following select:
    SELECT SINGLE * FROM EKPO INTO wa_checkekpo
          WHERE bstyp EQ 'K'
            AND banfn EQ l_eban-banfn
            AND bnfpo EQ l_eban-bnfpo.
    This kind of query is quite consuming (more than three seconds in my process) due to the fact that banfn and bnfpo don't belong to a key for the table.
    Any idea/workaround that can lead to better performance? Please note I'm not interested in retrieving the contract number (KONNR), it's sufficient to know it exists.

    Hi,
    > Do not use select * if you just want to check existence of the record.
    so far so good.
    > Use a single variable to store teh count.
    But why should we count the records if we just want to know if a key exists in
    the db or not? change the second half of the recommendation to:
    Use a single field of the used index for the select list to check (sy-subrc or result
    of that field) if the record exists or not.
    Kind regards,
    Hermann

  • How to tune the following sql statements which has two unions in oracle 10g

    It takes a long time to run the following sql statement in 10g. Each select brings back about 4 million rows and there will be about 12 million rows. When I run each select statements seprately in sqlplus I can see the data immedaitely but when I run it as whole with two unions in the select it just takes very very long time? I want to know how to make this run faster? Can we add hints? or is it because of any table space? Any help is appreciated.
    select
    D.EMPLID
    ,D.COMPANY
    ,'CY'
    ,D.CALENDAR_YEAR
    ,D.QTRCD
    ,D.ERNCD
    ,D.MONTHCD
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,D.GRS_YTD
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,D.HRS_YTD
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FY'
    ,(case when D.MONTHCD > '06' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD) + decode(sign(3-to_number(D.QTRCD)),1,2,-2),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FF'
    ,(case when D.MONTHCD > '09' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD)+decode(sign(4-to_number(D.QTRCD)),1,1,-3),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD)+decode(sign(10-to_number(D.MONTHCD)),1,3,-9),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    Edited by: user5846372 on Mar 11, 2009 8:55 AM

    Hi,
    What i observed is that your table name and where clause is same in all the thress SELECTs whereas columns having some manipulations that is not going to be unique. I guess you can easily replace UNION with UNION ALL.
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'Note: I am not aware of your data and business requirement. Please test the result before removing. It is just a suggetion
    Cheers,
    Avinash

  • Explain me the following replace statement

    Hi guys,
    Please explain me the following replace statement with an example :
    REPLACE ALL OCCURRENCES OF '''' IN materialgroup_desc WITH ''''''.
    Please explain me the purpose of the above statement by showing the input and output.
    Regards,
    Vishu.

    Hi Rob,
    It's working fine .Thank you.But I just want to know the purpose of it as the functionality in one of the programs I have seen is as below  :
    Requirement :
    Need to get all the material groups and description2 based on the material descriptions we enter in the selection-screen .
    The program is coded in such a way that all the single quotes are replaced with double quotes :
    The following 3 statements are written in the code  :
    REPLACE ALL OCCURRENCES OF '''' IN materialgroup_desc  WITH ''''''.
    REPLACE ALL OCCURRENCES OF '*'  IN materialgroup_desc WITH '%'.
    REPLACE ALL OCCURRENCES OF '''' IN materialgroup_desc  WITH ''''''.
    and finally the result string is concatenated between quotes again to query the data.
    For instance if we give MAT'ER*IAL as the input it is converted to 'MAT''''ER%IAL'
    and by querying with a select statement using
    materialgroup_desc LIKE 'MAT''''ER%IAL' we are getting the required data.
    Hope you understand mny question.Please explain me why we are replacing the single quotes with double quotes 2 times.Is it a way to skip the special characters.
    Regards,
    Vishu shetty.

  • Some Import Operations failed to perform. The following files could not be imported because they cou

    Some Import Operations failed to perform. The following files could not be imported because they could not be read....(then all the files that I checked do not get imported

    As a Test:
    Hold down the option (or alt) key and launch iPhoto. From the resulting menu select 'Create Library'
    Import a few pics into this new, blank library. Is the Problem repeated there?

  • Delete adjacent duplicates how to use in the below select statement

    hi i have a problem
    i am suing the below select statement
    SELECT    a~extno
              a~guid_lclic       " for next select
              e~ctsim
              e~ctsex
    *revised spec 3rd
              f~guid_pobj
              f~amnt_flt
              f~amcur
              f~guid_mobj
              e~srvll     "pk
              e~ctsty     "PK
              e~lgreg  "PK
      INTO TABLE gt_sagmeld
      FROM /SAPSLL/LCLIC  as a
      INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
      inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic   " for ccngn1 selection
      inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
                               where   a~extno in s_extno.
      sort gt_sagmeld by guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ.
      delete adjacent duplicates from gt_sagmeld comparing guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ .
    now i am confused how to use delete adjacent dupliacate and on which fields
    as first table /sal../lclic primary key is guid_lclic
    and it is joined to table
    legcon by guid_lclci ( not a primary key here)
    legcon primary key is guid_legcon
    and table 3 legsv by lgreg (pk here)
    table 3 has tow more primary key srvll and ctsty also
    NOW MY QUESTIO IS TAHT IS I USE ABOVE DELETE ADJACENT STATMENT IT FETCHES 20 LAKH RECORDS
    I WANT TO REDUCE IS LET ME KNOW ON WHAT fields i need to use delete adjacen duplicates
    or use comparing all fields?
    regards
    Arora

    hi sudha
    if u see my select statement is contains four Primary keys
    srvll
    lgreg
    ctsty
    guid_lclic
    but the next table connected to this table legcon is by guid_pobj and anothe table by guid_mobj
    and if i take this gt_sagmeld to another temp table and i find abt 10 lakh uniques guid_pobj
    similary 6 lakh guid_mobj so the next slect is hanpering because of this
    not COMING TO OUR POINT IF I SORT ONLY BY OUR PRIMARY KEYS NOT TAKING INTO ACCOUNT TEH GUID_POBJ AND GUID_MOBJ
    THE ENTRIES ARE VERY LESS BUT IF I TAKE INOT ACCCOUNT IN GT_SAGMELD THE ENTRIES ARE ABT 20 LAKH
    SO I AM NOT SURE WHETHER TO TAKNE GUID_POBJ AND GUID_MOBJ INOT ACCOUNT FOR DELECTING ADJACENT DUPLICATES?
    HENCE THE QUESTION OF ON WHICH FIRLD DELETE OR COMPARING ALL FIELDS I USE?

  • Splitting the huge SELECT statement

    Hi Gurus,
    I need help in order to split the huge SELECT statement into individual select for each table (AFKO, AFVC)...I don't have to much experience into that, could someone guide me into or provide finished code?
    Thanks
    OPEN CURSOR WITH HOLD s_cursor FOR
    SELECT
    t1~mandt AS mandt
    t1~aufnr AS aufnr
    t1~aufpl AS aufpl
    t2~aplzl AS aplzl
    t2~banfn AS banfn
    t2~bnfpo AS bnfpo
    t3~ebeln AS ebeln
    t3~ebelp AS ebelp
    t4~vgabe AS vgabe
    t4~belnr AS belnr
    t4~buzei AS buzei
    t4~gjahr AS gjahr
    t4~zekkn AS zekkn
    t4~srvpos AS srvpos
    t6~menge AS menge "D02K924592
    t3~dmbtr AS dmbtr "D02K924378
    t4~cpudt AS cpudt
    t4~shkzg AS shkzg
    t4~budat AS budat
    t3~lifnr AS lifnr
    t2~vornr AS vornr_sactv
    t7~vornr AS vornr_actv
    t2~sumnr AS sumnr
    t2~prctr AS prctr
    t6~meins AS meins "D02K924592
    t3~waers AS waers "D02K924378
    t3~sakto AS kstar "D02K924456
    t6~packno AS packno "D02K924592
    t6~introw AS introw "D02K924592
    FROM afko AS t1
    INNER JOIN afvc AS t2 ON t2mandt = t1mandt
    AND t2aufpl = t1aufpl
    INNER JOIN mseg AS t3 ON t3mandt = t2mandt "D02K924373
    AND t3aufpl = t2aufpl "D02K924373
    AND t3aplzl = t2aplzl "D02K924373
    INNER JOIN ekbe AS t4 ON t4mandt = t3mandt
    AND t4ebeln = t3ebeln
    AND t4ebelp = t3ebelp
    AND t4zekkn = t3zekkn "D02K924373
    AND t4~vgabe = 1 "D02K924373
    AND t4gjahr = t3mjahr "D02K924373
    AND t4belnr = t3mblnr "D02K924373
    AND t4buzei = t3zeile "D02K924373
    INNER JOIN t430 AS t5 ON t5mandt = t2mandt "D02K924489
    AND t5~plnaw = '*' "D02K924489
    AND t5steus = t2steus "D02K924489
    AND t5~service = 'X' "D02K924489
    LEFT OUTER JOIN esll AS t6 ON t6mandt = t4mandt "D02K924592
    AND t6packno = t4packno "D02K924592
    AND t6introw = t4introw "D02K924592
    INNER JOIN afvc AS t7 ON t2mandt = t7mandt
    AND t2aufpl = t7aufpl
    AND t2sumnr = t7aplzl
    WHERE t1~mandt = sy-mandt
    AND t1~aufnr LIKE '00006%'
    AND t1~aufnr IN l_r_aufnr
    AND t2~prctr = '0000005080'
    AND t2~sumnr '00000000'
    AND t4~vgabe = 1
    AND t4~cpudt IN l_r_cpudt
    AND t2~steus IN l_r_steus "D02K924627
    AND t5~steus IN l_r_steus. "D02K924627.
    Regards

    you can use for all entries option like this...
    " first select data from first table
    data: it_table1 type table of afko .
    SELECT
    t1~mandt
    t1~aufnr
    t1~aufpl
    FROM afko  as t1
    WHERE t1~mandt = sy-mandt
    AND t1~aufnr LIKE '00006%'
    AND t1~aufnr IN l_r_aufnr into table it_table1 .
    " then we ll select the data from second table using the entries selected from the first table and field conditions for second tabel itself.
    data: it_table2 type table of afvc .
    select
    t2~aplzl
    t2~banfn
    t2~bnfpo
    t2~vornr
    t2~sumnr
    t2~prctr
    from afvc as t2 into table it_table2
    for all entries in it_table1
    where it_table1-mandt = t2~mandt
    and   it_table1-aufpl = t2~aufpl
    and t2~prctr = '0000005080'
    AND t2~sumnr '00000000'
    AND t2~steus IN l_r_steus "D02K924627 .
    " then we ll select the data from third table using the entries selected from the first and second table and field conditions for second tabel itself.
    data: it_table3 type table of mseg .
    select
    t3~ebeln AS ebeln
    t3~ebelp AS ebelp
    t3~dmbtr AS dmbtr "D02K924378
    t3~lifnr AS lifnr
    t3~waers AS waers "D02K924378
    t3~sakto AS kstar "D02K924456
    from mseg AS t3
    for all entries in it_table2
    where it_table2-mandt = t3~mandt
    and it_table2-aufpl = t3~aufpl
    and it_table2-aplzl = t3~aplzl .
    like wise u can do for all the tables you have...
    Edited by: prashanti korlepara on Jun 16, 2011 3:41 PM

  • Migration error The operation can only be performed if the following objects are writable

    Hi Experts ,
    The operation can only be performed if the following objects are writable:The project is not in the repository, but there are some read-only files
    Component com.*******k.custsmry.comp.VcCustSumryRptComp
            Read-only: D:\software\nwds -7.31SP12\eclipse\workspace.jdi\LocalDevelopment\DCs\******\portal_dev\custsmry\_comp\src\packages\com\*******\custsmry\comp\VcCustSumryRptComp.wdcomponent
    Regards
    Govardan

    Hi jun wu,
    Making it writable in windows works ,
    Actually my dc migrations is from nwds 7.01 to 7.3 ,
    in 7.01 it is NWDI , the dc is under a track so im migration the dc individually to 7.3 , i.e one by one instead of migrating the entire Track.
    After migration required dcs from 7.01 to 7.3 we are planning to move that to new track in 7.3 .
    will it have any impact when that dc is moved to new track ? is it right approach to make it wirtable throught windows.
    Regards
    Govardan

  • How do i convert the following case statement to a table and still implement it in the store procedure.

    if @CustNo = '0142'          begin              insert #custnos (CustNo, ClientNo)              values ('0142', '1100')                      ,('0142', '1200')                      ,('0142', '1201')                      ,('0142', '1700')                      ,('0142', '1602')                      ,('0142', '1202')                      ,('0142', '1603')                      ,('0142', '2002')          endstore procUSE ODSSupport
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_NULLS ON
    GO
    if exists (select * from dbo.sysobjects where id = object_id(N'dbo.pr_Load_PASOArgusClaims_Work') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    BEGIN
    drop procedure dbo.pr_Load_PASOArgusClaims_Work
    IF OBJECT_ID ('dbo.pr_Load_PASOArgusClaims_Work') IS NOT NULL
    PRINT '<<< FAILED DROPPING PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
    ELSE
    PRINT '<<< DROP PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
    END
    GO
    CREATE PROC dbo.pr_Load_PASOArgusClaims_Work
    @BatchNo varchar(7) = null,
    @CustNo char(4) = null,
    @NewBatchNo varchar(7) = null
    AS
    /* Object dbo.pr_Load_PASOArgusClaims_Work 2006234 */
    -- SSR# : 2242
    -- Date : 12/23/2005
    -- Author : Roxy Newbill
    -- Description : Add new PASO BCAT 1602
    -- SSR# 1932 - 2/22/2006 SEN - Add logic to include only ArgusCustNo - 0142
    -- and change PharmacyClaim.ProcessDate to DateWritten
    -- SSR# : 2419
    -- Date : 08/22/2006
    -- Author : Betty Doran
    -- Description : PASO reports project
    -- Correct mapping of Dispense fee amt from 'AmtProfFee' to 'DispenseFee' -
    -- Mapping changed by Argus - did not inform PHP. Used in calcs for mClaimTotAmtCharge and
    -- mClaimAmtAllowed fields.
    -- SSR# : 2496
    -- Date : 06/27/2007
    -- Author : Roxy Newbil
    -- Description : PASO Reporting Project
    -- Add data load for new columns: Prescription No, Drug Name, NDC
    -- SSR# : PEBB PROJECT
    -- Date : 10/13/2009
    -- Author : Tj Meyer
    -- Description : Add BCAT 1201 for new PEBB business--
    -- SSR# : 132707
    -- Date : 12/17/2009
    -- Author : Terry Phillips
    -- Description : PASO Reporting Project
    -- Fix data length issues for Argus_SubGroupId,Argus_PlanCode,vchParticipantId,
    -- vchProviderId
    -- SSR# : 3253
    -- Date : 03/28/2011
    -- Author : Susan Naanes
    -- Description : PrescriptionNo increased in size from 7 to 12 characters
    -- SSR# : SPOCK project
    -- Date : 08/09/2012
    -- Author : Raymond Beckett
    -- Description : Modifed to bring in RxKey from PharmacyClaim instead of using identity value for iRecId
    -- Also, modified to load any new batches since last batch loaded into PASOArgusClaims
    -- if @BatchNo not supplied
    -- Various 'fixes'
    -- - removed grouping from initial query due to unique grouping caused by BatchNo, ClaimNumber, ClaimType
    -- SSR# : TFS 5264 - Premera Remediation -(3997)
    -- Date : 12/21/2012
    -- Author : Satish Pandey
    -- Description : Add BCATs 1202 and 1603 to the Where clause selecting pharmclm.ArgusClientNo as BCAT
    -- SSR# : TFS 10286
    -- Date : 1/15/2014
    -- Author : Raymond Beckett
    -- Description : Add HRI Customer Number and BCAT's. Also add Customer Number and alternate batchno to parameters
    -- Only use '@NewBatchNo' if adding data from missed custno and the batchno already exists in PASOArgusClaims
    -- ITSM Ticket : 1800925
    -- Date : 4/15/2014
    -- Author : Roxy Newbill
    -- Description : Silverton Hospital had new BCAT (2002) with start of 2014 business. This was never accomodated for
    -- Adding this BCAT in so that we can start capturing these claims (Note, special insert being done to capture
    -- all BCAT 2002 claims prior to this fix.)
    -- ITSM Ticket : TFS 14587 -Intel BCAT Remediation
    -- Date : 08/14/2014
    -- Author : Andrew Omofonma
    -- Description : Added BCAT's (1604,& 2103) for Intel
    SET NOCOUNT ON
    DECLARE @iCount int
    create table #tmpArgusWork (
    iRecId int,
    BatchNo varchar (7) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    BatchDateTime datetime NULL ,
    BatchStatus varchar (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    ReadyDateTime datetime NULL ,
    Argus_GroupId varchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    Argus_SubGroupId varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    Argus_ClassId varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    Argus_PlanCode varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    Argus_BusinessCategory varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    FacetsClaimSubType varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    PASOClaimType varchar (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    vchClaimNumber varchar (14) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    dtPaidDate datetime NULL ,
    dtProcessDate datetime NULL ,
    dtServiceDate datetime NULL ,
    vchParticipantId varchar (14) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    vchProviderId varchar (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    vchProviderName varchar (55) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    mClaimTotAmtCharge money NULL ,
    mClaimAmtDiscount money NULL ,
    mClaimAmtAllowed money NULL ,
    mClaimAmtDenied money NULL ,
    mClaimAmtDeduct money NULL ,
    mClaimAmtCoinsurance money NULL ,
    mClaimAmtCopay money NULL ,
    mClaimAmtPaid money NULL ,
    PASO_GroupId varchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    PASO_SubGroupId varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    PASO_ClassID varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    PASO_PlanCode varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    PASO_BusinessCategory varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    RecordStatus varchar (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    ErrorDesc varchar (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    PrescriptionNo char(12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    DrugName varchar(30)COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    NDC char(11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
    create table #batches (
    BatchNo char(7) not null
    primary key (BatchNo))
    create table #custnos (
    CustNo char(4),
    ClientNo char(5), -- bcats associated with the customer
    primary key (CustNo, ClientNo)
    DECLARE
    @len_Argus_SubGroupId smallint,
    @len_Argus_PlanCode smallint,
    @len_vchParticipantId smallint,
    @len_vchProviderId smallint
    --Get field lengths for the following fields
    SELECT @len_Argus_SubGroupId = 4, --datalength([@tmpArgusWork].[Argus_SubGroupId]),
    @len_Argus_PlanCode = 8, --datalength(@tmpArgusWork.Argus_PlanCode),
    @len_vchParticipantId = 14, --datalength(@tmpArgusWork.vchParticipantId),
    @len_vchProviderId = 12 --datalength(@tmpArgusWork.vchProviderId)
    declare @maxbatch char(7)
    IF @BatchNo IS NULL
    begin
    -- assume normal run. Add ClientNo's and custno's to tables
    insert #custnos (CustNo, ClientNo)
    values ('0142', '1100')
    ,('0142', '1200')
    ,('0142', '1201')
    ,('0142', '1700')
    ,('0142', '1602')
    ,('0142', '1202')
    ,('0142', '1603')
    ,('0142', '2002')
    ,('0142', '1604')
    ,('0142', '2103')
    ,('0669', '*')
    -- get batches loaded since last batch loaded into PASOArgusClaims
    SELECT @maxbatch=Max(BatchNo)
    FROM ODSSupport.dbo.PASOArgusClaims
    declare @dt datetime
    declare @ds datetime
    select @dt = MIN(DateTimeStamp)
    from ODS.dbo.PharmacyClaim_Common
    where BatchNo <= @maxbatch
    and DateTimeStamp > DATEADD(dd,-16,getdate())
    insert #batches (BatchNo)
    select distinct BatchNo
    from ODS.dbo.PharmacyClaim_Common pcc
    inner join #custnos ct
    on ct.CustNo = pcc.ArgusCustNo
    and (
    ct.ClientNo = '*'
    or
    ct.ClientNo = pcc.ArgusClientNo
    where DateTimeStamp > @dt
    ; -- batch may have had a claim altered since last load, drop any batches already loaded into PASOArgusClaims
    with pba as (
    select distinct BatchNo
    from ODSSupport.dbo.PASOArgusClaims
    delete ba
    from #batches ba
    inner join pba
    on pba.BatchNo = ba.BatchNo
    end
    else if @NewBatchNo is not null and @CustNo is not null
    begin
    --make sure we haven't already done this batch number/customer combination
    set @maxbatch = @NewBatchNo
    SELECT @iCount=count(*)
    FROM PASOArgusClaims
    WHERE BatchNo=@maxbatch
    and Argus_BusinessCategory = @CustNo
    IF @iCount > 0
    begin
    PRINT 'Msg: Batch ' + @maxbatch + ' already exists for CustNo ' + @CustNo + '.'
    end
    else
    begin
    if @CustNo = '0142'
    begin
    insert #custnos (CustNo, ClientNo)
    values ('0142', '1100')
    ,('0142', '1200')
    ,('0142', '1201')
    ,('0142', '1700')
    ,('0142', '1602')
    ,('0142', '1202')
    ,('0142', '1603')
    ,('0142', '2002')
    ,('0142', '1604')
    ,('0142', '2103')
    end
    if @CustNo = '0669'
    begin
    insert #custnos (CustNo, ClientNo)
    values ('0669', '*')
    end
    insert #batches (BatchNo)
    values (@BatchNo)
    end
    end
    else
    begin
    --make sure we haven't already done this batch number
    set @maxbatch = @BatchNo
    SELECT @iCount=count(*)
    FROM PASOArgusClaims
    WHERE BatchNo=@maxbatch
    IF @iCount > 0
    begin
    PRINT 'Msg: Batch ' + @maxbatch + ' already loaded.'
    end
    else
    begin
    insert #batches (BatchNo)
    values (@maxbatch)
    end
    end
    ** Insert Pharmacy Claims to temporary table
    INSERT INTO #tmpArgusWork
    SELECT
    pharmClm.RxKey,
    isnull(@NewBatchNo, pharmClm.BatchNo),
    pharmclm.OrigDateTimeStamp as BatchDateTime,
    'PENDING' as BatchStatus,
    NULL as ReadyDateTime,
    substring(pharmClm.GrpNumber,1,8)as Argus_GroupID,
    left(pharmClm.ArgusSubgroup1,@len_Argus_SubGroupId) as Argus_SubgroupID,
    substring(pharmClm.GrpNumber,9,4) as Argus_ClassId,
    substring(pharmClm.GrpNumber,13,@len_Argus_PlanCode) as Argus_PlanCode,
    pharmClm.ArgusClientNo as Argus_BusinessCategory,
    '' as vchFacetsClaimSubtype,
    PASOClaimType = CASE WHEN pharmClm.ClaimType='A'
    THEN 'PHARMACY-ADJUST'
    ELSE 'PHARMACY'
    END,
    pharmClm.ClaimNo,
    pharmClm.DateCutoff as dtPaidDate,
    pharmClm.DateWritten as dtProcessDate,
    NULL as dtServiceDate,
    left(pharmClm.MemberId,@len_vchParticipantId) as vchParticipantId,
    left(pharmClm.PharmacyNo,@len_vchProviderId) as vchProviderId,
    vchProviderName = CASE WHEN pharmclm.PayMemberInd = 'Y'
    THEN 'Member Reimbursement'
    ELSE pharm.PharmName
    END,
    mClaimTotAmtCharge = CASE WHEN pharmclm.PayMemberInd = 'Y' -- When this is a member reimbursement use the amt paid
    THEN isnull(pharmClm.IngredientCostPaid,0) + isnull(pharmClm.DispenseFee,0) + isnull(APSFee,0) -- as amt charged.
    ELSE isnull(pharmClm.AmtBilled,0)
    END,
    case when pharmclm.PayMemberInd = 'Y'
    then isnull(pharmClm.AmtRejected,0) * -1
    else isnull(pharmClm.AmtBilled,0) - isnull(pharmClm.IngredientCostPaid,0) - isnull(pharmClm.DispenseFee,0) - isnull(APSFee,0) -isnull(pharmClm.AmtRejected,0)
    end as mClaimAmtDiscount,
    isnull(pharmClm.IngredientCostPaid,0) + isnull(pharmClm.DispenseFee,0) + isnull(APSFee,0) as mClaimAmtAllowed,
    isnull(pharmClm.AmtRejected,0) as mClaimAmtDenied,
    isnull(pharmClm.MemberPaidAmt,0) - isnull(pharmClm.MemberCopayAmt,0) as mClaimAmtDeduct,
    0 as mClaimAmtCoinsurance,
    isnull(pharmClm.MemberCopayAmt,0) as mClaimAmtCopay,
    isnull(pharmClm.AmtPaid,0) + isnull(APSFee,0) as mClaimAmtPaid,
    NULL as PASO_GroupID,
    NULL as PASO_SubgroupID,
    NULL as PASO_ClassID,
    NULL as PASO_PlanCode,
    NULL as PASO_BusinessCategory,
    'OK' as RecordStatus,
    NULL as ErrorDesc,
    PrescriptionNo = pharmClm.PrescriptionNo,
    DrugName = pharmClm.DrugName,
    NDC = pharmClm.NDC
    FROM ODS..PharmacyClaim as pharmClm
    LEFT JOIN ODS..pharmacy as pharm on
    pharmClm.PharmacyNo = pharm.PharmacyNo
    INNER join #batches ba
    on ba.BatchNo = pharmClm.BatchNo
    INNER join #custnos ct
    on ct.CustNo = pharmClm.ArgusCustNo
    and (
    ct.ClientNo = '*'
    or
    ct.ClientNo = pharmClm.ArgusClientNo
    WHERE pharmClm.ClaimType in ('P','A') -- Processed or Adjusted
    --AND pharmClm.ProcessCode <> 'MC' --code doesn't exist
    --GROUP BY
    -- pharmClm.BatchNo,
    -- substring(pharmClm.GrpNumber,1,8),
    -- substring(pharmClm.GrpNumber,9,4) ,
    -- substring(pharmClm.GrpNumber,13,@len_Argus_PlanCode),
    -- pharmClm.ArgusSubgroup1,
    -- pharmClm.ClaimNo,
    -- pharmClm.ArgusClientNo,
    -- pharmClm.DateCutoff,
    -- pharmClm.DateWritten,
    -- pharmClm.MemberId,
    -- pharmClm.PayMemberInd,
    -- pharmClm.PharmacyNo,
    -- pharm.PharmName,
    -- pharmClm.OrigDateTimeStamp,
    -- pharmClm.ClaimType,
    -- pharmClm.PrescriptionNo,
    -- pharmClm.DrugName,
    -- pharmClm.NDC
    IF @@RowCount=0
    BEGIN
    PRINT 'Msg: No records found.'
    RETURN
    END
    --Update the Discount column for these Pharmacy Claims
    --UPDATE @tmpArgusWork
    --SET mClaimAmtDiscount=mClaimTotAmtCharge-mClaimAmtAllowed-mClaimAmtDenied
    ** Get the lowest service Date for each claim and update temp table
    UPDATE #tmpArgusWork
    SET dtServiceDate = (SELECT min(pharmclm.DateSvc)
    FROM ODS..pharmacyClaim AS pharmclm
    WHERE pharmclm.ClaimNo = tcpr.vchClaimNumber
    AND pharmclm.MemberID = tcpr.vchParticipantId)
    FROM #tmpArgusWork as tcpr
    ** Copy over the eligibility fields that Argus provided
    UPDATE #tmpArgusWork
    SET PASO_GroupId = Argus_GroupID,
    PASO_SubGroupId = Argus_SubGroupId,
    PASO_ClassID=Argus_classid,
    PASO_PlanCode=Argus_PlanCode,
    PASO_BusinessCategory=Argus_BusinessCategory
    FROM #tmpArgusWork pw
    WHERE COALESCE(Argus_GroupID,'') <> ''
    OR COALESCE(Argus_SubGroupId,'') <> ''
    OR COALESCE(Argus_classid,'') <> ''
    OR COALESCE(Argus_PlanCode,'') <> ''
    OR COALESCE(Argus_BusinessCategory,'') <> ''
    ** If Argus did not provide all 5 eligibility fields, get them from faEnrollmentHistory
    ** based on the group, member, date of service
    UPDATE #tmpArgusWork
    SET PASO_GroupId = eh.GroupId,
    PASO_SubGroupId = eh.SubGroupId,
    PASO_ClassID=eh.Class,
    PASO_PlanCode=eh.PlanCode,
    PASO_BusinessCategory=eh.BusinessCategory
    FROM #tmpArgusWork pw
    INNER JOIN ODS..FAEnrollmentHistory eh
    ON eh.MemberID =pw.vchParticipantID
    AND eh.Groupid =pw.Argus_GroupID
    AND eh.eligind='Y'
    AND eh.ProcessCode<>'ID'
    AND pw.dtServiceDate BETWEEN eh.EligEffDate AND eh.EligTermDate
    WHERE COALESCE(Argus_GroupID,'') = ''
    OR COALESCE(Argus_SubGroupId,'') = ''
    OR COALESCE(Argus_classid,'') = ''
    OR COALESCE(Argus_PlanCode,'') = ''
    OR COALESCE(Argus_BusinessCategory,'') = ''
    ** If we have eligibility for all records, go ahead and set the ready date to today.
    IF NOT EXISTS ( SELECT *
    FROM #tmpArgusWork
    WHERE COALESCE(PASO_GroupID,'') = ''
    OR COALESCE(PASO_SubGroupID,'') = ''
    OR COALESCE(PASO_ClassID,'') = ''
    OR COALESCE(PASO_PlanCode,'') = ''
    OR COALESCE(PASO_BusinessCategory,'') = '')
    BEGIN
    UPDATE #tmpArgusWork
    SET ReadyDateTime=convert(varchar(10),GetDate(),101),
    BatchStatus='READY'
    END
    ELSE
    BEGIN
    PRINT 'Msg: Exceptions found.'
    UPDATE #tmpArgusWork
    SET RecordStatus='ERR',
    ErrorDesc='No valid Eligible span for this Member/Group/Subgroup at time of Service'
    WHERE COALESCE(PASO_GroupID,'') = ''
    OR COALESCE(PASO_SubGroupId,'') = ''
    OR COALESCE(PASO_ClassID,'') = ''
    OR COALESCE(PASO_PlanCode,'') = ''
    OR COALESCE(PASO_BusinessCategory,'') = ''
    END
    ** Insert the records into the final table.
    INSERT INTO PASOArgusClaims
    SELECT * FROM #tmpArgusWork
    SET NOCOUNT OFF
    END
    GO
    -- Verify that the stored procedure was created successfully.
    IF OBJECT_ID ('dbo.pr_Load_PASOArgusClaims_Work') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
    ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
    GO
    GRANT EXECUTE ON dbo.pr_Load_PASOArgusClaims_Work to role_ODSLoad
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON

    this part of the code below
    if@CustNo
    = '0142'
       begin
    insert #custnos(CustNo,
    ClientNo)
    values ('0142',
    '1100')
    ,('0142',
    '1200')
    ,('0142',
    '1201')
    ,('0142',
    '1700')
    ,('0142',
    '1602')
    ,('0142',
    '1202')
    ,('0142',
    '1603')
    ,('0142',
    '2002')
       end
    store proc
    How do I covert it to a common table where the values can be selected from when needed.

  • How to write the following CASE statement

    I need to calculate Retainer amount. The derivation of it is as follows:
    "A fixed value of 10000 per month for employees who have served for less than 2 years and 15000 for more than 2 years. This increment will be affected in two cycles a year, in the January or July."
    The years of service can be calculated using date_of_joining.

    Use this logic
    SELECT DECODE(SIGN(SYSDATE - ADD_MONTHS(HIREDATE,24)),-1,10000,1,15000) from <table_name>Is this you need
    In every Jan/July month employee get a Sal+Fixed allownce (10000 if less than 2 years in company/15000 if more than 2 years). In other month they get just the salary
    SELECT CASE WHEN TO_CHAR(SYSDATE,'MM') IN ('01','07') THEN
                   CASE WHEN SYSDATE- ADD_MONTHS(HIREDATE,24)> 0 THEN
                        SAL+15000
                    ELSE
                        SAL+10000
                    END
            ELSE
              SAL
            END  SAL
    FROM EMP
    /Edited by: Lokanath Giri on १७ सितंबर, २०१० ४:५६ अपराह्न

  • Need solution for the following(Selection Screen)

    Hi all,
    currently iam working with report program,there i need to populate one field in the selection screen based on the another parameter in the same selection screen.
    iam having field called work center as a parameter with the search help.
    This search help is providing the corresponding plant for the particular work center.
    Now what i need to do is,if i select the work center thru F4 help,i need the correseponding plant to get populated in the other textbox.
    Currently iam having that work center field as parameter,
    now i need another textbox for the plant adjacent to this workcenter textbox,in this textbox only i need that corresponding plant.
    Following is the code for that workcenter textbox.
    PARAMETERS:P_ARBPL LIKE CRHD-ARBPL MATCHCODE OBJECT CRAM.
    Note: The Serach help CRAM is having corresponding  plant with the workcenter.

    Hi swaminathan,
    1. If u want to DIRECTLY
       populate other fields
       based upon selection,
      then we have to use our own
      selection function.
    2. just copy paste this code in new program.
      ( it will display help for BUKRS
      and AS SOON AS the user selects some company code,
      the other fields
      get populated AUTOMATICALLY)
    3.
    REPORT abc.
    DATA : dd     LIKE     TABLE OF dselc WITH HEADER LINE. "*--- IMPORTANT
    DATA : ft     LIKE     TABLE OF dfies WITH HEADER LINE.
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    PARAMETERS : bukrs LIKE t001-bukrs .
    PARAMETERS : butxt LIKE t001-butxt.
    PARAMETERS : ort01 LIKE t001-ort01.
    PARAMETERS : waers LIKE t001-waers.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR bukrs.
       SELECT * FROM t001 INTO TABLE t001.
    IMPORTANT
       REFRESH dd.
       dd-fldname = 'BUTXT'.
       dd-dyfldname = 'BUTXT'.
       APPEND dd.
       dd-fldname = 'ORT01'.
       dd-dyfldname = 'ORT01'.
       APPEND dd.
       dd-fldname = 'WAERS'.
       dd-dyfldname = 'WAERS'.
       APPEND dd.
    *------- IMPORTANT
       REFRESH ft.
       ft-tabname  = 'T001'.
       ft-fieldname = 'BUTXT'.
       APPEND ft.
       ft-tabname  = 'T001'.
       ft-fieldname = 'WAERS'.
       APPEND ft.
       ft-tabname  = 'T001'.
       ft-fieldname = 'ORT01'.
       APPEND ft.
       CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
         EXPORTING
          ddic_structure  = 'T001'   "*----- IMPORTANT IF STANDARD STRUCT
           retfield        = 'BUKRS'
           dynpprog        = sy-repid
           dynpnr          = sy-dynnr
           dynprofield     = 'BUKRS'
           value_org       = 'S'
         TABLES
           field_tab       = ft "*---- IMPORTANT
           value_tab       = t001
           dynpfld_mapping = dd   "* IMPORTANT
         EXCEPTIONS
           parameter_error = 1
           no_values_found = 2
           OTHERS          = 3.
    regards,
    amit m.

  • Performance problem of asset selection statement.

    Hi guys quick question.
    SELECT a~bukrs
               a~anln1
               b~anln2
               a~anlkl
               a~aktiv
               a~txt50
               a~lvtnr
               b~afabe
               b~afabg
               b~ndjar
               b~ndper
               INTO TABLE it_anla
               FROM anla AS a
               INNER JOIN anlb AS b
               ON a~bukrs EQ b~bukrs
               AND a~anln1 EQ b~anln1
               WHERE a~bukrs IN s_bukrs
               AND a~anln1 IN s_anln1
               AND a~anln2 EQ '0000'
               AND a~anlkl IN s_anlkl
               AND a~aktiv EQ '00000000'
               AND a~lvtnr IN s_lvtnr
               AND b~afabe EQ 01.
    I have a select statement which is filtered by capitalization date which is the field AKTIV. This select alone has 450 thousand hits. Having an ANLN2 = 0 and AKTIV  = blank/no date means that the asset group is no longer active.
    Now for another scenario I have to retrieve table ANLA again excluding all the Main Asset Number/ANLN1 found on that table.
    Is there a way to select by doing it only once?
    I tried to pass all the anln1 to a range table but the program dumps. I think the range table can't handle too many entries.
    Retrieving all the entries from the DB then processing it takes longer.
    I tried to delete the table using a loop but it takes to long as it process the table every loop.
    LOOP AT it_anla WHERE anln2 EQ '0000' AND aktiv EQ '0000000'.
          DELETE it_anla WHERE bukrs EQ it_anla-bukrs AND anln1 EQ it_anla-anln1.
        ENDLOOP.
    Thanks.
    Edited by: Thomas Zloch on Sep 21, 2010 5:39 PM - please use code tags

    Moderator message - Welcome to SCN
    If the range table for anln1 is large and contains distinct values, you can try using it in a FOR ALL ENTRIES construct rather than IN.
    Rob

  • Can any tell me the error in following select statement

    data: header_hashed like hashed table of header with unique key kunnr.
    select single name1 into corresponding fields of table header_hashed from kna1 where kunnr = header-kunnr.

    hi Ansuman,
    I think you have sytactical error in the code.
    try this.
    data: header_hashed like
                        hashed table
                               of  kna1
                            with unique key kunnr
                            with header line.
    select single name1
                 into corresponding fields of  header_hashed
    from kna1 where kunnr = header_hashed-kunnr.
    <removed_by_moderator>
    Thanks.
    Anirban Bhattacharjee
    Edited by: Julius Bussche on Aug 28, 2008 4:16 PM

Maybe you are looking for