Application Development and Automation 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: 
Read only

Subroutines doubt

Former Member
0 Likes
765

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

6 REPLIES 6
Read only

Former Member
0 Likes
722

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

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
722

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

Read only

Former Member
0 Likes
722

Also true )

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
722

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.

Read only

0 Likes
722

solved..Thanks..

Read only

0 Likes
722

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