This document explain how Automate the APO Master Data loading when materials are Ciffed from ECC to APO.
1- Introduction:
Most companies with large scale have installed specialized software to manage the supply chains. Companies typically spend thousand of USD to install supply chain planning modules.
However companies are disappointed in the return on their investments in these systems. The systems does not deliver the desired benefits of optimizing inventory and customer service levels. In extreme cases, business users may even reach a point where they don’t trust the planning system’s guidance and simply execute transactions according to their own ideas of what will work.
These kinds of failures are usually not due to inherent problems or lack of capability in the planning systems themselves. Rather, a likely cause of a supply chain planning system’s underperformance is a widespread problem in providing accurate inputs to make the system work well.
Due to the advanced planning methods in APO the APO master data is more extensive then ERP master data. Not all APO master data can be filled from ERP via CIF.
2- Enhancements APO Master Data Automation
In practice the APO-specific master data canfilled via customer specific programs.
There is a list of SAP APO and SAP ERP user exits that can be used to customize and facilitate the data transfer process via the core interface (CIF).
Master Data Exits/BAdIs — SAP APO:
3- Product Master Data Automation: BAdI: SMOD_APOCF005:
This is an example of a simple code to automate the Master Data of some fields.
In this code a custom table: zaposetup is defined and defaults values per location are entered in the custom table. Then this BAdI will look for the corresponding defaults in the custom table.
This BAdI work in APO side and will need to access ECC data in order to make some data validations. So here in this ABAP code you will see how APO can be conneted to ECC in ABAP. In the custom table we also entered which is the ECC system conected to the APO system.
METHOD if_ex_smod_apocf005~exit_/sapapo/saplcif_prod_001.
*----------------------------------------------------------------------*
* BADI SMOD_APOCF005 *
*----------------------------------------------------------------------*
********************************************************************
* PROGRAM DECLARATION
********************************************************************
* PROGRAM ID SMOD_APOCF005
* AUTHOR Mariano Cabalen
* R/3 RELEASE VERSION APO 7.0
* DESCRIPTION The user exit is used to default APO fields
* in the product masters in APO
***********************************************************************
* VERSION CONTROL (Most recent at bottom):
* DATE AUTHOR CTS REQ DESCRIPTION
************************************************************************
DATA: wa_it_matloc TYPE /sapapo/cif_matloc,
wa_it_matlocx TYPE /sapapo/cif_matlocx,
x_zvalue TYPE zaposetup-zvalue,
x_zoukey1 TYPE zaposetup-zoukey1,
ta_custom TYPE TABLE OF zaposetup,
wa_custom TYPE zaposetup.
DATA: ta_data TYPE TABLE OF tab512,
ta_fields TYPE TABLE OF rfc_db_fld,
ta_options TYPE TABLE OF rfc_db_opt,
wa_fields TYPE rfc_db_fld,
wa_data TYPE tab512,
wa_options TYPE rfc_db_opt,
ta_data1 TYPE TABLE OF tab512,
ta_fields1 TYPE TABLE OF rfc_db_fld,
ta_options1 TYPE TABLE OF rfc_db_opt,
wa_fields1 TYPE rfc_db_fld,
wa_data1 TYPE tab512,
wa_options1 TYPE rfc_db_opt,
ta_data2 TYPE TABLE OF tab512,
ta_fields2 TYPE TABLE OF rfc_db_fld,
ta_options2 TYPE TABLE OF rfc_db_opt,
wa_fields2 TYPE rfc_db_fld,
wa_data2 TYPE tab512,
wa_options2 TYPE rfc_db_opt,
x_tabix TYPE sy-tabix.
DATA: zmatnr(18) TYPE c.
DATA: zmatnr2(20) TYPE c.
DATA: zwerks2(6) TYPE c.
DATA: subcon(20) TYPE c.
DATA: zstrgr(2) TYPE c. " Planning strategy group
DATA: zmtart(4) TYPE c. " Material Type
DATA: zupdate(1) TYPE c.
DATA: zmatnr3(40) TYPE c.
DATA: zmatnr4(40) TYPE c.
DATA: zactiv1(1) TYPE c.
DATA: zactiv2(1) TYPE c.
DATA: xactiv1(1) TYPE c.
DATA: xactiv2(1) TYPE c.
CLEAR x_zoukey1.
SELECT SINGLE zoukey1
INTO x_zoukey1
FROM zaposetup
WHERE zprog EQ 'APOCF005'
AND zinkey1 EQ 'SYSTEM'.
IF NOT x_zoukey1 IS INITIAL AND sy-subrc EQ 0.
LOOP AT it_matloc INTO wa_it_matloc. " go through all materials
x_tabix = sy-tabix.
READ TABLE it_matlocx INTO wa_it_matlocx INDEX x_tabix. " read corresponding X table
REFRESH: ta_custom.
CLEAR: wa_custom.
SELECT zfield
INTO CORRESPONDING FIELDS OF TABLE ta_custom
FROM zaposetup
WHERE zprog EQ 'APOCF005'
AND locno EQ wa_it_matloc-ext_locno.
SORT ta_custom BY zfield.
DELETE ADJACENT DUPLICATES FROM ta_custom COMPARING zfield.
IF NOT ta_custom IS INITIAL.
* *** Start of Check ECC Fields not included in APO MAT1 structures....
REFRESH: ta_options, ta_fields, ta_data,
ta_options1, ta_fields1, ta_data1,
ta_options2, ta_fields2, ta_data2.
CLEAR: subcon, zstrgr, zmtart,
wa_options, wa_fields, wa_data,
wa_options1, wa_fields1, wa_data1,
wa_options2, wa_fields2, wa_data2.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_it_matloc-ext_matnr
IMPORTING
output = zmatnr.
CONCATENATE '''' zmatnr '''' INTO zmatnr2.
CONCATENATE '''' wa_it_matloc-ext_locno '''' INTO zwerks2.
IF NOT wa_it_matloc-ext_locno IS INITIAL.
CONCATENATE 'WERKS = ' zwerks2 INTO wa_options SEPARATED BY space.
CONCATENATE wa_options 'AND MATNR = ' zmatnr2 INTO wa_options SEPARATED BY space.
APPEND wa_options TO ta_options .
CLEAR wa_options.
ENDIF.
CONCATENATE 'MATNR = ' zmatnr2 INTO wa_options2 SEPARATED BY space.
APPEND wa_options2 TO ta_options2 .
CLEAR wa_options2.
wa_fields-fieldname = 'SOBSL'.
APPEND wa_fields TO ta_fields.
wa_fields1-fieldname = 'STRGR'.
APPEND wa_fields1 TO ta_fields1.
wa_fields2-fieldname = 'MTART'.
APPEND wa_fields2 TO ta_fields2.
*******Trigger BAPI to get data from ECC********
* Special Procurement Type
CALL FUNCTION 'RFC_READ_TABLE'
DESTINATION x_zoukey1
EXPORTING
query_table = 'MARC'
delimiter = ' '
no_data = ' '
rowskips = 0
rowcount = 1
TABLES
options = ta_options
fields = ta_fields
data = ta_data
EXCEPTIONS
table_not_available = 1
table_without_data = 2
option_not_valid = 3
field_not_valid = 4
not_authorized = 5
data_buffer_exceeded = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WRITE: 'RFC Read Error'.
ELSE.
LOOP AT ta_data INTO wa_data.
subcon = wa_data-wa.
ENDLOOP.
ENDIF.
*******Trigger BAPI to get data from ECC********
* Planning strategy group
CALL FUNCTION 'RFC_READ_TABLE'
DESTINATION x_zoukey1
EXPORTING
query_table = 'MARC'
delimiter = ' '
no_data = ' '
rowskips = 0
rowcount = 1
TABLES
options = ta_options
fields = ta_fields1
data = ta_data1
EXCEPTIONS
table_not_available = 1
table_without_data = 2
option_not_valid = 3
field_not_valid = 4
not_authorized = 5
data_buffer_exceeded = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WRITE: 'RFC Read Error'.
ELSE.
LOOP AT ta_data1 INTO wa_data1.
zstrgr = wa_data1-wa.
ENDLOOP.
ENDIF.
*******Trigger BAPI to get data from ECC********
* Material Type
CALL FUNCTION 'RFC_READ_TABLE'
DESTINATION x_zoukey1
EXPORTING
query_table = 'MARA'
delimiter = ' '
no_data = ' '
rowskips = 0
rowcount = 1
TABLES
options = ta_options2
fields = ta_fields2
data = ta_data2
EXCEPTIONS
table_not_available = 1
table_without_data = 2
option_not_valid = 3
field_not_valid = 4
not_authorized = 5
data_buffer_exceeded = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WRITE: 'RFC Read Error'.
ELSE.
LOOP AT ta_data2 INTO wa_data2.
zmtart = wa_data2-wa.
ENDLOOP.
ENDIF.
* *** End of Check ECC Fields not included in APO MAT1 structures....
CLEAR: zactiv1, zactiv2.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_it_matloc-ext_matnr
IMPORTING
output = zmatnr3.
SELECT SINGLE matnr
INTO zmatnr4
FROM /sapapo/v_matloc
WHERE matnr EQ zmatnr3
AND locno EQ wa_it_matloc-ext_locno.
* IF sy-subrc EQ 0 means that it is MM02
IF sy-subrc EQ 0.
zactiv2 = 'X'.
* ELSE means that it is MM01
ELSE.
zactiv1 = 'X'.
ENDIF.
LOOP AT ta_custom INTO wa_custom.
CLEAR: x_zvalue, xactiv1, xactiv2, zupdate.
SELECT SINGLE zvalue zactiv1 zactiv2
INTO (x_zvalue, xactiv1, xactiv2)
FROM zaposetup
WHERE zprog EQ 'APOCF005' AND locno EQ wa_it_matloc-ext_locno
AND zfield EQ wa_custom-zfield AND zinkey1 EQ wa_it_matloc-beskz
AND zinkey2 EQ subcon AND zinkey3 EQ zmtart
AND zinkey4 EQ zstrgr.
IF sy-subrc EQ 0.
zupdate = 'X'.
ELSE.
SELECT SINGLE zvalue zactiv1 zactiv2
INTO (x_zvalue, xactiv1, xactiv2)
FROM zaposetup
WHERE zprog EQ 'APOCF005' AND locno EQ wa_it_matloc-ext_locno
AND zfield EQ wa_custom-zfield AND zinkey1 EQ wa_it_matloc-beskz
AND zinkey2 EQ subcon AND zinkey3 EQ zmtart.
IF sy-subrc EQ 0.
zupdate = 'X'.
ELSE.
SELECT SINGLE zvalue zactiv1 zactiv2
INTO (x_zvalue, xactiv1, xactiv2)
FROM zaposetup
WHERE zprog EQ 'APOCF005' AND locno EQ wa_it_matloc-ext_locno
AND zfield EQ wa_custom-zfield AND zinkey1 EQ wa_it_matloc-beskz
AND zinkey2 EQ subcon.
IF sy-subrc EQ 0.
zupdate = 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zupdate = 'X'.
IF xactiv1 IS INITIAL AND xactiv2 IS INITIAL.
ELSE.
IF zactiv1 EQ xactiv1 OR zactiv2 EQ xactiv2.
CASE wa_custom-zfield.
WHEN 'BESKZ'. " WA_IT_MATLOC-BESKZ - Procurement Type
wa_it_matloc-beskz = x_zvalue.
wa_it_matlocx-beskz = 'X'.
WHEN 'SPREX'. " WA_IT_MATLOC-SPREX - Supply Profile
wa_it_matloc-sprex = x_zvalue.
wa_it_matlocx-sprex = 'X'.
WHEN 'DPREX'. " WA_IT_MATLOC-DPREX - Demand Profile
wa_it_matloc-dprex = x_zvalue.
wa_it_matlocx-dprex = 'X'.
WHEN 'DPLEX'. " WA_IT_MATLOC-DPLEX - Deployment Profile
wa_it_matloc-dplex = x_zvalue.
wa_it_matlocx-dplex = 'X'.
WHEN 'HEUR_ID'. " WA_IT_MATLOC-HEUR_ID - PPC Heuristics
wa_it_matloc-heur_id = x_zvalue.
wa_it_matlocx-heur_id = 'X'.
WHEN 'RQMKY'. " WA_IT_MATLOC-RQMKY - Requirements Profile
wa_it_matloc-rqmky = x_zvalue.
wa_it_matlocx-rqmky = 'X'.
WHEN 'GRPRT'. " WA_IT_MATLOC-GRPRT - Goods Receipt Processing Time
wa_it_matloc-grprt = x_zvalue.
wa_it_matlocx-grprt = 'X'.
WHEN 'RRP_TYPE'. " WA_IT_MATLOC-RRP_TYPE - PP Planning Procedure
wa_it_matloc-rrp_type = x_zvalue.
wa_it_matlocx-rrp_type = 'X'.
WHEN 'TARGET_METHOD'. " WA_IT_MATLOC-TARGET_METHOD - Target Stock Level Method
wa_it_matloc-target_method = x_zvalue.
wa_it_matlocx-target_method = 'X'.
WHEN 'TSTRID'. " WA_IT_MATLOC-TSTRID - Planning Calendar for Periodic Lot Sizing Procedure
wa_it_matloc-tstrid = x_zvalue.
wa_it_matlocx-tstrid = 'X'.
WHEN 'GIPRT'. " WA_IT_MATLOC-GIPRT - Goods Issue Processing Time
wa_it_matloc-giprt = x_zvalue.
wa_it_matlocx-giprt = 'X'.
WHEN 'PLIFZ'. " WA_IT_MATLOC-PLIFZ - Planned Delivery Time in Days
wa_it_matloc-plifz = x_zvalue.
wa_it_matlocx-plifz = 'X'.
WHEN 'PLANNER_SNP'. " WA_IT_MATLOC-PLANNER_SNP - SNP Planner
IF NOT x_zvalue IS INITIAL.
IF x_zvalue = 'PLANNER_PPS'.
wa_it_matloc-planner_snp = wa_it_matloc-planner_pps.
wa_it_matlocx-planner_snp = 'X'.
ELSE.
wa_it_matloc-planner_snp = x_zvalue.
wa_it_matlocx-planner_snp = 'X'.
ENDIF.
ENDIF.
ENDCASE.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
MODIFY it_matloc FROM wa_it_matloc.
MODIFY it_matlocx FROM wa_it_matlocx INDEX x_tabix.
CLEAR: wa_it_matlocx, wa_it_matloc.
ELSE.
ENDIF.
ENDLOOP.
ENDIF.
ENDMETHOD.
This is a view of the custom table ZAPOSETUP (some defaults were hidden because are specific definitions taken in one client).
Hope this can be usefull.
Thanks and Regards,
Mariano Cabalen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |