‎2008 May 09 6:05 AM
Hi,
the current syntax we are using for looping a internal table is
1. loop at itab
assigning <fs_itab>.
if <fs_itab> is assigned.
..................................
endif.
endloop.
My TL suggested me that if the field symbol is not assigned then it will not move into the loop. So there is no need for checking if the field symbol is assiged or not. I am not sure please suggest.
2. One more question current read syntax we are using
read itab assigning <fs_itab>............
if <fs_itab> is assigned.
endif.
instead of checking if the field symbol is assigned can check the sy-subrc.
will there be any case in which even if the field symbol is not assigned there is chance of sy-subrc eq 0. Please suggest
‎2008 May 09 6:31 AM
Hi,
Your TL is absolutely correct.
1. No need of checking whether field-symbol is assigned or not, since the control will get inside LOOP only if data is thr in internal table and if data is thr field-symbol will be assgined...i.e. it will defintely point to the corresponding entry in internal table.....
2. If field symbol is not assigned then sy-subrc will not be 0. No way it will be 0 even if field-symbol is not assigned....only if condition are met then only field-symbol will get assigned.....So here also no need of checking whether field-symbol is assigned or not.
Rewards if useful....
Regards,
ABAPer 007
Edited by: ABAPer 007 on May 9, 2008 11:09 AM
‎2008 May 09 8:04 AM
Hi,
For ur first question field symbol check is not required as the field symbol will get assigned only if the itab contains the data.
But for ur second question, it is better to check with SY-SUBRC as the field symbol always contains the data of the internal table for every iteration. It could be a problem if u r reading the data with some where clause as the the field symbol will not get refreshed and contains the previous record data irrelevent to the success of the READ statement.
U need to perform some operation only if the read statement is successfull. If u r using READ statment then it is always better to use SY-SUBRC instead of checking with destination one.
Reward points if this is helpful for u.
Chandrasekhar K
‎2008 May 09 9:34 AM
Hi,
1. No need to check whether <fs_itab> is assigned becoz the loop is entered only if there is a matching record in case you have given any condition or incase the table is not empty. If the table is empty, it will not enter the loop at all.
2. It is alwasy better to use the check of sy-subrc = 0 when u perfiorm read.... Also befor you read ur internal table clear the header of the internal table so that no wrong data is picked.. it happens sometimes that the old record remains in the header if u do not clear it.
Hope this helps u.
Reward if useful.
Regards,
Anu.