导入
IV_BUKRS TYPE BUKRS 公司代码
IV_ANLKL TYPE ANLKL 资产分类
IV_TXT50 TYPE TXA50_ANLT 资产描述
IV_TXA50 TYPE TXA50_MORE 附加资产描述
IV_ANLHTXT TYPE ANLHTXT 资产主号说明
IV_MEINS TYPE MEINS 基本计量单位
IV_MENGE TYPE MENGE_D 数量
IV_KOSTL TYPE KOSTL 成本中心
IV_KOSTLV TYPE KOSTLV 成本中心对资产负责
IV_SERNR TYPE AM_SERNR 序列号
IV_INVNR TYPE INVNR_ANLA 存货号
IV_INVZU TYPE INVZU_ANLA 补充库存说明
IV_AUFNR TYPE AUFNR 订单号
IV_ASSET TYPE BF_ANLN1 主资产号
导出
EV_ASSET TYPE BF_ANLN1 主资产号
EV_STATUS TYPE CHAR1 状态
EV_MESSAGE TYPE CHAR100 描述
FUNCTION zfm_create_zg.
*“----------------------------------------------------------------------
"“本地接口:
*” IMPORTING
*” VALUE(IV_BUKRS) TYPE BUKRS OPTIONAL
*" VALUE(IV_ANLKL) TYPE ANLKL OPTIONAL
*" VALUE(IV_TXT50) TYPE TXA50_ANLT OPTIONAL
*" VALUE(IV_TXA50) TYPE TXA50_MORE OPTIONAL
*" VALUE(IV_ANLHTXT) TYPE ANLHTXT OPTIONAL
*" VALUE(IV_MEINS) TYPE MEINS OPTIONAL
*" VALUE(IV_MENGE) TYPE MENGE_D OPTIONAL
*" VALUE(IV_KOSTL) TYPE KOSTL OPTIONAL
*" VALUE(IV_KOSTLV) TYPE KOSTLV OPTIONAL
*" VALUE(IV_SERNR) TYPE AM_SERNR OPTIONAL
*" VALUE(IV_INVNR) TYPE INVNR_ANLA OPTIONAL
*" VALUE(IV_INVZU) TYPE INVZU_ANLA OPTIONAL
*" VALUE(IV_AUFNR) TYPE AUFNR OPTIONAL
*" VALUE(IV_ASSET) TYPE BF_ANLN1 OPTIONAL
*" EXPORTING
*" VALUE(EV_ASSET) TYPE BF_ANLN1
*" VALUE(EV_STATUS) TYPE CHAR1
*" VALUE(EV_MESSAGE) TYPE CHAR100
*"----------------------------------------------------------------------
*(修改日志)--------------------------------------------------------
*
IF iv_asset IS INITIAL.
"创建资产卡片
PERFORM frm_create_anln1 USING iv_bukrs "公司代码
iv_anlkl "资产分类
iv_txt50 "资产描述
iv_txa50 "附加资产描述
iv_anlhtxt "资产主号说明
iv_meins "基本计量单位
iv_menge "数量
iv_kostl "成本中心
iv_kostlv "成本中心对资产负责
iv_sernr "序列号
iv_invnr "存货号
iv_invzu "补充库存说明
ev_asset "资产编号
ev_status"状态
ev_message"描述
.
ELSE.
ev_asset = iv_asset.
ENDIF.
IF ev_status <> ‘E’
AND iv_aufnr IS NOT INITIAL
AND ev_asset IS NOT INITIAL.
"新增内部订单结算规则
PERFORM frm_ko02_bdc USING iv_aufnr
ev_asset
ev_status"状态
ev_message"描述
.
ENDIF.
IF ev_status <> ‘E’
AND iv_aufnr IS NOT INITIAL.
"内部工单完全结算
PERFORM frm_ko88_bdc USING iv_aufnr
ev_status"状态
ev_message"描述
.
ENDIF.
ENDFUNCTION.
----------------------------------------------------------------------
***INCLUDE LZFG_ECC_JDF05.
----------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form FRM_CREATE_ANLN1
&---------------------------------------------------------------------
创建资产卡片
----------------------------------------------------------------------
FORM frm_create_anln1 USING pv_bukrs TYPE bukrs "公司代码
pv_anlkl TYPE anlkl "资产分类
pv_txt50 TYPE txa50_anlt "资产描述
pv_txa50 TYPE txa50_more "附加资产描述
pv_anlhtxt TYPE anlhtxt "资产主号说明
pv_meins TYPE meins "基本计量单位
pv_menge TYPE menge_d "数量
pv_kostl TYPE kostl "成本中心
pv_kostlv TYPE kostlv "成本中心对资产负责
pv_sernr TYPE am_sernr "序列号
pv_invnr TYPE invnr_anla "存货号
pv_invzu TYPE invzu_anla "补充库存说明
pv_asset TYPE bf_anln1 "资产编号
pv_status TYPE char1 "状态
pv_message TYPE char100 "描述
.
DATA:ls_key LIKE bapi1022_key,
ls_gen LIKE bapi1022_feglg001,
ls_genx LIKE bapi1022_feglg001x,
ls_tim LIKE bapi1022_feglg003,
ls_timx LIKE bapi1022_feglg003x.
DATA:ls_inventory LIKE bapi1022_feglg011.
DATA:ls_inventoryx LIKE bapi1022_feglg011x.
DATA:ls_return LIKE bapiret2.
ls_key-companycode = pv_bukrs. "公司代码
ls_gen-assetclass = pv_anlkl. "资产分类
ls_gen-descript = pv_txt50. "资产描述
ls_gen-descript2 = pv_txa50. "附加资产描述
ls_genx-assetclass = ‘X’.
ls_genx-descript = ‘X’.
ls_genx-descript2 = ‘X’.
ls_genx-serial_no = ‘X’.
ls_genx-invent_no = ‘X’.
ls_genx-quantity = ‘X’.
ls_genx-base_uom = ‘X’.
ls_genx-main_descript = ‘X’.
ls_inventory-note = pv_invzu."库存注记
ls_inventoryx-note = ‘X’.
ls_tim-costcenter = pv_kostl.
ls_tim-resp_cctr = pv_kostlv.
ls_timx-costcenter = ‘X’.
ls_timx-resp_cctr = ‘X’.
CALL FUNCTION ‘BAPI_FIXEDASSET_CREATE1’
EXPORTING
key = ls_key
generaldata = ls_gen
generaldatax = ls_genx
inventory = ls_inventory
inventoryx = ls_inventoryx
timedependentdata = ls_tim
timedependentdatax = ls_timx
IMPORTING
asset = pv_asset
return = ls_return.
IF pv_asset IS NOT INITIAL .
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
pv_status = ‘S’.
pv_message = ‘资产编号创建成功’.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
pv_status = ls_return-type.
pv_message = ls_return-message.
ENDIF.
ENDFORM.
----------------------------------------------------------------------
***INCLUDE LZFG_ECC_JDF06.
----------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form FRM_KO02_BDC
&---------------------------------------------------------------------
新增内部订单结算规则
----------------------------------------------------------------------
-->P_IV_AUFNR text
-->P_EV_ASSET text
-->P_EV_STATUS text
-->P_EV_MESSAGE text
-->P_ENDFUNCTION text
----------------------------------------------------------------------
FORM frm_ko02_bdc USING pv_aufnr TYPE aufnr
pv_asset TYPE bf_anln1 "资产编号
pv_status TYPE char1 "状态
pv_message TYPE char100 "描述
.
DATA:lv_message TYPE string.
DATA:lv_objnr TYPE j_objnr.
REFRESH:bdcdata,
messtab.
CLEAR:bdcdata,
messtab.
"结算规则重复检查
lv_objnr = ‘OR’ && pv_aufnr.
SELECT SINGLE *
INTO @DATA(ls_cobrb)
FROM cobrb
WHERE objnr = @lv_objnr
AND bureg = ‘0’.
IF sy-subrc = 0.
pv_status = ‘E’.
IF pv_message IS INITIAL.
pv_message = lv_message.
ELSE.
pv_message = pv_message && '/'&& '该内部订单已分配过转固结算规则'.
ENDIF.
ELSE.
PERFORM bdc_dynpro USING 'SAPMKAUF' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'COAS-AUFNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'COAS-AUFNR'
pv_aufnr.
PERFORM bdc_dynpro USING 'SAPMKAUF' '0600'.
PERFORM bdc_field USING 'BDC_CURSOR'
'COAS-KTEXT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ABVO'.
PERFORM bdc_field USING ‘COAS-KTEXT’
record-ktext_002.
PERFORM bdc_dynpro USING ‘SAPLKOBS’ ‘0130’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘COBRB-KONTY(01)’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=NEUR’.
PERFORM bdc_dynpro USING ‘SAPLKOBS’ ‘0100’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘COBRB-GABJA’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=SICH’.
PERFORM bdc_field USING ‘COBRB-GABPE’
sy-datum+4(2).
PERFORM bdc_field USING ‘COBRB-GABJA’
sy-datum+0(4).
PERFORM bdc_field USING ‘COBRB-PERBZ’
‘FUL’.
PERFORM bdc_field USING ‘COBRB-PROZS’
‘100’.
PERFORM bdc_field USING ‘COBL-ANLN1’
pv_asset.
IF bdcdata[] IS NOT INITIAL.
CALL TRANSACTION 'KO02' USING bdcdata
MODE bdcmode
UPDATE bdcupdate
MESSAGES INTO messtab.
READ TABLE messtab INTO DATA(ls_message) WITH KEY msgid = 'KO'
msgnr = '109'.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
IF pv_message IS INITIAL.
pv_message = lv_message.
ELSE.
pv_message = pv_message && '/'&& '内部订单' && pv_aufnr && '结算规则维护成功'.
ENDIF.
ELSE.
ROLLBACK WORK.
pv_status = 'E'.
LOOP AT messtab INTO ls_message.
CLEAR : lv_message.
CALL FUNCTION 'MESSAGE_TEXT_BUILD' " 显示出具体的错误讯息
EXPORTING
msgid = ls_message-msgid
msgnr = ls_message-msgnr
msgv1 = ls_message-msgv1
msgv2 = ls_message-msgv2
msgv3 = ls_message-msgv3
msgv4 = ls_message-msgv4
IMPORTING
message_text_output = lv_message.
CONDENSE lv_message NO-GAPS.
IF pv_message IS INITIAL.
pv_message = lv_message.
ELSE.
pv_message = pv_message && '/'&& lv_message.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
----------------------------------------------------------------------
Start new screen *
----------------------------------------------------------------------
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = ‘X’.
APPEND bdcdata.
ENDFORM.
----------------------------------------------------------------------
Insert field *
----------------------------------------------------------------------
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDFORM.
----------------------------------------------------------------------
***INCLUDE LZFG_ECC_JDF07.
----------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form FRM_KO88_BDC
&---------------------------------------------------------------------
内部工单完全结算
----------------------------------------------------------------------
-->P_IV_AUFNR text
-->P_EV_STATUS text
-->P_EV_MESSAGE text
----------------------------------------------------------------------
FORM frm_ko88_bdc USING pv_aufnr TYPE aufnr
pv_status TYPE char1 "状态
pv_message TYPE char100 "描述
.
DATA:lv_message TYPE string.
REFRESH:bdcdata,
messtab.
CLEAR:bdcdata,
messtab.
PERFORM bdc_dynpro USING ‘SAPLKO71’ ‘1000’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘LKO74-TESTLAUF’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=AUSF’.
PERFORM bdc_field USING ‘LKO74-PERIO’
sy-datum+4(2)."期间月
PERFORM bdc_field USING ‘LKO74-GJAHR’
sy-datum+0(4)."年
PERFORM bdc_field USING ‘LKO74-VAART’
‘8’."固定值 8 完全结算
PERFORM bdc_field USING ‘LKO74-TESTLAUF’
‘’."固定值 空 测试运行
PERFORM bdc_field USING ‘LKO74-TDCHECK’
‘’."固定值 空 检查业务数据
PERFORM bdc_field USING ‘CODIA-AUFNR’
pv_aufnr."订单
IF bdcdata[] IS NOT INITIAL.
CALL TRANSACTION 'KO88' USING bdcdata
MODE bdcmode
UPDATE bdcupdate
MESSAGES INTO messtab.
READ TABLE messtab INTO DATA(ls_message) WITH KEY msgtyp = 'E'.
IF sy-subrc <> 0.
COMMIT WORK AND WAIT.
IF pv_message IS INITIAL.
pv_message = '结算成功'.
ELSE.
pv_message = pv_message && '/'&& '结算成功'.
ENDIF.
ELSE.
ROLLBACK WORK.
pv_status = 'E'.
LOOP AT messtab INTO ls_message.
CLEAR : lv_message.
CALL FUNCTION 'MESSAGE_TEXT_BUILD' " 显示出具体的错误讯息
EXPORTING
msgid = ls_message-msgid
msgnr = ls_message-msgnr
msgv1 = ls_message-msgv1
msgv2 = ls_message-msgv2
msgv3 = ls_message-msgv3
msgv4 = ls_message-msgv4
IMPORTING
message_text_output = lv_message.
CONDENSE lv_message NO-GAPS.
IF pv_message IS INITIAL.
pv_message = lv_message.
ELSE.
pv_message = pv_message && '/'&& lv_message.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM.