1.物料主數據
1.1創建/擴展物料主數據:
1.1.1 除分類視圖和檢驗視圖的創建和擴展
CALL FUNCTION ‘BAPI_MATERIAL_SAVEDATA’
EXPORTING
HEADDATA = IS_HEADER
CLIENTDATA = IS_MARA
CLIENTDATAX = IS_MARAX
PLANTDATA = IS_MARC
PLANTDATAX = IS_MARCX
STORAGELOCATIONDATA = IS_MARD
STORAGELOCATIONDATAX = IS_MARDX
VALUATIONDATA = IS_MBEW
VALUATIONDATAX = IS_MBEWX
SALESDATA = IS_MVKE
SALESDATAX = IS_MVKEX
IMPORTING
RETURN = OS_RETURN
TABLES
MATERIALDESCRIPTION = IT_MAKT
UNITSOFMEASURE = IT_MARM
UNITSOFMEASUREX = IT_MARMX
MATERIALLONGTEXT = IT_TEXT
TAXCLASSIFICATIONS = IT_MLAN
RETURNMESSAGES = OT_LOG.
1.1.2 分類視圖的創建和擴展
CALL FUNCTION ‘BAPI_OBJCL_CREATE’
EXPORTING
OBJECTKEYNEW = ZOBJCT
OBJECTTABLENEW = ‘MARA’
CLASSNUMNEW = IS_OBJECT-CLASSNUMNEW
CLASSTYPENEW = IS_OBJECT-CLASSTYPENEW
STATUS = ‘1’
KEYDATE = SY-DATUM
IMPORTING
CLASSIF_STATUS = EP_CLASSIF_STATUS
TABLES
RETURN = TAB_LOG1.
1.1.3 檢驗視圖的創建和擴展
CALL FUNCTION ‘BAPI_MATINSPCTRL_SAVEREPLICA’
TABLES
RETURN = TAB_LOG
INSPECTIONCTRL = IT_QMAT.
1.2 顯示物料主數據
1.2.1 主要的數據可直接查詢表MARA,MARC,MARD,MVKE,MARM,MLAN,MAKT,QMAT,MBEW;
1.2.2 分類視圖的顯示
CALL FUNCTION ‘CLAF_CLASSIFICATION_OF_OBJECTS’
EXPORTING
class = ‘BATCH’
classtext = ‘X’
classtype = ‘023’
language = sy-langu
object = p_object
objecttable = ‘MARA’
key_date = sy-datum
initial_charact = ‘X’
TABLES
t_class = et_class
t_objectdata = et_objectdata
EXCEPTIONS
no_classification = 1
no_classtypes = 2
invalid_class_type = 3
OTHERS = 4.
1.2.3 文本的讀取
CALL FUNCTION ‘READ_TEXT’
1.3 修改物料主數據(除修改分類視圖調用的函數不一樣外其餘相同)
CALL FUNCTION ‘BAPI_OBJCL_CHANGE’
EXPORTING
objectkey = zobjct
objecttable = is_object-objecttablenew”‘MARA’
classnum = is_object-classnumnew”‘BATCH’
classtype = is_object-classtypenew “‘023’
status = ‘1’
keydate = sy-datum
IMPORTING
classif_status = ep_classif_status
TABLES
allocvaluesnumnew = it_allocvaluesnum
allocvaluescharnew = it_allocvalueschar
allocvaluescurrnew = it_allocvaluescurr
return = tab_log1.
1.4 刪除、解除刪除物料主數據
CALL FUNCTION ‘BAPI_MATERIAL_SAVEDATA’
EXPORTING
headdata = is_mathead
clientdata = is_mara
clientdatax = is_marax
plantdata = is_marc
plantdatax = is_marcx
salesdata = is_mvke
salesdatax = is_mvkex
IMPORTING
return = os_log
TABLES
returnmessages = ot_log.
1.5 物料修改記錄的查詢
CALL FUNCTION ‘CHANGEDOCUMENT_READ’
EXPORTING
objectclass = ‘MATERIAL’
objectid = ip_matnr
TABLES
editpos = ot_positions
EXCEPTIONS
no_position_found = 1
wrong_access_to_archive = 2
time_zone_conversion_error = 3
OTHERS = 4.
1.6 修改物料類型:使用BDC即可
1.7 查詢物料的諸多單位
1.7.1 主要數據可直接查詢表MARA,MARM表
單位相關表
T006 計量單位
T006_OIB 計量單位,附加定義
T006A 分配內部到語言相關單位
(內部單位轉換到外部貿易、技術單位用T006A表,比如要顯示CAR則把數據庫中的KAR在次表中轉換)
T006B 貿易分配到內部測量單位
( 外部貿易單位和轉換到內部單位就是用T006B表,比如 PC轉到ST,CAR轉到KAR等)
T006C 外部技術到內部測量單位的分配
T006D 尺寸
T006D_OIB 附加維數
T006E 計量單位系統(組件,映射)
T006EE 計量單位系統(實用程序)
T006ET 計量單位系統(使用程序 -> 文
T006I 計量單位的 ISO 代碼
T006J ISO 測量文本單位碼
T006M 計量單位組
T006T 維數文本…
1.7.2 單位轉換
1.7.2.1轉換爲外部格式
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_OUTPUT’
EXPORTING
input =
IMPORTING
output =
1.7.2.1轉換爲內部格式
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_INPUT’
EXPORTING
input =
IMPORTING
output =
1.7.2.2 物料數量不同單位的轉換
CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT’
EXPORTING
I_MATNR = IOMAMO_TAB-MATNR
I_IN_ME = IOMAMO_TAB-ERFME
I_OUT_ME = ‘KG’
I_MENGE = IOMAMO_TAB-ERFMG
IMPORTING
E_MENGE = IOMAMO_TAB-ERFMG
EXCEPTIONS
ERROR_IN_APPLICATION = 1
ERROR = 2
OTHERS = 3.
1.7.2.3 物料基本計量單位轉換爲其他單位
CALL FUNCTION ‘MATERIAL_UNIT_CONVERSION’
________________________________________
2 庫存需求查詢
CALL FUNCTION ‘MD_STOCK_REQUIREMENTS_LIST_API’
EXPORTING
matnr = ip_matnr
werks = ip_werks
IMPORTING
e_mdsta = os_mdsta
TABLES
mdezx = ot_mdezx
EXCEPTIONS
material_plant_not_found = 1
plant_not_found = 2
OTHERS = 3.
________________________________________
3 物料庫存查詢:通過標準程序RMMMBESTN做 SET PARAMETER ID XXXX FIELD XXXXX在RFC內接GET即可.
________________________________________
4 生產訂單
4.1 創建生產訂單
CALL FUNCTION ‘BAPI_PRODORD_CREATE’
EXPORTING
ORDERDATA = ORDERDATA
IMPORTING
RETURN = RETURN
ORDER_NUMBER = ORDER_NUMBER.
4.2 修改生產訂單
CALL FUNCTION ‘BAPI_PRODORD_CHANGE’ “訂單數量和交貨數量未判斷
EXPORTING
NUMBER = IS_ORDER-AUFNR
ORDERDATA = ORDERDATA
ORDERDATAX = ORDERDATAX
IMPORTING
RETURN = RETURN.
4.3 顯示生產訂單
CALL FUNCTION ‘BAPI_PRODORD_GET_DETAIL’ “根據實際情況調整輸出信息
EXPORTING
NUMBER = IP_AUFNR
ORDER_OBJECTS = ORDER_OBJECTS
TABLES
HEADER = HEADER
OPERATION = OPERATION
PROD_REL_TOOL = PROD_REL_TOOL.
________________________________________
5.工程更改號
5.1創建、修改、刪除工程更改號
CALL FUNCTION ‘CCAP_ECN_MAINTAIN’ “根據實際情況調整輸入信息
EXPORTING
CHANGE_HEADER = CHANGE_HEADER
OBJECT_BOM = OBJECT_BOM
OBJECT_DOC = OBJECT_DOC
OBJECT_TLIST = OBJECT_TLIST
IMPORTING
CHANGE_NO = CHANGE_NO
EXCEPTIONS
CHANGE_NO_ALREADY_EXISTS = 1
ERROR = 2.
5.2 顯示工程更改號,查詢表 AENR , AENV即可
5.3 工程更改號有效期
CALL FUNCTION ‘CC_CHANGE_NUMBER_READ’
EXPORTING
EAENNR = IS_ZRFC_S_PP005-AENNR
IMPORTING
ADATUV = ADATUV_X
EXCEPTIONS
NO_RECORD_FOUND = 1
OTHERS = 2.
________________________________________
6 BOM
6.1 初始化API
CALL FUNCTION ‘CALO_INIT_API’.
6.2 創建BOM
CALL FUNCTION ‘CSAP_MAT_BOM_MAINTAIN’
EXPORTING
MATERIAL = IS_ZRFC_S_PP001-MATNR
PLANT = IS_ZRFC_S_PP001-WERKS
BOM_USAGE = IS_ZRFC_S_PP001-STLAN
ALTERNATIVE = IS_ZRFC_S_PP001-STLAL
CHANGE_NO = IS_ZRFC_S_PP001-AENNR
I_STKO = I_STKO
FL_NO_CHANGE_DOC = ‘ ‘
FL_COMMIT_AND_WAIT = ‘X’
FL_CAD = ‘ ‘
FL_BOM_CREATE = ‘X’
FL_NEW_ITEM = ‘X’
FL_COMPLETE = ‘X’
FL_DEFAULT_VALUES = ‘X’
FL_IDENTIFY_BY_GUID = ‘ ‘
IMPORTING
FL_WARNING = FL_WARNING
O_STKO = O_STKO
TABLES
T_STPO = T_STPO
EXCEPTIONS
ERROR = 1
OTHERS = 2.
6.3 拷貝日誌
CALL FUNCTION ‘CALO_MSG_APPEND_DB_LOG’
EXCEPTIONS
LOG_OBJECT_NOT_FOUND = 1
LOG_SUBOBJECT_NOT_FOUND = 2
LOG_INTERNAL_ERROR = 3
OTHERS = 4.
6.4 讀取日誌
CALL FUNCTION ‘CALO_LOG_READ_MESSAGES’
TABLES
MESSAGES_AND_PARAMETERS = LT_MESSAGES
EXCEPTIONS
OTHERS = 1.
6.5 修改、刪除BOM
“修改時 IS_ZRFC_S_PP003-ITEM_GUID+ IS_ZRFC_S_PP003-ITEM_NO 爲項目唯一標示
“文本相關:擡頭長文本 OBJECT_ID = ‘0’,可選長文本 OBJECT_ID = ‘1’ 各需添加一行空行;行項目長文本OBJECT_ID = ‘2’,每個行項目文本需添加兩行空行
CALL FUNCTION ‘CSAP_MAT_BOM_MAINTAIN’
EXPORTING
MATERIAL = IS_ZRFC_S_PP004-MATNR
PLANT = IS_ZRFC_S_PP004-WERKS
BOM_USAGE = ‘1’
ALTERNATIVE = ‘1’
FL_NEW_ITEM = ‘X’
CHANGE_NO = IS_ZRFC_S_PP004-AENNR
I_STKO = TSTK1
IMPORTING
FL_WARNING = FLG_WARNING
O_STKO = TSTK2
TABLES
T_STPO = TSTP3
T_LTX_LINE = IS_LTX_LINE
EXCEPTIONS
OTHERS = 1.
6.6 讀取BOM(修改時調用)
CALL FUNCTION ‘CSAP_MAT_BOM_OPEN’
EXPORTING
MATERIAL = IS_ZRFC_S_PP005-MATNR
PLANT = IS_ZRFC_S_PP005-WERKS
BOM_USAGE = IS_ZRFC_S_PP005-STLAN
ALTERNATIVE = IS_ZRFC_S_PP005-STLAL
VALID_FROM = DATUV
CHANGE_NO = IS_ZRFC_S_PP005-AENNR
IMPORTING
O_STKO = STKO1
TABLES
T_STPO = OT_STPO
EXCEPTIONS
ERROR = 1
OTHERS = 2.
6.7 讀取BOM(顯示)
CALL FUNCTION ‘CSAP_MAT_BOM_READ’
EXPORTING
MATERIAL = IS_ZRFC_S_PP005-MATNR
PLANT = IS_ZRFC_S_PP005-WERKS
BOM_USAGE = IS_ZRFC_S_PP005-STLAN
ALTERNATIVE = IS_ZRFC_S_PP005-STLAL
VALID_FROM = DATUV
CHANGE_NO = IS_ZRFC_S_PP005-AENNR
TABLES
T_STPO = OT_STPO1
T_LTX_LINE = OT_LTX_LINE
EXCEPTIONS
ERROR = 1
OTHERS = 2.
6.8 BOM更改記錄
CONCATENATE : SY-MANDT ‘M’ OT_STKO-BOM_NO INTO OBJECTID.
CALL FUNCTION ‘CHANGEDOCUMENT_READ’
EXPORTING
OBJECTCLASS = ‘STUE’
OBJECTID = OBJECTID
DATE_UNTIL = ‘99991231’
TIME_UNTIL = ‘235959’
TABLES
EDITPOS = OT_EDITPOS
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
TIME_ZONE_CONVERSION_ERROR = 3
OTHERS = 4.
6.9 BOM多層展開
CALL FUNCTION ‘CS_BOM_EXPL_MAT_V2’
EXPORTING
altvo = ‘ ‘
aufsw = ‘ ‘
auskz = ‘ ‘
bagrp = ‘ ‘
beikz = ‘ ‘
bessl = ‘ ‘
brems = ‘ ‘
capid = is_zrfc_s_pp008-capid
datuv = is_zrfc_s_pp008-datuv
drldt = ‘ ‘
ehndl = ‘1’
erskz = ‘ ‘
erssl = ‘ ‘
mtnrv = is_zrfc_s_pp008-matnr
mehrs = ‘X’ “多層
mmory = ‘1’
stlal = is_zrfc_s_pp008-stlal
stlan = ‘1’
werks = is_zrfc_s_pp008-werks
aumgb = ‘X’
IMPORTING
topmat = topmat
TABLES
stb = stb
matcat = matcat
EXCEPTIONS
alt_not_found = 1
call_invalid = 2
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
no_plant_data = 6
no_suitable_bom_found = 7
conversion_error = 8
OTHERS = 9.
6.10 BOM使用位置清單
CALL FUNCTION ‘CS_WHERE_USED_MAT’
EXPORTING
DATUB = SY-DATUM
DATUV = SY-DATUM
MATNR = ZIDNRK
WERKS = ZWERKS
IMPORTING
TOPMAT = TOPMAT
TABLES
WULTB = WULTB
EQUICAT = EQUICAT
KNDCAT = KNDCAT
MATCAT = MATCAT
STDCAT = STDCAT
TPLCAT = TPLCAT
PRJCAT = PRJCAT
EXCEPTIONS
CALL_INVALID = 1
MATERIAL_NOT_FOUND = 2
NO_WHERE_USED_REC_FOUND = 3
NO_WHERE_USED_REC_SELECTED = 4
NO_WHERE_USED_REC_VALID = 5
OTHERS = 6.
________________________________________
7 工藝路線
7.1 創建修改工藝路線,使用BDC
7.2 查詢物料的工藝路線
CALL FUNCTION ‘CP_SE_ALT_READ_BY_MAT’
EXPORTING
kunr_max = ”
kunr_min = ”
lifnr_max = ”
lifnr_min = ”
matnr = is_zrfc_s_pp017-matnr
plnal_max = ”
plnal_min = ”
plnme = ”
plnnr = ”
plnty_max = ”
plnty_min = ‘N’
statu = ”
aennr = is_zrfc_s_pp017-aennr
sttag = is_zrfc_s_pp017-sttag
werks_mat = is_zrfc_s_pp017-werks
TABLES
mapl_exp = mapl_exp
plko_exp = plko_exp
EXCEPTIONS
not_found = 1
OTHERS = 2.
CALL FUNCTION ‘CARO_ROUTING_READ’
EXPORTING
date_from = date_from
date_to = date_from
plnty = ot_zrfc_s_pp018-plnty
plnnr = ot_zrfc_s_pp018-plnnr
plnal = ot_zrfc_s_pp018-plnal
matnr = is_zrfc_s_pp017-matnr
buffer_del_flg = ‘X’
delete_all_cal_flg = ‘X’
adapt_flg = ‘X’
iv_create_add_change = ‘ ‘
TABLES
tsk_tab = tsk_tab
seq_tab = seq_tab
opr_tab = opr_tab
com_tab = com_tab
EXCEPTIONS
not_found = 1
ref_not_exp = 2
not_valid = 3
OTHERS = 4.