ABAP:AS01固定资产主数据创建BAPI

BAPI_FIXEDASSET_CREATE1

*&---------------------------------------------------------------------*
*& Form frm_zzsdr_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_zzsdr_data.
  DATA:lv_asset                TYPE bapi1022_1-assetmaino, "主资产号
       lv_subnumber            TYPE bapi1022_1-assetsubno, "资产次级编号
       ls_key                  TYPE bapi1022_key,
       ls_generaldata          TYPE bapi1022_feglg001,
       ls_generaldatax         TYPE bapi1022_feglg001x,
       ls_inventory            TYPE bapi1022_feglg011,
       ls_inventoryx           TYPE bapi1022_feglg011x,
       ls_timedependentdata    TYPE bapi1022_feglg003,
       ls_timedependentdatax   TYPE bapi1022_feglg003x,
       ls_allocations          TYPE bapi1022_feglg004,
       ls_allocationsx         TYPE bapi1022_feglg004x,
       ls_origin               TYPE bapi1022_feglg009,
       ls_originx              TYPE bapi1022_feglg009x,
       ls_depreciationareas    TYPE bapi1022_dep_areas, "折旧范围数据
       ls_depreciationareasx   TYPE bapi1022_dep_areasx,
       lt_depreciationareas    TYPE STANDARD TABLE OF bapi1022_dep_areas,
       lt_depreciationareasx   TYPE STANDARD TABLE OF bapi1022_dep_areasx,
       ls_return               TYPE bapiret2,
       ls_investacctassignmnt  TYPE bapi1022_feglg010,
       ls_investacctassignmntx TYPE bapi1022_feglg010x,
       ls_ztps005              LIKE ztps005,
       lt_extensionin          TYPE STANDARD TABLE OF bapiparex,
       ls_extensionin          TYPE bapiparex,
       ls_te_anlu              TYPE bapi_te_anlu.

  CHECK gt_outtab IS NOT INITIAL.
  DATA(lt_upload) = gt_outtab.
  DELETE lt_upload WHERE icon = icon_led_green.
  IF lt_upload IS NOT INITIAL.
    MESSAGE '数据检查未通过,请检查数据后导入' TYPE 'E'.
  ENDIF.

  LOOP AT gt_outtab ASSIGNING FIELD-SYMBOL(<fs_outtab>).
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = <fs_outtab>-anlkl
      IMPORTING
        output = ls_generaldata-assetclass. "资产分类

    "基本视图
    ls_key-companycode = <fs_outtab>-bukrs.         "公司代码
*    ls_generaldata-assetclass    = <fs_outtab>-anlkl.  "资产分类
    ls_generaldata-descript      = <fs_outtab>-txt50.  "资产描述
    ls_generaldata-descript2     = <fs_outtab>-txa50.  "附加资产描述
    ls_generaldata-quantity      = <fs_outtab>-menge.  "数量
    ls_generaldata-base_uom      = <fs_outtab>-meins.  "单位

    ls_generaldatax-assetclass = 'X'.
    ls_generaldatax-descript   = 'X'.
    ls_generaldatax-descript2  = 'X'.
    ls_generaldatax-quantity   = 'X'.
    ls_generaldatax-base_uom   = 'X'.

*时间相关
    ls_timedependentdata-costcenter  = <fs_outtab>-kostl. "成本中心
    ls_timedependentdata-resp_cctr   = <fs_outtab>-kostlv."责任成本中心
*    ls_timedependentdata-wbs_element_cost = <fs_outtab>-ps_psp_pnr2.

    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
      EXPORTING
        input  = <fs_outtab>-ps_psp_pnr2
      IMPORTING
        output = ls_timedependentdata-wbs_element_cost.
    ls_timedependentdatax-costcenter = 'X'.
    ls_timedependentdatax-resp_cctr  = 'X' .
    ls_timedependentdatax-wbs_element_cost = 'X'.

    "
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = <fs_outtab>-lifnr
      IMPORTING
        output = <fs_outtab>-lifnr.
    SELECT SINGLE name1 INTO <fs_outtab>-liefe FROM lfa1 WHERE lifnr = <fs_outtab>-lifnr.
    ls_origin-vendor_no = <fs_outtab>-lifnr.
    ls_origin-vendor = <fs_outtab>-liefe.
    ls_origin-manufacturer = <fs_outtab>-herst."制造商
    ls_originx-vendor_no = 'X'.
    ls_originx-vendor = 'X'.
    ls_originx-manufacturer = 'X'.

    "投资科目分配
    ls_investacctassignmnt-wbs_elem = <fs_outtab>-posnr.
    ls_investacctassignmntx-wbs_elem = 'X'.

    "分配
    ls_allocations-evalgroup1       = <fs_outtab>-ord41. "自用或投放
    ls_allocations-evalgroup2       = <fs_outtab>-ord42. "购入方式
    ls_allocations-evalgroup4       = <fs_outtab>-ord44.
    ls_allocationsx-evalgroup1      = 'X'.             "自用或投放
    ls_allocationsx-evalgroup2      = 'X'.             "购入方式
    ls_allocationsx-evalgroup4      = 'X'.

    "折旧范围
    ls_depreciationareas-area = '01'.
    ls_depreciationareas-ulife_yrs  = <fs_outtab>-ndjar ."计划使用年
    ls_depreciationareas-ulife_prds = <fs_outtab>-ndper ."计划使用月
    ls_depreciationareasx-area = '01'.
    ls_depreciationareasx-ulife_yrs  = 'X' .
    ls_depreciationareasx-ulife_prds = 'X' .
    APPEND  ls_depreciationareas TO  lt_depreciationareas.
    APPEND  ls_depreciationareasx TO  lt_depreciationareasx.

    CALL FUNCTION 'BAPI_FIXEDASSET_CREATE1'
      EXPORTING
        key                  = ls_key
        generaldata          = ls_generaldata
        generaldatax         = ls_generaldatax
        inventory            = ls_inventory
        inventoryx           = ls_inventoryx
        timedependentdata    = ls_timedependentdata
        timedependentdatax   = ls_timedependentdatax
        allocations          = ls_allocations
        allocationsx         = ls_allocationsx
        origin               = ls_origin
        originx              = ls_originx
        investacctassignmnt  = ls_investacctassignmnt
        investacctassignmntx = ls_investacctassignmntx
      IMPORTING
        asset                = lv_asset
        return               = ls_return
      TABLES
        depreciationareas    = lt_depreciationareas
        depreciationareasx   = lt_depreciationareasx
        extensionin          = lt_extensionin.
    IF ls_return-type CA 'AEX'.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      <fs_outtab>-icon = icon_led_red.
      <fs_outtab>-msg = ls_return-message && <fs_outtab>-msg.
    ELSE.
      <fs_outtab>-icon = icon_led_green.
      <fs_outtab>-anln1 = lv_asset.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.

    IF <fs_outtab>-schrw IS NOT INITIAL.
      UPDATE anlb SET schrw = <fs_outtab>-schrw WHERE bukrs = <fs_outtab>-bukrs
                                                  AND anln1 = lv_asset
                                                  AND afabe = '01'.
      COMMIT WORK AND WAIT.
    ENDIF.

    MOVE-CORRESPONDING <fs_outtab> TO ls_ztps005.
    ls_ztps005-anln2 = '0000'.
    ls_ztps005-erdat = sy-datum.
    ls_ztps005-ernam = sy-uname.
    ls_ztps005-ertim = sy-uzeit.
    MODIFY ztps005 FROM ls_ztps005.
    COMMIT WORK AND WAIT.
    CLEAR:ls_return,ls_ztps005,ls_key,ls_generaldata,ls_generaldatax,ls_inventory,ls_inventoryx,ls_timedependentdata,
    ls_timedependentdatax,ls_allocations,ls_allocationsx,ls_origin,ls_originx,ls_investacctassignmnt,ls_investacctassignmntx,
    lv_asset,lt_depreciationareas,lt_depreciationareasx,ls_extensionin,lt_extensionin,ls_te_anlu.
  ENDLOOP.

ENDFORM.

 

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