Skip to Content
author's profile photo Former Member
Former Member

Conditions problem

Hi every one,

my requirement is as below.....

SELECT lfsta

fksaa

gbsta FROM vbup INTO TABLE t_vbup

WHERE vbeln = vbap-vbeln AND

posnr = vbap-posnr AND

lfsta IN s_status AND

gbsta IN s_bilst AND

fksaa IN s_bilst.

IF sy-subrc NE 0 .

SELECT lfsta

fksaa

gbsta FROM vbup INTO TABLE t_vbup

WHERE vbeln = vbap-vbeln AND

posnr = vbap-posnr AND

lfsta IN s_status AND

fksaa IN s_bilst.

ELSEIF sy-subrc NE 0.

SELECT lfsta

fksaa

gbsta FROM vbup INTO TABLE t_vbup

WHERE vbeln = vbap-vbeln AND

posnr = vbap-posnr AND

lfsta IN s_status AND

gbsta IN s_bilst.

ENDIF.

when the first query fails it should check in second and then if it fails then it should check in third.....all the conditions for first to entries are satisfying and my logic is working gud.....but there is a problem in third query if never populates into table......but when i take this query out of the if and elseif condition it works properly but my requirement fails for the given scenario.....how can i make this third qurey work properly without effecting my scenario requirement.....

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 09:47 PM

    Try this

    SELECT lfsta

    fksaa

    gbsta FROM vbup INTO TABLE t_vbup

    WHERE vbeln = vbap-vbeln AND

    posnr = vbap-posnr AND

    lfsta IN s_status AND

    gbsta IN s_bilst AND

    fksaa IN s_bilst.

    IF sy-subrc NE 0 .

    SELECT lfsta

    fksaa

    gbsta FROM vbup INTO TABLE t_vbup

    WHERE vbeln = vbap-vbeln AND

    posnr = vbap-posnr AND

    lfsta IN s_status AND

    fksaa IN s_bilst.

    IF sy-subrc NE 0.

    SELECT lfsta

    fksaa

    gbsta FROM vbup INTO TABLE t_vbup

    WHERE vbeln = vbap-vbeln AND

    posnr = vbap-posnr AND

    lfsta IN s_status AND

    gbsta IN s_bilst.

    ENDIF.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 09:47 PM

    Change the elseif to an if and add an endif:

    SELECT lfsta fksaa gbsta 
    FROM vbup INTO TABLE t_vbup
    WHERE vbeln = vbap-vbeln AND
    posnr = vbap-posnr AND
    lfsta IN s_status AND
    gbsta IN s_bilst AND
    fksaa IN s_bilst.
    
    IF sy-subrc NE 0 .
    
      SELECT lfsta
      fksaa
      gbsta FROM vbup INTO TABLE t_vbup
      WHERE vbeln = vbap-vbeln AND
      posnr = vbap-posnr AND
      lfsta IN s_status AND
      fksaa IN s_bilst.
    
      IF sy-subrc NE 0.      "<========
    
        SELECT lfsta
        fksaa
        gbsta FROM vbup INTO TABLE t_vbup
        WHERE vbeln = vbap-vbeln AND
        posnr = vbap-posnr AND
        lfsta IN s_status AND
        gbsta IN s_bilst.
    
      ENDIF.
    ENDIF.     "<=======

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Rob and Sams,

      I've already tried with this below thing but the problem is regarding my scenario...l'l have to tell u this for getting my scenario.......

      l have my vbup table with fksaa and gbsta field active.....

      lets take a example....from vbup for better understanding

      <b><u>vbeln posnr fksaa gbsta</u></b>

      30001 10 B B

      30001 20 A A

      30001 30 B B

      30001 40 C B

      30002 10 --- B

      30003 20 -


      C

      Now when i give some entry in s_bilst in selection screen field for example A to B then as you know the very first select query gets B and A related entries into the table...and displays the entries like below

      30001 10 B B

      30001 20 A A

      30001 30 B B

      and for 4th entry the third query triggers and displays the 4th entry too after the third entry.....like

      30001 40 B

      This is what i dont want because i'm giving only A to B range in the selection screen(which is common for both fksaa and gbsta and i'm restricted to have only one selection screen for both the fields) and it shud not show the four entries instead it should show only three entries.......and when i give only C in the entry the 4th entry is displaying properly for ur said logic.....every thing works fine but apart from the above problem with ur if conditions.......

      And for my logic it wont be displaying the fourth entry it instead displays the 3 enties when A to B range is given and only single entry when C is given in the selection screen.......but the only problem is with the last entry where fksaa field is empty this is not triggering the last select query and not ...........for my if and elseif conditions....i already tried with ur if conditions but no solution how should i solve this without effecting my requirement.....

  • author's profile photo Former Member
    Former Member
    Posted on Sep 20, 2007 at 04:33 AM

    Hi

    Try this

    SELECT lfsta

    fksaa

    gbsta FROM vbup INTO TABLE t_vbup

    WHERE vbeln = vbap-vbeln AND

    posnr = vbap-posnr AND

    (

    lfsta IN s_status or

    gbsta IN s_bilst or

    fksaa IN s_bilst ).

    thanks

    Dharmishta

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.