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: 

raise error message in loop and exit

Former Member
0 Kudos

Dear Friends,

I am looping on an internal table and validating data.

so if in between if i find any inconsistency, i want to throw an error and exit.

let me put it in sample code.

loop at itab1 into wa1.

perform check_data using wa1.

endloop.

form check_data using wa1.

if wa1-field1 is initial.

message 'No Data can't save' type 'E'.

i want to give this error and end loop processing

  • how can i give?

  • i can't use continue also as its not in loop endloop.

  • friends pls suggest.

endif.

endform.

Regards,

Simha

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Simha,

Hope following code can give you idea:

loop at itab1 into wa1.

perform check_data using wa1 changing lv_error.

if lv_error = 'X'.

message 'No Data can't save' type 'E'.

exit.

endif.

endloop.

form check_data using wa1 changing p_error.

if wa1-field1 is initial.

p_error = 'X'.

endif.

endform.

Thanks,

Victor.

Edited by: Victor Wijaya on Jun 25, 2008 10:26 AM

4 REPLIES 4

Former Member
0 Kudos

Hi Simha,

Hope following code can give you idea:

loop at itab1 into wa1.

perform check_data using wa1 changing lv_error.

if lv_error = 'X'.

message 'No Data can't save' type 'E'.

exit.

endif.

endloop.

form check_data using wa1 changing p_error.

if wa1-field1 is initial.

p_error = 'X'.

endif.

endform.

Thanks,

Victor.

Edited by: Victor Wijaya on Jun 25, 2008 10:26 AM

vinod_vemuru2
Active Contributor
0 Kudos

Hi Simha,

do like this.

DATA: w_message TYPE c.

loop at itab1 into wa1.

perform check_data using wa1 CHANGING w_message.

CHECK w_message EQ 'X'.

EXIT.

endloop.

form check_data using wa1 CHANGING p_message.

Do ur validations

CHECK wa1-field1 is initial.

message 'No Data can't save' type 'E'.

MOVE 'X' TO p_message.

endform.

Another way could be issue message directly in the loop instead of doing in form and then exit.

DATA: w_message TYPE c.

loop at itab1 into wa1.

perform check_data using wa1.

CHECK wa1-field1 is initial.

message 'No Data can't save' type 'E'.

EXIT.

endloop.

form check_data using wa1.

Do ur validations

endform.

Thanks,

Vinod.

Edited by: Vinod Reddy Vemuru on Jun 25, 2008 2:01 PM

Former Member
0 Kudos

Hi,

try the following :

data:

begin of wa1,

field1 type i,

end of wa1.

data:

itab1 like standard table of wa1.

start-of-selection.

write logic for fetching the data into itab1.

loop at itab1 into wa1.

perform check_data using wa1-field1.

endloop.

form check_data using wa1-field1.

if wa1-field1 is initial.

w_flag = 'X'.

stop.

endif.

end-of-selection.

if w_flag = 'X'.

message 'No Data can't save' type 'E'.

endif.

0 Kudos

Hi friends,

Thanks for your suggestions.

I now understand that i can't raise a Error message in form endform and only way is to pass back a flag indicating that there is an error.

I got it.

Thanks for your help.

Regards,

Simha