ABAP Query Code timeout issue

Hi,
I have a SAP query which was the following code which is causing a timeout issue when running the report, can anyone suggest how I can change the code to make it more efficent?
* This gets the sum of all labour costs on WBSEs.
  clear X_COEP_WKGBTR_LAB_W.
  if PRPS-OBJNR is not initial.
  select sum( WKGBTR ) from COEP
    into X_COEP_WKGBTR_LAB_W
    where
    PERIO = ZPERIODT
    and
    GJAHR = ZYEAR
    and
    KSTAR >= 'A43'
    and
    KSTAR =< 'A43ZZZZZZZ'
    OR
     KSTAR = '0005767012'
    and
    OBJNR = PRPS-OBJNR.
  endif.
thanks
Joe

Hi Joe,
I see none of the Key fields were used in select query.
Create a secondary index for the table and use it in select query.
It increases the performance.
COEP~1 and COEP~2 are already existing.
select sum( WKGBTR ) from COEP
    into X_COEP_WKGBTR_LAB_W
    where
    PERIO = ZPERIODT
    and
    GJAHR = ZYEAR
    and
    KSTAR >= 'A43'
    and
    KSTAR =< 'A43ZZZZZZZ'
    OR
     KSTAR = '0005767012'
    and
    OBJNR = PRPS-OBJNR
%_HINTS ORACLE 'INDEX("COEP" "COEP~1").
Thanks,
Anil

Similar Messages

  • ABAP Query Code for Count Function

    Hi,
    I have an ABAP Query and just created a new field which requires ABAP Code to do the following :-
    The report is for Purchase Orders and Purchase Requisitions. 2 Purchase Orders may have the same requisition, so what I want to do is count the number of the same requisitions in the report
    e.g.
    PO                Req             Count
    45000001     10015              2
    45000020     10015              2
    Can some one please provide with the full code? Points will be awarded
    Thanks

    Hi,
    No errors in the below code but it is bringing a value 0 even though there are duplicates in the table which is suggesting to me that the code is not working.
    Any help would be appreciated. Thanks
    DATA : BEGIN OF itab OCCURS 0,
            aufnr LIKE ekkn-aufnr,
           END OF itab.
    DATA : count(2) TYPE p.
    DATA : no_of_records(3) TYPE p.
    Clear no_of_records.
    select aufnr from ekkn into itab.
    endselect.
    SORT itab BY aufnr.
    LOOP AT itab.
      ADD 1 TO count.
      AT END OF aufnr.
        IF count GE 2.
          ADD count TO no_of_records.
        ENDIF.
        CLEAR count.
      ENDAT.
    ENDLOOP.
    *WRITE :/ 'Good Bye'.
    DUPLICATES = NO_of_records.

  • ABAP Query : code to change the display

    Hi all,
    I have created an Abap Query and generated it. I see the output now as follows:
    <u>Bill.doc</u>     <u>Item</u>   <u>Net value</u>  <u>Total amt</u>
    900000                    10                  100                  600
    900000                    20                  200                  600
    900000                    30                  300                  600
    900001                    10                  250                  250
    900002                    10                  300                  500
    900002                    20                  200                  500
    Now I want the total amt to be displayed only once for each billing document only for the first item and for the other line items it should be blank as shown below.
    <u>Bill.doc</u>   <u>Item</u>   <u>Net value</u>  <u>Total amt</u>
    900000   10      100            600
    900000   20      200           
    900000   30      300           
    900001   10      250            250
    900002   10      300            500
    900002   20      200
    Can someone please explain me where and how I should write the code to get this working?
    Thanks,
    N
    Helpful answers will be awarded for sure.

    Hi Manohar,
    I am getting the total amount from a field which exists in one of the tables which i used in the abap query.
    the total amount is appearing correctly...i dont need to modify that. i just need to display it only once for each billing doc for the first item.
    i want to know where i should do the coding...i mean in the Infoset or the Abap Program that gets created when i generate the infoset.
    Thanks!
    N
    Message was edited by:
            Narmada Mallavaram
    null

  • Display long text in an ABAP Query.

    Hi all,
    Could any one please help me in guiding me, to tell how can I display the long text which is got from the function module 'READ_TEXT'  in an ABAP query.
    The issue here is that Iam able to loop at the <itab> table and get the long text for each of the records any, but Iam not able to display it on an infoset..
    Send me the examples if any..
    Thanks & Regards,
    Sanjay Mankar.

    Dear dont try with ABAP Qualry
    use alv or like that
    sample code is attach here
    if you have any claryfication reply me
    *&      Form  F001-BasicData_LText
          text
         -->IN_PAR     text
         -->OUT_PAR    text
    FORM F001-BasicData_LText TABLES in_par  STRUCTURE itcsy out_par STRUCTURE itcsy.
      DATA :
           IT_LTEXT       TYPE STANDARD TABLE OF TLINE,
           WA_LTEXT       TYPE TLINE,
           W_FTEXT(100)   TYPE   C,
           W_FTEXT1(100)  TYPE   C,LW_LEN TYPE I.
      DATA :
           W_ID          LIKE thead-tdid,                  "Text ID
           W_LANGU       LIKE THEAD-TDSPRAS,              "Language
           W_NAME        LIKE thead-tdname,                "Name
           W_OBJECT      LIKE thead-tdobject.              "Texts:
      READ TABLE in_par WITH KEY 'EKPO-MATNR'.
        w_NAME = in_par-value.
      W_ID      =  'GRUN'.
      W_OBJECT  =  'MATERIAL'.
      W_LANGU   =  SY-LANGU.
      CALL FUNCTION 'READ_TEXT'
        EXPORTING
          ID                      = W_ID
          LANGUAGE                = W_LANGU
          NAME                    = W_NAME
          OBJECT                  = W_OBJECT
        TABLES
          lines                   = IT_LTEXT
        EXCEPTIONS
          id                      = 1
          language                = 2
          name                    = 3
          not_found               = 4
          object                  = 5
          reference_check         = 6
          wrong_access_to_archive = 7
          OTHERS                  = 8.
      Loop at IT_LTEXT into WA_LTEXT.
        W_FTEXT1 = WA_LTEXT-TDLINE.
        CONCATENATE W_FTEXT W_FTEXT1 INTO W_FTEXT SEPARATED BY SPACE.
      Endloop.
    LOOP AT out_par WHERE name EQ 'W_FTEXT'.
          out_par-value = W_FTEXT.
          MODIFY out_par.
        ENDLOOP.
    ENDFORM.                    "F001-BasicData_LText
    *&      Form  F001-LTEXT_DEVIDING
          text
         -->P_IT_DVTXT  text
    FORM F001-LTEXT_DEVIDING TABLES in_par  STRUCTURE itcsy out_par STRUCTURE itcsy.
    DATA : W_TEXTLINE(100)    TYPE  C,
           W_DELIMITER        TYPE  C,
           W_OUTPUTLEN        TYPE  I,
           W_FTEXT(100)       TYPE  C,
           OUT_LINE1          TYPE  C,
           OUT_LINE2          TYPE  C,
           OUT_LINE3          TYPE  C,
           W_LINE1(35)        TYPE  C,
           W_LINE2(35)        TYPE  C,
           W_LINE3(35)        TYPE  C.
      READ TABLE in_par WITH KEY 'W_FTEXT'.
          W_FTEXT = IN_PAR-VALUE.
          W_TEXTLINE   = W_FTEXT.
          W_DELIMITER  = ' '.
          W_OUTPUTLEN  = 30.
      CALL FUNCTION 'RKD_WORD_WRAP'
        EXPORTING
          TEXTLINE    = W_TEXTLINE
          DELIMITER   = W_DELIMITER
          OUTPUTLEN   = W_OUTPUTLEN
        IMPORTING
            OUT_LINE1 = W_LINE1
            OUT_LINE2 = W_LINE2
            OUT_LINE3 = W_LINE3.
      LOOP AT out_par.
        if out_par-name eq 'W_LINE1'.
        out_par-value = W_LINE1.
          elseif out_par-name eq 'W_LINE2'.
          out_par-value = W_LINE2.
            elseif out_par-name eq 'W_LINE3'.
            out_par-value = W_LINE3.
        endif.
      MODIFY out_par.
      ENDLOOP.
    ENDFORM.                    " F001-LTEXT_DEVIDING
    rewads if helpful

  • Adding code in ABAP Query(ABAP HR)

    I have created an ABAP Query for getting the Absence details of employee within a specified period.I am populating the fields
    Employee number, Organization Unit,Absence start date,Absence hours, Absence enddate.
    If an employee is in leave for 10 days, this information will be stored in PA2001 table,and this table is not Organization specific.
    During the specified period(20 days), if an employee is under two Organization units(5 days in 1st Org Unit,15 days in 2nd Org Unit). The query is extracting two records for the same employee, because of two Organization units. And while populating the data, the query is getting the Absence information from PA2001 table, and this is causing overlapping of data. So it is showing the Absence details for that employee as 40 days(20 days in 1st Org Unit and 20 days in 2nd Org Unit,Instead of total 20 days). So i would like to add validation over here after extraction of data from the PA2001 table,before displaying the data.
    I have tried adding the code in the infoset, at END OF SELECTION Event,but i am not able to change the list, as i am not able to access the tables used by the Query.
    Can anybody suggest me where to add the code in the Query, so that i will be able to solve this issue, instead of changing the code in the Report program generated by the Query.

    you can look at BAPI_PTIMEOVERVIEW_GET
    this gives the output back for the selected period so you don't get alle the records back from you're pa2001 table. (only this overview doesn't take into considerationd the distiction the difference between leave and illness)
    further on if you consider using the pa2001 table you can loop through the begda and endda and add 1 day for each record and programm the logic how you want to intrepet each day you'reself
    I use the data from perws which comes from the function HR_PERSONAL_WORK_SCHEDULE
    (which is also used in the BAPI mentioned above)
    and from PA0001 you can retrieve how long somebody was in 1 org unit !!
      LOOP AT it_2001 WHERE begda BETWEEN i_begda AND i_endda
                        OR endda BETWEEN i_begda AND i_endda.
          h_datum = it_2001-begda.
          IF it_2001-awart BETWEEN '0100' AND '0199'.
            WHILE h_datum <= it_2001-endda.
              READ TABLE it_perws WITH KEY datum = h_datum.
              IF sy-subrc = 0.
    * you're logic
              ENDIF.
              CALL FUNCTION 'FKK_DTE_ADD'
                EXPORTING
                  i_base_date               = h_datum
                 i_periode                 = 'D'
                 i_period_factor           = 1
    *       I_USE_FACCAL              = ' '
    *       I_WORKDAY_INDICATOR       = '-'
                IMPORTING
                  e_datum                   = h_datum
    *     EXCEPTIONS
    *       ERROR_OCCURED             = 1
    *       OTHERS                    = 2
              IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
              ENDIF.
            ENDWHILE.
    kind regards
    arthur de smidt
    Edited by: A. de Smidt on Jul 16, 2008 8:47 AM

  • ABAP Query: add field on layout based on Company code

    Hello Experts,
    I currently working on ABAP Query report  for asset master issues and would like one more field added to layout for Company code XXXX . Is it possible to add fields to this layout based on company code .
    Thanks in Advance
    Nupur

    Hello Andreas,
    I'm asking is that possible to change ABAP Query report layout based on Company code.
    For Instance:
    Company code :1111
    Layout should : A B C D E F
    other than 1111.
    layout should : A X Y Z F
    My scenario is :
    ABAP Query is working fine but users from UK wants some more fields on the layout but rest of the country users other than UK, they don't want such changes.
    Regards,
    nupur

  • Attaching Abap Query to a T-code

    Hi ,
    I am attaching a T-code to an Abap query.
    I used the following :
    Parameter Transaction.
    In transaction field: START_REPORT.
    CHECK: Skip First Screen.
    D_SREPOVARI-REPORTTYPE  AQ
    D_SREPOVARI-REPORT           'ZASSETS_SSFL'
    D_SREPOVARI-EXTDREPORT  'ZAM001'
    But I am getting an error message saying user group ZASSETS_SSFL has not yet been created.
    Please suggest.
    Are the quotes creating an issue?

    Hey Newbie ,
    You have done almost right.
    Program name will be the "AQFKSYSTQV000006DELIVERY======" 
    Now you need to select the package in which the object ie query will be stored.
    3 ways .
    1) choose already existing package  ie press f4 and select the package z* ie starting with zname.
    2) If you want it in another package then create it .
    there are 2 ways to create a package.
    One is Through SE80.
      Other one is SE21(package Builder).
    ->How to create a package?
    Goto SE80 Transaction or SE21
    Select Package and below give the package name and click on enter.
    then u get a pop up asking to create package. Click yes. then u get a pop up Package Builder: Create package
    Give the description and the Application component and click on create.
    3) If you dont want this object to be moved to QAS then give the package name as $TMP  which is a local package this wont allow the objects which is stored in it to move to other servers.
    If you still face any problems in that , pls revert, happy to help you.
    Regards,
    Vvieks
    "Grow and help others to Grow"

  • Getting error while assigning ABAP Query to Tr.Code

    Hi Guys,
    There is a problem iam facing with ABAP query while transporting which need to solved asap. It will very greatfull if u guys can resolve this problem.
    My problem is, I created one ABAP Query with Name ASSETOVERVIEW. I had transported this even, now when iam going to assign it to one transaction code with se93 lets say ZAOR. I need to give its description and program name in se93 right. now my question is what is program name i need to give in se93. Bcoz in SQ01 where i created the query, there is no name as 'program name' rather there is 'Name' in that we will create the query name i.e, ASSETOVERVIEW. In se93 u give tr.code and when u see down there will be radiobuttons in 'start object',in that i had checked program and selection screen (report transaction) is this right button i had checked or any other i need to check?. I had assigned this name i.e,ASSETOVERVIEW and development class and then when i check the name for syntax check its giving "'ASSETOVERVIEW' does not exist". I don't understand what program name i need to give.
    If u guys can help me out with this problem it will be very much appreciable and definetly can get the reward points.
    Thanks for as usual help in advance.
    Regards.

    Hi omer,
    1. Just run the query.
    2. one selection screen will come
    3. then using SYSTEM---->STATUS, (from menu)
       look for the program name
    4. the program name will be something wired foramt.
    /asdfasdf/asdfdas etc.
    5. Give that name in se93.
    regards,
    amit m.

  • Abap query issue.

    Hi ,
    I have an existing abap query whose infoset has logical database ADA.
    Now I have to add a new table ANLC to this existing query .
    My main task is to add 3 new fields in the output of the existing abap query  One is a direct field from the ANLC table namely  Acquisition value and 2 other fields will be derived from the following formula :
    anlc-Acc ordinary depreciation + anlc-Ord. depreciation posted = Total accumulated depreciation.
    NBV = Acquisition value u2013 Total Acc depreciation
    Could you please sugest:
    1.  how to add  the ANLC table in the query?
    2.  How to calculate the above two fields and populate the output in an abap query?
    Thanks,
    Suchi.

    No, above mentioned is not the solution for your problem.
    I believe you want to write ABAP Query (i.e. Tcode SQ01), NOT the SQL Query in a normal program.
    Now, if you want to put abap code behind a field in your SQ01 query then you need to create custom field in your infoset. To learn how to create custom fields I have written a blog: SAP Adhoc Query SQ01 SQ02 SQ03
    Good news is that you do not need to create custom fields for the requirement that you mentioned.
    i want to fetch data where one field begins with 1* or 2* or 3* or 4* .
    For this, simply put the field on the selection screen by selecting appropriate check box and just use 1, 2, 3* or 4* in on the selection screen.
    Where should i COUNT the data selected and display it .
    when you execute the report, click on the 'Layout' icon, and select 'Column for number of rows'. It will give you last row with count. You can then save the layout as default layout so that it appears automatically.
    If you want to do anything different than above then you need to create custom fields, see my blog for that.

  • Issue in ABAP Query varient

    I have created the varient name CUS& for attaching the abap query varient in tranport request.  I have done this. but I am geting following error. please help me on this. thanks.
    The varient is created as Protected by default. I can't able to create the varient unprotected. Can you tell me how to create unprotected varient for SAP Query? becuase other user can't able to change the varient it is giving the error message with my user name as " No authorization to change the varient <varient name> Protected by <my user name>".
    Please could you help me how to fix it. this issue?

    Hi
    Thanks for your inputs.I am using ABAP query for first time. Can you advice where to check for same.
    Regards
    Dinesh

  • Generation of program code for the ABAP Query

    Dear all,
    In the creation of the ABAP query, in the final step of SQ01, Query- more functions- generate program is made.
    Why the program code is generated for the ABAP query? please  give the logical explaination for the same.
    Thanks and Regards,
    Prash

    Prash,
    a) Do you mean Program code does not have significance in query creation?
    No it does not mean this.  All queries run based on an ABAP program.  In the standard query editing process, when you save and execute the query, you will automatically re-build the existing ABAP program as necessary.  You do not need, though, to execute the menu steps you outlined in order to build, maintain, or execute the query.  It is only there for special purposes, as outlined above by Jürgen
    b) Can we see the program code generated in any transaction?
    From any screen, System > Status.  Place your cursor on the field in "Program (screen)".  Double click.
    Rgds,
    DB49

  • Select from KONV using Additional Code in ABAP Query

    I'm attempting to modify an ABAP Query Infoset (using transaction SQ02) that already has a join in it between tables VBAP and VBAK, and two additional alias tables on KONV (to get price history for sales documents).  I wish to get history of all PN00 records from KONV.  I can get ONE record with the following code in the Record Processing of the Extras element in my Infoset:
    SELECT SINGLE KBETR KPEIN KMEIN KDATU
    INTO (PN00_PRICE, PN00_PER, PN00_UOM, PN00_DATE) FROM KONV
      WHERE KNUMV  = VBAK-KNUMV
      AND KPOSN  = VBAP-POSNR
      AND STUNR = 198
      AND ZAEHK = 01.
    But we have many counters (field ZAEHK) for the PN00 condition and I want to have a new row for each PN00 record in KONV.  I've tried some loop syntax, but I've not been able to get any code to function or return more than one row for each sales order item row (VBAP-POSNR).
    Thanks for any hints.
    Dan Gallagher

    Change it like this
    SELECT KBETR KPEIN KMEIN KDATU
      INTO (PN00_PRICE, PN00_PER, PN00_UOM, PN00_DATE)
      FROM KONV
    WHERE KNUMV = VBAK-KNUMV
       AND KPOSN = VBAP-POSNR
       AND STUNR = 198.
    ..... do something with this record and store
    ENDSELECT.

  • ABAP Query - Not showing the required changes through Z T.Code

    Hi,
    I have a ABAP Query for OPEN DELIVERY QUANTITY (T.Code - ZABC).  I change something in QUERY and activate. After that i execute it, and saw required changes.
    But when i execute it with the T.Code - ZABC, it does not show the changes. Even i Save and Test with the SQ01 t.code.
    Please tell me, what is the problem in it. Why not showing the required changes through T.Code - ZABC.
    Regards...

    HI,
    Dear, it seems that you have changed the query in SQ02 and then just save it and not generated.
    or may be after generation again clicked on SAVE button.
    So untill unless you will not generate the query, it won't work.
    Secondly, by chanegs in the query, i don't think it changes the name of the main program.
    Regds,
    Anil

  • ABAP Query Execution via Custom Transaction Code - Not working

    We have created an ABAP Query in our DEV client and we then created a transaction code to run that query. We have done this because the customer does not want anyone to have access to SQ01, SQ02 in production. This works great in DEV but we can not get it to work in production.
    The ABAP Query was exported to our Prod client successfully.  I say exported because you do not do direct transports with queries.
    We then transported the new transaction code to run the query to production and it was successful.
    However, when we run the transaction is production we get a sys dump stating it can not find the query.
    We believe the problem is the TRDIR table is missing an entry for the program in production (it has an entry in DEV).
    I would have thought that the export on the query would have brought in this entry -but obviously not.
    Any suggestions on how we can get this entry into the production client?  Did we miss a step on the export that would do this?  We want to only bring over this entry - not the entire TRDIR table for obvious reasons (size (1.5 million entries, programs not ready for production, etc.).
    Please help!
    Thanks.
    Scott

    Hi,
    The above solution will work if you assign the transaction in one server, If you want this will not work in quality/production boxes when transported the query..the program name will not be the same in all the servers...
    For this. Do the below:
    In SE93, Create a Paramter Transaction
    -> Transaction = Start_report
    -> In default values, give the below details:
         D_SREPOVARI-REPORTTYPE = AQ
         D_SREPOVARI-EXTDREPORT = Name of the Query
         D_SREPOVARI-REPORT = User Group
    Save the transaction..Now if the program is generated with different names in the quality/proudction, this will still work..
    Regards
    Vijay Hebbal

  • ABAP Query layout issue

    Hi,
    I need to add a new column in a ABAP-Query, while adding this column and executing the same. The layout has changed from custom to standard one.
    Is there any way to retain the custom layout in the "Basic List" while changing the Infoset Query.
    Thanks in advance.
    Best Regards,
    Gopi

    hi,
    I guess the transaction code directly calls the generated ABAP program, which is the bad approach, because the generated ABAP program might have different names in different systems (like here). You have to create a transaction, which calls transaction START_REPORT with the following parameters/attributes filled :
    D_SREPOVARI-REPORTTYPE= AQ "parameter indicating Abap Query
    D_SREPOVARI-REPORT= '...' "Query User group
    D_SREPOVARI-EXTDREPORT= '...' "Query name
    Of course you have to replace the dots with real usergoup and query names. You create this transaction code in the development system and transport it to test and production. It will work everywhere (in case the query is transported as well).
    hope this helps
    ec

Maybe you are looking for