‎2008 Jun 25 9:22 AM
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
‎2008 Jun 25 9:25 AM
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
‎2008 Jun 25 9:25 AM
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
‎2008 Jun 25 9:30 AM
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
‎2008 Jun 25 9:33 AM
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.
‎2008 Jun 25 11:11 AM
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