ABAP:ABAW资产减值重固BAPI

BAPI_ASSET_REVALUATION_POST

*&---------------------------------------------------------------------*
*& Form frm_import_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> PV_UCOMM
*&---------------------------------------------------------------------*
FORM frm_import_data  USING pv_ucomm.
  DATA: ls_post    TYPE bapifapo_gen_info,
        ls_reval   TYPE bapifapo_revaluation,
        ls_info    TYPE bapifapo_add_info,
        ls_return  TYPE bapiret2,
        lt_return2 TYPE TABLE OF bapiret2,
        ls_rz      TYPE ztfi0025.

  CHECK gt_outtab IS NOT INITIAL.
  "全部行项目没有错误时才能正式导入
  DATA(lt_import) = gt_outtab.
  DELETE lt_import WHERE icon = icon_led_green.
  IF lt_import IS NOT INITIAL.
    MESSAGE '数据检查未通过,不可导入' TYPE 'E'.
  ENDIF.

  LOOP AT gt_outtab ASSIGNING FIELD-SYMBOL(<fs_outtab>).

    SELECT SINGLE waers
      FROM t001
      INTO ls_reval-currency
     WHERE bukrs = <fs_outtab>-bukrs.

    ls_post-comp_code = <fs_outtab>-bukrs."公司代码
    ls_post-assetmaino = <fs_outtab>-anln1."主资产号
    ls_post-assettrtyp = <fs_outtab>-bwasl."事物类型
    ls_post-acc_principle = <fs_outtab>-accounting_principle."会计准则
    ls_post-depr_area = <fs_outtab>-afabe."折旧范围
    ls_post-doc_date = <fs_outtab>-bldat."凭证日期
    ls_post-pstng_date = <fs_outtab>-budat."过账日期

    ls_reval-valuedate = <fs_outtab>-bzdat."资产起息日
    ls_reval-amount = <fs_outtab>-anbtr."减值金额

    ls_info-item_text = <fs_outtab>-sgtxt."凭证文本

    CALL FUNCTION 'BAPI_ASSET_REVALUATION_POST'
      EXPORTING
        generalpostingdata = ls_post
        revaluationdata    = ls_reval
      IMPORTING
        return             = ls_return
      TABLES
*       revalareavalues    =
        return_all         = lt_return2.

    LOOP AT lt_return2 INTO DATA(ls_return2) WHERE type CA 'AEX'.
      <fs_outtab>-msg = ls_return2-message && <fs_outtab>-msg.
      CLEAR:ls_return2.
    ENDLOOP.

    IF sy-subrc EQ 0.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      <fs_outtab>-icon  = icon_led_red.
    ELSE.
      READ TABLE lt_return2 INTO ls_return2 WITH KEY type = 'S'
                                                     id = 'FAA_POST'
                                                     number = '091'.
      IF sy-subrc EQ 0.
        <fs_outtab>-msg = ls_return2-message_v1.
      ENDIF.
      <fs_outtab>-icon  = icon_led_green.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.

    ls_rz-uuid = cl_uuid_factory=>create_system_uuid(  )->create_uuid_x16( ).
    ls_rz-erdat = sy-datum.
    ls_rz-ernam = sy-uname.
    ls_rz-erzet = sy-uzeit.
    ls_rz-type = ls_return2-type.
    ls_rz-mseg = ls_return2-message.
    ls_rz-znumber = ls_return2-message_v1.
    MOVE-CORRESPONDING <fs_outtab> TO ls_rz.

    MODIFY ztfi0025 FROM ls_rz .
    COMMIT WORK AND WAIT.

    CLEAR:ls_rz,ls_return2.
  ENDLOOP.

ENDFORM.
posted @ 2024-02-18 17:28  阿胖的阿多  阅读(158)  评论(0编辑  收藏  举报