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: 

STOP LOOPING_table control

naveen_inuganti2
Active Contributor
0 Kudos

iam having following sytax....

in my pai module...

PROCESS AFTER INPUT.

LOOP AT ITAB.

CHAIN.

FIELD ITAB-filed1.

FIELD ITAB-field2.

FIELD ITAB-field3.

FIELD ITAB-SELKZ Module ON_SELECT on request.

endchain.

ENDLOOP.

MODULE LOAN_USER_COMMAND.

.....so in above coding... ithink you can under stand that SELKZ is for to selct the table control row.... so if you selct the table control row then it will go into the module followed by...SELKZ,

and here now iam modifiying above coding like this.....

PROCESS AFTER INPUT.

LOOP AT ITAB.

CHAIN.

FIELD ITAB-filed1.

FIELD ITAB-field2.

FIELD ITAB-field3.

FIELD ITAB-SELKZ.

endchain.

ENDLOOP.

Module ON_SELECT on request.

MODULE LOAN_USER_COMMAND.

.......it was also properly working but....the thing is...

in first coding the loop is partially running before gointo this module....but in second part the loop is completing....so because if this iam facing trouble inthe caluculation part which is in that module and linked with the entries of the field1 and filed2....

so now my quetio is...

i want to stop that...

loop in second..... one when one perticuler value is met.....but if i write if condition,...it was showing error like...if is not defined....

please answer...

Thank you,

Naveen.....

1 ACCEPTED SOLUTION

Former Member
0 Kudos

I believe you need type of syntax for the select row


  loop at IT_WK.
    chain.
      field WK_REC-SPNUM.
    endchain.
    field WK_REC-SEL "<== This is the selecti field that was added to the table
      module TBLCLT_MAIN_mark on request.
  endloop.

3 REPLIES 3

Former Member
0 Kudos

Hi,

we can't stop loop without giving error message.so erroe msg only will stop loop in PAI event. my succession is , do some validation outside the loop like itab one row to another row comparetion.

Former Member
0 Kudos

I believe you need type of syntax for the select row


  loop at IT_WK.
    chain.
      field WK_REC-SPNUM.
    endchain.
    field WK_REC-SEL "<== This is the selecti field that was added to the table
      module TBLCLT_MAIN_mark on request.
  endloop.

Former Member
0 Kudos

I think you may need to read up a little on the "on request" functionality...

http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbabbd35c111d1829f0000e829fbfe/content.htm

So basically the logic you first had was saying


loop around my table control
" inside loop
  if the value in field SELKZ is changed (i.e. selected / deselected) 
    then run module ON_SELECT
  endif
endloop

but you have changed it to say


loop around my table control
endloop
" after loop
if the value in field SELKZ is changed (i.e. selected / deselected) then run module ON_SELECT

If I understand your requirement correctly, then what you might want to do is something like


LOOP AT ITAB.
CHAIN.
  FIELD ITAB-filed1.
  FIELD ITAB-field2.
  FIELD ITAB-field3.
  FIELD ITAB-SELKZ Module ON_SELECT on request. "do logic in ON_SELECT
endchain.
ENDLOOP.

then inside your ON_SELECT module you need to flag that you've done the work required


module on_select input.
" Flag we've been here this loop
break-point.  "so you can bebug your code - i.e. check you reach here
  if itab-SELKZ is initial.  "row was un-selected
    g_marked = space.
    clear: g_result.
  endif.
  if g_marked = 'X'. "already marked - so exit as we don't process any lines after the first one selected
    exit. "leave the module so no calc done on this loop
  endif.
  g_marked = 'X'.   "remember to clear this global in the PBO
  g_result = itab-field1 * itab-field2.  "or whatever your calc is
endmodule

This will mean you are able to tell in the loan_user_command whether any line was selected (from g_marked being "X"), and g_result can hold the answer to the calculation on the selected row.

Jonathan