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-Index

rahul2000
Contributor
0 Likes
1,294

Dear all,

I am unable to get the index read correctly for my IT_DISPLAY table.There are 2 values in plaf table and multible in display table.

how to get the correct index value for my display table?since currently it is on plaf table.due to this index problem,my values get moved incoreectly

code is as follows

SORT IT_AFPO BY PLNUM.

SORT IT_PLAF BY PLNUM.

LOOP AT IT_AFPO INTO WA_AFPO.

LOOP AT IT_PLAF INTO WA_PLAF.

W_INDEX = SY-TABIX.

IF WA_PLAF-PLNUM = WA_AFPO-PLNUM.

MOVE:WA_PLAF-GSMNG TO WA_DISPLAY-GAMNG.

MODIFY IT_DISPLAY INDEX W_INDEX FROM WA_DISPLAY TRANSPORTING GAMNG.

ENDIF.

CLEAR:WA_PLAF,WA_DISPLAY.

ENDLOOP.

CLEAR:WA_AFPO.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
1,248

Hai Rahul try like this..

SORT IT_AFPO BY PLNUM.

SORT IT_PLAF BY PLNUM.

LOOP AT IT_AFPO INTO WA_AFPO.

read table IT_PLAF INTO WA_PLAF with key PLNUM = WA_AFPO-PLNUM binary search.

if sy-subrc eq 0.

W_INDEX = SY-TABIX.

MOVE:WA_PLAF-GSMNG TO WA_DISPLAY-GAMNG.

MODIFY IT_DISPLAY INDEX W_INDEX FROM WA_DISPLAY TRANSPORTING GAMNG.

endif.

ENDIF.

CLEAR:WA_PLAF,WA_DISPLAY.

CLEAR:WA_AFPO.

ENDLOOP.

if you have to do a loop in a loop

SORT IT_AFPO BY PLNUM.

SORT IT_PLAF BY PLNUM.

LOOP AT IT_AFPO INTO WA_AFPO.

LOOP AT IT_PLAF INTO WA_PLAF where PLNUM = WA_AFPO-PLNUM .

W_INDEX = SY-TABIX.

MOVE:WA_PLAF-GSMNG TO WA_DISPLAY-GAMNG.

MODIFY IT_DISPLAY INDEX W_INDEX FROM WA_DISPLAY TRANSPORTING GAMNG.

CLEAR:WA_PLAF,WA_DISPLAY.

ENDLOOP.

CLEAR:WA_AFPO.

ENDLOOP.

10 REPLIES 10
Read only

former_member156446
Active Contributor
0 Likes
1,249

Hai Rahul try like this..

SORT IT_AFPO BY PLNUM.

SORT IT_PLAF BY PLNUM.

LOOP AT IT_AFPO INTO WA_AFPO.

read table IT_PLAF INTO WA_PLAF with key PLNUM = WA_AFPO-PLNUM binary search.

if sy-subrc eq 0.

W_INDEX = SY-TABIX.

MOVE:WA_PLAF-GSMNG TO WA_DISPLAY-GAMNG.

MODIFY IT_DISPLAY INDEX W_INDEX FROM WA_DISPLAY TRANSPORTING GAMNG.

endif.

ENDIF.

CLEAR:WA_PLAF,WA_DISPLAY.

CLEAR:WA_AFPO.

ENDLOOP.

if you have to do a loop in a loop

SORT IT_AFPO BY PLNUM.

SORT IT_PLAF BY PLNUM.

LOOP AT IT_AFPO INTO WA_AFPO.

LOOP AT IT_PLAF INTO WA_PLAF where PLNUM = WA_AFPO-PLNUM .

W_INDEX = SY-TABIX.

MOVE:WA_PLAF-GSMNG TO WA_DISPLAY-GAMNG.

MODIFY IT_DISPLAY INDEX W_INDEX FROM WA_DISPLAY TRANSPORTING GAMNG.

CLEAR:WA_PLAF,WA_DISPLAY.

ENDLOOP.

CLEAR:WA_AFPO.

ENDLOOP.

Read only

Former Member
0 Likes
1,247

hi,

when ur reading the second internal table read this based on a where condition and that should link both ur tables first.

Reward points if helpful,

Regards,

Sumanjeet.

Read only

Former Member
0 Likes
1,247

Better take a variable and keep Incrementing in the inner loop and clear it in the outer loop.

  • Awrd opints if useful*

Bhupal

Read only

Former Member
0 Likes
1,247

Hi Rahul ,

Could you please specify what exactly do you want to do.

Regards

Arun

Read only

Former Member
0 Likes
1,247

Hi,

In the given code, it is not clear about IT_DISPLAY internal table. What data does it contain and whether there is any link between WA_PLAF and IT_DISPLAY. It is not clear, why u are trying to use WA_PLAF index to modify IT_DISPLAY.

If this point is clear, i hope u can easily solve.

Let us know the relation.

Read only

0 Likes
1,247

Dear Arun/Ramesh,

IT_DISPLAY is the internal table which contains the data to be displayed.

My problem is that if there is a planned order quantity of 10,and production order quantity for that planned order is also 10,then no problem.

But if it is anything less than 10,then the problem is that it shows 0.

also when a planned order quantity is converted to planned order quantity completely (that is 10 out of 10)

then from PLAF TABLE no more contains that PLNUM.

bUT IF IT IS PARTIAL(ANYTHING LESS THAN 10),then that PLNUM IS COMMON in both PLAF AND AFPO.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,247

SORT IT_AFPO BY PLNUM.

SORT IT_PLAF BY PLNUM.

LOOP AT IT_AFPO INTO WA_AFPO.

LOOP AT IT_PLAF INTO WA_PLAF.

W_INDEX = SY-TABIX.

IF WA_PLAF-PLNUM = WA_AFPO-PLNUM.

MOVE:WA_PLAF-GSMNG TO WA_DISPLAY-GAMNG.

MODIFY IT_DISPLAY INDEX W_INDEX FROMWA_DISPLAY TRANSPORTING GAMNG.*

ENDIF.

CLEAR:WA_PLAF,WA_DISPLAY.

ENDLOOP.

CLEAR:WA_AFPO.

ENDLOOP.

since IT_DISPLAY is a new table use append IT_DISPLAY.

Read only

0 Likes
1,247

as per u r code the wk_tabix will contain the index of IT_PLAF...

then how can u modify IT_DISPLAY with the index of IT_PLAF.

Read only

0 Likes
1,247

Dear Keshu,

How can i do this.yes you are correct.

Can uou tell me some alternative way out?

Read only

0 Likes
1,247

Take a variable and keep Incrementing in the inner loop and clear it in the outer loop.

When ur loopng and modifying ur values consider the value of this variable as the index.

awrd points if useful

Bhupal