Skip to Content

combining sy-subrc with other conditions

i have a below code..

{}

REFRESH IT_ZVM_MARGIN.

SELECT * FROM ZVM_MARGIN

INTO TABLE IT_ZVM_MARGIN

WHERE MODEL = F_MATKL

AND PERIOD_FROM LE SY-DATUM

AND PERIOD_TO GE SY-DATUM

AND MARGIN_CODE EQ LV_MARGIN_CODE

AND DEALER = WA_VLCVEHICLE-KUNNR

AND MAINTAINED EQ XFLAG_GC.

IF SY-SUBRC = 0 AND IT_ZVM_MARGIN[] IS NOT INITIAL.

{}

in above code i used the combination of sy-subrc with internal table check... is it a wrong coding practice?? and i am not understanding the benefits of two conditions combined together i.e. sy-subrc and checking whether internal table is empty...

what is the difference in below statement performance wise ???

IF SY-SUBRC = 0 AND IT_ZVM_MARGIN[] IS NOT INITIAL.

or

IT_ZVM_MARGIN[] IS NOT INITIAL.

some people say meaning of the above statements is same.. but as per me sy-subrc should be checked...

can u pls guide on the same..

regards,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Jul 31, 2012 at 12:26 PM

    Hi Santosh,

    I think it is better to check the sy-subrc, because if there is not any row in the db table which matches the selection condition the internal table will not be changed. The SELECT statement do not a initialization of target table if the is not any selected row. In the case if the internal table has been already filled before the SELECT execution and you check only the content of the internal table you get a true condition. It can be wrong in some cases. For example if you use the same internal table in several SELECT statements.

    In your example SELECT statement you can use sy-subrc as well as lt_iteb[] check. But it does not make sence to use a combination of both.

    Best regards,

    Viktor

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 31, 2012 at 12:44 PM

    Why do you want to use a combination?

    If the "SELECT * FROM ZVM_MARGIN" fails, SY-SUBRC will = 4. And IT_ZVM_MARGIN will be initial.

    Therefore, you only need the "IF SY_SUBRC = 0" part.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 31, 2012 at 12:52 PM

    Hi Santosh

    I think it's a code redundancy to check SY-SUBRC = 0 AND IT_ZVM_MARGIN[] IS NOT INITIAL below of a select statement.

    Because when the SY-SUBRC = 0 then a set of records will be returned into internal table make it not initial and when SY-SUBRC <> 0 no records will be returned into internal table make it initial.

    Performance wise you have an extra check statement with negligible cost, but this not means that this statement is not redundancy

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 31, 2012 at 12:56 PM

    In the above context both of your conditions mean the same. Why do you want to check both of them.?

    If the Select query executes that means, it returns Sy-SUBRC = 0 else 4.

    If it returns SY-SUBRC = 0 means, IT_ZVM_MARGIN[] will have atleast one record.

    However, your mentioned syntax is incorrect. You can write the same statment in this way

    IF SY-SUBRC = 0.

    IF IT_ZVM_MARGIN[] IS NOT INITIAL

    <....Your logic....>

    ENDIF.

    ENDIF.

    Regards

    uday

    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.