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

Looping problem

Former Member
0 Likes
1,154

Hi Experts,

i ve writtern some peace of code like below,

loop at it_prps.

loop at it_final into it_output

WHERE pspnr1 = it_prps-pspnr

AND wrttp = '04'

AND beltp = '02'

AND versn = '000'

AND ( vorga = 'COIN' OR vorga = 'RKU2' ).

MOVE it_output-wlp01 TO t_act_billing.

act_billing = act_billing + t_act_billing.

if sy-subrc EQ 0.

else.

write:/10 'There ia no data....'.

endif.

ENDLOOP.

ENDLOOP.

in above code there are 2loops,

1st is looping properly but 2nd one is not looping .

loop at it_prps-pspnr and it_final-pspnr1 same.

but loop at it_final into it_output is not looping, but in WHERE clause all cond all right. but why its not working.

is there any other way to write this.

could anybady tell me where i went wrong..

very urgent.

Rgds,

sudharsan.

12 REPLIES 12
Read only

Former Member
0 Likes
1,135

Hi Sudarshan,

First check one thing whether the it_output is a line type of it_final, i.e. it_output should be the Workarea of the internal table it-final, and both should be of the same structure, else the loop coondition which you have written will not work.

Rest of the code is fine.Hope this is helpful to you. If you need further information, revert back.

Reward all the helpful answers.

Regards

Nagaraj T

Read only

Former Member
0 Likes
1,135

Hi,

Both the structures of these two should be same.

it_final and it_output.

Sachin.

Read only

0 Likes
1,135

Hi friends,

both it_final and it_output are same.

here it_prps-posid and it_final-posid are same.

but the problem is: intially both headers are empty. then,

once i loop the it_prps first record will come into header, then control is coming to loop at it_final into it_output now it is empty but here am doing both i.e looping and checking, so here data is not matching.

so how to fix this one.

Rgds,

sudharsan.

Read only

0 Likes
1,135

Hi sudharsan,

can u tell me what do u want fetch and what do u want display.

Read only

Former Member
0 Likes
1,135

Dear Sudarshan,

Why you are using loop with in loop.

Better you first sort the internal table with the where condition keys

and go for read.

Performance wise it will work fine.

Revert if you have any problem.

Regards,

madan.

Read only

0 Likes
1,135

Hi Readdy,

ur right i was tryed like that also. first i sorted, then if i use where cond in Read stat then its giving error.

i ve given like:

READ TABLE it_final into it_output WITH KEY posid = it_prps-posid AND wrttp = c_04 BINARY SEARCH.

it is giving error.

Read only

0 Likes
1,135

there is no AND in READ statement. Try this:

READ TABLE it_final into it_output WITH KEY posid = it_prps-posid

wrttp = c_04 BINARY SEARCH.

regards,

madhumitha

Read only

0 Likes
1,135

hi

can u specify the fileds of it_final

and where the data r coming from

and it_prps too..

with regrads,

Rohan Shetty

Read only

0 Likes
1,135

hi,

dont give AND in read...

just write like this........

Read table int_table with key abc = '123'

xyz = 'qwe'

psr = 'qws'.....like this...

Sachin.

Read only

0 Likes
1,135

hi Friends, thanks for replay,

if i give read stat then how to give below stat

( vorga = c_coin OR vorga = c_rku2 ).

my peace of code is:

loop at it_prps into wa_it_prps.

*loop at it_final.

  • CASE month.

  • WHEN '10'.

  • loop at it_final into wa_final

READ TABLE it_final into it_output WITH KEY posid = wa_it_prps-posid

wrttp = c_04

beltp = c_02

versn = c_0

( vorga = c_coin OR vorga = c_rku2 ) BINARY SEARCH.

endloop.

but in last line giving error, i.e how to give OR condition in read stat.

Rgds,

sudharsan.

Read only

0 Likes
1,135

Hi,

You can give the READ in 2 statements. ie,

READ TABLE it_final into it_output WITH KEY posid = wa_it_prps-posid

wrttp = c_04

beltp = c_02

versn = c_0

vorga = c_coin BINARY SEARCH.

If sy-subrc ne 0.

READ TABLE it_final into it_output WITH KEY posid = wa_it_prps-posid

wrttp = c_04

beltp = c_02

versn = c_0

vorga = c_rku2 BINARY SEARCH.

endif.

Its just an option instead of OR statement, because i dont think READ stmt supports OR".

Hope this helps

Deepti

Read only

Former Member
0 Likes
1,135

Hi,

Hope below code will help u a lot.

data: wa_prps type it_prps,

wa_final type it_final.

loop at it_prps into wa_prps.

loop at it_final into wa_final

WHERE pspnr1 = wa_prps-pspnr

AND wrttp = '04'

AND beltp = '02'

AND versn = '000'

AND ( vorga = 'COIN' OR vorga = 'RKU2' ).

MOVE wa_final-wlp01 TO t_act_billing.

act_billing = act_billing + t_act_billing.

ENDLOOP.

ENDLOOP.

Reward points if this code helps

Regards,

Vijay