05-16-2006 4:10 AM
Hi,
I have small question regarding <b>LOOP ..... ENDLOOP</b> statement against <b>SY-SUBRC</b> Check.
I have a loop as below:
<b> LOOP AT i_vbap WHERE vbeln = i_vbak-vbeln.
Some Code
ENDLOOP.
IF sy-subrc <> 0.
APPEND i_sdata.
CLEAR i_sdata.
ENDIF.</b>
Is the above <b>Code/Syntax</b> is correct one.
Can we use <b>SY-SUBRC</b> Check against <b>LOOP ... ENDLOOP</b> statement.
Is this the right way of writing the code as per standards.
Can anybody give sujjestions regarding the same.
Thanks in advance.
Thanks & Regards,
Prasad.
05-16-2006 4:42 AM
Hi Prasad,
The stetements are absolutely right.
what it do is ,
to Check the table I_VBAP has any records for each I_VBAK-VBELN,if so appending the record to I_SDATA. else not doing any thing.
SY-SUBRC Will be 0 only when each VBAK-VBELN, have atleast 1 record in VBAP table. then only it will become 0.
Regards
Srikanth
05-16-2006 4:26 AM
Hi Prasad,
Syntax is correct only, here one suggestion is that in this case you can use READ instead of LOOP ENDLOOP unless if you are not doing anything with the internal table data.
Regards,
Arun.
05-16-2006 4:26 AM
Hi Prasad,
Yes, you could use sy-subrc after the endloop. For example:
loop at itab1 where kunnr = itab2-kunnr.
some conditions...
endloop.
if sy-subrc = 0.
write: 'Success!'.
else.
leave program.
endif.
if you press F1 while highlighting the LOOP statement here are the meaning of sy-subrc in loop...endloop.
SY-SUBRC = 0:
At least one loop pass was processed.
SY-SUBRC = 4:
The loop was not processed because the table contains no entries or no entries satisfied the conditions.
Regards!
05-16-2006 4:26 AM
Hi Prasad,
U can use sy-subrc against Loop .. Endloop.
It's normal programming convention u r checking.
It's doesn;t lead to any programming errors.
Even u can try it in ur logic.
Cheers,
Simha.
05-16-2006 4:37 AM
yes, this is the correct way to check sy-subrc.
As the sap help says,
"At the end of loop processing (that is after ENDLOOP), the return code value of SY-SUBRC specifies whether the loop was actually processed.
SY-SUBRC = 0:
The loop was executed at least once.
SY-SUBRC = 4:
The loop was not executed, either because there was no entry at all or because there was no entry which satisfied the conditions."
05-16-2006 4:42 AM
Hi Prasad,
The stetements are absolutely right.
what it do is ,
to Check the table I_VBAP has any records for each I_VBAK-VBELN,if so appending the record to I_SDATA. else not doing any thing.
SY-SUBRC Will be 0 only when each VBAK-VBELN, have atleast 1 record in VBAP table. then only it will become 0.
Regards
Srikanth