接口中实现CU41创建物料配置
开发测试过程中的问题:
1.在中文语言下,创建时不传入当前语言(或固定语言)时,创建成功,但是在VA01进行特性分配时显示的特性跟当前语言的不一致
2.执行后没有明确的报错,只能通过sy-subrc <> 0 ,判断错误,读取错误消息
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
INTO DATA(mtext)
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
但错误也不明确。
3.执行出来的结果和前台执行的结果,在CUCO表上有不一致的(有些值是X,前台执行是空),还不知道是哪里的问题。
代码如下:
"CU41 配置物料
SELECT SINGLE * INTO @DATA(ls_cuco)
FROM cuco
WHERE objek = @i_material-matnr
.
IF sy-subrc NE 0.
DATA:con_object_key LIKE STANDARD TABLE OF object_key WITH HEADER LINE,
con_pro_attributes LIKE STANDARD TABLE OF cpro_attr WITH HEADER LINE,
con_pro_dependency_descr LIKE STANDARD TABLE OF cpdep_desc WITH HEADER LINE.
CALL FUNCTION 'CALO_INIT_API'.
con_object_key-key_feld = 'MATNR'.
con_object_key-kpara_valu = i_material-matnr.
APPEND con_object_key.
CLEAR con_object_key.
con_pro_attributes-c_profile = i_material-klasse.
con_pro_attributes-classtype = '300'.
con_pro_attributes-status = '1'.
con_pro_attributes-prio = '10'.
con_pro_attributes-neutr = '2'.
APPEND con_pro_attributes.
CLEAR con_pro_attributes.
con_pro_dependency_descr-language = '1'.
APPEND con_pro_dependency_descr.
CLEAR con_pro_dependency_descr.
CALL FUNCTION 'CAMA_CON_PROFILE_MAINTAIN'
EXPORTING
object_type = 'MARA'
TABLES
con_object_key = con_object_key
con_pro_attributes = con_pro_attributes
con_pro_dependency_descr = con_pro_dependency_descr
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ls_return1-type = 'E'.
ELSE.
ls_return1-type = 'S'.
COMMIT WORK AND WAIT.
ENDIF.
ls_return1-id = 24.
CONCATENATE i_material-matnr '创建物料配置结果' INTO ls_return1-message.
APPEND ls_return1 TO it_return.
ENDIF.
CU41相关性
相关性的内容,没找到怎么写进去,上面的方法里也有相关性的内容,查资料没查到,尝试把内容填进去,也没效果。
最后,找到祖传代码里有关工艺路线的相关性,尝试了一下可以用。
上面,方法:CAMA_CON_PROFILE_MAINTAIN中,
字段 fl_sc_dep 需要设置。
fl_sc_dep = 'X'.
"获取分类特性
CALL FUNCTION 'BAPI_CLASS_GETDETAIL'
EXPORTING
classtype = '300'
classnum = 'BM'
IMPORTING
return = ls_return
TABLES
classdescriptions = lt_classdescriptions
classlongtexts = lt_classlongtexts
classcharacteristics = lt_classcharacteristics "特性
classcharvalues = lt_classcharvalues.
"获取特性对应的内部号
SELECT knnam,knnum INTO TABLE @DATA(lt_cukb)
FROM cukb
FOR ALL ENTRIES IN @lt_classcharacteristics
WHERE knnam = @lt_classcharacteristics-name_char.
SORT lt_cukb BY knnam.
"获取 具有分配相关性的对象编号
CALL FUNCTION 'CUKD_GET_EARLY_ALLOC_NUMBER' IMPORTING ev_allocation_number = lv_knobj.".
"将对应的值填进去。
LOOP AT lt_classcharacteristics INTO DATA(ls_classcharacteristics) WHERE no_display <> 'X'.
READ TABLE lt_cukb INTO DATA(ls_cukb) WITH KEY knnam = ls_classcharacteristics-name_char BINARY SEARCH.
IF sy-subrc EQ 0.
ls_cuob-knobj = lv_knobj.
ls_cuob-kntab = 'CUCO'.
ls_cuob-knnum = ls_cukb-knnum.
ls_cuob-knmod = 'N'.
APPEND ls_cuob TO lt_cuob_tab.
ENDIF.
ENDLOOP.
"执行方法,直接把内容加到表里
CALL FUNCTION 'CUVB_MODIFY_ALLOCATIONS' TABLES cuob_tab = lt_cuob_tab .
CLEAR lt_cuob_tab.
"查询cuco对应的值。
SELECT SINGLE * INTO @DATA(ls_cuco)
FROM cuco
WHERE objek = @con_object_key-kpara_valu.
"modify 表
ls_cuco-knobj = ls_cuob-knobj.
MODIFY cuco FROM ls_cuco.
COMMIT WORK.
相关性对应的表
cuco,cuob,cukb.
cuco-KNOBJ = cuob-KNOBJ
cuob-KNNUM = cukb-KNNUM
注意,CUOB表有个表ID字段(KNTAB),具有分配相关性的对象编号(knobj),不同的表可能是不一样的