Skip to Content

Hi all,

The below code is going to help us , to change the fields for partners of the Opportunity and delete the partner records from Opportunity.

Delete the Particular  partners from Opportunity

DATA: ls_guid TYPE crmt_object_guid,
lt_guid
TYPE crmt_object_guid_tab,
lt_adminh
TYPE crmt_orderadm_h_wrkt,
lt_opporth
TYPE crmt_opport_h_wrkt,
ls_adminh
TYPE  crmt_orderadm_h_wrk,
ls_opporth
TYPE crmt_opport_h_wrk,
lt_partner
TYPE crmt_partner_external_wrkt,
ls_partner
TYPE crmt_partner_external_wrk.

DATA :ls_partner_wrk       TYPE crmt_partner_external_wrk.
DATA:  lt_input_fields 
TYPE  crmt_input_field_tab,
ls_input_field  
TYPE  crmt_input_field,
ls_input_field_names
TYPE crmt_input_field_names ,
lt_input_field_names
TYPE crmt_input_field_names_tab.
DATA : lit_partner          TYPE crmt_partner_comt,
wa_partner          
LIKE LINE OF lit_partner.
DATA: ls_logic_partner_key 
TYPE crmt_partner_logic_partner_key.
DATA : lt_order_h TYPE crmt_orderadm_h_comt,
ls_order_h
TYPE crmt_orderadm_h_com.
DATA : lv_partner_no TYPE bu_partner.
DATA : lv_partner_no1 TYPE bu_partner.
REFRESH lt_guid.

ls_guid = guid.
APPEND ls_guid TO lt_guid.
CLEAR ls_guid.

CALL FUNCTION ‘CRM_ORDER_READ’
EXPORTING
it_header_guid       = lt_guid
IMPORTING
et_orderadm_h        = lt_adminh
et_opport_h          = lt_opporth
et_partner           = lt_partner
*     et_appointment       = lt_appointment
EXCEPTIONS
document_not_found   =
1
error_occurred       =
2
document_locked      =
3
no_change_authority  =
4
no_display_authority =
5
no_change_allowed    =
6
OTHERS               = 7.
IF sy-subrc EQ 0.
READ TABLE lt_adminh INTO ls_adminh INDEX 1.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING ls_adminh TO ls_order_h.
INSERT ls_order_h INTO TABLE lt_order_h.

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input  = partner
IMPORTING
output = lv_partner_no.
.

LOOP AT lt_partner INTO ls_partner_wrk .
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input  = ls_partner_wrk-partner_no
IMPORTING
output = lv_partner_no1.

CHECK    lv_partner_no1  EQ lv_partner_no.

*        MOVE-CORRESPONDING ls_partner_wrk TO wa_partner.

MOVE :ls_partner_wrk-ref_guid   TO               wa_partner-ref_guid,
ls_partner_wrk-ref_handle
TO                  wa_partner-ref_handle,
ls_partner_wrk-ref_kind   
TO                wa_partner-ref_kind,
ls_partner_wrk-ref_partner_handle
TO          wa_partner-ref_partner_handle,
ls_partner_wrk-ref_partner_fct   
TO          wa_partner-ref_partner_fct,
ls_partner_wrk-ref_partner_no   
TO           wa_partner-ref_partner_no,
ls_partner_wrk-ref_no_type       
TO          wa_partner-ref_no_type,
ls_partner_wrk-ref_display_type  
TO          wa_partner-ref_display_type.
*              ls_partner_wrk-kind_of_entry      TO          wa_partner-kind_of_entry.

ls_input_field_names-fieldname = ‘PARTNER_FCT’.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.

        CLEAR ls_logic_partner_key.
ls_logic_partner_key-ref_partner_handle = ls_partner_wrk-ref_partner_handle.
ls_logic_partner_key-ref_partner_fct = ls_partner_wrk-ref_partner_fct.
ls_logic_partner_key-ref_partner_no = ls_partner_wrk-ref_partner_no.
ls_logic_partner_key-ref_no_type = ls_partner_wrk-ref_no_type.
ls_logic_partner_key-ref_display_type = ls_partner_wrk-ref_display_type.
ls_input_field-logical_key = ls_logic_partner_key.

ls_input_field-ref_guid    = guid.
ls_input_field-ref_handle = ‘0000000000’.
ls_input_field-ref_kind    =
‘A’.
ls_input_field-objectname  =
‘PARTNER’.
ls_input_field-field_names = lt_input_field_names.
INSERT ls_input_field INTO TABLE lt_input_fields.
INSERT wa_partner INTO TABLE lit_partner.
clear : lt_input_field_names.

ENDLOOP.

CALL FUNCTION ‘CRM_ORDER_MAINTAIN’
EXPORTING
it_partner        = lit_partner
CHANGING
ct_orderadm_h     = lt_order_h
ct_input_fields   = lt_input_fields
EXCEPTIONS
error_occurred    =
1
document_locked   =
2
no_change_allowed =
3
no_authority      =
4
OTHERS            = 5.
IF sy-subrc EQ 0.
DATA: lt_guid1
TYPE crmt_object_guid_tab,
lv_header_guid
TYPE crmt_object_guid.

lv_header_guid = guid.
*
APPEND lv_header_guid TO lt_guid1.

CALL FUNCTION ‘CRM_ORDER_SAVE’
EXPORTING
it_objects_to_save = lt_guid1.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.
* IMPORTING
*   RETURN        =

ENDIF.

ENDIF.
ENDIF.

Change the data for partners of the opportunity

DATA:

lv_ref_handle       TYPE numc4,

ls_partner_wrk      TYPE crmt_partner_external_wrk,

lt_partner_wrk      TYPE crmt_partner_external_wrkt,

ls_partner_com      TYPE crmt_partner_com,

lt_partner_com      TYPE crmt_partner_comt,

ls_input_fields     TYPE crmt_input_field.

DATA : lt_partner_attributes TYPE crmt_partner_attribute_com_tab,

ls_partner_attributes TYPE crmt_partner_attribute_com.

DATA : ls_logical_key TYPE comt_partner_logic_partner_key.

DATA:  lv_handle TYPE crmt_handle.

DATA:  lt_input_fields TYPE crmt_input_field_tab,

ls_input_field  TYPE crmt_input_field,

ls_input_field_names TYPE crmt_input_field_names ,

lt_input_field_names TYPE crmt_input_field_names_tab.

DATA : lit_partner         TYPE CRMT_PARTNER_COMT,

wa_partner          LIKE LINE OF lit_partner.

DATA : LT_ORDER_H type CRMT_ORDERADM_H_COMT,

ls_order_H type CRMT_ORDERADM_H_COM.

move-corresponding ls_adminh to ls_order_h.

   insert ls_order_h into table lt_order_h.

           LOOP AT t_partner INTO ls_partner_wrk .

            

ls_partner_wrk-zzfld000010 = ‘X’.  “ changed DATA

            move-corresponding ls_partner_wrk to wa_partner.

ls_input_field_names-fieldname = ‘DISPLAY_TYPE’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘KIND_OF_ENTRY’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘MAINPARTNER’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘NO_TYPE’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘PARTNER_FCT’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘CALENDAR’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘RELATION_PARTNER’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘PARTNER_NO’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

ls_input_field_names-fieldname = ‘ZZFLD000010’.

             INSERT ls_input_field_names INTO TABLE lt_input_field_names.

DATA: ls_logic_partner_key TYPE crmt_partner_logic_partner_key.

ls_logic_partner_key-ref_partner_handle = ls_partner_wrk-ref_partner_handle.

ls_logic_partner_key-ref_partner_fct = ls_partner_wrk-ref_partner_fct.

ls_logic_partner_key-ref_partner_no = ls_partner_wrk-ref_partner_no.

ls_logic_partner_key-ref_no_type = ls_partner_wrk-ref_no_type.

ls_logic_partner_key-ref_display_type = ls_partner_wrk-ref_display_type.

   ls_input_field-logical_key = ls_logic_partner_key.

ls_input_field-ref_guid    = iv_guid.

ls_input_field-ref_kind    = ‘A’.

ls_input_field-objectname  = ‘PARTNER’.

ls_input_field-field_names = lt_input_field_names.

       INSERT ls_input_field INTO TABLE lt_input_fields.

        insert wa_partner into table lit_partner.

ENDLOOP.

             CALL FUNCTION ‘CRM_ORDER_MAINTAIN’

                  EXPORTING

IT_PARTNER = lit_partner

                  CHANGING

CT_ORDERADM_H = lt_order_h

CT_INPUT_FIELDS = lt_input_fields

                  EXCEPTIONS

ERROR_OCCURRED = 1

DOCUMENT_LOCKED = 2

NO_CHANGE_ALLOWED = 3

NO_AUTHORITY = 4

                       OTHERS = 5.

DATA: lt_guid1 TYPE crmt_object_guid_tab,
lv_header_guid
TYPE crmt_object_guid.

lv_header_guid = guid.
*
APPEND lv_header_guid TO lt_guid1.

CALL FUNCTION ‘CRM_ORDER_SAVE’
EXPORTING
it_objects_to_save = lt_guid1.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.
* IMPORTING
*   RETURN        =

ENDIF.

regards,

ajayram

To report this post you need to login first.

1 Comment

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

  1. Former Member

    It’s nice of you to share this piece of code, but whoever might need it some day will probably be a junior developper since this is pretty much the basics of CRM programming.

    And giving an uncommented piece of code to a junior, doesn’t seem very helpful to me. Neither this is giving a good example of what code must look like since you have 0 comments in it.

    (0) 

Leave a Reply