FUNCTION function
*“----------------------------------------------------------------------
"“本地接口:
*” IMPORTING
*” VALUE(I_BZDH) TYPE ZBZDH
*" VALUE(I_USNAM) TYPE USNAM
*" VALUE(I_CPUDT) TYPE CPUDT
*" VALUE(I_BUKRS) TYPE BUKRS
*" VALUE(I_BKTXT) TYPE BKTXT
*" EXPORTING
*" VALUE(RTYPE) TYPE BAPI_MTYPE
*" VALUE(RTMSG) TYPE BAPI_MSG
*" TABLES
*" IT_TAB STRUCTURE ZSSF_051_INPUT
*" GT_TABLE STRUCTURE ZSSF_051_OUTPUT OPTIONAL
*"----------------------------------------------------------------------
DATA:BEGIN OF ls_data.
INCLUDE STRUCTURE zssf_051_input.
DATA:budat TYPE bkpf-budat,
awtyp TYPE awtyp,
aworg TYPE aworg,
END OF ls_data,
lt_data LIKE STANDARD TABLE OF ls_data.
DATA:
ls_output type ZSSF_051_OUTPUT,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_documentreference TYPE bapi6037_doc_ref,
ls_return TYPE bapiret2,
ls_origindocreference TYPE bapi6037_doc_ref,
ls_origindocumentkey TYPE bapi6037_doc_key,
ls_reversaldata TYPE bapi6037_rev_data.
CLEAR :rtype ,rtmsg,gt_table[].
zfmparavalsave1 ‘ZSSF_051’.
zfmparavalsave2 ‘B’.
lt_data[] = it_tab[].
IF i_bzdh IS INITIAL.
rtype = ‘E’.
rtmsg = rtmsg && ‘报账单号不能为空.’.
ENDIF.
IF i_usnam IS INITIAL.
rtype = ‘E’.
rtmsg = rtmsg && ‘财务审核人不能为空.’.
ENDIF.
IF i_cpudt IS INITIAL.
rtype = ‘E’.
rtmsg = rtmsg && ‘财务审核日期不能为空.’.
ENDIF.
IF i_bukrs IS INITIAL.
rtype = ‘E’.
rtmsg = rtmsg && ‘记账公司不能为空.’.
ENDIF.
IF i_bktxt IS INITIAL.
rtype = ‘E’.
rtmsg = rtmsg && ‘申请事由不能为空.’.
ENDIF.
IF it_tab[] IS INITIAL.
rtype = ‘E’.
rtmsg = rtmsg && ‘IT_TAB明细信息 不能为空.’.
ENDIF.
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<fs_data>).
APPEND INITIAL LINE TO gt_table ASSIGNING FIELD-SYMBOL(<fs_table>).
<fs_table>-anln1 = <fs_data>-i_anln1.
IF <fs_data>-i_anln1 IS INITIAL.
rtype = 'E'.
rtmsg = rtmsg && '行' && sy-tabix && '转出资产号不能为空.'.
<fs_table>-message = <fs_table>-message && '转出资产号不能为空.'.
<fs_table>-rtype = 'E'.
ENDIF.
IF <fs_data>-i_gjahr IS INITIAL.
rtype = 'E'.
rtmsg = rtmsg && '行' && sy-tabix && '财年不能为空.'.
<fs_table>-message = <fs_table>-message && '财年不能为空.'.
<fs_table>-rtype = 'E'.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_data>-i_anln1
IMPORTING
output = <fs_data>-i_anln1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_data>-i_belnr
IMPORTING
output = <fs_data>-i_belnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_data>-i_belnr2
IMPORTING
output = <fs_data>-i_belnr2.
IF <fs_data>-i_belnr IS INITIAL
AND <fs_data>-i_belnr2 IS INITIAL .
rtype = 'E'.
rtmsg = rtmsg && '行' && sy-tabix && '凭证编号和资产凭证编号不能同时为空.'.
<fs_table>-message = <fs_table>-message && '凭证编号和资产凭证编号不能同时为空.'.
<fs_table>-rtype = 'E'.
ELSEIF <fs_data>-i_belnr IS NOT INITIAL.
SELECT SINGLE budat INTO <fs_data>-budat
FROM bkpf
WHERE bukrs = i_bukrs
AND belnr = <fs_data>-i_belnr
AND gjahr = <fs_data>-i_gjahr.
IF sy-subrc <> 0.
rtype = 'E'.
rtmsg = rtmsg && '行' && sy-tabix && '凭证编号' && <fs_data>-i_belnr
&& '会计年度' && <fs_data>-i_gjahr && '不存在.'.
<fs_table>-message = <fs_table>-message && '凭证编号' && <fs_data>-i_belnr
&& '会计年度' && <fs_data>-i_gjahr && '不存在.'..
<fs_table>-rtype = 'E'.
ENDIF.
ELSEIF <fs_data>-i_belnr2 IS NOT INITIAL.
SELECT SINGLE budat awtyp aworg
INTO ( <fs_data>-budat,<fs_data>-awtyp,<fs_data>-aworg )
FROM anek
WHERE bukrs = i_bukrs
AND anln1 = <fs_data>-i_anln1
AND gjahr = <fs_data>-i_gjahr
AND belnr = <fs_data>-i_belnr2.
IF sy-subrc <> 0.
rtype = 'E'.
rtmsg = rtmsg && '行' && sy-tabix && '资产凭证编号' && <fs_data>-i_belnr
&& '会计年度' && <fs_data>-i_gjahr && '不存在.'.
<fs_table>-message = <fs_table>-message && '资产凭证编号' && <fs_data>-i_belnr
&& '会计年度' && <fs_data>-i_gjahr && '不存在.'..
<fs_table>-rtype = 'E'.
ENDIF.
ENDIF.
ENDLOOP.
IF rtype = ‘E’.
ls_output-rtype = ‘E’.
MODIFY gt_table FROM ls_output TRANSPORTING rtype
WHERE rtype = ‘’.
zfmparavalsave2 ‘R’.
RETURN.
ENDIF.
REFRESH gt_table.
EXPORT p1 = i_usnam TO MEMORY ID ‘ZSSF_050’.
LOOP AT lt_data ASSIGNING <fs_data>.
APPEND INITIAL LINE TO gt_table ASSIGNING <fs_table>.
<fs_table>-bukrs = i_bukrs .
<fs_table>-anln1 = <fs_data>-i_anln1 .
CLEAR :ls_reversaldata,
ls_origindocreference,
ls_origindocumentkey.
ls_reversaldata-fisc_year = i_cpudt+0(4).
ls_reversaldata-fis_period = i_cpudt+4(2).
IF <fs_data>-budat+0(6) = i_cpudt+0(6)..
ls_reversaldata-reason_rev = '03'.
ELSE.
ls_reversaldata-pstng_date = i_cpudt.
ls_reversaldata-reason_rev = '04'.
ENDIF.
IF <fs_data>-i_belnr IS NOT INITIAL.
ls_origindocumentkey-comp_code = i_bukrs.
ls_origindocumentkey-ac_doc_no = <fs_data>-i_belnr .
ls_origindocumentkey-fisc_year = <fs_data>-i_gjahr.
ELSE.
ls_origindocreference-obj_type = <fs_data>-awtyp.
ls_origindocreference-ref_doc = <fs_data>-i_belnr2.
ls_origindocreference-ref_org_un = <fs_data>-aworg.
ENDIF.
"BREAK ex05.
CLEAR :ls_documentreference,
ls_return,
lt_return[].
CALL FUNCTION 'BAPI_ASSET_REVERSAL_POST'
EXPORTING
origindocreference = ls_origindocreference
origindocumentkey = ls_origindocumentkey
reversaldata = ls_reversaldata
IMPORTING
documentreference = ls_documentreference
return = ls_return
TABLES
return_all = lt_return.
"BREAK ex05.
rtmsg = rtmsg && ls_return-message . .
LOOP AT lt_return INTO DATA(ls_ret)
WHERE type CA 'AEX' .
<fs_table>-rtype = 'E'.
<fs_table>-message = <fs_table>-message && ls_ret-message .
ENDLOOP.
IF sy-subrc = 0. .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
rtype = 'E'.
ELSE.
IF ls_documentreference-ref_doc IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
<fs_table>-belnr = ls_documentreference-ref_doc.
<fs_table>-message = ls_return-message .
<fs_table>-gjahr = ls_documentreference-ref_org_un+4(4).
<fs_table>-rtype = 'S'.
DATA:lv_message_v1 TYPE bapiret2-message_v1.
IF <fs_data>-i_belnr IS NOT INITIAL."会计凭证
-
<fs_table>-rtype = 'S' lv_message_v1 = <fs_table>-bukrs . CLEAR ls_ret. READ TABLE lt_return INTO ls_ret WITH KEY type = 'S' id = 'FAA_POST' number = '092' message_v1 = lv_message_v1 . IF sy-subrc <> 0. READ TABLE lt_return INTO ls_ret WITH KEY type = 'S' id = 'FAA_POST' number = '092'.
-
message_v1 = <fs_table>-bukrs .
-
else. ENDIF. IF sy-subrc = 0. <fs_table>-belnr = ls_ret-message_v2. <fs_table>-message = ls_ret-message . <fs_table>-gjahr = i_cpudt+0(4). rtmsg = rtmsg && ls_ret-message . DO 5 TIMES. SELECT SINGLE belnr INTO <fs_table>-belnr FROM bkpf WHERE bukrs = i_bukrs AND belnr = <fs_table>-belnr AND gjahr = <fs_table>-gjahr. IF sy-subrc = 0. UPDATE bkpf SET usnam = i_usnam bktxt = i_bktxt xblnr_alt = i_bzdh WHERE bukrs = i_bukrs AND belnr = <fs_table>-belnr AND gjahr = <fs_table>-gjahr. IF sy-subrc = 0. COMMIT WORK. ENDIF. ELSE. WAIT UP TO '0.5' SECONDS . ENDIF. ENDDO. ENDIF. ENDIF. ELSE. rtmsg = rtmsg && ls_return-message . <fs_table>-rtype = 'E'. rtype = 'E'. ENDIF.
ENDIF.
ENDLOOP.
IF rtype IS INITIAL .
rtype = ‘S’.
ENDIF.FREE MEMORY ID ‘ZSSF_050’.
zfmparavalsave2 ‘R’.
ENDFUNCTION.