2010 Mar 22 3:06 PM
Hi folks,
If field1 is initial then i want to pass an error message from message class(zclasss)
and i want to save the error message text from(zclass) to and varirable(err_msg1).
like dat only for field2, field3..
for getting the message from message class im using function module " Message_prepare".
how to use the subroutines for this because im using function module.from function module im
getting the value..
IF NOT gs_str-werks IS INITIAL.
gs_output-dcid = gs_str-werks.
ELSE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
* LANGUAGE = 'EN'
MSG_ID = 'ZHR'
MSG_NO = '007'
IMPORTING
MSG_TEXT = err_msg1 .
MOVE: gc_err to gs_err-err_type.
ENDIF.
* If Driverid is empty then call an errrormessage
IF NOT gs_str-usrid IS INITIAL.
gs_output-driverid = gs_str-usrid.
ELSE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
* LANGUAGE = 'EN'
MSG_ID = 'ZHR'
MSG_NO = '008'
IMPORTING
MSG_TEXT = err_msg2 .
MOVE: gc_err to gs_err-err_type.
ENDIF.
* If Drivername is empty then call an errrormessage
IF NOT gs_str-cname is initial.
gs_output-drivername = gs_str-cname.
ELSE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
* LANGUAGE = 'EN'
MSG_ID = 'ZHR'
MSG_NO = '009'
IMPORTING
MSG_TEXT = err_msg3 .
MOVE: gc_err to gs_err-err_type.
ENDIF.Moderator message - Please use code tags to format your code Also - please follow up on your previous questions. Mark them as closed if they are and assign po1nts to helpful answers,
Edited by: Rob Burbank on Mar 22, 2010 11:24 AM
Hi folks,
If field1 is initial then i want to pass an error message from message class(zclasss)
and i want to save the error message text from(zclass) to and varirable(err_msg1).
like dat only for field2, field3..
for getting the message from message class im using function module " Message_prepare".
how to use the subroutines for this because im using function module.from function module im
getting the value..
IF NOT gs_str-werks IS INITIAL.
gs_output-dcid = gs_str-werks.
ELSE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
* LANGUAGE = 'EN'
MSG_ID = 'ZHR'
MSG_NO = '007'
IMPORTING
MSG_TEXT = err_msg1 .
MOVE: gc_err to gs_err-err_type.
ENDIF.
* If Driverid is empty then call an errrormessage
IF NOT gs_str-usrid IS INITIAL.
gs_output-driverid = gs_str-usrid.
ELSE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
* LANGUAGE = 'EN'
MSG_ID = 'ZHR'
MSG_NO = '008'
IMPORTING
MSG_TEXT = err_msg2 .
MOVE: gc_err to gs_err-err_type.
ENDIF.
* If Drivername is empty then call an errrormessage
IF NOT gs_str-cname is initial.
gs_output-drivername = gs_str-cname.
ELSE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
* LANGUAGE = 'EN'
MSG_ID = 'ZHR'
MSG_NO = '009'
IMPORTING
MSG_TEXT = err_msg3 .
MOVE: gc_err to gs_err-err_type.
ENDIF.Moderator message - Please use code tags to format your code Also - please follow up on your previous questions. Mark them as closed if they are and assign po1nts to helpful answers,
Edited by: Rob Burbank on Mar 22, 2010 11:24 AM
2010 Mar 22 3:10 PM
Hi
Just use subroutin with parameters USING MSG_NO -> pass message number
CHANGING MSG_TEXT -> get message text
All else leave as is.
Best Regards
Yossi Rozenebrg
2010 Mar 22 3:13 PM
Hello Swetha,
No need to use any FM to get the message text. SAP provides the addition [INTO text|http://help.sap.com/abapdocu_70/en/ABAPMESSAGE_OPTIONS.htm#!ABAP_ADDITION_3@3@] with [MESSAGE |http://help.sap.com/abapdocu_70/en/ABAPMESSAGE.htm]
BR,
Suhas
2010 Mar 22 3:19 PM
2010 Mar 22 4:14 PM
Check this sample
IF NOT gs_str-werks IS INITIAL.
gs_output-dcid = gs_str-werks.
ELSE.
lv_msgno = '007'.
if 1 = 2.
message e007(zhr).
endif.
perform build_message using lv_msgno
lv_msgtype.
endif.
IF NOT gs_str-usrid IS INITIAL.
gs_output-driverid = gs_str-usrid.
ELSE.
lv_msgno = '008'.
if 1 = 2.
message e008(zhr).
endif.
perform build_message using lv_msgno
lv_msgtype.
ENDIF.
IF NOT gs_str-cname is initial.
gs_output-drivername = gs_str-cname.
ELSE.
lv_msgno = '009'.
if 1 = 2.
message e009(zhr).
endif.
perform build_message using lv_msgno
lv_msgtype.
ENDIF.
form build_message using p_msgno type sy-msgno
p_type type sy-msgtype.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
LANGUAGE = sy-langu
MSG_ID = 'ZHR'
MSG_NO = p_msgno
IMPORTING
MSG_TEXT = err_msg1 .
err_msg1-msgtype = p_type.
append err_msg1 to gt_return.
clear err_msg1.
endform.
2010 Mar 22 4:29 PM
2010 Mar 22 4:31 PM
Hi,
It's worth noting that the function module MESSAGE_PREPARE is not released, so Suhas's suggestion of using MESSAGE...INTO is the better approach. It's also good practice to use the technique IF 1=2.... to preserve the where-used for the message, but I've kept that out of this code.
Gives you something like;
IF NOT gs_str-werks IS INITIAL.
gs_output-dcid = gs_str-werks.
ELSE.
PERFORM build_message USING '007' gc_error.
ENDIF.
IF NOT gs_str-usrid IS INITIAL.
gs_output-driverid = gs_str-usrid.
ELSE.
PERFORM build_message USING '008' gc_error.
ENDIF.
IF NOT gs_str-cname IS INITIAL.
gs_output-drivername = gs_str-cname.
ELSE.
PERFORM build_message USING '009' gc_error.
ENDIF.
FORM build_message USING p_msgno TYPE sy-msgno
p_type TYPE sy-msgtype.
MESSAGE ID 'ZHR' TYPE p_type NUMBER p_msgno INTO err_msg1.
err_msg1-msgtype = p_type.
APPEND err_msg1 TO gt_return.
CLEAR err_msg1.
ENDFORM.
Regards,
Nick
Edited by: Nick Young on Mar 22, 2010 4:54 PM
Remove a statement that was, when I took some time to think about it, incorrect
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |