背景:
创建生产订单工序时需要通过BAPI来维护圈起来的字段,但是BAPI不包含这些字段,所以对BAPI进行一些增强处理。
实现过程:
1.拷贝标准BAPI:CO_SE_PRODORD_OPR_CREATE至ZCO_SE_PRODORD_OPR_CREATE(最好放在新的自定义函数组)。
2.追加增强结构至工序创建结构(为避免以后函数支持这些字段,故此处以ZZ开头)。
3.传入参数mapping到标准结构的处理在这个form中,所以创建自己的逻辑来检查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'EXPORTINGlfa1_lifnr = us_opr_create-zzlifnr
* KZRFB = ' 'EXCEPTIONSnot_found = 1OTHERS = 2.IF sy-subrc <> 0.lv_msgv1 = us_opr_create-zzlifnr.* Creditor &1 does not existPERFORM error_handling USING gs_caufvd-aufnr gc_error_msg'LOCORE' '026'lv_msgv1 space space spaceCHANGING 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'EXPORTINGi_waers = us_opr_create-zzwaers
* IMPORTING
* E_TCURC =EXCEPTIONSnot_found = 1OTHERS = 2.IF sy-subrc <> 0.lv_msgv1 = us_opr_create-zzwaers.* Currency key & is not includedPERFORM error_handling USING gs_caufvd-aufnr gc_error_msg'KO' '087'lv_msgv1 space space spaceCHANGING 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'EXPORTINGbuchungskreis = gs_caufvd-bukrssachkonto = us_opr_create-zzsakto
* AUTH_CHECK_ACTIVITY = ' '
* IMPORTING
* KONTENPLAN_WA =
* SACHKONTO_WA =EXCEPTIONSkontenplan_not_found = 1sachkonto_not_found = 2not_authorized = 3OTHERS = 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 spaceCHANGING 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_msgv4CHANGING 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来写入自己想更新的字段。