Acorel
To Acorel.nl
Acorel background

Reading messages and exceptions after calling CRM order maintain

Edwin van den Meijdenberg, 30 May 2012

Within SAP CRM the function module “CRM_ORDER_MAINTAIN” is used to create and change an Order. Although it has some exceptions implemented, the function module will not return the messages and exceptions within the Order itself. Instead it only tells if the maintain was executed correctly or not. It might be necessary to read the messages and exceptions afterwards, for instance to return them to a portal. This blog contains an overview of the steps that need to be executed.

Scenario

Within the CRM Webclient we entered an invalid Sold-To-Party. We’ll use this scenario to show how to get this exception message after calling function module “CRM_ORDER_MAINTAIN”.

Step 1 : Get log handles

After calling function module “CRM_ORDER_MAINTAIN” we first need to determine the currently existing log handles. Function module “CRM_MESSAGES_GET_LOG_HANDLES” can be used to read these log handles.


  DATA:
    lt_log_handle TYPE bal_t_logh.

* Get Log Handle(s)
  CALL FUNCTION ‘CRM_MESSAGES_GET_LOG_HANDLES’
    IMPORTING
      et_log_handle = lt_log_handle.

Step 2 : Get messages and exceptions

Once we have determined the log handles, we can search for messages and exceptions within these log handles, using function module “CRM_MESSAGES_GET_EXCEPTIONS”.

The code below reads the exceptions for the log handles, determined in step 1.


  DATA:
    lt_exception TYPE crmt_exception_t.

  FIELD-SYMBOLS:
    <lfs_log_handle> TYPE balloghndl.

* Get Exception(s)
  LOOP AT lt_log_handle ASSIGNING <lfs_log_handle>.
    CALL FUNCTION ‘CRM_MESSAGES_GET_EXCEPTIONS’
      EXPORTING
        iv_log_handle   = <lfs_log_handle>
        iv_from_regmsg  = abap_true
      IMPORTING
        et_exception    = lt_exception
      EXCEPTIONS
        parameter_error = 1
        not_found       = 2
        OTHERS          = 3.
  ENDLOOP.

Step 3 : Get message

Within step 2 we determined the exception messages within a log handle. Once we have the exceptions, we can read the corresponding messages using function module “CRM_MESSAGES_GET_MSG_INFO”.

The code below processes all exceptions, determined in step 2.


  DATA:
    ls_msg TYPE bal_s_msg.

  FIELD-SYMBOLS:
    <lfs_exception> TYPE crmt_exception.

* Get Exception Message(s)
  LOOP AT lt_exception ASSIGNING <lfs_exception>.
    CLEAR
      ls_msg.

    CALL FUNCTION ‘CRM_MESSAGES_GET_MSG_INFO’
      EXPORTING
        is_msg_handle           = <lfs_exception>-msg_handle
      IMPORTING
        es_msg                  = ls_msg
      EXCEPTIONS
        not_found               = 1
        wrong_context_structure = 2
        data_error              = 3
        OTHERS                  = 4.
  ENDLOOP.


The actual message and it’s attributes are stored in structure “LS_MSG”.

Conclusion

Although standard function module “CRM_ORDER_MAINTAIN” doesn’t return functional messages and exceptions, it is quite easy to read them. 

Edwin van den Meijdenberg

Read all my blogs

Receive our weekly blog by email?
Subscribe here: