FI AB08 冲销 BAPI_ASSET_REVERSAL_POST

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().

APPEND INITIAL LINE TO gt_table ASSIGNING FIELD-SYMBOL().

-anln1 = -i_anln1.

IF -i_anln1 IS INITIAL.
  rtype = 'E'.
  rtmsg = rtmsg && '行' && sy-tabix && '转出资产号不能为空.'.
  -message = -message && '转出资产号不能为空.'.
  -rtype = 'E'.
ENDIF.

IF -i_gjahr IS INITIAL.
  rtype = 'E'.
  rtmsg = rtmsg && '行' && sy-tabix && '财年不能为空.'.
  -message = -message && '财年不能为空.'.
  -rtype = 'E'.
ENDIF.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = -i_anln1
  IMPORTING
    output = -i_anln1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = -i_belnr
  IMPORTING
    output = -i_belnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = -i_belnr2
  IMPORTING
    output = -i_belnr2.

IF -i_belnr IS INITIAL
AND -i_belnr2 IS INITIAL  .
  rtype = 'E'.
  rtmsg = rtmsg && '行' && sy-tabix && '凭证编号和资产凭证编号不能同时为空.'.
  -message = -message && '凭证编号和资产凭证编号不能同时为空.'.
  -rtype = 'E'.
ELSEIF -i_belnr IS NOT INITIAL.

  SELECT SINGLE budat INTO -budat
  FROM bkpf
  WHERE bukrs = i_bukrs
    AND belnr = -i_belnr
    AND gjahr = -i_gjahr.
  IF sy-subrc <> 0.
    rtype = 'E'.
    rtmsg = rtmsg && '行' && sy-tabix && '凭证编号' && -i_belnr
            && '会计年度' && -i_gjahr && '不存在.'.
    -message = -message &&  '凭证编号' && -i_belnr
            && '会计年度' && -i_gjahr && '不存在.'..
    -rtype = 'E'.
  ENDIF.

ELSEIF -i_belnr2 IS NOT INITIAL.

  SELECT SINGLE budat awtyp aworg
    INTO ( -budat,-awtyp,-aworg )
    FROM anek
    WHERE bukrs = i_bukrs
      AND anln1 = -i_anln1
      AND gjahr = -i_gjahr
      AND belnr = -i_belnr2.
  IF sy-subrc <> 0.
    rtype = 'E'.
    rtmsg = rtmsg && '行' && sy-tabix && '资产凭证编号' && -i_belnr
            && '会计年度' && -i_gjahr && '不存在.'.
    -message = -message &&  '资产凭证编号' && -i_belnr
            && '会计年度' && -i_gjahr && '不存在.'..
    -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 .

APPEND INITIAL LINE TO gt_table ASSIGNING .



-bukrs = i_bukrs .
-anln1 = -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 -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 -i_belnr IS NOT INITIAL.
  ls_origindocumentkey-comp_code = i_bukrs.
  ls_origindocumentkey-ac_doc_no = -i_belnr .
  ls_origindocumentkey-fisc_year = -i_gjahr.

ELSE.

  ls_origindocreference-obj_type = -awtyp.
  ls_origindocreference-ref_doc = -i_belnr2.
  ls_origindocreference-ref_org_un = -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' .
  -rtype = 'E'.
  -message =  -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'.

    -belnr = ls_documentreference-ref_doc.
    -message = ls_return-message .
    -gjahr = ls_documentreference-ref_org_un+4(4).
    -rtype = 'S'.

    DATA:lv_message_v1 TYPE bapiret2-message_v1.

    IF -i_belnr IS NOT INITIAL."会计凭证
  •      -rtype = 'S'
        lv_message_v1 = -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 = -bukrs .
    
  •       else.
    
    
        ENDIF.
    
        IF sy-subrc = 0.
    
          -belnr = ls_ret-message_v2.
          -message =  ls_ret-message .
          -gjahr = i_cpudt+0(4).
          rtmsg = rtmsg &&  ls_ret-message .
    
          DO 5 TIMES.
    
            SELECT SINGLE belnr INTO -belnr
              FROM bkpf
              WHERE bukrs = i_bukrs
                AND belnr = -belnr
                AND gjahr = -gjahr.
            IF sy-subrc = 0.
              UPDATE bkpf SET usnam = i_usnam
                              bktxt = i_bktxt
                              xblnr_alt = i_bzdh
                WHERE bukrs = i_bukrs
              AND belnr = -belnr
              AND gjahr = -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 .
      -rtype = 'E'.
      rtype = 'E'.
    ENDIF.
    

    ENDIF.

    ENDLOOP.

    IF rtype IS INITIAL .
    rtype = ‘S’.
    ENDIF.

    FREE MEMORY ID ‘ZSSF_050’.

    zfmparavalsave2 ‘R’.

ENDFUNCTION.

你可能感兴趣的:(前端)