How to write IF-THEN-ELSE in query (syntx)

Dear Experts,
As the decode syntx is Oracel's, is there any syntx could be used for IF-THen-Else function in query generator?
Thanks.
Emily

Morning, Gouri,
It works!!  Thanks very much!
BTW, in Inventory menu, the report 'Inventory Posting  List, does it pull data from table 'OINM' ?
It looks like OINM does not link with tables of ODLN (PL/delivery) and OPOR (PO), is it correct?
If I would like link OINM to ODLN and OPOR, which table interrelated between them??
Pls kinldy asdvise.
Thanks in advance.
Emily

Similar Messages

  • How to write Additional Logic IN SAP Query

    Hi All,
    I need to Add 1 more field in Query.
    How to Write a Logic in Infoset?
    For Ex : Need to add age field in the output.
    Thanks
    Partha.

    Hi,
    Refer to this link..Additional field in SAP Query
    [Creating Additional Fields |http://help.sap.com/saphelp_nw04/helpdata/en/d9/9958e0c50a11d396f80000e82de14a/frameset.htm]
    [Code|http://help.sap.com/saphelp_nw04/helpdata/en/d9/9958e0c50a11d396f80000e82de14a/frameset.htm]

  • How to write a if else logic expression for this condition

    Hai All
    I have written some if else logic for for my condition
    If the time is betweeb 0145 and 0630 and timeout is a column in a table is null than update sysdate-1
    then if time is bet0645 and 0900 then timein is null then insert into timein in table called dail_att
    and time bet 1130 and 1300 then if barcode null then insert timein else update timeout
    and bet 1645 and1730 then if barcode null and timein null then insert timein or update time out
    this is my condition for generating attendance. Ive tried some logic and pls tell case executed faster than ifelse logic
    and give me a soluton
    This is my coding
    if :bartime between 0145 and 0630 and :barcode is not null then
    update dail_att
    set timeout = :bartime
    where barcode= :barcode
    and timein is not null
    and ATTEND_DATE = :BARDATE-1;
    else if :bartime between 0645 and 0900 and :barcode is null then
    insert into dail_att(barcode,timein,attend_date)
    values(:barcode,:bartime,:bardate);
    else if     :bartime between 1145 and 1300 and :barcode is null then
         insert into dail_att(barcode,timein,attend_date)
    values(:barcode,:bartime,:bardate);
    else
         update dail_att
    set timeout = :bartime
    where barcode= :barcode
    and ATTEND_DATE = :BARDATE ;
    end if;
    else if :bartime between 1645 and 1730 and :barcode is null then
              insert into dail_att(barcode,timein,attend_date)
    values(:barcode,:bartime,:bardate);
    else
         update dail_att
    set timeout = :bartime
    where barcode= :barcode
    and ATTEND_DATE = :BARDATE ;
    end if;
    else :bartime > 1730 and :barcode is null then
         update dail_att
    set timeout = :bartime
    where barcode= :barcode
    and ATTEND_DATE = :BARDATE ;
    end if ;
    EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE' OR :BARCODE IS NULL;
    NEXT_RECORD;
    forms_ddl('commit');
    end loop;
    Regards
    Srikkanth.M

    Hai Sir
    I am storing time in 24hrs format and its datatype is varchar.Pls tell me we can write an if else with in a elseif
    Regards
    Srikkanth.M

  • How to use if-then-else-end if in template building?

    hi,
    I am not able to use the "if-then-else-end if" in my template. I want to display a data based on a condition. My requirement is as follows:
    if bal_for_vd < 0 then
    bal_for_vd * no_of_days
    else 0
    end if
    I tried using
    1.<?if: BAL_FOR_VD < 0 then BAL_FOR_VD*NO_OF_DAYS else 0 end if?>
    2.<?xdofx:if BAL_FOR_VD < 0 then BAL_FOR_VD * NO_OF_DAYS end if?>
    3.<?choose:?>
    <?when:BAL_FOR_VD < 0?> <?BAL_FOR_VD * NO_OF_DAYS ?>
    <?end when?>
    <?otherwise?>0
    <?end otherwise?>
    <?end choose?>
    4.<?if:BAL_FOR_VD < 0?><?BAL_FOR_VD*NO_OF_DAYS?><end if?>
    but ended up getting errors or nothing is getting displayed.
    When i used <?BAL_FOR_VD * NO_OF_DAYS ?> alone its working fine and correct getting result. But on giving condition its erring out.
    I will be glad if i get some solution for this.
    Regards,
    Vishnu T Ramakrishnan

    Hi..
    Below syntax should work..I tried with a sample xml..
    <?xdofx:if BAL_FOR_VD < 0 then BAL_FOR_VD * NO_OF_DAYS
      else
    0
    end if?>HTH..

  • How to do IF THEN  ELSE logic in Workflow?

    I need to do "if then else" logic in Workflow. The key part of the probem is that there are several "else" (elsif) possibilities, so I can't use a Boolean or Yes/No as a return result code. When I use a function, I can't see a way to "check" the value before it passes to a next process. HELP!

    Whether you are using a function as your comparator or the Standard WF Compare Operators, this can be done. I will explain two scenarios, one with your own written functions as the comparator and the other using the standard Compare Text function.
    Create a PL/SQL procedure that returns a boolean. In this procedure you would pull two attributes from the workflow, the test case and the value you want to compare to. You would check to see if they are equal and return true, otherwise false. I do not know what you are trying to compare in your if statement, but whatever it is, if its true, return true, otherwise false.
    Now in the workflow, you would put a couple of these in your process diagram representing each if statement. Set the two (or more) attributes in the Node Attributes tab of each function node to the values you want to compare. For the first node, have the <true> transition go to whatever you want done and then to an END node. Have the <default> or <false> transition point to the next function node you have. Do the same for each one except at the last one, its only transition would be <default> and that would go to END. This way if the first function resolves true, it will do whatever should be done and then skip the rest of the conditions. If its false, it will go to the next conditional. The last one will be gotten to only if every other conditional was false that would be your final else statement.
    To do this with the Compare Text option, have the same set up in your workflow diagram exception have the <EQUALS> be your true path and the <DEFAULT> transition go to the next compare text node.
    -->O-{default}->O-{default}->O->default
         |                 |                 |             |
        true           true            true           |
         |                 |                 |             |
      doWork     doWork     doWork      else
         |                 |                 |             |
          ---------------->---------------->------------|
                                                          |
                                                      end

  • How to write customer exist for Keyfigure( query )

    Hi gurus,
    I have to write customer exist for a key figure.
    Please tell me how to write it.
    Thanks,
    James

    Pankesh,
    SE24 is for  defining classes .. are you sure this is for customer exits ?..
    Use a formula variable filled by a customer exit... go to TCode CMOD and follow the normal procedure for defining Exits.. look up the forums for detailed steps on how to write an exit..
    Arun
    Hope it helps...

  • How to write a condition in BEX Query Designer

    Hi
    How can i write a condition in Query Designer
    Scenario
    An employee can purchase any no of policies in a day or month.each policy will have start date and expiry date.
    My requirment
    Count all the policies(valid) by employee on a ranges basis exception reporting
    (0-10;10-20;20-30;30-40) and then able to drill down by policy start date and expiry date.
    As per the requirment is to show policies which are not yet expired (active) i need to write a condition that will count only policies whose Expiry date is > Current calender day
    As Policy Expiry Date is a char i am converting it to KF using fourmala variable so that i can write a condition on it using current cal day formula variable sap exit
    But i char assigment of a condition i find 4 option
    How can i achieve this
    Thanks

    Hi Aurun,
    Thanks for the help,Really appreciated
    As this is my first enhancement using ABAP & CMOD
    What type of key (either Access or developer ) do i require to perform the following  enhancement......so that i can raise request with basis team
    I shall be great ful if u can asnwer below question
    First, you need to create a variable for expiry date with processing type as customer exit, and then give the necessary info.
    In details tab, unchk ready for input as we wont be taking the value from the prompt.
    Now go to CMOD transaction.
    Open the correcsponding project which has the exit code
    (How can i identify the project which has exit code)
    and go to ZXRSRU001 module inside taht.
    Go to the module where u write the exit.
    (How to locate the required module)
    Then, under i step 1, write the code:
    IF I_STEP = 1.
    CASE V_NAME  (What is 'V_NAME',Is it my variable technical name)
    WHEN 'X' " X is the variable u created for the exit
    l_s_range-low = SY-DATUM.
    l_s_range-opt = 'I'.
    l_s_range-sign = 'GT'.
    APPEND l_s_range TO e_t_range.
    END CASE.

  • How to implement "if/then/else" or "case" logic in a Statement Expression?

    I need a loop in my test sequence, so I define a Locals.LoopIndex which is of type Number, and I also define a Locals.PromptMessage, which is of type String. Within the loop body, have a statement step, in which I want to assign Locals.PromptMessage different strings according to the value of Locals.LoopIndex. The logic is like this (in suedo code)
    case Locals.LoopIndex:
    1: Locals.PromptMessage = "string1";
    break;
    2: Locals.PromptMessage = "string2";
    break;
    or
    if (Locals.LoopIndex == 1)
    then Locals.PromptMessage = "string1";
    else if (Locals.LoopIndex == 2)
    then Locals.PromptMessage = "string2";
    How can I implement this in the Statement Expression?
    Thanks!

    You can use the conditional expression (not sure what it is called). Syntax is Locals.variable=(BooleanExpression?ValueIfTrue:ValueIfFalse). To implement your pseudo code it would look like this:
    Locals.PromptMessage=(Locals.LoopIndex==1?"string1":"string2")
    This means the same as:
    If Locals.LoopIndex=1 then
    Locals.PromptMessage = "string1"
    Else
    Locals.PromptMessage = "string2"
    End If
    Another way to do it is like this, but the first method is preferred:
    Locals.LoopIndex==1?(Locals.PromptMessage="string1")Locals.PromptMessage="string2") -- must use parenthesis as shown
    This syntax is BooleanExpression?(Statement if BooleanExpression is true)Statement if BooleanExpression is false)
    You can nest the expression to create ElseIf conditions:
    Locals.PromptMessage=(Locals.LoopIndex==1?"string1"Locals.LoopIndex==2?"string2":"string3"))
    This means the same as:
    If Locals.LoopIndex=1 then
    Locals.PromptMessage = "string1"
    ElseIf Locals.LoopIndex=2 then
    Locals.PromptMessage = "string2"
    Else
    Locals.PromptMessage = "string3"
    End If
    I don't know if there is a limit to the nesting.
    Hope this helps.
    - tbob
    Inventor of the WORM Global

  • How to write ABAP Logic in SAP Query to fetch records from many Tables

    Hi Expert,
    I have one requirement, want to display all BOM (Equipment BOM, Function Location BOM and Meterial BOM) from a particular plant.
    List of tables as below:
    EQST: Equipment to BOM Link
    TPST: Link Between Functional Location and BOM
    MAST: Material to BOM Link
    STPO:BOM item
    Requirement: When user enters Plant then SAP Query should execute and fetch all BOMs (as mentioned above) from STPO Table.
    I have done so far is as follows:
    I create User Group, Infoset and SAP Query.
    While creating INFOSET, i used 4 tables (EQST,TPST,MAST & STPO) and link between then is as follows:
    STPO-STLNR ---> EQST-STLNR : Left Outer Join
    STPO-STLNR ---> TPST-STLNR : Left Outer Join
    STPO-STLNR ---> MAST-STLNR : Left Outer Join
    Now its showing all BOM from all plants though I enter one Plant value.
    Please advise me to write SAP Query and Logic to fetch all BOM from selected Plant Value.
    Thanks,
    Jay.
    Edited by: jaykrishna007 on Jul 29, 2011 11:41 AM

    Hi FCannavo,
    Thanks for your quick reply.
    See, now I changed my Infoset design.
    I added one Plant Table (T001W) and then
    T001W-WERKS--->EQST-WERKS
    T001W-WERKS--->MAST-WERKS
    T001W-WERKS--->TPST-WERKS
    and then
    EQST-STLNR--->STPO-STLNR
    MAST-STLNR--->STPO-STLNR
    TPST-STLNR--->STPO-STLNR
    on selection screen, user will enter Plant Value.
    Now its showing some records, but i dont think so i would be correct output or not, please guide me whether it is correct or not?
    Thanks,
    Jay.

  • How to write SQL hints for this query?

    The query is like:
    select * from foo, t
    where foo.name in
    (select name from bar
    where id in (
    select id from car
    where date < sysdate
    and foo.a = t.b;
    I want the innermostsubquery 'select id from car ...' to be executed first, and the subquery 'select name from bar ...' to be execute second, and the outermost query 'select * from foo,t ...' to be executed the last. How can I write the Oracle sql hints to force the order?
    Thanks.

    user553560
    You might be able to create a large set of hints to force the access path you want - but unless you really know what you are doing with hints, you may find that your solution is very unstable (it might be luck rather than correctness that let's it work to start with).
    The difficulty in this query is the double layer of IN subqueries, so if you can rewrite the query, you might try manually unnesting as follows:
    select
         t1.*. t.*
    from
              select     
                   distinct t2.name
              from     t2
              where     t2.id in (
                        select     t3.id
                             from     t3
                        where     t3.dated < sysdate
         )     v,
         t1,
         t
    where
         t1.name = v.name
    and     t1.a = t.bDepending on your indexing and statistics, you may find that a simple /*+ unnest */ hint in the first subquery will be sufficient to do this for your. Again depending on the statistics you may find that you have to put extra hints into the above to make Oracle use the join method and indexes you think appropriate.
    N.B. The first step (as others have noted) is to check that your statistics are good before you start manipulating the code or using hints.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • IF THEN ELSE in DATA TEMPLATE NOT IN RTF

    Hi,
    Can any one tell me How to Implement IF THEN ELSE or DECODE or CASE Logic in a DATA TEMPLATE not in RTF
    as I saw loads of Post about implementing them in RTF not in the Template itself.
    I have a requirement please click this below for the Detailed Version of this Post, Else Please Just give me a Snippet from which i can Implement the IF THEN ELSE Logic in a DATA TEMPLATE( the .xml file) bu please not via a RTF not using PL/SQL Package
    Logic to select Report name based on User's input.
    Thanks
    vasanthanand

    Hello
    I am looking to do the same type of thing did you ever get an answer without having to use a RTF format perhaps in another forum or through investigation?

  • How to write Boolean function (If Then Else) For Date Caluclation.

    Dear All,
    I have a scenario where i need to calculate Position time hold by an employee in an organisation.
    I have 2 date Char ( DATE FROM & DATE TO), the problem is that is , If an employee is having
    2/3 position in an organisation its current position End Date is always 31.12.999 as its End date is
    not know. For previous position End Date is maintained.
    My requirement is to calculate Position hold time including Current position.
    Can it be done directly in formula variable with If Then Else condition.
    or i need to write user exit if its exit,
    please guide me for ABAP Code.
    Thanks V V much.
    Regards,

    Hi,
    Following options are available for you:
    1. Is the valid to, valid from dates available as a result of standard time dependency of navigational attributes? if yes , you can not use them in calculations, in such case you may have to write a full fledged routine at formula variable, using uxer exit.
    2. Another simple method, that i would suggest would be using temporal joins (infoSets), that precisely fits you case.
    Helpful links:
    About Infosets:
    [http://help.sap.com/saphelp_nw70/helpdata/EN/ed/084e3ce0f9fe3fe10000000a114084/frameset.htm]
    About Temporal joins:
    [http://help.sap.com/saphelp_nw70/helpdata/EN/11/723c3b35703079e10000000a114084/frameset.htm]
    Hope this helps.
    Cheers,
    Sumit

  • How  to write  a  query  for this output

    I have a string ' if i know good acting , I am a hero '
    now if 'hero' is present in the string it will return ' i am hero' else
    'you are hero'
    How to write a sql query to return the same .

    SQL> select (case
    2 when '&a' like '%hero%' then 'I am hero'
    3 ELSE 'u r hero'
    4 end) output from dual;
    Enter value for a: if i know good acting , I am a hero
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
    OUTPUT
    I am hero
    SQL> /
    Enter value for a: jkhkh
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'jkhkh' like '%hero%' then 'I am hero'
    OUTPUT
    u r hero
    Hope this helps.

  • How to write a query for the given scenario ?

    Hi All ,
    I am having two tables EMP, DEPT with the below data.
    EMP TABLE :--
    EID     ENAME     JOB     SAL     DEPID
    111     RAM     MANAGER     1500     10
    222     SAM     ASST MANAGER     2000     20
    333     KALA     CLERK     2500     10
    444     BIMA     MANAGER     3000     20
    555     CHALA     MANAGER     3500     30
    666     RANI     ASST MANAGER     4000     10
    777     KAMAL     MANAGER     2400     10
    DEPT TABLE :--
    DEPID     DNAME
    10     XX
    20     YY
    30     ZZ
    Q1 : I want the sum of salary of each department and for the particular job . Here in each departmant manager, asst. manager, clerk posts are there .
    I want to display the result like below ....
    JOB     10     20     30
    MANAGER     3900     3000     3500
    ASST MANAGER 4000     2000     NULL
    CLERK     2500     NULL     NULL
    please tell me how to write a sql query ?
    Thanks
    Sai

    In general case, you cannot write this query.
    This is one of the limits of relational database concepts. The number of columns must be known up-front. In the SELECT clause, you have to list and name all columns returned by the query. So you have to know number of departments. (There are some workarounds - you can return one column with concatenated values for all departments, separated by space character).
    If you know that you have 3 departments then you qurey will return 4 columns:
    SELECT
       e.job,
       SUM ( CASE WHEN d.deptid = 10 THEN e.sal ELSE NULL END) d10,
       SUM ( CASE WHEN d.deptid = 20 THEN e.sal ELSE NULL END) d20,
       SUM ( CASE WHEN d.deptid = 30 THEN e.sal ELSE NULL END) d30
    FROM dept d, emp e
    WHERE d.deptno = e.deptno
    GROUP BY e.job

  • If then else in update query

    Hello,
    I was hoping anyone could provide ideas on the best way to do an update query based on an if then else statement I am using Oracle 11 on a linux server. I am writing within a perl script. I've researched online and saw some examples using case. Below is the basic query logic I am trying to implement. I would really appreciate any suggestions.
    Thanks,
    JC
    If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') and askme_temp.CKT_ID = heci.CKT_ID then SUBPRODUCT =’IPAG’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') AND REGION=’SE’ then SUBPRODUCT =’METRO_E’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') then SUBPRODUCT =’OPT_E_MAN’

    Hi,
    Welcome to the forum!
    CASE sounds like a good idea to me.
    For example:
    UPDATE     table_x
    SET     subproduct = CASE
                   WHEN  askme_temp.CKT_ID = heci.CKT_ID
                         THEN  'IPAG'
                   WHEN  region          = 'SE'
                         THEN  'METRO_E'
                         ELSE  'OPT_E_MAN'
                   END
    WHERE     maint_center     IN ( 'ENOC1CENTER'
                      , 'PMCTGAAHSDC'
                      , 'ATTCSPCRT01'
                      , 'ATTCSPCWS01'
                      , 'NTNLWHS4NSA'
    AND   cac1                  = 'S'
    AND   SUBST (ckt_id, 4, 2)  IN ('KQ', 'KR', 'KS', 'KP', 'L1', 'L2', 'L3', 'VL')
    AND   ...
    ;CASE expressions are evaluated in the order in which you write them, so if askme_temp.ckt_id = heci.ckt_id (whatever those things are), subproduct will be set to 'IPAG'. It won't matter whether region is 'METRO_E' or not; if the 1st condition is TRUE, the first THEN value is returned, and the other WHEN expressions aren't even evaluated.
    What do you want to do if none of those conditions are met?
    Any conditions that are common to all the rows being UPDATEd can be put in the WHERE clause; they don't have to be repeated in the CASE expression.
    Remember, MERGE is often more convenient to use than UPDATE.
    Edited by: Frank Kulash on Jul 27, 2011 3:23 PM

Maybe you are looking for

  • The iPod "iHazen" cannot be synced. You do not have enough access....

    privileges for this operation." When I attempt to plug my iPod into my macbook, it begins syncing then this happens: First, iTunes tells me the default "It could damage your ipod to disconnect it without ejecting it" message. Then I get: "The iPod "i

  • Error 2: SAVE_FOLDER is undefined. Line: 361 -

    Hi. Every time I try to run a script it comes up with the following message Error 2: SAVE_FOLDER is undefined. Line: 361 -> I've tried uninstalling and reinstalling photoshop/deleting the script from all sources/reinstalling the script/reset photosho

  • Suggestion weather to go for BI7 or not

    hai we are planning to use BI7.0.But it is said tat BI7.0 supports excell 2003 but not excell2000. The problem is that all our core data is in excell 2000 so can anyone give a suggesion wat to do . Can we go for BI7.0?

  • Java.lang.SecurityException: Security violation, expect: 514, actual: 0

    [import] Connect to http://bi-internal.oracleoutsourcing.com/xmlpserver using ***** [import] Import "****.xdo" from "****" to "****.xdo" Command Error: import->importObject java.lang.SecurityException: Security violation: ****.xdo, user: ****, expect

  • Using DVD-RAM drive

    I have tried using my dvd-ram drive many times. The problem is i can't find a dvd-ram disc that actually works. It just spits out the dvd. im using a 450 sawtooth with dvd-ram drive. This is the original drive from 5 years ago before there was dvd-bu