背景:
创建生产订单工序时需要通过BAPI来维护外协加工页签上这些圈起来的字段,但是BAPI不包含这些字段,所以对BAPI进行一些增强处理。
实现过程:
1.拷贝标准BAPI:CO_SE_PRODORD_OPR_CREATE至ZCO_SE_PRODORD_OPR_CREATE(最好放在新的自定义函数组)。
2.追加增强结构至工序创建结构(为避免以后函数支持这些字段,故此处以ZZ开头)。
3.传入参数映射到标准结构的处理在这个LOOP中,所以创建自己的逻辑来检查mapping即可。
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_CUSTOM_FIELDS
*&---------------------------------------------------------------------*
* 增强字段检查映射
*----------------------------------------------------------------------*
* -->us_opr_create 工序创建结构
*----------------------------------------------------------------------*
FORM frm_check_custom_fields USING us_opr_create TYPE cose_s_opr_create.
DATA:
lv_msgv1 TYPE symsgv,
lv_msgv2 TYPE symsgv,
lv_msgv3 TYPE symsgv,
lv_msgv4 TYPE symsgv.
* 供应商
IF us_opr_create-zzlifnr IS NOT INITIAL.
CALL FUNCTION 'LFA1_SINGLE_READ'
EXPORTING
lfa1_lifnr = us_opr_create-zzlifnr
* KZRFB = ' '
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
lv_msgv1 = us_opr_create-zzlifnr.
* Creditor &1 does not exist
PERFORM error_handling USING gs_caufvd-aufnr gc_error_msg
'LOCORE' '026'
lv_msgv1 space space space
CHANGING gs_return.
EXIT.
ELSE.
IF gs_afvgd-lifnr IS INITIAL.
gs_afvgd-lifnr = us_opr_create-zzlifnr.
ENDIF.
ENDIF.
ENDIF.
* 价格
IF us_opr_create-zzpreis IS NOT INITIAL.
IF gs_afvgd-preis IS INITIAL.
gs_afvgd-preis = us_opr_create-zzpreis.
ENDIF.
ENDIF.
* 价格单位
IF us_opr_create-zzpeinh IS NOT INITIAL.
IF gs_afvgd-peinh IS INITIAL.
gs_afvgd-peinh = us_opr_create-zzpeinh.
ENDIF.
ENDIF.
* 货币码
IF us_opr_create-zzwaers IS NOT INITIAL.
CALL FUNCTION 'READ_TCURC'
EXPORTING
i_waers = us_opr_create-zzwaers
* IMPORTING
* E_TCURC =
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
lv_msgv1 = us_opr_create-zzwaers.
* Currency key & is not included
PERFORM error_handling USING gs_caufvd-aufnr gc_error_msg
'KO' '087'
lv_msgv1 space space space
CHANGING gs_return.
EXIT.
ELSE.
IF gs_afvgd-waers IS INITIAL.
gs_afvgd-waers = us_opr_create-zzwaers.
ENDIF.
ENDIF.
ENDIF.
* 成本元素
IF us_opr_create-zzsakto IS NOT INITIAL.
CALL FUNCTION 'READ_HAUPTBUCH'
EXPORTING
buchungskreis = gs_caufvd-bukrs
sachkonto = us_opr_create-zzsakto
* AUTH_CHECK_ACTIVITY = ' '
* IMPORTING
* KONTENPLAN_WA =
* SACHKONTO_WA =
EXCEPTIONS
kontenplan_not_found = 1
sachkonto_not_found = 2
not_authorized = 3
OTHERS = 4.
IF sy-subrc <> 0.
lv_msgv1 = us_opr_create-zzsakto.
* Cost element &1 is not found (check entry)
PERFORM error_handling USING gs_caufvd-aufnr gc_error_msg
'CO' '862'
lv_msgv1 space space space
CHANGING gs_return.
EXIT.
ELSE.
IF gs_afvgd-sakto IS INITIAL.
gs_afvgd-sakto = us_opr_create-zzsakto.
ENDIF.
ENDIF.
ENDIF.
* 采购组织
IF us_opr_create-zzekorg IS NOT INITIAL.
SELECT SINGLE * FROM t024e WHERE ekorg = us_opr_create-zzekorg.
IF sy-subrc <> 0.
lv_msgv1 = us_opr_create-zzekorg.
lv_msgv4 = 'T024E'.
* Entry & & & does not exist in &4 (check entry)
PERFORM error_handling USING gs_caufvd-aufnr gc_error_msg
'00' '058'
lv_msgv1 space space lv_msgv4
CHANGING gs_return.
EXIT.
ELSE.
IF gs_afvgd-ekorg IS INITIAL.
gs_afvgd-ekorg = us_opr_create-zzekorg.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " FRM_CHECK_CUSTOM_FIELDS
完整以上改动,调用新的BAPI即可进行更新。
以上,即可通过BAPI来写入自己想更新的字段。