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 loop inside loop

Former Member
0 Likes
1,319

Hi Experts,

i ve writtern some peace of code like below,

loop at it_prps.

  • CASE month.

  • WHEN '01'.

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.

  • ENDCASE.

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.

15 REPLIES 15
Read only

Former Member
0 Likes
1,277

Hi,

Just comment the below code and check.

if sy-subrc EQ 0.

else.

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

endif.

Read only

0 Likes
1,277

Hi,

no velangini,

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' ).

if sy-subrc EQ 0.

else.

write:/ 'no data'.

endif.

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.

if i check sy-subrc also, control is not coming to if statment. its not checking subrc is 0 ir not at all.

directly it is coming to last endloop.

could anyone check pls..

Rdgs,

sudharsan.

ENDLOOP.

Read only

0 Likes
1,277

Since the where clause of the loop has all constants but for it_prps-pspnr, did you check if there are no leading zeroes in one of the variables ?

As per me, there might be leading zeroes on either the left hand side or the Right hand side of the expression.

Do let me know if this helped.

Pranjal.

Read only

0 Likes
1,277

Hi pranjal,

there is no leading zeros like that , both data is same.

could check is there any other thing...

Rgds,

sudharsan.

Read only

0 Likes
1,277

Then we will require to know how you ahve defined the 2 internal tables . If you could paste that part of the data declaration?

Because if you are saying that both the tables have proper data, it only means that one of the AND conditions in the where clause is not getting satisfied...we will need to check the data declarations, if the hardcoded numbers in where clause are specified with the required length.

Read only

0 Likes
1,277

Hi!

If you wanted to check is your LOOP successful or not, you have to use the sy-subrc after the ENDLOOP statement.

loop at...

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.

ENDLOOP.

if sy-subrc NE 0.

write:/10 'There is no data in it_final....'.

endif.

endloop.

Regards

Tamá

Read only

Former Member
0 Likes
1,277

hi,

instead of loop u can use read Table

read table 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' ).

if sy-subrc EQ 0.

else.

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

endif.

MOVE it_output-wlp01 TO t_act_billing.

act_billing = act_billing + t_act_billing.

Regards,

priya

Read only

0 Likes
1,277

Hi priya,

thanks for ur replay, if i use read stat it is giving comma error.

am nt sure can we use where clause with read stat.

Thanks & Rgds,

sudharsan.

Read only

0 Likes
1,277

Further, I do not think read will help because what if ther are more than 1 record satisfyin the conditions in the where clause? we want the sum so loop has to be there.

Also, Read statement cant have NOT EQUALTO equations, it only supports EQ and not NE/GT/LT operations.

SUdarshan, read statement cant have WHERE clause but it can have WITH KEY in place of WHERE, though you wont need read statement here.

Read only

Former Member
0 Likes
1,277

Hi,

The reason is in your second loop where condition you have used wrttp beltp versn vorga with some constant values. These constant values may not be satisfiedl.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
1,277

Hey Sudharsan,

Check whether the fields you comparing have the same type.

pspnr1 = it_prps-pspnr.

Example: pspnr in prps table in NUMC ,the field pspnr1 is also same type.

You also have to give the if sy-subrc = 0 condition at the end of loop inside.

Thanks&Regards,

Karthik.

Read only

0 Likes
1,277

Hi Friends,

After abserving in Debugging, there is a pronlem with header data.

in both tables the body data is same. but initially in header data is diff,

so body records are same. once first loop is execute the data of header is changing, so its not matching with 2nd table header data.

so before looping 2tables can i delete header data from 2tables.

if can how ? can i use clear.

Rgds,

sudharsan.

Read only

0 Likes
1,277

yes, you can.

clear itab.

this clears the header of the internal table itab.

regards,

madhu

Read only

0 Likes
1,277

Hi friends,

ur right i can clear, but the problem is, if i clear there is no data in both headers, it is ok fine,

but once 1st loop is finish ( loop at it_prps) it is having 1st record, then control comes to 2nd loop, here same time am doing looping and comparing, so once control comes to 2nd loop there is no header data to compare .

so its not comparing.

so how can i procede.

Rgds,

sudha.

Read only

Former Member
0 Likes
1,277

Hi Sudharsan,

If you were not able to identify the rootcause simple comment Where conditions fields except the pspnr and try with one more condition.

For example, first have the WRTTP field condition only in the where clause and comment other validations. You can simply identify the rootcause yourself when you check this one by one.

WHERE pspnr1 = it_prps-pspnr

AND wrttp = '04'

AND beltp = '02'

AND versn = '000'

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

Your where condition would be correct but I am not sure about your constant values and format.

Please let me know the tables from which you fetch the values to the internal tables. If you give that I can analyse and provide the rootcause and solution.

regards,

Saravanan V