ABAP read table with OR condition

So is it possible to add an OR condition to the key values of the read statement? The simple answer is no, but you can replicate this functionality using one of two methods.

Method 1 – Using multiple ABAP READ statements within nested IF statements

The first method would be to use multiple READ statements to check each condition but nest these within IF statements. i.e. Read condition 1 if no entry found read condition 2 if no entry found read condition 3 etc etc

Method 2 – Using an ABAP LOOP statement

The second method would be to use a LOOP statement with all the options within the where clause and simply EXIT on the first loop pass.i.e.LOOP at itab where condition 1 or condition 2.EXIT.ENDLOOP.If sy-subrc eq 0.”Data foundendif.

data: IT_COMPONENT type standard table of SEOCOMPO,WA_COMPONENT like line of IT_COMPONENT.select *from SEOCOMPO as A inner join SEOCOMPOTX as Bon B~CLSNAME = A~CLSNAMEand B~CMPNAME = A~CMPNAMEinner join SEOCOMPODF as Con C~CLSNAME = A~CLSNAMEand C~CMPNAME = A~CMPNAMEinto corresponding fields of table IT_COMPONENTwhere A~CMPTYPE in (0,1,2)and B~LANGU eq SY-LANGU.sort IT_COMPONENT by clsname cmptype.”READ solutionread table IT_COMPONENT transporting no fieldswith key CLSNAME = WA_CLASS-CLSNAMECMPTYPE = 0 binary search.if SY-SUBRC eq 0.”perform entry_found.else.read table IT_COMPONENT transporting no fieldswith key CLSNAME = WA_CLASS-CLSNAMECMPTYPE = 1 binary search.if SY-SUBRC eq 0.”perform entry_found.else.EXIT.endif.endif.”loop solutionLOOP at IT_COMPONENT into WA_COMPONENT where CLSNAME = WA_CLASS-CLSNAMEAND ( CMPTYPE = 0 or CMPTYPE = 1 ).ENDLOOP.if sy-subrc eq 0.”at least one entry foundelse.EXIT.endif.