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

unending loop.

Former Member
0 Likes
873

hi masters,

i have in my internal table 4 records. i want to update all the 4 records, so am LOOPING it.

when i loop the internal table it finishes 4records and again starts with the 1st and it goes on and not ending.

what could be the problem... how can i solve it?

this is my code:

loop at i_mara INTO WA_MARA.

move WA_mara-matnr to t_key.

LOOP AT lt_chars.

AT NEW classnum.

CLEAR: lt_allocvaluesnumnew,

lt_allocvaluescharnew,

lt_allocvaluescurrnew,

lt_return.

REFRESH: lt_allocvaluesnumnew,

lt_allocvaluescharnew,

lt_allocvaluescurrnew,

lt_return.

l_classnum = lt_chars-classnum.

l_classtype = lt_chars-classtype.

ENDAT.

REFRESH lt_return.

CALL FUNCTION 'BAPI_CHARACT_GETDETAIL'

EXPORTING

charactname = lt_chars-atnam

IMPORTING

charactdetail = ls_charactdetail

TABLES

return = lt_return.

REFRESH lt_return.

CALL FUNCTION 'BAPI_OBJCL_CHANGE'

EXPORTING

objectkey = l_objectkey

objecttable = l_objecttable

classnum = l_classnum

classtype = l_classtype

TABLES

allocvaluesnumnew = lt_allocvaluesnumnew

allocvaluescharnew = lt_allocvaluescharnew

allocvaluescurrnew = lt_allocvaluescurrnew

return = lt_return

.

READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

ENDAT.

ENDLOOP.

move: MARA-MEINS TO WA_MARA-MEINS,

MARA-LVORM TO WA_MARA-LVORM.

APPEND WA_MARA TO I_MARA.

MODIFY MARA FROM TABLE I_MARA." TRANSPORTING MEINS.

endloop.

move: MARA-MEINS TO WA_MARA-MEINS,

MARA-LVORM TO WA_MARA-LVORM.

APPEND WA_MARA TO I_MARA.

MODIFY MARA FROM TABLE I_MARA." TRANSPORTING MEINS.

endloop.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
830

Hi,

Check APPEND WA_MARA TO I_MARA statement in your coding

appending new line to same internal table will give endless loop.

i guess only modify statement is enough to update.

move: MARA-MEINS TO WA_MARA-MEINS,

MARA-LVORM TO WA_MARA-LVORM.

APPEND WA_MARA TO I_MARA.

MODIFY MARA FROM TABLE I_MARA." TRANSPORTING MEINS.

endloop.

Regards,

Ravi

5 REPLIES 5
Read only

Former Member
0 Likes
831

Hi,

Check APPEND WA_MARA TO I_MARA statement in your coding

appending new line to same internal table will give endless loop.

i guess only modify statement is enough to update.

move: MARA-MEINS TO WA_MARA-MEINS,

MARA-LVORM TO WA_MARA-LVORM.

APPEND WA_MARA TO I_MARA.

MODIFY MARA FROM TABLE I_MARA." TRANSPORTING MEINS.

endloop.

Regards,

Ravi

Read only

anversha_s
Active Contributor
0 Likes
830

Hi,

U are appending the same internal table inside the loop. See the code.

move: MARA-MEINS TO WA_MARA-MEINS,
MARA-LVORM TO WA_MARA-LVORM.
APPEND WA_MARA TO I_MARA.

This wll create the infinite loop.

Use another temp internal table for your purpose.

Rgds,

Anversha

Read only

Former Member
0 Likes
830

Hi,

I think you wanted to Modify the internal table. You have instead appended data to it.


move: MARA-MEINS TO WA_MARA-MEINS,
MARA-LVORM TO WA_MARA-LVORM.
APPEND WA_MARA TO I_MARA. "modify i_mara from wa_mara index sy-tabix.

Read only

Former Member
0 Likes
830

Hi Pasalabasker,

Never use APPEND to the same internal Table inside loop of same internal Table.. If will be never ending process.. as it's appending same internal table...

Change below line of code..

"APPEND WA_MARA TO I_MARA. " Comment this line..
MODIFY I_MARA FROM WA_MARA INDEX SY-TABIX. " Insert this line

Modify your code as below...

loop at i_mara INTO WA_MARA.
move WA_mara-matnr to t_key.

LOOP AT lt_chars.
AT NEW classnum.
CLEAR: lt_allocvaluesnumnew,
lt_allocvaluescharnew,
lt_allocvaluescurrnew,
lt_return.

REFRESH: lt_allocvaluesnumnew,
lt_allocvaluescharnew,
lt_allocvaluescurrnew,
lt_return.

l_classnum = lt_chars-classnum.
l_classtype = lt_chars-classtype.

ENDAT.

REFRESH lt_return.

CALL FUNCTION 'BAPI_CHARACT_GETDETAIL'
EXPORTING
charactname = lt_chars-atnam
IMPORTING
charactdetail = ls_charactdetail
TABLES
return = lt_return.

REFRESH lt_return.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = l_objectkey
objecttable = l_objecttable
classnum = l_classnum
classtype = l_classtype

TABLES
allocvaluesnumnew = lt_allocvaluesnumnew
allocvaluescharnew = lt_allocvaluescharnew
allocvaluescurrnew = lt_allocvaluescurrnew
return = lt_return
.

READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
ENDAT.
ENDLOOP.
move: MARA-MEINS TO WA_MARA-MEINS,
MARA-LVORM TO WA_MARA-LVORM.
"APPEND WA_MARA TO I_MARA. " Comment this line..
MODIFY I_MARA FROM WA_MARA INDEX SY-TABIX. " Insert this line

MODIFY MARA FROM TABLE I_MARA." TRANSPORTING MEINS.

endloop.

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

Read only

Former Member
0 Likes
830

i have sorted problem by self however it is great to see your reply.

thank you all for ur great contribution.

thanks again.