Load budget in FM with BAPI_0050_CREATE
Details
- Details
- Category: ABAP
- Created on Thursday, 17 January 2013 14:45
- Last Updated on Thursday, 17 January 2013 14:45
- Published on Thursday, 17 January 2013 14:45
- Written by Administrator
- Hits: 15186
Load budget data in SAP FM with function BAPI_0050_CREATE from text file :
Text File Structure ( tab delimited ) :
- year
- month
- BUDCAT
- BUDTYPE
- FUND
- FUNDS_CTR
- CMMT_ITEM
- FUNC_AREA
- TOTAL_AMOUNT
- ITEM_TEXT
ABAP Program :
REPORT ZUP_BUD_FM line-size 255.
**********************************************************************
* Upload Budget in FM
*
* www.developerpages.gr
*
**********************************************************************
DATA : TAB.
CLASS cl_abap_char_utilities DEFINITION LOAD.
TAB = Cl_abap_char_utilities=>horizontal_tab.
data: begin of itab occurs 100,
year type string,
month type string,
BUDCAT type string,
BUDTYPE type string,
FUND type string,
FUNDS_CTR type string,
CMMT_ITEM type string,
FUNC_AREA type string,
TOTAL_AMOUNT type string,
ITEM_TEXT type string.
data : end of itab.
data : l type i.
PARAMETERS : fname type string OBLIGATORY.
perform load_file.
DESCRIBE TABLE itab lines l.
if l > 0.
perform upload_budget.
else.
write :/ 'Cannot find data into file!'.
endif.
*&---------------------------------------------------------------------*
*& Form load_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form load_file.
data : rec type string.
open DATASET fname for INPUT IN LEGACY TEXT MODE.
do.
read DATASET fname INTO rec.
IF sy-subrc <> 0.
exit.
else.
split rec at tab INTO
itab-year
itab-month
itab-budcat
itab-BUDTYPE
itab-FUND
itab-FUNDS_CTR
itab-CMMT_ITEM
itab-FUNC_AREA
itab-TOTAL_AMOUNT
itab-ITEM_TEXT.
append itab.
ENDIF.
ENDDO.
CLOSE DATASET fname.
endform. "load_file
*&---------------------------------------------------------------------*
*& Form insert_budget
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form upload_budget.
data : l_header_data type BAPI_0050_HEADER.
data : begin of l_item_data OCCURS 100.
include STRUCTURE BAPI_0050_ITEM.
data : end of l_item_data.
data : begin of l_period_data OCCURS 100.
include STRUCTURE BAPI_0050_PERIOD.
data : end of l_period_data.
data : l_RETURN like TABLE OF BAPIRET2.
data : wa_return like LINE OF l_return.
data : l_language type BAPI_0050_FIELDS-LANGUAGE.
data : l_num type i.
l_header_data-FM_AREA = ''. "<-- insert your value
l_header_data-VERSION = ''. "<-- insert your value
l_header_data-DOCDATE = sy-datum.
l_header_data-DOCTYPE = ''. "<-- insert your value
l_header_data-DOCSTATE = ''. "<-- insert your value
l_header_data-PROCESS = ''. "<-- insert your value
clear l_num.
LOOP AT itab.
add 1 to l_num.
l_item_data-ITEM_NUM = l_num.
UNPACK l_item_data-ITEM_NUM to l_item_data-ITEM_NUM.
l_item_data-FISC_YEAR = itab-year.
l_item_data-BUDCAT = itab-BUDCAT.
l_item_data-BUDTYPE = itab-BUDTYPE.
l_item_data-FUND = itab-FUND.
l_item_data-FUNDS_CTR = itab-FUNDS_CTR.
l_item_data-CMMT_ITEM = itab-CMMT_ITEM.
l_item_data-FUNC_AREA = itab-FUNC_AREA.
l_item_data-MEASURE = ''.
l_item_data-GRANT_NBR = ''.
l_item_data-TRANS_CURR = ''. "<-- insert your value
l_item_data-TRANS_CURR_ISO = ''. "<-- insert your value'.
l_item_data-DISTKEY = ''.
l_item_data-ITEM_TEXT = itab-item_text.
l_item_data-VALTYPE = ''. "<-- insert your value
append l_item_data.
l_period_data-ITEM_NUM = l_item_data-ITEM_NUM.
l_period_data-BUDGETING_PERIOD = itab-month.
l_period_data-PERIOD_AMOUNT = itab-TOTAL_AMOUNT.
APPEND l_period_data. clear l_period_data.clear l_item_data.
ENDLOOP.
CALL FUNCTION 'BAPI_0050_CREATE'
EXPORTING
LANGUAGE = l_language
HEADER_DATA = l_header_data
TESTRUN = ''
TABLES
ITEM_DATA = l_item_data
PERIOD_DATA = l_period_data
RETURN = l_return.
LOOP AT l_return INTO wa_return.
write :/ wa_return-type, wa_return-MESSAGE.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDFORM. "upload_budget