Hi All,
Anyone having idea on the below points,
. Basically my requirement is,
I have copied the standard and made into Z function module. I made the changes from line number 205 onwards,
1. While creating IBASE from equipment, it should check the partner number if the partner already having IBASE then this Equipment will be the part of previous IBASE itself. If not it should create a new IBASE.
2. Apart from that it should add the address of the partner in the IBASE.
Currently if i create new equipment in ECC using the txn IE01, its not creating the IBASE also after implementing the BADI.
Can any one guide me on this.
FUNCTION zcrm_create_ibase_from_equi.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IS_HEADER) TYPE SMW3_FHD
*" REFERENCE(IT_EQUI_DMBDOC) TYPE CRMT_EQUI_DMBDOC
*" CHANGING
*" REFERENCE(ET_ERROR_SEGMENTS) TYPE SMW_ERRTAB
*" EXCEPTIONS
*" TECHNICAL_ERROR
*"----------------------------------------------------------------------
* Equi-MBdoc segments
DATA: ls_equi TYPE crmt_equi_mess,
ls_equz TYPE crmt_equz_mess,
ls_iloa TYPE crmt_iloa_mess,
ls_businesspartner TYPE crmt_ihpa_mess.
* Partner data
DATA: ls_partner TYPE ibap_part4,
lt_partner TYPE ibap_part4_tab.
* Structure for crmt_equi_dmbdoc
DATA: lt_equi_dmbdoc TYPE crmt_equi_dmbdoc.
* Product data (required for individual objects)
DATA: lt_product TYPE comt_product_maintain_api_tab,
ls_product_ibase TYPE comt_product_maintain_api,
lv_product_id TYPE comt_product_id.
* Index table for child their father is not here yet.
DATA: lt_equipindx TYPE ibequiindx.
* Class used to communicate with outbound part (mBODC CRM_IBASE_MESS)
DATA: lv_crm_iba_msg_rtstore
TYPE REF TO cl_crm_iba_msg_rtstore.
************************************
DATA : ls_component TYPE ibap_comp3,
ls_father_pod TYPE ibap_dat1.
************************************
CLEAR lt_equipindx.
* Initialize the temporary component buffer.
CLEAR gt_comp_buffer.
* Read the Equi-Load customizing.
PERFORM read_customizing
USING
is_header.
* Forward site_id to prevent resend data to R/3 for mBDOC PRODUCT_INDOBJ
CALL FUNCTION 'CRM_PROD_OUTBOUND_SET_BDOCH'
EXPORTING
is_inbound_bdoc_header = is_header.
* Initialize the BADI for the load.
CALL FUNCTION 'CRM_EQUI_LOAD_BADI_BUFFER'
IMPORTING
e_upload_badi = g_upload_badi.
* Map partner from R/3 to CRM.
CALL FUNCTION 'CRM_EQUI_MAP_PARTNER_CS_TO_CRM'
EXPORTING
it_equi_dmbdoc = it_equi_dmbdoc
IMPORTING
et_equi_dmbdoc = lt_equi_dmbdoc
CHANGING
et_error_segments = et_error_segments
EXCEPTIONS
mapping_error = 1
OTHERS = 2.
lt_equi_dmbdoc-warrenty = it_equi_dmbdoc-warrenty.
IF sy-subrc <> 0.
CALL FUNCTION 'CRM_EQUI_UPLOAD_ERROR_HANDLER'
EXPORTING
i_msg_id = gc_error_msg_id
i_msg_no = '020'
CHANGING
c_error_seg = et_error_segments.
RAISE technical_error.
ENDIF.
* Create the individual objects from the equi-bdoc.
DATA: lv_update TYPE xflag.
CALL FUNCTION 'CRM_CREATE_OBJECT_FROM_EQUI'
EXPORTING
it_equi_dmbdoc = lt_equi_dmbdoc
*{ PDu INSERT
is_header = is_header
*} INSERT
IMPORTING
et_product = lt_product
ev_updated_ibases = lv_update
CHANGING
ct_equi_index = lt_equipindx
ct_error_segments = et_error_segments
EXCEPTIONS
technical_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
CALL FUNCTION 'CRM_EQUI_UPLOAD_ERROR_HANDLER'
EXPORTING
i_msg_id = gc_error_msg_id
i_msg_no = '012'
CHANGING
c_error_seg = et_error_segments.
RAISE technical_error.
ENDIF.
* Badi-Call -> after_object_creation
IF NOT g_upload_badi IS INITIAL.
CALL METHOD g_upload_badi->after_object_creation
CHANGING
ct_product = lt_product
ct_error_segment = et_error_segments
EXCEPTIONS
equi_load_badi_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
CALL FUNCTION 'CRM_EQUI_UPLOAD_ERROR_HANDLER'
EXPORTING
i_msg_id = gc_error_msg_id
i_msg_no = '039'
i_msgv1 = 'after_object_creation'
CHANGING
c_error_seg = et_error_segments.
RAISE technical_error.
ENDIF.
ENDIF.
* Forward site_id to prevent resend data to R/3
* for CRM_IBASE_MESS mBDOC
CALL METHOD cl_crm_iba_msg_rtstore=>singleton
RECEIVING
ev_crm_iba_msg_rtstore = lv_crm_iba_msg_rtstore.
CALL METHOD lv_crm_iba_msg_rtstore->set_header
EXPORTING
is_header = is_header.
* Go home when no objects have been created.
IF lt_product[] IS INITIAL.
PERFORM post_index USING lt_equipindx.
PERFORM post_ibase.
RETURN.
ENDIF.
* Prepare the data for IBase-Mapping
LOOP AT lt_equi_dmbdoc-equi INTO ls_equi.
PERFORM equi_nr_to_object_id
USING
ls_equi-equnr
CHANGING
lv_product_id
et_error_segments.
* Seek product data for Ibase
LOOP AT lt_product INTO ls_product_ibase
WHERE com_product-product_id = lv_product_id.
ENDLOOP.
* If found ...
IF sy-subrc = 0.
REFRESH lt_partner.
* prepare time depending records
PERFORM get_time_seg
USING
ls_equi-equnr
lt_equi_dmbdoc
CHANGING
ls_equz.
CLEAR ls_iloa.
IF ls_equz-iloan IS NOT INITIAL.
READ TABLE lt_equi_dmbdoc-iloa INTO ls_iloa WITH KEY iloan = ls_equz-iloan.
ENDIF.
* Fill the partner table
PERFORM get_business_partner
USING
ls_equi-equnr
lt_equi_dmbdoc
CHANGING
lt_partner.
***************************Modification*********************************************
*Changes by ANANDHAN+++>
************************************************************************************
* In case of IBase category "03" a different processing for the
* creation of object structures is necessary
* IF gc_ibase_type EQ '03'.
* CALL FUNCTION 'CRM_EQUI_INSERT_INTO_STRUC_OS'
* EXPORTING
* is_object = ls_product_ibase
* iv_father = ls_equz-hequi
* iv_current = ls_equi-equnr
* iv_father_tplnr = ls_iloa-tplnr
* CHANGING
* ct_equiindx = lt_equipindx
* ct_error_seg = et_error_segments
* EXCEPTIONS
* technical_error = 1
* OTHERS = 2.
*
* IF sy-subrc <> 0.
* CALL FUNCTION 'CRM_EQUI_UPLOAD_ERROR_HANDLER'
* EXPORTING
* i_msg_id = 'CRM_OBJ_STRUC_MSG_OS'
* i_msg_no = '001'
* i_msgv1 = ls_equi-equnr
* CHANGING
* c_error_seg = et_error_segments.
*
* RAISE technical_error.
* ENDIF.
* ELSE.
************************************************
" INTO wa_equi with KEY
DATA: lt_id_range TYPE comt_prwb_object_id_range_t.
DATA: lt_comps TYPE ibap_comp4_tab.
DATA: wa_comps TYPE ibap_comp4.
DATA: cv_object_id TYPE comt_prwb_object_id.
DATA: ls_id_range TYPE LINE OF comt_prwb_object_id_range_t.
DATA : it_equi TYPE crmt_equi_mess_t.
DATA : wa_equi TYPE crmt_equi_mess.
DATA : it_desc TYPE crmt_eqkt_mess_t.
DATA : wa_desc TYPE crmt_eqkt_mess.
DATA : lv_ib_partner TYPE ibap_part1.
DATA : lt_ib_head_tab TYPE ibap_head1_tab.
DATA : ls_ib_head_tab TYPE ibap_head1.
DATA : wa_partner TYPE ibap_part4.
DATA : wa_but000 TYPE but000.
DATA : e_sadr TYPE STANDARD TABLE OF sadr.
DATA : wa_sadr TYPE sadr.
DATA : ls_address TYPE addr1_data.
TYPES: BEGIN OF gs_comp_buffer,
equi_nr TYPE smo3equnr,
component TYPE ibap_dat1,
END OF gs_comp_buffer.
DATA : ls_comp_buffer TYPE gs_comp_buffer.
****************************************************************************************
it_equi = it_equi_dmbdoc-equi. " Get the Equipement table seprately
it_desc = it_equi_dmbdoc-equipmenttext. " Get the Equipment Description
READ TABLE it_equi INTO wa_equi INDEX 1. " Reading the IBASE table
READ TABLE it_desc INTO wa_desc INDEX 1. " Reading the description
ls_id_range-sign = 'I'.
ls_id_range-option = 'EQ'.
ls_id_range-low = wa_equi-equnr.
CLEAR ls_id_range-high.
APPEND ls_id_range TO lt_id_range.
CALL FUNCTION 'CRM_IBASE_COMP_INDOBJ_SEARCH_R' " To find the IBASE using the Equipment
EXPORTING
it_product_id_range = lt_id_range
IMPORTING
et_comp = lt_comps
EXCEPTIONS
not_specified = 1
not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
READ TABLE lt_comps INTO wa_comps INDEX '1'.
**************To find the IBASE for the Ship to PARTY**************************
READ TABLE lt_partner INTO wa_partner WITH KEY partner_fct = '00000002'. " To find the IBASE for the Ship to party
IF sy-subrc = 0.
SELECT SINGLE * FROM but000 " To GET the BP details
INTO wa_but000 WHERE
partner = wa_partner-partner_no.
IF sy-subrc = 0 .
lv_ib_partner-partner_fct = wa_partner-partner_fct.
lv_ib_partner-partner_no = wa_but000-partner_guid.
ENDIF.
ENDIF.
*************To Get the Ship to Party address from ECC System*********************
CALL FUNCTION 'Z_PARNER_ADDR_GET' DESTINATION 'RFC_ECC_100' "To Get the Ship to Party address from ECC
EXPORTING
crm_kunnr = wa_but000-partner
TABLES
sadr = e_sadr.
READ TABLE e_sadr INTO wa_sadr INDEX 1.
CALL FUNCTION 'CRM_IBASE_PARTNER_SEARCH' " To get the IBASE based on the PARTNER as ship to party
EXPORTING
i_partner = lv_ib_partner
* I_DATE =
* I_TIME =
* I_CASEKZ =
IMPORTING
e_ibase_tab = lt_ib_head_tab
EXCEPTIONS
not_specified = 1
not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
READ TABLE lt_ib_head_tab INTO ls_ib_head_tab INDEX 1.
IF sy-subrc = 0 .
********* -fill Component objects structure*****************
ls_father_pod-ibase = ls_ib_head_tab-ibase. "'000000000000003947'.
ls_component-descr = wa_desc-eqktx. "'TESTING'.
ls_component-deviceid = 'TEST'.
ls_component-posnr = '1'.
ls_component-extobjtyp = 'CRMBASIC'.
ENDIF.
***********Fill Address Data******************************** "To Updating the Address in the IBASE
ls_address-title = wa_sadr-anred.
ls_address-name1 = wa_sadr-name1.
ls_address-name2 = wa_sadr-name2.
ls_address-name3 = wa_sadr-name3.
ls_address-name4 = wa_sadr-name4.
ls_address-post_code1 = wa_sadr-pstlz.
ls_address-city1 = wa_sadr-ort01.
ls_address-city2 = wa_sadr-ort02.
ls_address-street = wa_sadr-stras.
ls_address-country = wa_sadr-land1.
**************************************************************
CALL FUNCTION 'CRM_IBASE_COMP_CREATE'
EXPORTING
i_father = ls_father_pod " '3947'
i_comp_det = ls_component
* i_address_data = ls_address
* I_ADDRESS_ADMIN =
* I_PARTNER =
* I_DATE =
* I_TIME =
* I_CHECK_ADDRESS = 'X'
IMPORTING
e_comp = ls_father_pod
* TABLES
* ERROR_TABLE =
EXCEPTIONS
data_not_consistent = 1
ibase_locked = 2
not_succesful = 3
no_authority = 4
OTHERS = 5
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
ls_comp_buffer-equi_nr = wa_equi-equnr. "Getting all the Componnent data for further process
MOVE-CORRESPONDING ls_father_pod TO ls_comp_buffer-component.
APPEND ls_comp_buffer TO gt_comp_buffer.
ENDIF.
******************************************************************
******************************************************************
ls_equz-hequi = ls_father_pod-instance.
** Build the installation with its components and structure!
CALL FUNCTION 'CRM_EQUI_INSERT_INTO_HIERARCHY'
EXPORTING
i_partner = lt_partner
i_object = ls_product_ibase
i_father = ls_equz-hequi"ls_father_pod-INSTANCE
i_father_tplnr = ls_iloa-tplnr
i_child = ls_equi-equnr
CHANGING
c_equiindx = lt_equipindx
c_error_seg = et_error_segments
EXCEPTIONS
technical_error = 1
OTHERS = 2.
*
IF sy-subrc <> 0.
CALL FUNCTION 'CRM_EQUI_UPLOAD_ERROR_HANDLER'
EXPORTING
i_msg_id = gc_error_msg_id
i_msg_no = '025'
i_msgv1 = ls_equi-equnr
CHANGING
c_error_seg = et_error_segments.
RAISE technical_error.
ENDIF.
ENDIF.
PERFORM prepare_enlarge_component_data USING ls_equi
lt_equi_dmbdoc
ls_product_ibase
et_error_segments.
* ENDIF.
ENDLOOP.
* Reconcile the original- and working-table of the father-index
PERFORM post_index CHANGING lt_equipindx.
* If every thing is OK, then start posting ibase and i.-objects.
* (i.-objects will be posted by commit work)
PERFORM post_ibase.
*********************************************
* COMMIT WORK WILL BE SET BY THE MIDDLEWARE.*
********************************************
ENDFUNCTION.
*&--------------------------------------------------------------------*
*& Form post_index
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->CT_EQUIPINDtext
* -->CT_INDX_ORGtext
*---------------------------------------------------------------------*
FORM post_index
USING
it_equipindx TYPE ibequiindx.
* Write the father-index table into the database.
CALL FUNCTION 'CRM_IBASE_EQU_INDEX_POST' IN UPDATE TASK
TABLES
it_ibaseindex = it_equipindx
Reg
Anandnan