Products Industries
Industries Services Support
Services and Support Training
Training Community
Community Developer
Developer Partner
Partner About
About
Ask a Question Write a Blog Post Login
Former Member
November 7, 2013 25 minute read
Generic Delta Extraction using Function Module along with currency conversion in source system
Follow RSS feed Like
1. Need to have addi onal fields from Sales Partner Table (VBPA) for all Order Line Items in Sales Item Table (VBAP) for Sales Order Line Item Level Repor ng. Standard data sources cannot be
used as many info providers such as DSO’s; Cubes are using them so it involves lots of effort in terms of me and money maintaining the same. Also this approach involves a lot of risk
considering if anything gets deac vated during Transports.
2. In addi on to this Currency Conversion has to be done in Source system as per client norms.
R3 Side: In order to meet the above 2 requirements we decided to go for Generic Delta Extrac on using Func on Module. Need to make sure that Generic Extrac on is Delta Based as Sales
Order Items Table (VBAP) contains all the line item level informa on for Orders and its not easy extrac ng everything i.e. doing full update on daily basis and then maintaining the same in BW.
Here, we shall be building a logic using AEDAT (Created on) and ERDAT (Changed on) of VBAP to extract the order Items ge ng changed/Created since the last BW Extrac on.
1. Create an Extract structure including DLTDATE field in addi on to all other required fields. DLTDATE would be used to build the logic to extract the delta using AEDAT and ERDAT.
2. Copy the Func on group RSAX from SE80, give new func on group as ZRSAX_TEST.
3. Copy func on module. Deselect all and then select only RSAX_BIW_GET_DATA_SIMPLE name it as ZBW_FUNCTION.
4. Go to the Include folder and double-click on LZRSAX_TESTTOP define the structure and Field symbol and internal table as below.
INCLUDE LZRSAX_TESTTOP.
END OF ty_vbap.
END OF ty_vbap.
END OF ty_ord_final.
* Internal table
*Work areas
* Variables
save_ukurx(8) TYPE p,
* counter
* cursor
* Select ranges
* (following calls)?
IF i_initflag = sbiwa_c_flag_on.
************************************************************************
************************************************************************
CASE i_dsource.
WHEN ‘ZBW_DS_TEST’.
WHEN OTHERS.
* This is a typical log call. Please write every error message like this
‘ ‘. “message variable 2
RAISE error_passed_to_mess_handler.
ENDCASE.
s_s_if-requnr = i_requnr.
s_s_if-dsource = i_dsource.
s_s_if-maxsize = i_maxsize.
* and database table fields this may be far from beeing trivial)
************************************************************************
************************************************************************
IF s_counter_datapakid = 0.
* Fill range tables BW will only pass down simple selection criteria
CASE l_s_select-fieldnm.
WHEN ‘VBELN’.
ls_vbeln-sign = ls_select-sign.
ls_vbeln-option = ls_select-option.
ls_vbeln-low = ls_select-low.
ls_vbeln-high = ls_select-high.
APPEND l_r_vbeln.
WHEN ‘POSNR’.
ls_posnr-sign = ls_select-sign.
ls_posnr-option = ls_select-option.
ls_posnr-low = ls_select-low.
ls_posnr-high = ls_select-high.
APPEND l_r__posnr.
WHEN ‘DLTDATE’.
ls_delta_date-sign = ls_select-sign.
ls_delta_date-option = ls_select-option.
ls_delta_date-low = ls_select-low.
ls_delta_date-high = ls_select-high.
APPEND l_r_dltdate.
ENDCASE.
ENDLOOP.
* be determined.
OR ( itm~aedat NE ‘00000000’
REFRESH: t_vbap.
OF TABLE t_vbap
IF sy-subrc <> 0.
RAISE no_more_data.
ENDIF..
<i_fs_order_item>-posnr TO t_final-posnr,
<i_fs_order_item>-netwr TO t_final-netwr,
<i_fs_order_item>-waerk TO t_final-waerk,
<i_fs_order_item>-dldat TO t_final-dltdate.
SELECT SINGLE pernr FROM vbpa INTO t_final-pernr
IF sy-subrc NE 0.
t_final-pernr = space.
ENDIF.
IF sy-subrc = 0.
IF sy-subrc = 0.
IF sy-subrc = 0.
t_final-loc_curr = lv_waers.
t_final-rep_curr = ‘USD’.
ENDIF.
* Select the pricing date based on sales document and sales docu item
IF sy-subrc NE 0.
ENDIF.
IF <i_fs_order_item>-waerk NE lv_waers.
EXPORTING
date = lv_prsdt
foreign_amount = 1
foreign_currency = <i_fs_order_item>-waerk
local_currency = lv_waers
type_of_rate = ‘M’
IMPORTING
exchange_rate = save_ukurs
foreign_factor = save_ffact
local_amount = save_tfact
local_factor = save_ffact1
exchange_ratex = save_ukurx
derived_rate_type = save_kurst
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5.
IF sy-subrc = 0.
IF save_ffact1 NE 0 .
ENDIF.
t_final-netwr_loc_val = lv_netwr.
ENDIF.
ELSE.
t_final-netwr_loc_val = <i_fs_order_item>-netwr.
ENDIF.
IF lv_waers NE ‘USD’ .
CLEAR : save_ukurs1,lv_netwr,save_ukurs,
save_ffact,save_tfact,save_ffact1,
save_ukurx,save_kurst.
EXPORTING
date = lv_prsdt
foreign_amount = 1
foreign_currency = lv_waers
local_currency = ‘USD’
type_of_rate = ‘M’
IMPORTING
exchange_rate = save_ukurs
foreign_factor = save_ffact
local_amount = save_tfact
local_factor = save_ffact1
exchange_ratex = save_ukurx
derived_rate_type = save_kurst
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5.
IF sy-subrc = 0.
IF save_ffact1 NE 0 .
ENDIF.
ENDIF.
ELSE.
t_final-netwr_rep_val = t_final-netwr_loc_val.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
s_counter_datapakid = s_counter_datapakid + 1.
ENDFUNCTION.
The l_r_delta_date range is created for the mestamp. The selec on criteria for the extractor will be filled up into this range. This would be used to build the logic for extrac ng delta from VBAP
using AEDAT and ERDAT.
CASE l_s_select-fieldnm.
WHEN ‘VBELN’.
ls_vbeln-sign = ls_select-sign.
ls_vbeln-option = ls_select-option.
ls_vbeln-low = ls_select-low.
ls_vbeln-high = ls_select-high.
APPEND l_r_vbeln.
This part of the code is used to pass down the selec ons of vbeln from OLAP to OLTP. The same applies with 2 other fields for POSNR and DLTDATE.
OR ( itm~aedat NE ‘00000000’
Here, we are basically extrac ng the delta records from VBAP based upon the selec on passed for DLTDATE using ERDAT and AEDAT.Basically 2 condi ons are used to extract delta:
Therea er, once the above is done we are upda ng the final internal table T_VBAP.
IF sy-subrc NE 0.
t_final-pernr = space.
ENDIF.
Looping over this table to extract addi onal fields as per the requirement. In our case we need to extract addi onal partner fields from VBPA based upon orders ge ng created /changed since
last BW extrac on.
Currency Conversions
1. Document Currency: The Currency in which a document is posted in R/3 is called Document Currency. It is stored at document level as available in VBAP as it contains Sales Document Item
Level Informa on i.e. WAERK.
2. Local Currency: The Company Code Currency is called Local Currency. It is stored at Company Code level in T001 Table.
Now in order to get Local currency one needs to have the Company Code (BUKRS) but this is not available at Sales Order Item Level (VBAP).
1. Fetch Sales Organiza on (VKORG) first for all the Orders extracted earlier.
2. Fetch Corresponding Company Code (BUKRS) for all the Sales Organiza on (VKORG) extracted above from TVKO.
3. Fetch Corresponding Local Currency from the Table T001 for all company Code (BUKRS) extracted above.
This way we have fetched all the currencies for all the Order Items i.e. Document, Local and Repor ng Currency. Now we need to do the conversion of the net value in Document Currency to net
value in Local and Repor ng Currency.
We shall be using a Standard Func on Module ‘CONVERT_TO_LOCAL_CURRENCY’ for doing various conversions i.e. Local and Repor ng Currency from Document Currency.
Input Parameters:
In this part of the code we are fetching Pricing Date (PRSDT) from VBKD based upon Order Items already extracted from VBAP.
Finally we are passing everything to the Func on Module to have the Conversion done to Local Currency first and later to Repor ng Currency.
2. Fill in the various Details including the Func on module and Structure name.
3. Select the op on Timestamp and select the DLTDATE field you had added in your extract structure. Also set the safety limits as required.
Note: We could have selected Calend. Day but in that case the delta extrac on can only be done once in a day.
4. Click Save to go back to the previous screenand click Save again. The following screen comes up.
Note that the DLTDATE field is disabled for selec on; this is because this will be populated automa cally as part of the delta. As a result, it will be unavailable for manual entry in the Info package
or in RSA3
Alert Moderator
Following this step, create the corresponding ODS, Data source etc. in BW side and replicate. These steps are similar to what would be done for a normal generic data source.
Assigned tags
Later this ODS ac ve table is read to have these addi onal fields in BW Old Flow.
Thanks.
Related Blog Posts
5 Comments
Ganesh Bothe
Like (0)
The importing thing here is setting up Delta to extract Changed/Created Orders from VBAP.
Thanks
Kamal
Like (0)
mohamed ra k
Like (0)
GANAPATHI .
Thanks for providing this useful document on generic extraction with currency conversion .
Like (0)
Venkatesh Veera
why are we not using ranges varibles in the above select statement (l_r_vbeln, l_r_posnr, i_r_dltdate) instead you used (ls_vbeln, ls_posnr and s_delta_date). How are they getting
populated?? Can you please let me know it.
for newly created sales orders ( ERDAT will have value and AEDAT will be empty)
For changed ones do we need to write in the condition that AEDTA NE ‘000000’ ( I think its optional)
Thanks
Like (0)
Share & Follow Privacy Terms of Use Legal Disclosure Copyright Trademark Cookie Preferences Sitemap Newsletter