Application Development 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: 

Compare Range with internal table

Former Member
0 Kudos

Hello Friends,

I need to compare an internal table with range , that in this internal table same value as in range, and if any value does not match-> has to do other functionality and if match other logic,

I was just curios to know , is there any elegant way of doing so, or that traditional coding means loops over internal table and then inside the loop again loop for range ??

if you guys have an alternative suggestion, would be really appreiciated.

Thanks in advance

10 REPLIES 10

former_member181962
Active Contributor
0 Kudos

YOu can do this way.

loop at itab where field1 in range1.

do what you want.

endloop.

loop at itab where not field1 in range1.

do what you want.

endloop.

REgards,

Ravi

Former Member
0 Kudos

hi

u can do like this

loop at itab where field1 in range

//code

endloop

rahulkavuri
Active Contributor
0 Kudos

I misundersttod to select first, check this oneo

<b> LOOP AT IT_T001 WHERE BUKRS IN S_BUKRS.</b>

IF SY-SUBRC = 0.

IT_VBRK-BUTXT = IT_T001-BUTXT.

MODIFY IT_VBRK INDEX CTAB.

CLEAR CTAB.

ENDIF.

ENDLOOP.

S_BUKRS is the range

<b>

please reward points if found helpful</b>

Former Member
0 Kudos

HII SHAH,

i'm not sure if your query is with select options or ranges in particular ..

select-options are explictly for selection-screen.

If we dont want to display anything on screen,

we can use RANGES having the same functionality ,same structure .

Select options are displayed on the selection screen . Ranges are not displayed on the sel. screen.

Be Careful with range table. The size of statement might exceed the limit depending on the size of the range table!

Data: Ranges ran_field1 for dbtable1-field1.

Select * from dbtab1 into table itab1.
ran_field1-sign = ‘I’. 
ran_field1-option = ‘EQ’.

Loop at itable1 where itable1-field1 in ran_field1 .
Move itable1-field1 To ran_field1-low.
Append ran_field1.
EndLoop.

Loop at itable1 where not itable1-field1 in ran_field1 .
Select * from dbtable2 where field2 in ran_field1.
... 
EndSelect.


endloop.

</b>

Reward points if helpful

Revert back for more help.

Regards

Naresh

0 Kudos

Hi Shah,

If I understood your requirement correctly, then at least one loop is must.

Loop at lt_itab into lw_itab.

if lw_itab-rangefield IN Range1.

  • Do something here

else.

  • Do else part

endif.

endloop.

former_member188685
Active Contributor
0 Kudos
LOOP AT ITAB WHERE FIELD IN S_FIELD.

"Here you can do what ever you want..


ENDLOOP.

Regards

vijay

Former Member
0 Kudos

Hi shah,

1. Unfortunately we have to LOOP

at every record,

and check IN Range.

2. Like this.

LOOP AT ITAB.

<b> IF FIELD NOT IN MYRANGE.</b>

*---- CODE.

ENDIF.

ENDLOOP.

regards,

amit m.

0 Kudos

okey, friends many thanks for your kind inputs, actually I did now like following:

delete lt_kna1 where not land1 in s_land. " RANGE

Loop at lt_kna1 into ls_kna1.

Loop at lt_vbpa into ls_vbpa where kunnr eq ls_kna1-kunnr.

ls_c_vbpa-vbeln = ls_vbpa-vbeln.

append ls_c_vbpa to lt_c_vbpa.

Endloop.

Endloop.

So actually I want to delete not same entries from internal table and range,

What about comapring the two internal tables, as the example i given above, is there any more efficient way of doing the same ?

Thanks in advance,

Regards.

Former Member
0 Kudos

hii shah,

<b>delete lt_kna1 where not land1 in s_land. " RANGE

 Prepare for Binary Search
sort IT_KNA1 by KUNNR.

loop at IT_KNA1 .

read table IT_VBAP with key kunnr = IT_KNA1-KUNNR binary search.

if IT_VBAP-KUNNR <> IT_KNA1-KUNNR.

DELETE IT_KNA1 .

endif.

Endloop.</b>

REWARD POINTS IF HELPFUL

Regards

Naresh

Former Member
0 Kudos

Hi,

Try this this works much faster,

delete lt_kna1 where not land1 in s_land. " RANGE

<b>sort lt_vbpa by kunnr</b>

Loop at lt_kna1 into ls_kna1.

read table lt_vbpa with key kunnr eq ls_kna1-kunnr binary serach.

if sy-subrc = 0.

Loop at lt_vbpa into ls_vbpa from sy-tabix

if ls_vbpa-kunnr <> ls_kna1-kunnr.

exit.

endif.

ls_c_vbpa-vbeln = ls_vbpa-vbeln.

append ls_c_vbpa to lt_c_vbpa.

Endloop.

endif.

Endloop.

Sreedhar