Skip to Content

Hello All,

Some opportunities will contain invalid Business Partners( like archived, marked for deletion, not released). If such business partners are added then system will throw error message saying ” The BP is marked for deletion / archived / not released with the BP number”.

Now in this blog i am going to show how to display first name and last name of the BP instead of the BP number in the error message.

This will involve 3 steps.

1. Delete the standard error messages.

2. Structure the custom message.

3. Display the custom error message.

You can use all the below code in do_prepare_output method of the opportunity view.

1.Delete the standard error messages.

DATA: lr_msg_cont    TYPE REF TO  if_genil_message_container,
          lr_msg_service TYPE REF TO cl_bsp_wd_message_service.

     DATA: lt_msg                TYPE crmt_genil_message_tab,
               lv_partner            TYPE bu_partner,
               ls_bp_detail         TYPE bapibus1006_central_person,
               lv_chk_msg         TYPE boolean,
               ls_msg               TYPE crmt_genil_message,
               lt_msg_partner    TYPE crmt_genil_message_tab,
               ls_msg_partner   TYPE crmt_genil_message,
               lv_guid               TYPE crmt_genil_object_guid,
 
*****Initially delete the standard error messages raised for the invalid BPs
      lr_msg_service = cl_bsp_wd_message_service=>get_instance( ).
      lr_msg_cont er_entity->get_message_container( ).


*These are the standard error messages thrown by system when we add invalid BPs to sales team
     ls_msgid = ‘R11’.
     ls_msgnumber = ‘185’.
     APPEND ls_msg TO lt_msg.

     ls_msgid = ‘COM_PARTNER’.
     ls_msgnumber = ‘156’.
     APPEND ls_msg TO lt_msg.

     ls_msgid = ‘COM_PARTNER’.
     ls_msgnumber = ‘158’.
     APPEND ls_msg TO lt_msg.

     IF lr_msg_cont IS BOUND.
       LOOP AT  lt_msg INTO ls_msg.
         lr_msg_cont->delete_messages( iv_msg_id     = ls_msgid
                                                         iv_msg_number = ls_msgnumber ).
       ENDLOOP.
     ENDIF.“lr_msg_cont

     lv_guid = er_entity->get_property_as_string( ‘GUID’ ) .



2. Structure the custom message.


*function module to read the invalid BPs from the opportunity and structuring the custom error message

     CALL FUNCTION ‘ZCHECK_PARTNERS’
       EXPORTING
         iv_guid    =      lv_guid
       IMPORTING
         et_message = lt_msg_partner.


3. Display the custom error message.


     IF lt_msg_partner IS NOT INITIAL.
       LOOP AT lt_msg_partner INTO ls_msg_partner.
         IF lr_msg_service IS BOUND.
           lr_msg_service->add_message( iv_msg_type         = ls_msg_partnertype
                                                          iv_msg_id            = ls_msg_partnerid
                                                          iv_msg_number    = ls_msg_partnernumber
                                                          iv_msg_v1            = ls_msg_partnervar1
                                                          iv_msg_v2            = ls_msg_partnervar2
                                                          iv_msg_v3            = ls_msg_partnervar3
                                                          iv_msg_v4            = ls_msg_partnervar4
                                            ).
         ENDIF.“lr_msg_service
       ENDLOOP.
     ENDIF.




function module source code.

ZCHECK_PARTNERS



FUNCTION zcheck_partners.
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     REFERENCE(IV_GUID) TYPE  CRMT_OBJECT_GUID
*”  EXPORTING
*”     REFERENCE(ET_MESSAGE) TYPE  CRMT_GENIL_MESSAGE_TAB
*”———————————————————————-

*****Data Declarations
   DATA: lt_header_guid      TYPE crmt_object_guid_tab,
             lt_partner              TYPE crmt_partner_external_wrkt,
             ls_but000              TYPE but000,
             lt_msg                  TYPE crmt_genil_message_tab,
             ls_msg                 TYPE crmt_genil_message,
             ls_partner_fct        TYPE CRMC_PARTNER_FT,
             ls_partner             TYPE crmt_partner_external_wrk,
             lt_partner_fct        TYPE STANDARD TABLE OF crmc_partner_ft,
             lt_but000              TYPE STANDARD TABLE OF but000.

   CHECK iv_guid IS NOT INITIAL.

   APPEND iv_guid TO lt_header_guid.

   CALL FUNCTION ‘CRM_ORDER_READ’
     EXPORTING
       it_header_guid       = lt_header_guid
       iv_no_auth_check     = ‘X’
     IMPORTING
       et_partner           = lt_partner
.

   CLEAR: lt_but000,lt_msg,ls_msg,lt_partner_fct,ls_partner_fct.

   SELECT * FROM but000 INTO TABLE lt_but000 FOR ALL ENTRIES IN lt_partner WHERE type = 1
                                                                           AND  partner_guid = lt_partnerbp_partner_guid.
   SELECT * FROM CRMC_PARTNER_FT INTO TABLE lt_partner_fct where spras = ‘E’.

   IF lt_but000 IS NOT INITIAL.
     LOOP AT lt_partner INTO ls_partner.
       READ TABLE lt_but000 INTO ls_but000 WITH KEY partner_guid = ls_partnerbp_partner_guid.
       IF sysubrc IS INITIAL.
         CONCATENATE ls_but000name_first ls_but000name_last INTO ls_msgvar2 SEPARATED BY SPACE.
*****Now Read the Partner function description
         READ TABLE lt_partner_fct INTO ls_partner_fct WITH KEY partner_fct = ls_partnerpartner_fct.
         IF sysubrc IS INITIAL.
           CONCATENATE ‘(‘ ls_partner_fctdescription ‘)’ into ls_msgvar3.
         ENDIF.“lt_partner_fct

         IF ls_but000xdele EQ ‘X’.“If BP marked for deletion.
           ls_msgtype = ‘E’.
           ls_msgid =‘XXXXXX’.
           ls_msgnumber = ‘000’.
           ls_msgvar1 = ‘Business Partner’.
           ls_msgvar4 = ‘has status “Flagged for Archiving”‘.

           append ls_msg to lt_msg.
         ENDIF.“ls_but000-XDELE

         IF ls_but000xblck EQ ‘X’.“If the BP is blocked
           ls_msgtype = ‘E’.
           ls_msgid =‘XXXX’.
           ls_msgnumber = ‘000’.
           ls_msgvar1 = ‘Business Partner’.
           ls_msgvar4 = ‘has status “Locked”‘.

           append ls_msg to lt_msg.
         ENDIF.“ls_but000-XBLCK

         IF ls_but000not_released EQ ‘X’.“If the BP marked as not released
           ls_msgtype = ‘E’.
           ls_msgid =‘XXXX’.
           ls_msgnumber = ‘000’.
           ls_msgvar1 = ‘Business Partner’.
           ls_msgvar4 = ‘has status “Not Released”‘.

           append ls_msg to lt_msg.
         ENDIF.“ls_but000-NOT_RELEASED
       ENDIF.“sy-subrc
       clear: ls_msg.
     ENDLOOP.“lt_partner
   ENDIF.“lt_but000

et_message = lt_msg.

ENDFUNCTION.



The final result will be like this.


Standard error messages.


Custom error messages.



Br,

Navn

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply