07-31-2012 1:16 PM
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,
07-31-2012 1: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
07-31-2012 2:30 PM
Hi Viktor
I think you are wrong for the table initialization the correct answer is:
(I get it from help for the select statement)
The result set is inserted into the internal table itab line-by-line; a sorting process is executed in the case of a sorted table. If INTO is used, the internal table is initialized. Previous lines remain intact if APPENDING is used.
07-31-2012 2:43 PM
Hi George,
thanks for your reply. I tried it in a simple report and it is true. The internal table behind INTO TABLE is initialized. Now I can avoid the CLEAR statement before a SELECT INTO statement and do my code more faster. 😉
Thanks,
Viktor
07-31-2012 1: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.
07-31-2012 1: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
07-31-2012 1: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