1.维护字段组
事务代码OMSR
复制标准的字段组,将字段名修改为附加字段名
维护状态和ALE字段组可以用标准已存在的
本例为EDVKALBQPSZXCFG和GR_GLOB
使用复制功能将所有附加字段维护完毕,所有附加字段可以用同一个维护状态和ALE字段组
维护完毕如下:
字段组必须维护,本例为200
传输请求:
可按照字段组排序和按照字段组搜索,将需要传输的条目排列在一块
选中需要传输的条目
创建请求
点击包含在请求中
最后点击保存,才能将条目包含在请求中,这一点非常重要!!!
2.建立三个结构,用于承接数据和标记修改数据
由于BAPI传参每个字段长度为250位,当附加字段总长度超过250位之后,就需要多建立几个结构,本例字段较多,建立2个传参结构,注意所有字段类型必须是CHAR
标记修改的结构
3.函数BAPI_MATERIAL_MAINTAINDATA_RT传参
DATA:ls_fields1 TYPE zsmm0022.
DATA:ls_fields2 TYPE zsmm0024.
DATA:ls_fieldsx TYPE zsmm0023.
DATA:lt_clientext TYPE TABLE OF bapie1maraextrt,
ls_clientext TYPE bapie1maraextrt.
DATA:lt_clientextx TYPE TABLE OF bapie1maraextrtx,
ls_clientextx TYPE bapie1maraextrtx.
"增强字段
MOVE-CORRESPONDING iv_data TO ls_fields1.
MOVE-CORRESPONDING iv_data TO ls_fields2.
ls_clientext-function = c_bapifn.
ls_clientext-material = iv_data-matnr.
ls_clientext-field1 = ‘ZSMM0022’.
ls_clientext-field2 = ls_fields1.
ls_clientext-field3 = ls_fields2.
APPEND ls_clientext TO lt_clientext.
CLEAR:ls_clientext.
ls_clientextx-material = iv_data-matnr.
ls_clientextx-field1 = ‘ZSMM0023’.
PERFORM frm_fill_extx CHANGING ls_fieldsx.
ls_clientextx-field2 = ls_fieldsx.
APPEND ls_clientextx TO lt_clientextx.
CLEAR:ls_clientextx.
FORM frm_fill_extx CHANGING fc_fieldsx TYPE zsmm0023.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE fc_fieldsx
TO FIELD-SYMBOL(<fs_value>).
IF <fs_value> IS ASSIGNED.
<fs_value> = abap_true.
UNASSIGN:<fs_value>.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
4.CMOD增强
事务代码CMOD
新建项目
MGV00003
在包含文件ZXMGVU07编写代码,在f_clientext取出附加字段值,f_clientextx取出修改标记,根据修改标记对应字段值,更新到f_mara_ueb里对应字段即可。
完整代码如下:
DATA:ls_ext1 TYPE zsmm0022.
DATA:ls_ext2 TYPE zsmm0024.
DATA:ls_mara TYPE mara.
DATA:ls_extx TYPE zsmm0023.
DATA:lt_dfies_tab TYPE TABLE OF dfies.
IF f_clientext-field1 = ‘ZSMM0022’.
ls_ext1 = f_clientext-field2.
ls_ext2 = f_clientext-field3.
MOVE-CORRESPONDING ls_ext1 TO ls_mara.
MOVE-CORRESPONDING ls_ext2 TO ls_mara.
IF f_clientextx-field1 = ‘ZSMM0023’.
ls_extx = f_clientextx-field2.
CALL FUNCTION ‘DDIF_FIELDINFO_GET’
EXPORTING
tabname = ‘ZSMM0023’
TABLES
dfies_tab = lt_dfies_tab
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
"标记为X的字段修改为新值
LOOP AT lt_dfies_tab INTO DATA(ls_dfies_tab).
ASSIGN COMPONENT ls_dfies_tab-fieldname OF STRUCTURE ls_extx TO FIELD-SYMBOL(<fs_extx>).
IF <fs_extx> IS ASSIGNED.
IF <fs_extx> = 'X'.
ASSIGN COMPONENT ls_dfies_tab-fieldname OF STRUCTURE ls_mara TO FIELD-SYMBOL(<fs_new_value>).
IF <fs_new_value> IS ASSIGNED.
ASSIGN COMPONENT ls_dfies_tab-fieldname OF STRUCTURE f_mara_ueb TO FIELD-SYMBOL(<fs_old_value>).
IF <fs_old_value> IS ASSIGNED.
<fs_old_value> = <fs_new_value>.
UNASSIGN:<fs_old_value>.
ENDIF.
UNASSIGN:<fs_new_value>.
ENDIF.
ENDIF.
UNASSIGN:<fs_extx>.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.