When we develop Sap abap applications, it is hard to avoid to use 'Loop' key words to implement our business requirments, even it is very often to use two loops or using 'read table' in a loop. Under this condition, many loops or using 'read table' in loops could occur very bad performance when large number of data is looped. For today's blog, I would like to give some of my suggestions to solve these problems.
1, If we loop standard tables in our funcation modules or methods, we can sort these tables first, then use binary search in read table, it could largely improve the search performance.
2, Using sorted table to instead of standard table.
for example:
DATA: it_tab type sorted table of s_vbrk with non-unique key vbeln,
it_tab1 type sorted table of s_vbrk with non-unique key vbeln,
ls_vbrk type s_vbrk,
ls_vbrk1 type s_vbrk.
Loop at it_tab into ls_vbrk.
read table it_tab1 into ls_vbrk1 with key vbeln = ls_vbrk-vbeln.
endloop.
These simple code demonstrates that sorted table can help developers to sort the tables and use binary search to imporve the code performance. becasue sorted table can do the binary search automatically, but do remember when we use sorted table , we need to use key field as search criteria,if we do not follow this rule, it generates very bad result.

浙公网安备 33010602011771号