Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Sap

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13
At a glance
Powered by AI
The report is uploading asset data to SAP using BAPIs. It defines data structures for the asset data and calls various BAPIs to create, update and commit the asset transactions.

The report is used to upload asset master data from an external system into SAP. It extracts the asset data and maps it to various SAP asset master BAPI structures before calling the relevant BAPIs.

The report defines structures like ty_data to store the asset data extracted from the external system. It also defines various BAPI structures to map the asset data for the different BAPI calls.

*&---------------------------------------------------------------------*

*& Report ZFI_ASSET_UPLOAD


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zfi_asset_upload.
" type declaration ==============================================
TYPES:BEGIN OF ty_data,
* asset(12) TYPE c,
* tcode(4) TYPE c,
anlkl(8) TYPE c, " anlkl,
bukrs(4) TYPE c, " bukrs,
txt50_1(45) TYPE c, " txt50,
txt50_2(45) TYPE c, " txt50,
main_descript(50) TYPE c,
* txa50 type t c,xa50,
sernr(8) TYPE c, "sernr,
invnr(25) TYPE c, " invnr,
menge(13) TYPE c, " menge,
meins(3) TYPE c, "meins,
history(50) TYPE c,
include_in_list(1) TYPE c,
aktiv(18) TYPE c, "aktiv,
kostl(10) TYPE c, "kostl,
werks(4) TYPE c, "plant
location(10) TYPE c,
* room(8) TYPE c,
evalgroup1(4) TYPE c,
evalgroup2(4) TYPE c,
no_pieces(10) TYPE c,
lifnr(10) TYPE c,
manufacturer(30) TYPE c,
* trade_id(6) TYPE c,
* country(3) TYPE c,
* type_name(15) TYPE c,
orig_acq_yr(4) TYPE c,
orig_value(23) TYPE c,
* inhouse_prod_percentage(5) TYPE c,
block_key(5) TYPE c,

put_to_use_date(10) TYPE c,
bl_key_add_depr(5) TYPE c,
* type(2) TYPE c,

* base_value(23) TYPE c,
* purchprice(23) TYPE c,
* no_paymnts(5) TYPE c,

* payment(23) TYPE c,

afasl(4) TYPE c, "afasl,


ndjar(3) TYPE c, "ndjar,
ulife_prds(3) TYPE c,
afabg(10) TYPE c, " afabg,

* afasl_02(4) TYPE c, "afasl,


* ndjar_02(3) TYPE c, "ndjar,
* afabg_02(10) TYPE c, " afabg,
* afabe(10) TYPE c, " afabe, depreciation area
kansw(15) TYPE c, " kansw,
knafa(15) TYPE c, " knafa,
nafag(15) TYPE c,
* afabe_02(10) TYPE c, " afabe,
kansw_02(15) TYPE c, " kansw,
knafa_02(15) TYPE c, " knafa,

END OF ty_data.

" data declaration ==============================================


DATA: it_data TYPE TABLE OF ty_data,
wa_data TYPE ty_data.

" bapi Data and tables Declaration ==============================

DATA:
wa_key LIKE bapi1022_key,
wa_reference LIKE bapi1022_reference,
wa_createsubnumber LIKE bapi1022_misc-xsubno,
wa_creategroupasset LIKE bapi1022_misc-xanlgr,
wa_testrun LIKE bapi1022_misc-testrun,
wa_generaldata LIKE bapi1022_feglg001,
wa_generaldatax LIKE bapi1022_feglg001x,
wa_inventory LIKE bapi1022_feglg011,
wa_inventoryx LIKE bapi1022_feglg011x,
wa_postinginformation LIKE bapi1022_feglg002,
wa_postinginformationx LIKE bapi1022_feglg002x,
wa_timedependentdata LIKE bapi1022_feglg003,
wa_timedependentdatax LIKE bapi1022_feglg003x,
wa_allocations LIKE bapi1022_feglg004,
wa_allocationsx LIKE bapi1022_feglg004x,
wa_origin LIKE bapi1022_feglg009,
wa_originx LIKE bapi1022_feglg009x,
wa_glo_in_gen LIKE bapi1022_glo_in_gen,
wa_glo_in_genx LIKE bapi1022_glo_in_genx,
wa_lease LIKE bapi1022_feglg005,
wa_leasex LIKE bapi1022_feglg005x.

DATA: it_depreciationareas TYPE TABLE OF bapi1022_dep_areas,


wa_depreciationareas TYPE bapi1022_dep_areas,
it_depreciationareasx TYPE TABLE OF bapi1022_dep_areasx,
wa_depreciationareasx TYPE bapi1022_dep_areasx,
it_cumulatedvalues TYPE TABLE OF bapi1022_cumval,
wa_cumulatedvalues TYPE bapi1022_cumval,
it_postedvalues TYPE TABLE OF bapi1022_postval,
wa_postedvalues TYPE bapi1022_postval,

it_return_dis TYPE TABLE OF bapiret2,


wa_return_dis TYPE bapiret2,
it_return TYPE TABLE OF bapiret2,
wa_return TYPE bapiret2.

DATA: gv_companycode LIKE bapi1022_1-comp_code,


gv_asset LIKE bapi1022_1-assetmaino,
gv_subnumber LIKE bapi1022_1-assetsubno,
gv_assetcreated LIKE bapi1022_reference.

" global veriable declaration ===================================


DATA : it_raw TYPE truxs_t_text_data. " for excel convert
" SELECTION DECLARATION ===============================================

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.


PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'


EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'p_file'
IMPORTING
file_name = p_file.

" Start of selection ======================================================

START-OF-SELECTION.

IF p_file IS INITIAL.
MESSAGE 'Please select upload file' TYPE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = p_file
TABLES
i_tab_converted_data = it_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

PERFORM pass_data .
PERFORM display_log.

*&---------------------------------------------------------------------*
*& Form PASS_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM pass_data .

LOOP AT it_data INTO wa_data.


wa_key-companycode = wa_data-bukrs.
* wa_key-asset = wa_data-asset.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = wa_data-anlkl
IMPORTING
output = wa_data-anlkl.

wa_generaldata-assetclass = wa_data-anlkl .
wa_generaldata-descript = wa_data-txt50_1 .
wa_generaldata-descript2 = wa_data-txt50_2 .
wa_generaldata-serial_no = wa_data-sernr .
wa_generaldata-invent_no = wa_data-invnr .
wa_generaldata-quantity = wa_data-menge .
wa_generaldata-main_descript = wa_data-main_descript .
wa_generaldata-history = wa_data-history .

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'


EXPORTING
input = wa_data-meins
language = sy-langu
IMPORTING
output = wa_data-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.

wa_generaldata-base_uom = wa_data-meins .

wa_generaldatax-assetclass = 'X'.
wa_generaldatax-descript = 'X'.
wa_generaldatax-descript2 = 'X'.
wa_generaldatax-serial_no = 'X'.
wa_generaldatax-invent_no = 'X'.
wa_generaldatax-quantity = 'X'.
wa_generaldatax-base_uom = 'X'.
wa_generaldatax-main_descript = 'X'.
wa_generaldatax-history = 'X'.

wa_inventory-include_in_list = wa_data-include_in_list.
wa_inventoryx-include_in_list = 'X'. "wa_data-INCLUDE_IN_LIST'.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'


EXPORTING
date_external = wa_data-aktiv
* accept_initial_date =
IMPORTING
date_internal = wa_data-aktiv
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.

wa_postinginformation-cap_date = wa_data-aktiv.
wa_postinginformationx-cap_date = 'X'.

wa_timedependentdata-costcenter = wa_data-kostl.
wa_timedependentdatax-costcenter = 'X'.

wa_timedependentdata-plant = wa_data-werks.
wa_timedependentdatax-plant = 'X'.

wa_timedependentdata-location = wa_data-location.
wa_timedependentdatax-location = 'X'.
* wa_timedependentdata-room = wa_data-room.
* wa_timedependentdatax-room = 'X'.

wa_allocations-evalgroup1 = wa_data-evalgroup1.
wa_allocationsx-evalgroup1 = 'X'.
wa_allocations-evalgroup2 = wa_data-evalgroup2.
wa_allocationsx-evalgroup2 = 'X'.

wa_origin-vendor_no = wa_data-lifnr.
wa_origin-manufacturer = wa_data-manufacturer.
* wa_origin-trade_id = wa_data-trade_id.
* wa_origin-country = wa_data-country.

* wa_origin-type_name = wa_data-type_name.
wa_origin-orig_acq_yr = wa_data-orig_acq_yr.
wa_origin-orig_value = wa_data-orig_value.
* wa_origin-inhouse_prod_percentage = wa_data-inhouse_prod_percentage.

wa_originx-vendor_no = 'X'.
wa_originx-manufacturer = 'X'.
* wa_originx-trade_id = 'X'.
* wa_originx-country = 'X'.

* wa_originx-type_name = 'X'.
wa_originx-orig_acq_year = 'X'.
wa_originx-orig_value = 'X'.
* wa_originx-inhouse_prod_percentage = 'X'.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'


EXPORTING
date_external = wa_data-put_to_use_date
* accept_initial_date =
IMPORTING
date_internal = wa_data-put_to_use_date
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.

wa_glo_in_gen-block_key = wa_data-block_key.
wa_glo_in_gen-bl_key_add_depr = wa_data-bl_key_add_depr.
wa_glo_in_gen-put_to_use_date = wa_data-put_to_use_date.

wa_glo_in_genx-block_key = 'X'.
wa_glo_in_genx-bl_key_add_depr = 'X'.
wa_glo_in_genx-put_to_use_date = 'X'.

* wa_lease-type = wa_data-type.
* wa_lease-base_value = wa_data-base_value.
* wa_lease-purchprice = wa_data-purchprice.
* wa_lease-no_paymnts = wa_data-no_paymnts.

* wa_lease-payment = wa_data-payment.

* wa_leasex-type = 'X'.
* wa_leasex-base_value = 'X'.
* wa_leasex-purchprice = 'X'.
* wa_leasex-no_paymnts = 'X'.
* wa_leasex-payment = 'X'.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'


EXPORTING
date_external = wa_data-afabg
* accept_initial_date =
IMPORTING
date_internal = wa_data-afabg
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.

*
* UNPACK wa_data-afabe TO wa_data-afabe.

* CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'


* EXPORTING
* date_external = wa_data-afabg_02
** accept_initial_date =
* IMPORTING
* date_internal = wa_data-afabg_02
* EXCEPTIONS
* date_external_is_invalid = 1
* OTHERS = 2.
wa_depreciationareas-area = 01."wa_data-afabe .
wa_depreciationareas-dep_key = wa_data-afasl .
wa_depreciationareas-ulife_yrs = wa_data-ndjar .
wa_depreciationareas-ulife_prds = wa_data-ulife_prds .
* wa_depreciationareas-exp_ulife_yrs = wa_data-AFABG .
wa_depreciationareas-odep_start_date = wa_data-afabg .
APPEND wa_depreciationareas TO it_depreciationareas.

* IF wa_data-afabe_02 IS NOT INITIAL.


* UNPACK wa_data-afabe_02 TO wa_data-afabe_02.
wa_depreciationareas-area = 15. "wa_data-afabe_02 .
wa_depreciationareas-dep_key = wa_data-afasl .
wa_depreciationareas-ulife_yrs = wa_data-ndjar .
wa_depreciationareas-ulife_prds = wa_data-ulife_prds .
* wa_depreciationareas-exp_ulife_yrs = wa_data-AFABG .
wa_depreciationareas-odep_start_date = wa_data-afabg .
APPEND wa_depreciationareas TO it_depreciationareas.

* ENDIF.

wa_depreciationareasx-area = 01. "wa_data-afabe ." 'X' .


wa_depreciationareasx-dep_key = 'X' .
wa_depreciationareasx-ulife_yrs = 'X' .
* wa_depreciationareasx-exp_ulife_yrs = 'X' .
wa_depreciationareasx-odep_start_date = 'X' .
wa_depreciationareasx-ulife_prds = 'X'.
APPEND wa_depreciationareasx TO it_depreciationareasx.

* IF wa_data-afabe_02 IS NOT INITIAL.


wa_depreciationareasx-area = 15. "wa_data-
afabe_02 ." 'X' .
wa_depreciationareasx-dep_key = 'X' .
wa_depreciationareasx-ulife_yrs = 'X' .
* wa_depreciationareasx-exp_ulife_yrs = 'X' .
wa_depreciationareasx-odep_start_date = 'X' .
wa_depreciationareasx-ulife_prds = 'X'.
APPEND wa_depreciationareasx TO it_depreciationareasx.
* ENDIF.

DATA lv_year(4) TYPE c.


CALL FUNCTION 'GM_GET_FISCAL_YEAR'
EXPORTING
i_date = sy-datum
i_fyv = 'V3'
IMPORTING
e_fy = lv_year
* EXCEPTIONS
* FISCAL_YEAR_DOES_NOT_EXIST = 1
* NOT_DEFINED_FOR_DATE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

wa_cumulatedvalues-area = 01. "wa_data-afabe.


wa_cumulatedvalues-fisc_year = lv_year.
wa_cumulatedvalues-acq_value = wa_data-kansw.
IF wa_data-knafa GE 0.
wa_data-knafa = wa_data-knafa * -1.
wa_cumulatedvalues-ord_dep = wa_data-knafa.
ELSE.
wa_cumulatedvalues-ord_dep = wa_data-knafa.
ENDIF.
* wa_cumulatedvalues-acq_value = wa_data-nafag.

APPEND wa_cumulatedvalues TO it_cumulatedvalues.

* IF wa_data-afabe_02 IS NOT INITIAL.


wa_cumulatedvalues-area = 15. "wa_data-afabe_02.
wa_cumulatedvalues-fisc_year = lv_year.
wa_cumulatedvalues-acq_value = wa_data-kansw_02.
APPEND wa_cumulatedvalues TO it_cumulatedvalues.

*** IF wa_data-knafa GE 0.
*** wa_data-knafa = wa_data-knafa * -1.
** IF wa_data-knafa_02 GE 0.
** wa_data-knafa_02 = wa_data-knafa_02 * -1.
** wa_postedvalues-ord_dep = wa_data-knafa_02.
** ELSE.
** wa_postedvalues-ord_dep = wa_data-knafa_02.
** ENDIF.
** APPEND wa_postedvalues TO it_postedvalues.
**
*** APPEND wa_cumulatedvalues TO it_cumulatedvalues.
*** ENDIF.

wa_postedvalues-area = 01. "wa_data-afabe.


wa_postedvalues-fisc_year = lv_year.
* wa_cumulatedvalues-acq_value = wa_data-kansw.
IF wa_data-nafag GE 0.
wa_data-nafag = wa_data-nafag * -1.
* wa_cumulatedvalues-ord_dep = wa_data-nafag.
wa_postedvalues-ord_dep = wa_data-nafag.
ELSE.
wa_postedvalues-ord_dep = wa_data-nafag.
ENDIF.
* wa_cumulatedvalues-acq_value = wa_data-nafag.
APPEND wa_postedvalues TO it_postedvalues.

* IF wa_data-afabe_02 IS NOT INITIAL.


** wa_postedvalues-area = 15. "wa_data-afabe_02.
** wa_postedvalues-FISC_YEAR = lv_YEAR.
*** wa_cumulatedvalues-acq_value = wa_data-kansw. "_02.
**
**
** IF wa_data-nafag GE 0.
** wa_data-nafag = wa_data-nafag * -1.
** wa_postedvalues-ord_dep = wa_data-nafag. "_02.
**
** ELSE.
** wa_postedvalues-ord_dep = wa_data-nafag. "_02.
** ENDIF.
** APPEND wa_postedvalues TO it_postedvalues.

PERFORM post_bapi.

CLEAR : wa_data
, it_depreciationareas
, it_depreciationareasx
, wa_generaldata
, wa_generaldatax
, wa_inventory
, wa_inventoryx
, wa_postinginformation
, wa_postinginformationx
, wa_timedependentdata
, wa_timedependentdatax
, wa_allocations
, wa_allocationsx
,wa_origin
,wa_originx
,it_cumulatedvalues
,it_postedvalues
,it_return.

ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form POST_BAPI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM post_bapi .

CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE'


EXPORTING
key = wa_key
* REFERENCE =
* CREATESUBNUMBER =
* CREATEGROUPASSET =
* TESTRUN = ' '
generaldata = wa_generaldata
generaldatax = wa_generaldatax
inventory = wa_inventory
inventoryx = wa_inventoryx
postinginformation = wa_postinginformation
postinginformationx = wa_postinginformationx
timedependentdata = wa_timedependentdata
timedependentdatax = wa_timedependentdatax
allocations = wa_allocations
allocationsx = wa_allocationsx
origin = wa_origin
originx = wa_originx
* INVESTACCTASSIGNMNT =
* INVESTACCTASSIGNMNTX =
* NETWORTHVALUATION =
* NETWORTHVALUATIONX =
* REALESTATE =
* REALESTATEX =
* INSURANCE =
* INSURANCEX =
leasing = wa_lease
leasingx = wa_leasex
* GLO_RUS_GEN =
* GLO_RUS_GENX =
* GLO_RUS_PTX =
* GLO_RUS_PTXX =
* GLO_RUS_TTX =
* GLO_RUS_TTXX =
glo_in_gen = wa_glo_in_gen
glo_in_genx = wa_glo_in_genx
* GLO_JP_ANN16 =
* GLO_JP_ANN16X =
* GLO_JP_PTX =
* GLO_JP_PTXX =
* GLO_TIME_DEP =
* GLO_RUS_GENTD =
* GLO_RUS_GENTDX =
* GLO_RUS_PTXTD =
* GLO_RUS_PTXTDX =
* GLO_RUS_TTXTD =
* GLO_RUS_TTXTDX =
* GLO_JP_IMPTD =
* GLO_JP_IMPTDX =
IMPORTING
companycode = gv_companycode
asset = gv_asset
subnumber = gv_subnumber
assetcreated = gv_assetcreated
TABLES
depreciationareas = it_depreciationareas
depreciationareasx = it_depreciationareasx
* INVESTMENT_SUPPORT =
* EXTENSIONIN =
cumulatedvalues = it_cumulatedvalues
postedvalues = it_postedvalues
* TRANSACTIONS =
* PROPORTIONALVALUES =
return = it_return
* POSTINGHEADERS =
.

LOOP AT it_return INTO wa_return.


IF wa_return-type EQ 'E'.

MOVE wa_return TO wa_return_dis.

APPEND wa_return_dis TO it_return_dis.

CLEAR:wa_return_dis.
ELSEIF wa_return-type EQ 'S'.

MOVE wa_return TO wa_return_dis.

APPEND wa_return_dis TO it_return_dis.

CLEAR:wa_return_dis.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.

ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_LOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM display_log .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_structure_name = 'BAPIRET2'
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_return_dis
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.

ENDFORM.

You might also like