AS01 Create fixed asset card BAPI_FIXEDASSET_CREATE1

Note

1. The depreciation range will be brought out by itself, just hit x for the field to be changed

 

demo code

function zfm_erp_012.

*"----------------------------------------------------------------------

*"*"Local interface:

*"  TABLES

*"      T_DATA STRUCTURE  ZFM_ERP_012_DATA

*"----------------------------------------------------------------------

 

  data:

    ls_key                   type bapi1022_key,

    ls_general_data          type bapi1022_feglg001,

    ls_general_data_x        type bapi1022_feglg001x,

    ls_postinginformation    type bapi1022_feglg002,

    ls_postinginformationx   type bapi1022_feglg002x,

    ls_time_dependent_data   type bapi1022_feglg003,

    ls_time_dependent_data_x type bapi1022_feglg003x,

    ls_allocations           type bapi1022_feglg004,

    ls_allocationsx          type bapi1022_feglg004x,

    ls_investacctassignmnt   type bapi1022_feglg010,

    ls_investacctassignmntx  type bapi1022_feglg010x,

    ls_origin                type bapi1022_feglg009, "源

    ls_originx               type bapi1022_feglg009x.

 

***Depreciation range

  data:

    lt_depreciationareas  like table of bapi1022_dep_areas,

    ls_epreciationareas   like line of lt_depreciationareas,

    lt_depreciationareasx like table of bapi1022_dep_areasx,

    ls_depreciationareasx like line of lt_depreciationareasx.

 

  "Output

  data:

    ls_return     type bapiret2,

    lv_message    type string,

    lv_assetmaino type bapi1022_1-assetmaino.

 

  do 2 times.

    if sy-index = 1.

      data (testrun) = 'X'.

    else.

      testrun = ''.

      read table t_data with key rtype = 'E'.

      if sy-subrc = 0.

        return.

      endif.

    endif.

  enddo.

  loop at t_data where rtype ne 'S'.

    t_data-anlkl = |{ t_data-anlkl alpha = in }|.

    t_data-eaufn = |{ t_data-eaufn alpha = in }|.

    t_data-kostl = |{ t_data-kostl alpha = in }|.

 

*Keyword field to be created

    ls_key-companycode = t_data-bukrs." Company code

 

*Logical Field Group 001-General Data

    ls_general_data-assetclass = t_data-anlkl. "Asset class

    ls_general_data_x-assetclass ='X'. "Updated information of related user data fields

    ls_general_data-descript = t_data-txt50. "Description required

    ls_general_data_x-descript =  'X'.

    ls_general_data-descript2 = t_data-txa50. "Optional additional asset description-fill in the factory number

    ls_general_data_x-descript2 = 'X'.

    ls_general_data-serial_no = t_data-sernr. "Serial number

    ls_general_data_x-serial_no = 'X'.

    ls_general_data-invent_no = t_data-invnr ."Inventory No.

    ls_general_data_x-invent_no = 'X'.

    ls_general_data-quantity = t_data-menge. "数量

    ls_general_data_x-quantity = 'X'.

    ls_general_data-base_uom = t_data-meins. "Basic unit of measurement

    ls_general_data_x-base_uom = 'X'.

 

*Logical Field Group 002-Accounting Information

    ls_postinginformation-cap_date = t_data-aktiv. "Capitalization date

    ls_postinginformationx-cap_date = 'X'.

 

*Logical field group 003-time related data

* ls_time_dependent_data-bus_area = t_data-gsber. "Business area

*    ls_time_dependent_data_x-bus_area = 'X' .

    ls_time_dependent_data-costcenter = t_data-kostl. "Required cost center

    ls_time_dependent_data_x-costcenter = 'X' .

 

*Logical Field Group 004-Assignment

    ls_allocations-inv_reason = t_data-izwek. "reason for investment

    ls_allocationsx-inv_reason = 'X'.

    ls_allocations-evalgroup1 = t_data-ord41. "Usage status

    ls_allocationsx-evalgroup1 = 'X'.

    ls_allocations-evalgroup2 = t_data-ord42. "Economic use

    ls_allocationsx-evalgroup2 = 'X'.

 

*Logical Field Group 010-Investment Account Assignment

    ls_investacctassignmnt-invest_ord = t_data-eaufn. "Investment order

    ls_investacctassignmntx-invest_ord = 'X'.

 

*Depreciation range

    ls_epreciationareas-area = '01'. "Actual depreciation area

    ls_epreciationareas-odep_start_date = t_data-afabg. "Depreciation calculation start date

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '01'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

    ls_epreciationareas-area = '02'. "Actual depreciation area

    ls_epreciationareas-odep_start_date = t_data-afabg. "Depreciation calculation start date

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '02'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

    ls_epreciationareas-area = '03'. "Actual depreciation area

    ls_epreciationareas-odep_start_date = t_data-afabg. "Depreciation calculation start date

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '03'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

    ls_epreciationareas-area = '04'. "Actual depreciation area

    ls_epreciationareas-odep_start_date = t_data-afabg. "Depreciation calculation start date

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '04'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

 

*source

    ls_origin-vendor = t_data-lifnr. "Vendor name

    ls_originx-vendor = 'X'.

    ls_origin-manufacturer = t_data-herst. "Asset manufacturer

    ls_originx-manufacturer = 'X'.

 

    call function 'BAPI_FIXEDASSET_CREATE1'

      exporting

        testrun = testrun

        key = ls_key

        origin               = ls_origin

        originx              = ls_originx

        generaldata = ls_general_data

        generaldatax         = ls_general_data_x

        postinginformation = ls_postinginformation

        postinginformationx = ls_postinginformationx

        allocations          = ls_allocations

        allocationsx         = ls_allocationsx

        investacctassignmnt = ls_investacctassignmnt

        investacctassignmntx = ls_investacctassignmntx

        timedependentdata = ls_time_dependent_data

        timedependentdatax   = ls_time_dependent_data_x

      importing

        asset                = lv_assetmaino

        return               = ls_return

      tables

        depreciationareas    = lt_depreciationareas

        depreciationareasx   = lt_depreciationareasx.

 

    if ls_return-type = 'S'.

      if testrun is initial.

        call function 'BAPI_TRANSACTION_COMMIT'

          exporting

            wait = 'X'.

        t_data-rtype = 'S'.

        t_data-rtmsg ='Success'.

        t_data-anln1 = |{ lv_assetmaino alpha = out }|.

      endif.

      if ls_return is not initial.

        message id ls_return-id type ls_return-type number ls_return-number

          with ls_return-message_v1         ls_return-message_v2         ls_return-message_v3          ls_return-message_v4 into lv_message.

      endif.

    else.

      call function 'BAPI_TRANSACTION_ROLLBACK'.

      if ls_return is not initial.

        message id ls_return-id type ls_return-type number ls_return-number

        with ls_return-message_v1         ls_return-message_v2         ls_return-message_v3          ls_return-message_v4 into lv_message.

      endif.

      t_data-rtype = 'E'.

      t_data-rtmsg = lv_message.

    endif.

    modify t_data.

  endloop.

 

 

 

endfunction.

 

Guess you like

Origin blog.csdn.net/cylcylcylcylwo/article/details/114077533