Message Check on Save

Identify Message Class and Number
You can activate extended message tracking by setting user parameter BSPWD_USER_LEVEL (and CRM_USER_LEVEL) to value 9 in transaction SU3 resp. SU01. Now you will see the wanted details on mouse hover of the message in Web UI.

Correct Error Flag
Sometimes it happen, that a Business Transaction contains no error messages but is still flagged as erroneous.

This inconsistency can be solved using report CRM_MESSAGES_CHECK like mentioned in SAP Note „1971092 – Wrong System Status ‚Contain Errors'“. However this report is not able to identify all issues: If a business transaction has no message log but is flagged as erroneous, it will not be identified. But if the message log exists and is empty it will be identified.

Error Message Replacement
Sometimes an error message shown in SAP Web Client UI might be too technical. In this case it is possible to replace it by a user-friendly one. The SAP Web Client UI standard feature “Message Replacement” can be used here.

  1. (Activate business function UI_FRW_1 and UI_FRW_1_DOCU in transaction SFW5.)
  2. Assigning function profile MSG_REPLACE to your business role.
  3. Create own message classes and messages using transaction SE91.
  4. Configure all wanted message replacements SPRO -> CRM -> UI Framework -> UI Framework Definition -> Define Messages to Be Replaced.

Mandatory Field Check on Save
Sometimes fields are configured as mandatory in SAP Web Client UI. In case of empty mandatory fields end-users will get an error message. It is still possible to save. To avoid saving you can activate the “SAP Web Client UI Mandatory Field Check on Save” feature.

  1. Configure your Web UI and mark fields as mandatory.
  2. Maintain parameter CRMORDER-NO_SAVE_MAND_FIELDS in configuration table SMOFPARSFA.

More details:

  • SAP Note „1353553 – Opportunity: Behavior of mandatory fields in Web UI“

Message Check on Save
Sometimes business transactions contains error messages. Usually end-users can still save. In most cases this is acceptable because status change to next status is not allowed in case of errors. In some cases saving is needed, because some activities are performed on save which might resolve the error together with the error message. However, in some seldom cases save shall be blocked for certain error messages.

One example is COM_PARTNER 145 „Business Partner is not a valid business partner.“

In SAP standard there exist no feature to disallow saving dependent on an certain error message. Therefore you have to develop it by creating a configuration table containing fields CLIENT, OBJECT_NAME, MSGTY, MSGID, MSGNO, LANGU and TEXT and by implementing BADI ORDER_SAVE (method CHECK_BEFORE_SAVE).

  1. Check if dialog mode is active using function module COM_PARTNER_DIALOG_MODE_CHECK (Check should only be performed in case of online/foreground processing)
  2. Check if SAP Web Client UI is active using method cl_thtmlb_util=>get_business_role_name (Check should only be performed in case of online/foreground processing)
  3. Select all configured messages using view /GLB/MECOS_R.
  4. Get all messages for current business transaction using function module CRM_MESSAGES_SEARCH.
  5. Get details for all messages using function module CRM_MESSAGES_GET_MSG_INFO.
  6. Check whether business transaction contains configured messages. Check on Object Name, Message Type, Message Class and Message Number. All fields can be left empty in configuration which means “all”.
  7. Cancel save by raising exception DO_NOT_SAVE. If an error message is configured transfer this customer specific error message.
METHOD if_ex_order_save~check_before_save.

lv_profile    TYPE crmt_ui_profile,
lt_message    TYPE TABLE OF /glb/mecos_r,
* ls_msg_idno TYPE bal_s_idno,
* lt_msg_idno TYPE bal_r_idno,
lt_msg_handle TYPE bal_t_msgh,
ls_msg_info   TYPE crmt_msg_info,
ls_msg        TYPE bal_s_msg.

<fs_message>    LIKE LINE OF lt_message,
<fs_msg_handle> LIKE LINE OF lt_msg_handle.


*Get dialog mode state.
no_dialog = 1
OTHERS    = 2.

*We are in dialog mode (online/foreground processing).
CHECK sy-subrc = 0.

*Get Business Role
CALL METHOD cl_thtmlb_util=>get_business_role_name
rv_role = lv_profile.

*We are in SAP Web Client UI (online/foreground processing).

*Alle registrierten Fehlermeldungen lesen.
INTO TABLE lt_message[]
FROM /glb/mecos_r.

*There are some messages configured.
CHECK lt_message[] IS NOT INITIAL.

**Build search conditions.
* REFRESH lt_msg_idno[].
* LOOP AT lt_message ASSIGNING <fs_message>.
* ls_msg_idno-low-msgid = <fs_message>-msgid.
* ls_msg_idno-low-msgno = <fs_message>-msgno.
* CLEAR ls_msg_idno-high.
* ls_msg_idno-sign = 'I'.
* ls_msg_idno-option = 'EQ'.
* APPEND ls_msg_idno TO lt_msg_idno.

*Search for matching messages.
* it_r_msgidno = lt_msg_idno[]
iv_ref_object   = iv_guid
iv_ref_kind     = 'A'
et_msg_handle   = lt_msg_handle
appl_log_error  = 1
error_occurred  = 2
OTHERS          = 3.

*There should never occur an error here.
*We found some messages.
CHECK sy-subrc = 0 AND lt_msg_handle[] IS NOT INITIAL.

LOOP AT lt_msg_handle ASSIGNING <fs_msg_handle>.

*Get message details.
is_msg_handle           = <fs_msg_handle>
es_info                 = ls_msg_info
es_msg                  = ls_msg
not_found               = 1
wrong_context_structure = 2
data_error              = 3
OTHERS                  = 4.

*There should never occur an error here.
CHECK sy-subrc = 0.

*Check all details.
LOOP AT lt_message
ASSIGNING <fs_message>
WHERE ( object_name = ls_msg_info-object_name OR object_name IS INITIAL ) AND
( msgty       = ls_msg-msgty            OR msgty       IS INITIAL ) AND
( msgid       = ls_msg-msgid            OR msgid       IS INITIAL ) AND
( msgno       = ls_msg-msgno            OR msgno       IS INITIAL ).


*All details are correct.
CHECK sy-subrc = 0.

*Prepare own error message for save abort.
IF <fs_message>-text IS NOT INITIAL.

cv_own_message = abap_true.
MESSAGE <fs_message>-text TYPE 'A' RAISING do_not_save.


*Abort save now (using standard error message).
RAISE do_not_save.