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

Problem with Internal table looping (range table condition in where clause)

Former Member
0 Likes
3,434

hi experts,

i am facing problem in looping using range table in where condition part.

LOOP AT gt_wv_trans INTO gwa_wv_trans WHERE hkont = r_scelem-low AND

kostl = r_skostl-low.

:

:

ENDLOOP.

Here the range table is taking the last value only and not from the first.

ie., gt_wv_trans has values ->

hkont kostl sgtxt

701000 9999 panasonic ltd.

702000 101 xxxxx

803000 9999 yyyyy

r_scelem value->

hkont

701000

702000

803000

r_skostl value ->

kostl-low kostl-high

9999

101 305

9999

now the looping is done only for the last value ie., 803000 and 9999

1). how to make the looping to do from the first value (ie., 701000 and 9999)

2). how to loop and check the conditions for the range table low and high value ?

plz help me.

thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,753

Hi Sakthi,

Check the below sample code to understand the logic,

DATA:BEGIN OF it_tab OCCURS 0,
     f1 TYPE i,
     f2 TYPE i,
     END OF it_tab.

RANGES: r_f1 FOR it_tab-f1.

"Jus data filling
it_tab-f1 = 1000.
it_tab-f2 = 2000.
APPEND it_tab.

it_tab-f1 = 1001.
it_tab-f2 = 2001.
APPEND it_tab.

it_tab-f1 = 1002.
it_tab-f2 = 2002.
APPEND it_tab.

r_f1-sign = 'I'.
r_f1-option = 'EQ'.
r_f1-low = 1000.
APPEND r_f1.

r_f1-sign = 'I'.
r_f1-option = 'EQ'.
r_f1-low = 1001.
APPEND r_f1.

"Here is the logic
LOOP AT it_tab WHERE f1 IN r_f1. 
  WRITE:/ it_tab-f1, it_tab-f2.
ENDLOOP.

Hope this helps you!

Regards,

Manoj Kumar P

Edited by: Manoj Kumar on Apr 15, 2009 6:17 AM

hi experts,

i am facing problem in looping using range table in where condition part.

LOOP AT gt_wv_trans INTO gwa_wv_trans WHERE hkont = r_scelem-low AND

kostl = r_skostl-low.

:

:

ENDLOOP.

Here the range table is taking the last value only and not from the first.

ie., gt_wv_trans has values ->

hkont kostl sgtxt

701000 9999 panasonic ltd.

702000 101 xxxxx

803000 9999 yyyyy

r_scelem value->

hkont

701000

702000

803000

r_skostl value ->

kostl-low kostl-high

9999

101 305

9999

now the looping is done only for the last value ie., 803000 and 9999

1). how to make the looping to do from the first value (ie., 701000 and 9999)

2). how to loop and check the conditions for the range table low and high value ?

plz help me.

thanks.

4 REPLIES 4
Read only

Former Member
0 Likes
1,753

Hi:

if u hv two options like

1. LOOP AT gt_wv_trans INTO gwa_wv_trans WHERE hkont GE r_scelem-low AND

kostl LE r_skostl-low.

:

:

ENDLOOP

2. select * from <table> into table gt_wv_trans where WHERE hkont GE r_scelem-low AND

kostl LE r_skostl-low.

- sort the internal table

- start the looping as per your requirement.

Regards

Shashi

Read only

Former Member
0 Likes
1,754

Hi Sakthi,

Check the below sample code to understand the logic,

DATA:BEGIN OF it_tab OCCURS 0,
     f1 TYPE i,
     f2 TYPE i,
     END OF it_tab.

RANGES: r_f1 FOR it_tab-f1.

"Jus data filling
it_tab-f1 = 1000.
it_tab-f2 = 2000.
APPEND it_tab.

it_tab-f1 = 1001.
it_tab-f2 = 2001.
APPEND it_tab.

it_tab-f1 = 1002.
it_tab-f2 = 2002.
APPEND it_tab.

r_f1-sign = 'I'.
r_f1-option = 'EQ'.
r_f1-low = 1000.
APPEND r_f1.

r_f1-sign = 'I'.
r_f1-option = 'EQ'.
r_f1-low = 1001.
APPEND r_f1.

"Here is the logic
LOOP AT it_tab WHERE f1 IN r_f1. 
  WRITE:/ it_tab-f1, it_tab-f2.
ENDLOOP.

Hope this helps you!

Regards,

Manoj Kumar P

Edited by: Manoj Kumar on Apr 15, 2009 6:17 AM

Read only

Former Member
0 Likes
1,753

Dear ,

See the range is also same as internal table .

First apply the loop on the selection option parameter then u apply the condition on the internal table for which you want to check the condition .

This will surely do debug and check .

for example :

Loop at s_option .

 "loop at the internal table where you want to check condition using where clause .

endloop .

rgds ankit

Read only

Former Member
0 Likes
1,753

r_scelem and r_skostl. are internal table with header line so when you specify only r_scelem-low AND

kostl = r_skostl-low value it will take the value in the header.

Just try these codes this will solve the issue.

LOOP AT gt_wv_trans INTO gwa_wv_trans.
IFgwa_wv_trans-hkont IN r_scelem AND
gwa_wv_trans-kostl IN r_skostl.
:
:
ENDLOOP.

Regards,

Gurpreet