Application Development 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: 

EXIT from the loop in PAI of MODULEPOOL

Former Member
0 Kudos

Hi All,

I am working on the module pool porgram.In module pool programming i have LOOP-ENDLOOP in PAI section, I have to exit from this loop with condition.

can anyone suggest any options in apab to do this.??

Quick response is appreciated.

Thanks ,

Sridhar

7 REPLIES 7

naimesh_patel
Active Contributor
0 Kudos

You can use the EXIT:

LOOP AT ITAB.
  IF ITAB-MATNR IS INITIAL.
     EXIT.   " << to exit from loop
  ENDIF.
ENDLOOP.

Regards,

Naimesh Patel

0 Kudos

Hi Naimesh,

In PAI section of the module pool(In ECC6.0) IF ...ENDIF and Exit are not defined.so i will egt a message like "Statement "IF" is not defined. Check your spelling. spelling. spelling.".

this will not work.

Kindly let me know if any other options..!

Thanks,

Sridhar

0 Kudos

I believe he meant you to put it in a module called from the PAI.

Rob

0 Kudos

Hi rob,

I tried that also, but the code inside the module of PAI, it exit from the module in PAI only,not exit the loop.

still loop is running for all other records.

my requirement is to come out of the loop once the condition fails.

which is not happening in both the cases suggested.

Thanks,

Sridhar

0 Kudos

OK - then put it in a form called from the module. I'm doing this in a program and it does work OK.

Rob

0 Kudos

Are you talking of a LOOP / ENDLOOP in the flow logic (e.g. one around a table control), or one in the module pool around an internal table? If the former, then it will always loop as many times are there are lines showing in the table control on the screen, but you can prevent any logic being executed for lines after an exception is found by setting a global flag field e.g. something along the following idea:


" PBO
process before output.
  module d9999_initialise.

" PAI flow logic for screen 9999.
process after input.
  loop with control tc_9999.
    module d9999_tc_pai.
  endloop.

& then


module d9999_initialise output.
  clear: g_hit_empty_line. "reset the bad data flag
endmodule.

module d9999_tc_pai input.

  if g_hit_empty_line = 'X'.
    exit.  "perform no checks until next PBO
  endif.

  if some condition I want to test for is true.
    g_hit_empty_line = 'X'.  "process no more TC rows this PAI
    exit.
  endif.

* logic here for good lines until a bad one found
  
endmodule.

Jonathan

p.s. btw I wouldn't normally put any code in the modules except "performs" - I reckon it's a lot tidier having all your code in subroutines, not the modules.

Former Member
0 Kudos

hai,

try this

u need to write like this

loop at itab where......[condition]

......

endloop