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

logical solution

Former Member
0 Likes
1,846

Hi friends,

LOOP AT BODY1.

LOOP AT TRANSFER_ITAB.

IF BODY1-SMONTH = TRANSFER_ITAB-TMONTH .

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

APPEND BODY1.

CLEAR BODY1.

exit.

ELSE.

continue.

ENDIF.

ENDLOOP.

APPEND BODY1.

CLEAR BODY1.

ENDLOOP.

**********************************

This is my loop.

BODY1 IS OUTER LOOP. (It has 4,5, 6, 7, 8,9,10, 11,12)

TRANSFER_ITAB IS INNER LOOP.(It has 4, 5 and 😎

When body1 has 4 and inner loop has also 4 .IF condition will be satisfy and then exit from if con. and loop.

When body1 would be 5 it will run same as earlier. But, when bod1 would be 6 my innerloop condition is not fulfill. I need here the control should go outer loop.

I hope my problem u guys would catch.

Regards,

Swapnika

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,819

loop at body 1.

read table transfer_itab with key tmonth = body1-smonth.

if sy-subrc = 0.

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

append body1.

clear body1.

endif.

endloop.

Edited by: BrightSide on Mar 13, 2009 11:34 AM

19 REPLIES 19
Read only

former_member242255
Active Contributor
0 Likes
1,819

instead you can add some where condition in the inner internal talbe.

Read only

Former Member
0 Likes
1,819

Hi,

Try like this, I hope u r problem was solved.

LOOP AT BODY1.

LOOP AT TRANSFER_ITAB.

IF BODY1-SMONTH = TRANSFER_ITAB-TMONTH .

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

APPEND BODY1.

CLEAR BODY1.

ELSE.

exit.

ENDIF.

ENDLOOP.

APPEND BODY1.

CLEAR BODY1.

ENDLOOP.

Read only

0 Likes
1,819

hi srinu,

Problem would be occur in scond time processing.

When outer loop have 5 and inner loop have 4 in first time process. It will be exit from the loop. But in inner loop has also 5. It will not consider if we use exit in this place.

Regards,

Swapnika

Read only

Former Member
0 Likes
1,820

loop at body 1.

read table transfer_itab with key tmonth = body1-smonth.

if sy-subrc = 0.

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

append body1.

clear body1.

endif.

endloop.

Edited by: BrightSide on Mar 13, 2009 11:34 AM

Read only

0 Likes
1,819

Thank you Very Much

Read only

Former Member
0 Likes
1,819

Hi place the following code in place of your code.

LOOP AT BODY1.

LOOP AT TRANSFER_ITAB where TMONTH = BODY1-SMONTH .

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

APPEND BODY1.

CLEAR BODY1.

ENDLOOP.

APPEND BODY1.

CLEAR BODY1.

ENDLOOP.

Read only

Former Member
0 Likes
1,819

But .it goes to infinite loop ...coz u always appending body1.

Read only

0 Likes
1,819

no, it will run till outer internal table get data.

Read only

0 Likes
1,819

well...thats wot i mean...coz u appending same table everytime the condition satisfies it appends to same table and that table will never run out of data and the loop will be endless.

to solve this

you should declare another internal table with the same structure

loop at body1

read table <anotha table> with key <key> = body1-<field>

if sy-subrc = 0.

move the fileds to new table.

append new table

clear body1.

endif.

endloop.

Read only

Former Member
0 Likes
1,819

Can you elaborate your requirement again, i hope instead of making code complex by using nested loops, try with alternatives.

But i am sure that the loop in your code will be infinitive.

Regards,

~Satya

Read only

Former Member
0 Likes
1,819

Hi,

LOOP AT BODY1.

LOOP AT TRANSFER_ITAB where SMONTH = BODY1-SMONTH .

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

APPEND BODY1.

CLEAR BODY1.

exit.

ENDLOOP.

ENDLOOP.

It'll work , check this,

I have one doubt, If u append the same internal table(BODY1) inside the BODY1 then it'll be endless loop right.

so create same structure other internal table and append it after the execution of the loop . append new internal table to BODY1.

Edited by: Selva M on Mar 13, 2009 5:21 PM

Read only

0 Likes
1,819

Hi Selva,

i m getting ur point but i have made a structure body1_itab which transfers tha data to smartform so i need to use same body1, here i can use Modify i think, m i right?

Plz tell me.

Regards,

Swapnika

Read only

0 Likes
1,819

USE BODY1_ITAB

Read only

0 Likes
1,819

Hi,

Yes, U can use modify instead of append or use one internal table like BODY1_NEW which has same structure as BODY1.

After coming out of the loop, append BODY!_NEW to BODY1. and do delete adjacent duplicates.

Read only

awin_prabhu
Active Contributor
0 Likes
1,819

Hi friend,

Try like this.

Data c type i value 0.

LOOP AT BODY1.

LOOP AT TRANSFER_ITAB.

if c ne 1.

IF BODY1-SMONTH = TRANSFER_ITAB-TMONTH .

c = 1.

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

APPEND BODY1.

CLEAR BODY1.

continue.

ENDIF.

else.

c = 0.

exit.

endif.

ENDLOOP.

APPEND BODY1.

CLEAR BODY1.

ENDLOOP.

Read only

awin_prabhu
Active Contributor
0 Likes
1,819

Hi friend,

Try like this.

Data c type i value 0.

LOOP AT BODY1.

LOOP AT TRANSFER_ITAB.

if c ne 1.

IF BODY1-SMONTH = TRANSFER_ITAB-TMONTH .

c = 1.

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

APPEND BODY1.

CLEAR BODY1.

continue.

ENDIF.

else.

c = 0.

exit.

endif.

ENDLOOP.

APPEND BODY1.

CLEAR BODY1.

ENDLOOP.

Thanks.

Read only

0 Likes
1,819

hi fried,

When outer loop has 6 and inner loop has not 6. The control should go to outerloop and become 7.

But this coding move only inside the innerloop .

Plz try to modified it.

Regards,

Swapnika

Read only

Former Member
0 Likes
1,819

Hi,

I think what u r doing shud work when bod1 is 6 control will come to outer loop,but 1st it will loop all over again to the already looped ones i.e. 4 and 5,

so inorder to improve oerformance what u can do is:

DATA : g_cnt TYPE i,
        g_flag(1) TYPE c.

  LOOP AT BODY1 INTO wa_ BODY1.
    LOOP AT TRANSFER_ITAB INTO wa_TRANSFER_ITAB.
     IF WA_BODY1-SMONTH = WA_TRANSFER_ITAB-TMONTH .
       MOVE WA_TRANSFER_ITAB-EMPLOYEEPF TO WA_BODY1-EMPLOYEEPF.
       MOVE WA_TRANSFER_ITAB-EMPLOYERPF TO WA_BODY1-EMPLOYERPF.
       APPEND wa_BODY1 to BODY1.

        DELETE TABLE TRANSFER_ITAB FROM wa_TRANSFER_ITAB.
        DESCRIBE TABLE TRANSFER_ITAB LINES g_cnt.
        EXIT.
      ELSE.
        IF g_cnt > 1.
          CONTINUE.
        ELSE.
          g_flag = 'X'.
          EXIT.
        ENDIF.
      ENDIF.
    ENDLOOP.
    if g_flag = 'X'.
      exit.
    ENDIF.
  ENDLOOP.
READ TABLE  TRANSFER_ITAB INTO wa_TRANSFER_ITAB INDEX 1.
READ TABLE  BODY1 INTO WA_BODY1 WITH KEY SMONTH = WA_TRANSFER_ITAB-TMONTH BINARY SEARCH.
IF SY-SUBRC = 0.
       MOVE WA_TRANSFER_ITAB-EMPLOYEEPF TO WA_BODY1-EMPLOYEEPF.
       MOVE WA_TRANSFER_ITAB-EMPLOYERPF TO WA_BODY1-EMPLOYERPF.
       APPEND wa_BODY1 to BODY1.
ENDIF.

Regards,

Neha

Read only

Former Member
0 Likes
1,819

Hi,

Instead of using loop inside a loop the better way to proceed with this could be using read statement.

LOOP AT BODY1.

read table transfer_tab with key month = body1-smonth.

if sy-subrc = 0.

MOVE TRANSFER_ITAB-EMPLOYEEPF TO BODY1-EMPLOYEEPF.

MOVE TRANSFER_ITAB-EMPLOYERPF TO BODY1-EMPLOYERPF.

modify body1 from body1 transporting employeepf employerpf where smonth = body1-smonth.

endif.

ENDLOOP.

I think this should solve your purpose.

Regards,

Siddarth