Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

loop and Read

Former Member
0 Likes
527

Will the below snippets are same,if not what is the difference,(performance??)

LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE

WHERE VNAM = 'ZVAR1'.

< logic x>

ENDLOOP

READ I_T_VAR_RANGE INTO LOC_VAR_RANGE

with Key VNAM = 'ZVAR1'.

IF sy-subrc = 0

< logic x>

endif

thanks

_R

4 REPLIES 4
Read only

Former Member
0 Likes
506

Hi,

If there is more than one record with the condition VNAM = 'ZVAR1'. Then LOOP AT I_T_VA_RANGE will process all the records that matches the condition..

LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE

WHERE VNAM = 'ZVAR1'.

< logic x>

ENDLOOP

The READ TABLE will get the first occurence of that condition...If there are more than one record..It will get the first record...

READ I_T_VAR_RANGE INTO LOC_VAR_RANGE

with Key VNAM = 'ZVAR1'.

IF sy-subrc = 0

< logic x>

endif

Thanks,

Naren

Read only

Former Member
0 Likes
506

They are not the same if there are more than one record satisfying the WHERE condition. They are same if you know for sure that there is only one record satisfying that WHERE condition.

Read only

0 Likes
506

got it thanks

Read only

ferry_lianto
Active Contributor
0 Likes
506

Hi,

The LOOP statement will process the records of the internal table where VNAM = 'ZVAR1'.

On the other hand, the READ statement will read the first suitable row where VNAM = 'ZVAR1' even you have more tan 1 records in the internal where VNAM = 'ZVAR1'.

Regards,

Ferry Lianto