ABAP Query Question

Hello.  Is there a way to dynamically generate a query? 
For example:  I'm doing an RFC call that sometimes the strings contains data, the other times they don't.  Is there a way of building the query to only 'and' the values when there are values there?
Like
a = '1'
b = ''
c = '2'
select * from whereever where a = 1 (dont include b because its empty) and c = 2
Any ideas?
thanks,  Graeme.

Heres a good solution I found:
Dynamic where clauses in open SQL
You can use an internal table to build a dynamic where clause:
data: where_tab(30) occurs 1 with header line,
where_clause(30) type c.
Build the where clause. Will look like this when finished
WHERE ZAFSTMD02 = 'X' AND rbusa = '5145'
With a constant, result: ZAFSTMD01 = 'X'
concatenate 'ZAFSTMD' zcostcheck-zmaaned ' = ''X''' into where_clause.
Append to internal table where_tab
append where_clause to where_tab.
With a variable, result: AND rbusa = '5145'
concatenate 'AND rbusa = ' '''' i_tab-zgsber ''''
append where_clause to where_tab.
Select
select * from zcostfreq
where (where_tab).
endselect.
Note that you can combine static and dynamic where clauses:
select * from zcostfreq
where bukrs = '2021' AND
(where_tab).
endselect.

Similar Messages

  • ABAP query question on drill down

    I want to be able to drill into a sales order listed in a sales abap query.  I thought I read somewhere that you can turn on something to make this query interactive but I cannot put my fingers on that.  Any help?
    Thanks so much!
    Susan

    Hi Susan,
    To use RRI in ALV mode, you'll have to follow indications in SAP note 675546 - ALV-RepRep: Report-report interface.
    Other information are also give in notes 50629 - ABAP/4 query: Report-Report-Interface, and 174365 - ABAP query: Report/report interface call in ALV
    BR
    Sandra

  • A few Questions on ABAP Query

    Hi Guru's
    I would like to ask some questions on ABAP query.
    1. Can you transport abab queries? Should it only be Global or you can also transport Standard Areas?
    2. Once transported, am i able to change query?
    Thanks,
    Jograd

    hi....
    you can transport a quary but for that the quary should be an object itself or attached to some object
    and
    if once transported to production....you cannot change it there and for changing you have to get it in developement sysytem and then make any change.
    regards

  • Question in ABAP query

    Hello All:
       I created ABAP query and when I transported the system created transport number but it also creates defualt description "transport for ABAP query". I did a mistake by not going to tranports and updating the description to something meaningful! I created several queries and all have same description "Transport for ABAP query" and when I go to se10 it does not tell me what query the transport is tied to!! Is there a way I can find the query I created based on tranport request number? Please help me.
    Thanks.
    Mithun

    Hi Mithun,
    Go into SQ02 or SQ03 and click the Transport button to get into the Query Transport functions (or you can execute RSAQR3TR from SA38).
    Select the Display radiobutton at the top of the screen.
    Input the transport number in the "Dataset with imports" field at the bottom of the screen.
    Click execute and you will get a list of the Query Transport contents.
    hope that helps
    Points Appreciated
    Robin

  • Question about ABAP Query

    Hi,
    I have a SQ01 query .. based on that query i have to call another query
    ie : when my basic list gets diplayed .. after i click on it a detailed list should be displayed (this again is another SQ01 query)... is this possible through abap Query and if it is where am i supposed to code this
    Thanks a lot in advance

    HI
    GOOD
    GO THROUGH THIS LINK
    http://www.ams.utoronto.ca/Asset353.aspx
    THANKS
    MRUTYUN

  • How to create an ABAP Query with OR logical expression in the select-where

    Hi,
    In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
    Please help me on this.. Points will be rewarded.
    Thanks a lot.
    Regards,
    Question Man

    Hi Bhupal, Shanthi, and Saipriya,
    Thanks for your replies. But that didn't answer my question.
    Bhupal,
    You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
    Shanthi,
    Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
    Saipriya,
    Like what I have said, this is a standard SAP code so we can't do your suggestion.
    I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
    Thanks a lot.
    Points will be rewarded.
    Regards,
    Question Man

  • 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 - Creation of Report

    Hi guys,
    I do have a question to ABAP Query:
    I want to create a report that shows me all current active employees and all of their corresponding positions from Infotype 1.
    I have got it to the part where the report gives me all employees (active and withdrawn).
    The question is:
    How can I show only active employees as of todays date?
    Thanks,
    Sascha

    Thanks for your reply,
    but if I enter date 31.12.9999 and status of active. it gives me for some the latest record and for some two - though I could not find out why?!
    I should say, I am using logical database PNP for this query
    null

  • Creation of ABAP query

    Dear All,
    This may be a technical question.  I am trying to create the ABAP query by using 2 tables.  Went to SQ02, entered the  description of Infoset and given the first table name in the "Table join in the basis table" row.  When i entered to type the second table name, the program is getting terminated. (If I want to create a query by using one table, then the system accepts)
    If possible, can anybody explain me what could be the proble,?
    Regards
    Manivannan R

    You can post u r req in Expert Forums  » Application Server  » SAP GUI forum
    7.10 is now released, you can get it at
    ftp://ftp.sap.com/pub/sapgui/win/710/compilation1/
    and on
    ftp://ftp.sap.com/pub/sapgui/win/710/patches
    there are the newest patches available.
    http://iris.tennessee.edu/sapgui_vista.htm
    Message was edited by:
            SHESAGIRI.G

  • PNPCE in ABAP Query(SQ01) Selection is not working completely

    Hi All,
    I have developed an ABAP query using LDB PNPCE. I am reading data from IT000,IT0001 etc . I test the query in QA and I noticed that the PNCPCE screen doesn’t care about the selection in query. Like I have given the date range in PNCPE default screen. But it’s not filtering that data at all. It pulling up the employee’s regardless of date, it behaves the same for field action type (P0000-MASSn). The surprising thing is that for company code its working fine. My question is that Why PNPCE standard screen-selection not filtering data in ABAP query.
    Did any one of you also experience that?
    FYI
    I also find an OSS note # 730005 but we are already on 52 Patch !!
    OSS note :PNPCE: Incorrect data of infotype 0000 and 0001
    Symptom
    When you carry out a reprot which is based on logical database PNPCE, errors occur during the processing of infotypes 0000 and 0001.
    Other terms
    PNPCE, AS PERSON, P0000, P0001, data selection period, person selection period, CHECK_IT_0000_DATA_RESTRICTED, CHECK_IT_0001_DATA_RESTRICTED
    Reason and Prerequisites
    You start a report which is based on logical database PNPCE. In the report, infotype 0000 or 0001 is processed (that is, it was declared via the INFOTYPES statement). At event 'GET GROUP' or 'GET PERAS', the system either returns too few data records in the infotype tables or it returns data records twice.
    The error (missing data records) has only occured since the implementation of Note 687004 or the import of Support Package SAPKE47028.
    Solution
    Implement the attached corrections. or import the corresponding Support Package.
    Thanks,
    Saquib Khan

    Hi Saquib,
       Recently i am facing the same issue can u pls do reply how you have overcome this issue..The data is not getting picked up at the right time it is lately picked up by the program . Earlier it was PNP and it has been changed to PNPCE also we had implemented OSS Note 687004 and the later's Notes  were also implemented but still now we are unable to track down why there is delay in picking up the records this has been happening for the past 8-10 Months(i m not sure far more before). I am finding 2 main issues,
    1. we are using GET peras in PNPCE and no other event after that may be this is not fetching all the data because my selection screen does contain PERSONID where i suppose there should be GET PERSON event to define it
    2. RP_READ_INFOTYPE macro while using for P0000 ,, the code in the macro is such that it fetches using P0001 also ...I suppose if there are any inconsistency between IT0 and IT1 then this might one to take care ...
    kindly let me know how you have approached to resolve this issue.

  • PNPCE in ABAP Query !!! Slection is not working completely

    Hi
      I have developed an ABAP query using LDB PNPCE. I am reading data from IT000,IT0001 etc . I test the query in QA and I noticed that the PNCPCE screen doesn’t care about the selection in query. Like I have given the date range in PNCPE default screen. But it’s not filtering that data at all. It pulling up the employee’s regardless of date, it behaves the same for field action type (P0000-MASSn). The surprising thing is that for company code its working fine. My question is that Why PNPCE standard screen-selection not filtering data in ABAP query.
    Did any one of you also experience that?
    <u>
    <b>FYI</b></u>
    I also find an OSS note # 730005 but we are already on 52 Patch !!
    OSS note :PNPCE: Incorrect data of infotype 0000 and 0001
    Symptom
    When you carry out a reprot which is based on logical database PNPCE, errors occur during the processing of infotypes 0000 and 0001.
    Other terms
    PNPCE, AS PERSON, P0000, P0001, data selection period, person selection period, CHECK_IT_0000_DATA_RESTRICTED, CHECK_IT_0001_DATA_RESTRICTED
    Reason and Prerequisites
    You start a report which is based on logical database PNPCE. In the report, infotype 0000 or 0001 is processed (that is, it was declared via the INFOTYPES statement). At event 'GET GROUP' or 'GET PERAS', the system either returns too few data records in the infotype tables or it returns data records twice.
    The error (missing data records) has only occured since the implementation of Note 687004 or the import of Support Package SAPKE47028.
    Solution
    Implement the attached corrections. or import the corresponding Support Package.
    Thanks
    Saquib Khan

    Hi Saquib,
       Recently i am facing the same issue can u pls do reply how you have overcome this issue..The data is not getting picked up at the right time it is lately picked up by the program . Earlier it was PNP and it has been changed to PNPCE also we had implemented OSS Note 687004 and the later's Notes  were also implemented but still now we are unable to track down why there is delay in picking up the records this has been happening for the past 8-10 Months(i m not sure far more before). I am finding 2 main issues,
    1. we are using GET peras in PNPCE and no other event after that may be this is not fetching all the data because my selection screen does contain PERSONID where i suppose there should be GET PERSON event to define it
    2. RP_READ_INFOTYPE macro while using for P0000 ,, the code in the macro is such that it fetches using P0001 also ...I suppose if there are any inconsistency between IT0 and IT1 then this might one to take care ...
    kindly let me know how you have approached to resolve this issue.

  • ABAP query processing in bgrnd and saving file to prsntn/application server

    Hello Gurus
    I have question regarding to ABAP query execution. Currently I try to find out if ABAP query can be executed in background and store the result into UNIX directory or in the presentation server(desktop). What I found is that the report need to be executed using option Private File and the data by default will be stored at directory /sap/outbound/.
    However what I found next is that the maximum fields should be 64 fields. If the query result has more than 64 fields, the error will occurs WRITE_TO_OFFSET_TOOLARGE.
    My question is:
    1. Can we set the directory in unix folder to someplace else than /sap/outbound/ ?
    2. Can we set in order to have the report stored without limitation 64 fields?
    Thanks in advance

    HI
    Yes you can set the directory in unix folder to someplace as you need to get confirmation for the path from your Functional Analyst.
    Thanks

  • User restrictions in a ABAP Query (sq01)

    Hello,
    I'm new into queries so I have a question for you gurus...
    I have a working abap query, created via SQ01 but this is showing all the data to all the users who have rights to call this transaction.
    BUT
    for example
    user A works for plant X
    user B works for plant Y
    if user A calls the query, he should only see the data from plant X
    if user B calls the query, he should only see the data from plant Y
    Can you guys please help me out to get this thing working...
    Since i'm new in SAP I don't know alot about restrictions etc
    so please help me out with a newbie-answer
    (please describe évery step that i should do so the users only get their local data)
    thank you very much for your help!

    We're looking into restrictions on SQ01 too.  We thought that creating protected variants would solve our issue; but, we can't prevent a user from copying or creating their own variant.  When the user can create his or her own variant, then all the protection we built into our admin team's variants are gone.

  • Excess Inventory/Scheduled Receipts Report using ABAP Query.

    Hi All,
    I want to create a ABAP query for Excess inventory & Scheduled receipts in a single report. I have identified tables, fields and some extra calculated fields in the report. Here are the following tables and fields.
    EKPO-MATNR      ( Material number)
    EKPO-WERKS     ( Plant)
    MAKT-MAKTX       (Material Discription)
    MARC-MAABC      ( ABC indicator)
    LFA1-NAME1        ( Supplier name)
    MBEW-STPRS      (Total value)
    EKET-EINDT         ( Item delivery date)
    RIBOF-AMOUNT
    S939-SPWOC or S032-SPWOC
    Calculation fields : Value execess this week.extend value, over or under this week, onhand inventory for last week and this week.
    Here my question is, when i was creating a infoset, how do i maintain relationship or joins from one table to another table...Is there any sequence for the above tables? Pl suggest. When i was adding all the tables in a infoset and try join the tables...it says illegal join...
    Pl suggest me.
    Thanks for your help
    PRadeep
    Edited by: Venkata Pr Papulugari on Jul 18, 2008 1:37 AM

    Hi Gordon,
    What i need to display is the remainder of the transaction that was received... if it is zero (0), i don't want to display it.
    i.e.
    transact # 100 inqty = 5
    transact # 200 outqty =1
    I'd like to display
    transact # 100     qty on hand = 4
    right know the transaction # that i am displaying is transact # 200.
    And also, it needs to be warehouse oriented. because i can have multiple warehose transactions.... and i am getting that wrong too.
    Regards,
    Manuel Roman

  • ABAp query SQ01

    Hi guys,
    I want to make a ABAP Query via SQ01on SAP ECC.
    First i had created an infoset, that only based on one table.
    My requirement is to fetch alle data from this table grouped by customer number.
    Using an sql statement is this very easy to do, but in i had trouble making this in SAP (SQ01):
    SELECT CUST_ID, COUNT(ORDERID)
    FROM
    TABLE
    WHRE CONDITIONS
    GROUP by CUST_ID
    HAVING COUNT(ORDERID) > 1
    My question is where to put my requirement in order to get result using standard ABAP query SQ01.
    I will really appreciate your help.
    nabil

    Hi,
    Welcome to SDN.
    This is not possible exactly with ABAP Query but can be easily done by ADHOC query. Using Set operation A-B.
    Check the links for ADHOC Query -
    <a href="http://www.sap.cmich.edu/fihr/hr/adhoc-query.doc">http://www.sap.cmich.edu/fihr/hr/adhoc-query.doc</a>
    Regards,
    Amit
    Reward all helpful replies.

Maybe you are looking for

  • How to Open & Close the periods in Asset Accounting for Depreciation.

    Dear All, How to to How to Open & Close the periods in Asset Accounting for Depreciation ? Please let me know If there is any T.Code or procedure for it. Your help is highly appreciated. Thanks & Regards, Pankaj.

  • Opem Items List - showing items closed manually

    Hi guys, I'm using 2005B PL 40 and I'm having a little problem. I've created a sales order nr 54 with 4 different items, one of each. Each one of them costs $25. So, my total is $100. Now, if I close one line manually, I'm only goint to deliver 3 ite

  • Itab creation on runtime

    Hi friends, Have run into to trouble trying to create a dynamic structure as follows "Material Land Nov.09 Dez.09 Jan.10 Feb.10 Mar.10 TotalCount" The dates are created dynamically with regard to the time period entered in the select options. The fir

  • CIF Activating an Integration model takes long time

    Hi , I have a strange issue that whenever I perform CIF from R/3 to SCM APO system, it takes a very long time for the very first time on a day even though the number of objects in the CIF model is only one material. After this activation completes su

  • Database development practise advise

    Hi friends, I am a fresher in the Development field..coming straight from college and certified in Oracle SQL so far, currently working on Pl/sql certification. I want to practise Quality industry Database Development as well as getting the experienc