1、事务码
MSC1N、MSC2N、MSC3N
2、常用表
MCH1、MCHA、AUSP、MCH*开头的几个
3、批次
1、创建批次
BAPI:BAPI_BATCH_CREATE
2、修改批次
BAPI:BAPI_BATCH_CHANGE
3、删除批次
BAPI:BAPI_BATCH_DELETE
4、获取批次明细
BAPI:BAPI_BATCH_GET_DETAIL
5、查询物料的分类视图是否扩充
BAPI: BAPI_OBJCL_GETCLASSES
OBJECTKEY_IMP:物料号 带前导0
OBJECTTABLE_IMP MARA
CLASSTYPE_IMP 022
4、特性值
1、获取类别
CALL FUNCTION 'VB_BATCH_2_CLASS_OBJECT'
EXPORTING
I_MATNR = LS_DATA-MATNR
I_CHARG = LS_DATA-CHARG
I_WERKS = LS_DATA-WERKS
IMPORTING
E_OBJEK = LV_OBJEK
E_OBTAB = LV_OBTAB
E_KLART = LV_KLART
E_CLASS = LV_CLASS.
DATA:LV_OBJEK TYPE CUOBN,
LV_OBTAB TYPE TABELLE,
LV_KLART TYPE KLASSENART,
LV_CLASS TYPE KLASSE_D.
2、通过物料+批次获取表和类别
SELECT SINGLE CUOBJ_BM FROM MCH1 INTO @DATA(LV_BM)
WHERE MATNR EQ XXX
AND CHARG EQ XXX.
DATA:LV_OBJECTNAME LIKE BAPI1003_KEY-OBJECT,
LV_OBJECTTABLE LIKE BAPI1003_KEY-OBJECTTABLE,
LV_CLASSTYPE LIKE BAPI1003_KEY-CLASSTYPE,
RETURN LIKE TABLE OF BAPIRET2 WITH HEADER LINE.
CALL FUNCTION 'BAPI_OBJCL_GET_OBJECT_OF_KEY'
EXPORTING
CLOBJECTKEYIN = LV_BM
IMPORTING
OBJECTNAME = LV_OBJECTNAME
OBJECTTABLE = LV_OBJECTTABLE
CLASSTYPE = LV_CLASSTYPE
TABLES
RETURN = RETURN.
3、获取特性值明细
DATA:I_OBJEK TYPE BAPI1003_KEY-OBJECT,
I_OBTAB TYPE BAPI1003_KEY-OBJECTTABLE,
I_KLART TYPE BAPI1003_KEY-CLASSTYPE,
I_CLASS TYPE BAPI1003_KEY-CLASSNUM.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
OBJECTKEY = I_OBJEK
OBJECTTABLE = I_OBTAB
CLASSNUM = I_CLASS
CLASSTYPE = I_KLART
UNVALUATED_CHARS = 'X'
TABLES
ALLOCVALUESNUM = CLASSVALUATIONSNUM
ALLOCVALUESCHAR = CLASSVALUATIONSCHAR
ALLOCVALUESCURR = CLASSVALUATIONSCURR
RETURN = RETURN.
4、特性值修改
BAPI:BAPI_OBJCL_CHANGE
5、批量修改批次特性值
BAPI:BAPI_BATCH_SAVE_REPLICA
5、分类、特性值关系
根据分类别查KLAH表,KLAH-CLASS = 'XXX',获取内部等级号 CLINT
根据KLAH-CLINT = KSML-CLINT取得分类下所有的内部特性号 IMERK
根据KSML-IMERK = CABN-ATINN取得特性详细信息,CABNT是特性描述
6、批次对应物料特性值读取
VC_I_GET_CONFIGURATION
批次分类特性值读取函数
BAPI_OBJCL_GETDETAIL
物料特性 /
200 特性通过数据库取值
SELECTobjek "将分类的对象的键值atinn "内部特性atwrt "特性值atflv "内部浮点自klart "类别种类INTO TABLE gt_auspFROM auspINNER JOIN cabnON cabn~atinn = ausp~atinnWHERE objek = '000000000101004001'AND klart = '200'AND atnam = 'WG0078'. " 内部特性SORT gt_ausp BY objek atinn.READ TABLE gt_ausp INTO gs_auspWITH KEY objek = '000000000101004001'atinn = 'WG0078'BINARY SEARCH.IF sy-subrc = 0.CALL FUNCTION 'MC_FLTP_CHAR'EXPORTINGfc_a_fld = gs_ausp-atflvIMPORTINGfc_r_fld = gs_alv-wg0078.ENDIF.
通过 BAPI 取值
DATA: lv_matnr TYPE matnr,lv_object TYPE objnum,ls_alloclist TYPE bapi1003_alloc_list,lt_alloclist TYPE TABLE OF bapi1003_alloc_list,ls_return TYPE bapiret2,lt_return TYPE TABLE OF bapiret2,ls_allocvaluesnum TYPE bapi1003_alloc_values_num,lt_allocvaluesnum TYPE TABLE OF bapi1003_alloc_values_num,ls_allocvalueschar TYPE bapi1003_alloc_values_char,lt_allocvalueschar TYPE TABLE OF bapi1003_alloc_values_char,ls_allocvaluescurr TYPE bapi1003_alloc_values_curr,lt_allocvaluescurr TYPE TABLE OF bapi1003_alloc_values_curr,ls_retur2 TYPE bapiret2,lt_retur2 TYPE TABLE OF bapiret2.lv_object = lv_matnr. " 物料号带前置零CALL FUNCTION 'BAPI_OBJCL_GETCLASSES' " 可以通过 cl03 查看EXPORTINGobjectkey_imp = lv_object " 物料号objecttable_imp = 'MARA'classtype_imp = '200'TABLESalloclist = lt_alloclistreturn = lt_return.READ TABLE lt_alloclist INTO ls_alloclist INDEX 1.CALL FUNCTION 'BAPI_OBJCL_GETDETAIL' " 也可以用 claf_classification_of_objects 取值EXPORTINGobjectkey = lv_objectobjecttable = 'MARA'classnum = ls_alloclist-classnumclasstype = '200'TABLESallocvaluesnum = lt_allocvaluesnumallocvalueschar = lt_allocvaluescharallocvaluescurr = lt_allocvaluescurrreturn = lt_retur2.
通过 BAPI 创建特性
l_objectkeynew = l_matnr.l_objecttablenew = 'MARA'.l_classnumnew = ls_tmp-class.l_classtypenew = ls_tmp-klart.CLEAR: lt_numout,lt_charout,lt_returnout.CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'EXPORTINGobjectkey = l_objectkeynewobjecttable = l_objecttablenewclassnum = l_classnumnewclasstype = l_classtypenewTABLESallocvaluesnum = lt_numoutallocvalueschar = lt_charoutallocvaluescurr = lt_curroutreturn = lt_returnout.CLEAR ls_return.READ TABLE lt_returnout INTO ls_return WITH KEY type = 'E'.IF sy-subrc <> 0.CLEAR lt_returnout.CALL FUNCTION 'BAPI_OBJCL_DELETE' "删除已有分类EXPORTINGobjectkey = l_objectkeynewobjecttable = l_objecttablenewclassnum = l_classnumnewclasstype = l_classtypenew* CHANGENUMBER =* KEYDATE = SY-DATUMTABLESreturn = lt_returnout.CLEAR ls_return.READ TABLE lt_returnout INTO ls_return WITH KEY type = 'E'.IF sy-subrc = 0.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.MESSAGE e000 WITH '删除物料' l_objectkeynew '已有分类失败'.ELSE.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.ENDIF.ENDIF.LOOP AT gt_upload INTO gs_upload WHERE matnr = ls_tmp-matnr AND klart =ls_tmp-klart AND class = ls_tmp-class.CLEAR: ls_num, ls_char,l_atinn,l_atfor.CALL FUNCTION 'CONVERSION_EXIT_ATINN_INPUT'EXPORTINGinput = gs_upload-atnamIMPORTINGoutput = l_atinn.* SELECT SINGLE atfor FROM cabn INTO l_atfor WHERE atinn = l_atinn.READ TABLE lt_cabn INTO ls_cabn WITH KEY atinn = l_atinn.IF sy-subrc <> 0.MESSAGE e000 WITH '特性没有维护,请先维护特性!'.ENDIF.l_atfor = ls_cabn-atfor.IF gs_upload-atwrt IS NOT INITIAL.IF l_atfor = 'CHAR'.ls_char-charact = gs_upload-atnam.ls_char-charact_descr = gs_upload-atbez.ls_char-value_char = gs_upload-atwrt.APPEND ls_char TO lt_char.ELSEIF l_atfor = 'NUM'.ls_num-charact = gs_upload-atnam.ls_num-charact_descr = gs_upload-atbez.ls_num-value_from = gs_upload-atwrt.APPEND ls_num TO lt_num.ENDIF.ENDIF.ENDLOOP.CALL FUNCTION 'BAPI_OBJCL_CREATE'EXPORTINGobjectkeynew = l_objectkeynewobjecttablenew = l_objecttablenewclassnumnew = l_classnumnewclasstypenew = l_classtypenewstatus = '1'* standardclass =* changenumber =* KEYDATE = SY-DATUM* NO_DEFAULT_VALUES = ' '* IMPORTING* CLASSIF_STATUS =tablesallocvaluesnum = lt_numallocvalueschar = lt_char* ALLOCVALUESCURR =return = lt_return.CLEAR: l_type,l_info, ls_return.READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.IF sy-subrc = 0.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.CLEAR l_info.CALL FUNCTION 'MESSAGE_TEXT_BUILD'EXPORTINGmsgid = ls_return-idmsgnr = ls_return-numbermsgv1 = ls_return-message_v1msgv2 = ls_return-message_v2msgv3 = ls_return-message_v3msgv4 = ls_return-message_v4IMPORTINGmessage_text_output = l_info.l_type = 'E'.ELSE.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.l_type = 'S'.l_info = '物料主数据分类视图创建特性成功'.ENDIF.
物料批次特性 / 023 特性
通过数据库取值
SELECTmch1~matnr,mch1~charg,cabn~atnam,ausp~atwrt,ausp~atflvFROM mch1INNER JOIN auspON ausp~objek = mch1~cuobj_bmINNER JOIN cabnON cabn~atinn = ausp~atinnWHERE mch1~matnr = '000000000101004001'AND mch1~charg = '152200110'.
销售订单特性 / VC 特性 / 可配置物料特性 / 300 特性
通过数据库取值
SELECTvbap~vbeln,vbap~posnr,cabn~atinn,"内部特性cabn~atnam,"特性名称ibsymbol~atwrt,"特性值ibsymbol~atflv,ibsymbol~atflbINTO TABLE @DATA(gt_data)FROM vbapINNER JOIN ibinON ibin~instance = vbap~cuobjAND ibin~valto = '99991231235959'INNER JOIN ibinvaluesON ibinvalues~in_recno = ibin~in_recnoINNER JOIN ibsymbolON ibsymbol~symbol_id = ibinvalues~symbol_idINNER JOIN cabnON cabn~atinn = ibsymbol~atinnWHERE vbap~vbeln = '2000046612'AND vbap~posnr = '000010'.
通过 BAPI 取值
SELECT SINGLEcuobjmatnrINTO (l_cuobj,l_matnr)FROM vbapWHERE vbeln = w_mseg-kdaufAND posnr = w_mseg-kdpos.DATA: t_configuration LIKE STANDARD TABLE OF conf_out WITH HEADER LINE.IF l_cuobj IS NOT INITIAL.CALL FUNCTION 'VC_I_GET_CONFIGURATION'EXPORTINGinstance = l_cuobjlanguage = '1'iv_max_massprocessing = 10TABLESconfiguration = t_configuration.ENDIF.