Вы находитесь на странице: 1из 19

Problem Resolution

Extend the Material Master BDOC


Consultant Owner:

Robert Kuhn

Project:

SAP CRM Implementation

Status:

Initial Document

Updated

2/24/2011

Description of Problem:
There are several fields in the Material Master of ECC that must be brought over to the Product Master in CRM.
These fields are currently not supported by the BDOC. To include these fields in the BDOC use the following
procedure. In this document Transportation relevant information is replicated from ECC to CRM.

Configuration in ECC for triggering the CRM Middleware download of data


Configuration Tables TBE24 and TPS34 in ECC must be maintained for triggering the CRM Middleware
download of data from ECC to CRM. In Table TPS34 the Process CRM0_200 contains the entry for CRM
Middleware download of data.
Activate Customer Product by maintaining table TBE24 using transaction SM30

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 1

Last Updated: 2/24/2011 10:24:00 AM

Add the function module that the OPEN_FI function module can find for a Business Transaction Event (BTE) as
an alternative to a standard function module by maintaining table TPS34 using transaction SM30

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 2

Last Updated: 2/24/2011 10:24:00 AM

Create Function module for mapping.


Function Module Z_SEND_PROD_TO_CRM handles mapping the custom fields to be transferred to the CRM
system. Here is an example of the code needed

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 3

Last Updated: 2/24/2011 10:24:00 AM

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 4

Last Updated: 2/24/2011 10:24:00 AM

SAMPLE CODE:
FUNCTION Z_SEND_PROD_TO_CRM.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
REFERENCE(I_OBJ_CLASS) LIKE BAPICRMOBJ-OBJCLASS
*"
REFERENCE(I_OBJ_NAME) LIKE BAPICRMOBJ-OBJ_NAME
*"
REFERENCE(I_BAPICRMDH2) LIKE BAPICRMDH2 STRUCTURE BAPICRMDH2
*"
OPTIONAL
*"
REFERENCE(I_KEYWORD_IN) LIKE CRM_PARA-KEYWORD_IN
*"
REFERENCE(I_CRMRFCPAR) LIKE CRMRFCPAR STRUCTURE CRMRFCPAR
*" EXPORTING
*"
REFERENCE(E_DO_NOT_SEND) LIKE CRM_PARA-XFELD
*" TABLES
*"
T_INT_TABLES STRUCTURE BAPIMTCS
*"
T_BAPISTRUCT STRUCTURE BAPIMTCS
*"
T_MESSAGES STRUCTURE BAPICRMMSG
*"
T_KEY_INFO STRUCTURE BAPICRMKEY
*"
T_BAPIIDLIST STRUCTURE BAPIIDLIST
*"
T_OTHER_INFO STRUCTURE BAPIEXTC
*" CHANGING
*"
REFERENCE(C_BAPICRMDH2) LIKE BAPICRMDH2 STRUCTURE BAPICRMDH2
*"
REFERENCE(C_RFCDEST) LIKE CRMRFCPAR STRUCTURE CRMRFCPAR
*"
REFERENCE(C_OBJNAME) LIKE BAPICRMOBJ-OBJ_NAME
*"---------------------------------------------------------------------DATA: ls_mara
TYPE mara,
ls_marc
TYPE marc.
* Communication Structure
DATA: BEGIN OF ls_com_key,
struct(20),
matnr(40),
END OF ls_com_key.
/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 5

Last Updated: 2/24/2011 10:24:00 AM

* Communication structure (additional MARA data)


DATA: BEGIN OF ls_com_data1,
tragr LIKE mara-tragr,
magrv LIKE mara-magrv,
END OF ls_com_data1.
* Communication structure (additional MARC data)
DATA: BEGIN OF ls_com_data2,
mfrgr(8),
ladgr(4),
vbamg(13),
vrvez(7),
vbeaz(7),
END OF ls_com_data2.
* Field Symbol for Casting BAPIMTCS
FIELD-SYMBOLS:
<source_x> TYPE x,
<target_x> TYPE x.
* Additional Fields used
DATA: lv_matnr TYPE mara-matnr.
DATA: ls_BAPISDCOND TYPE BAPISDCOND.
DATA: ORIGNAL_COST TYPE BAPISDCOND-COND_VALUE.

* DATA:
*** BEGIN **************************************************************
** ATTENTION: This declaration is needed, to get the right offset for
**
a later assign (to prevent alignment error at statement
**
ASSIGN ... CASTING ...)
* lv_casting
TYPE f,
"#EC NEEDED
**
Never insert a new definition between LV_CASTING and
**
and LS_BAPIMTCS !!!
* ct_bapimtcs
TYPE bapimtcs.
*** END ****************************************************************
**
*
FIELD-SYMBOLS:
<ledsource_x> TYPE BAPISDCOND,
<ledtarget_x> TYPE BAPISDCOND,
<lfs_data> type any.
DATA: gc_condition TYPE tabname30 VALUE 'BAPISDCOND'.
CASE i_obj_name.
WHEN 'MATERIAL'.
* We want to pick up the additional fields from MARA
* Mapping of MARA fields into table t_other_info
LOOP AT t_int_tables WHERE tabname = 'MARA'.
ASSIGN t_int_tables-data TO <source_x> CASTING.
ASSIGN ls_mara TO <target_x> CASTING.
IF <source_x> IS ASSIGNED AND
<target_x> IS ASSIGNED.

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 6

Last Updated: 2/24/2011 10:24:00 AM

<target_x> = <source_x>.
ELSE.
CONTINUE.
ENDIF.
ls_com_key-struct = 'MARA'.
ls_com_key-matnr = ls_mara-matnr.
MOVE-CORRESPONDING ls_mara TO ls_com_data1.

t_other_info-field1 = ls_com_key.
t_other_info-field2 = ls_com_data1.
APPEND t_other_info.

* We want to pick up the additional fields from MARC


lv_matnr = t_int_tables-data+3(40).
CLEAR ls_marc.
CALL FUNCTION 'MARC_SINGLE_READ'
EXPORTING
matnr = lv_matnr
*
* STILL NEEDS SOME WORK HERE
* There is a 1 to many relationship between MARA and MARC
* and we need to determine how to handle this.
* For testing purposes Plant 10 is hard coded
*
werks = '10 '
* END
IMPORTING
wmarc = ls_marc
EXCEPTIONS
OTHERS = 5.
MOVE-CORRESPONDING ls_marc TO ls_com_data2.
t_other_info-field3 = ls_com_data2.
APPEND t_other_info.
ENDLOOP.
WHEN 'LEDELIVERY'.
*t_int_tables
LOOP AT T_BAPISTRUCT WHERE tabname = 'BAPISDCOND'.
ASSIGN T_BAPISTRUCT-data TO <ledsource_x> CASTING.
ASSIGN ls_BAPISDCOND TO <ledtarget_x> CASTING.
IF <ledsource_x> IS ASSIGNED AND
<ledtarget_x> IS ASSIGNED.
*Following will pass data from T_BAPISTRUCT-data to ls_BAPISDCOND
*Both are having separate memory areas.
<ledtarget_x> = <ledsource_x>.
ELSE.
CONTINUE.
/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 7

Last Updated: 2/24/2011 10:24:00 AM

ENDIF.
ORIGNAL_COST = ls_BAPISDCOND-COND_VALUE.
*As <ledtarget_x> refers to ls_BAPISDCOND memory,
*in debugging, you can see <ledtarget_x>-con_value becomes 5000.
ls_BAPISDCOND-COND_VALUE = '5000'.
*<ledsource_x> refers to data field of header line (workline) of
*internal table T_BAPISTRUCT
*So following will change data field of header line of T_BAPISTRUCT
<ledsource_x> = ls_BAPISDCOND.
ENDLOOP.
ENDCASE.

Configuration in CRM for triggering the CRM Middleware download of data


In order to populate these fields in CRM there are a number of development objects which are needed in CRM:
1)

Every additional field from the Material Master in ECC must be created as an Attribute in CRM. Use
transaction COMM_ATTRSET to create the Attributes for the following fields:

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 8

Last Updated: 2/24/2011 10:24:00 AM

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 9

Last Updated: 2/24/2011 10:24:00 AM

a. ZMARA_BRGEW - Gross weight - not needed


b. ZMARA_NTGEW - Net weight - not needed
c. ZMARA_VOLUM - Volume - not needed
d. ZMARA_MFRGR - Material Freight Grp (Should be ZMARC_MFRGR)
e. ZMARA_TRAGR - Transportation Group
f.

ZMARC_LADGR - Loading Group

g. ZMARC_VBAMG - Base Qty. Shipping - not needed for now


h. ZMARC_VRVEZ - Shipping setup time - not needed for now

2)

i.

ZMARC_VBEAZ - Shipping processing time - not needed for now

j.

ZMARA_MAGRV - Material Group: Packaging Materials

Set Types must be created to handle all of the Attributes created. Set types can only handle 22
Attributes. Create multiple Set Types if needed to handle all of the Attributes. Use transaction
COMM_ATTRSET to create the Attributes for the following Set Types:
a. ZPROD_XPORT

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 10

Last Updated: 2/24/2011 10:24:00 AM

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 11

Last Updated: 2/24/2011 10:24:00 AM

This will be the ZZxxxx fields on the BDOC:

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 12

Last Updated: 2/24/2011 10:24:00 AM

b. ZMARA_BRGEW - Gross weight - ZZ0011


c. ZMARA_NTGEW - Net weight - ZZ0013
d. ZMARA_VOLUM - Volume - ZZ0015
e. ZMARA_MFRGR - Material Freight Grp - ZZ0016 (Should be ZMARC_MFRGR)
f.

ZMARA_TRAGR - Transportation Group - ZZ0017

g. ZMARC_LADGR - Loading Group - ZZ0018


h. ZMARC_VBAMG - Base Qty. Shipping - ZZ0019
i.

ZMARC_VRVEZ - Shipping setup time - ZZ0021

j.

ZMARC_VBEAZ - Shipping processing time - ZZ0022

k. ZMARA_MAGRV - Material Group: Packaging Materials - ZZ0023


NOTE:
If you make changes to the Set Type, then there is a possibility that the field mappings in BADI
PRODUCT_CUSTOMER2, method MAP_R3_TO_CRM_MATERIAL on the CRM side will have to be
changed. Please check the mappings after a set type change to ensure they are still correct.
Extend the complex data structure of the product master in CRM with the set type ZPORD_XPORT and
thus enable download from ECC into the CRM database.

Assign all of the Attributes to the Set Types created. Assign each Set Type to the Hierarchy Category
MAT_HALB using transaction COMM_HIERARCHY. See Figure below.

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 13

Last Updated: 2/24/2011 10:24:00 AM

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 14

Last Updated: 2/24/2011 10:24:00 AM

3)

If you defined custom fields in ECC you need to create additional structure tables called in CRM. These
tables will match the same table names in ECC. The tables should have the same field lengths as the
table-fields in R/3.

4)

The BADI PRODUCT_CUSTOMER2, method MAP_R3_TO_CRM_MATERIAL will have all of the code
changes needed to map the additional fields to the Set Types in CRM. Use transaction SE18. An
Implementation will be created called Z_PRODUCT_EXT (Used to populate extended product data). We
will need to add the Category MAT_HALB to the Product Master. The Category MAT_HALB has all of the
Set Types assigned to it which will map all of the custom fields from ECC into the Product Master in
CRM. See Code below.

MAP_R3_TO_CRM_MATERIAL:
METHOD if_ex_product_customer2~map_r3_to_crm_material .
/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 15

Last Updated: 2/24/2011 10:24:00 AM

CONSTANTS:
on TYPE comt_boolean VALUE 'X',
off TYPE comt_boolean VALUE ' ',
gc_org_scenario_sales TYPE om_attrscn VALUE 'SALE'.
DATA:
ls_category_bdoc
TYPE comt_prod_cat_rel_maintain,
ls_category
TYPE comt_prod_cat_rel,
lt_categories
TYPE comt_prod_cat_rel_tab,
ls_settype
TYPE comt_settype_ext,
ls_cat_settype_rel
TYPE comt_cat_frag_rel,
lt_cat_settype_rel
TYPE comt_cat_frag_rel_tab,
lt_cat_settype_rel_all TYPE comt_cat_frag_rel_tab.
DATA: ls_marc TYPE /1crmg0/plant_object01,
ls_mvke TYPE /1crmg0/sales_area01.
DATA: ls_comm_category TYPE comm_category,
ls_comm_prprdcatr TYPE comm_prprdcatr.
*- get all categories related to the product from CRM online:
CALL FUNCTION 'COM_PROD_CAT_REL_READ_WITH_PR'
EXPORTING
iv_product_guid = cs_product_bdoc-header-com_product-product_guid
iv_update_buffer = space
IMPORTING
et_set
= lt_categories.
*- add all categories related to the product from BDOC:
LOOP AT cs_product_bdoc-header-categories INTO ls_category_bdoc.
MOVE-CORRESPONDING ls_category_bdoc-data TO ls_category.
READ TABLE lt_categories
WITH KEY hierarchy_guid = ls_category-hierarchy_guid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
MODIFY lt_categories FROM ls_category INDEX sy-tabix.
ELSE.
APPEND ls_category TO lt_categories.
ENDIF.
ENDLOOP.
LOOP AT lt_categories INTO ls_category.
*- get category set type relations:
CALL FUNCTION 'COM_CAT_FRAG_REL_READ'
EXPORTING
iv_category_guid = ls_category-category_guid
IMPORTING
et_cat_frag_rel = lt_cat_settype_rel
EXCEPTIONS
wrong_call
=1
OTHERS
= 2.
IF sy-subrc = 0.
APPEND LINES OF lt_cat_settype_rel TO lt_cat_settype_rel_all.
ENDIF.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM lt_cat_settype_rel_all.
/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 16

Last Updated: 2/24/2011 10:24:00 AM

*Getting the info into the Set Types.


DATA: ls_zprod_xport TYPE zprod_xport_maintain,
lv_mara
TYPE bapimatmra,
lv_marc
TYPE bapimatmrc,
is_other_info
TYPE bapiextc,
ls_com_mara
TYPE zprod_struct_mara.
*
ls_com_marc
TYPE zprod_struct_marc.
DATA: BEGIN OF ls_com_marc,
zmfrgr(8),
zladgr(4),
zvbamg(13),
zvrvez(7),
zvbeaz(7),
END OF ls_com_marc.

FIELD-SYMBOLS:
<source_x> TYPE x,
<target_x> TYPE x.
LOOP AT lt_cat_settype_rel_all INTO ls_cat_settype_rel.
* - read comc_settype record
CALL FUNCTION 'COM_SETTYPE_READ_SINGLE'
EXPORTING
iv_settype_guid = ls_cat_settype_rel-frgtype_guid
IMPORTING
es_settype
= ls_settype
EXCEPTIONS
not_found
=1
no_import_values = 2
no_text_found = 3.
IF sy-subrc NE 0 .
* - some message would go here...
CONTINUE.
ENDIF.
CASE ls_settype-frgtype_id.
WHEN 'ZPROD_XPORT'.
ls_zprod_xport-relation-owner = on.
ls_zprod_xport-relation-logsys =
cs_product_bdoc-header-com_product-logsys.
*Polutate MARA Fields
LOOP AT it_other_info INTO is_other_info
WHERE field1(20) = 'MARA'
AND field1+20(18) = is_mara-material.
ENDLOOP.
ASSIGN is_other_info-field2 TO <source_x> CASTING.
ASSIGN ls_com_mara
TO <target_x> CASTING.

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 17

Last Updated: 2/24/2011 10:24:00 AM

IF <source_x> IS ASSIGNED AND


<target_x> IS ASSIGNED.
<target_x> = <source_x>.
ELSE.
CONTINUE.
ENDIF.
ls_zprod_xport-data-zz0017 = ls_com_mara-ztragr.
ls_zprod_xport-data-zz0023 = ls_com_mara-zmagrv.
*Polutate MARC Fields
ASSIGN is_other_info-field3 TO <source_x> CASTING.
ASSIGN ls_com_marc
TO <target_x> CASTING.
IF <source_x> IS ASSIGNED AND
<target_x> IS ASSIGNED.
<target_x> = <source_x>.
ELSE.
CONTINUE.
ENDIF.
ls_zprod_xport-data-zz0016
ls_zprod_xport-data-zz0018
ls_zprod_xport-data-zz0019
ls_zprod_xport-data-zz0021
ls_zprod_xport-data-zz0022

=
=
=
=
=

ls_com_marc-zmfrgr.
ls_com_marc-zladgr.
ls_com_marc-zvbamg.
ls_com_marc-zvrvez.
ls_com_marc-zvbeaz.

APPEND ls_zprod_xport TO cs_product_bdoc-data-zprod_xport.


APPEND ls_settype-frgtype_id TO cs_product_bdoc-data-mnt_settype.
ENDCASE.
ENDLOOP.

Description of how the User Exit is accessed via standard SAP:


During the Create/Change of a Product Master the Method MAP_R3_TO_CRM_MATERIAL is called

Testing:
1. Create a new material in ECC.
2. BDOC is automatically created at time of save and sent to CRM.
3. Product is automatically created in CRM from BDOC.

Related OSS Notes:


/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 18

Last Updated: 2/24/2011 10:24:00 AM

495196

/var/www/apps/conversion/tmp/scratch_1/325980299.doc
Page 19

Last Updated: 2/24/2011 10:24:00 AM

Вам также может понравиться