Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
shai_greenberg
Participant

Preface

This article explains how to perform a daily load with CO standard datasources that weren't designed for this purpose, using some less known BW features and some ABAP. These features are also useful for other loading scenarios.

Note 448693 describes a situation where CO standard datasources intended for a full load into an Infocube are used instead to load a DSO. The note describes two instances where this could cause data loss - identical keys from the same PSA request, and no update of zero value records. The note gives some tips on how to handle that situation anyway - summation of the key figures and use of selective deletion.

When a requirement calls for a daily data load to an ODS, and the amount of data is large, the best solution is usually standard delta or a non-standard datasource. However, one can still use a "partial" full load that fetches the recent data using the aforementioned tips. In the Infopackage, "recent data" is usually a selection with a range between a recent date and today (for a date field), or a recent period and the current one (for a fiscal period field).

As definitions such as "today" or "120 days ago" are dynamic, this necessitates the use of ABAP in the Infopackage selection, or a user-exit variable.

As mentioned in the note selective deletion is needed to delete the data with the same selection that is about to be loaded.

In the case of DSO, this requires use of an ABAP program in the process chain, which can be generated using the DELETE_FACTS transaction.

As the Infopackage selection is dynamic, the variant that is used for the ABAP program needs to be dynamic as well. This is made possible by Dynamic Variant Processing, which involves use of transaction STVARV and some ABAP.

Following is a description of each stage. Along the article you'll find links to recommended articles explaining the stages in detail. In the end are all the links as well as my ABAP code.

Dynamic Infopackage Selection

Infopackages allow ABAP and variables for implementing selection. See Surendra Kumar Reddy Koduru's article:

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d478b9-2394-2e10-fdb3-b17fa85e5...

Some additional notes:


1) In addition to the "EQ" selection option, of use is also the "BT" option, which allows the aforementioned requirement of getting the recent data. In that case you will also use l_t_range-high to store the upper limit.


2) I found dynamic representation of the current date/period especially useful as a replacement for the "very high upper limit" selection. A high upper limit is often used as a "temporary" placeholder meant to represent a date that is – assumingly - realistically higher than any possible value of the field within the system's life cycle. Using ABAP/a variable that represents the current date/period removes the need for that assumption. In one case, I found that it even improved performance, as 0co_om_nwa_1 spends redundant runtime on periods without data when using the FISCPER selection.


3) If you foresee a change of the required time difference, you can make the difference half-dynamic by storing it in a parameter table. You can also generalize this into a function that receives the parameter name, which can then be reused in several Infopackages. See the ABAP code at the bottom of the article.


Selective Deletion in Process Chain

As mentioned in note, there is no standard function for Selective deletion from a DSO with the same selection of a specific request.

However the transaction DELETE_FACTS generates an ABAP program, that performs a deletion from an Infoprovider according to existing variables and allows offsets. You can then use the ABAP program in your process chain.


This is explained in detail in the following article, also by Surendra Kumar Reddy Koduru :

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/603a9558-0af1-2b10-86a3-c685c6007...

You can't transport the generated programs, but you can copy them and transport the copied program. You can also transport the variants.

This works great with a date field selection. With a fiscal period field, things get a little more interesting.

Dynamic Variant Processing

In order to supply dynamic values for the deletion program when using a field other than date, you need to update a row in TVARVC with the relevant values. Since the selection needs to be dynamic, updating the table needs to be done using ABAP. Here's an article by Anish Koshy Oommen that explains how to do this:

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f05b0f0a-db27-2e10-b4a4-a0272a80f...

For the selective deletion program, I've found that I needed to use "Selection options" rather than a parameter. In the ABAP example given, this means c_p value should be S rather than P. Also, in STVARV you need to maintain the entry in the "Selection options" tab rather than the Parameter tab.

Also note that while Infopackage selection uses the YYYYMMM representation for a fiscal period, selection variants use the MMM.YYYY format - this can be solved by using conversion_exit_peri7_output:

http://www.se80.co.uk/sapfms/c/conv/conversion_exit_peri7_output.htm

Since the selection is essentially the same as that of the Infopackage, you may be able to reuse some code for both selections.

Following is a process chain that includes all the stages detailed above.

Thanks to Shani Bashkin from Xact Soft for her feedback and support.

ABAP example


Function for calculating fiscper range

FUNCTION

Z_BW_GET_FISCPER_DATA .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(NAME) TYPE ANY
*" VALUE(PERI7) TYPE C
*" EXPORTING
*" REFERENCE(LOW) TYPE ANY
*" REFERENCE(HIGH) TYPE ANY
*" REFERENCE(SIGN) TYPE ANY
*" REFERENCE(OPTION) TYPE ANY
*"----------------------------------------------------------------------
DATA:
l_value TYPE ZBW_PARAM-value,
l_per LIKE t009b-poper,
l_yr LIKE t009b-bdatj,
l_month(2) TYPE c,
l_prefix TYPE c,
l_period(7) TYPE c,
l_yeardiff TYPE i,
l_cmonth TYPE i,
l_origdate LIKE sy-datum.
SELECT SINGLE value from ZBW_PARAM
INTO l_value
WHERE pname = name.

IF sy-subrc <> 0.
l_value = 4.
ENDIF.


l_origdate = sy-datum.
l_month = l_origdate+4(2).
l_yr = l_origdate(4).
l_yeardiff = 0 .
l_prefix = ''.
l_cmonth = l_month.
l_cmonth = l_cmonth - l_value + 1.
IF l_cmonth <= 0.
l_yeardiff = ( ( ( -1 * ( l_cmonth ) ) div 12 ) ) + 1.
l_yr = l_yr - l_yeardiff.
l_cmonth = l_cmonth + ( l_yeardiff * 12 ).
ENDIF.
l_month = l_cmonth.

IF l_month < 10.
l_prefix = '0'.
ENDIF.

CONCATENATE l_yr l_prefix '0' l_month INTO l_period.

IF peri7 EQ 'X'.
low = l_period.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_PERI7_OUTPUT'
EXPORTING
INPUT = l_period
IMPORTING
OUTPUT = low.
ENDIF.
call function 'DATE_TO_PERIOD_CONVERT'
EXPORTING
I_DATE = l_origdate " Current Date
I_MONMIT = '00' " default value
I_PERIV = 'K4' " your fiscal variant
IMPORTING
E_BUPER = l_per " period only
E_GJAHR = l_yr. " year only

CONCATENATE l_yr l_per INTO l_period.
IF peri7 EQ 'X'.
high = l_period.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_PERI7_OUTPUT'
EXPORTING
INPUT = l_period
IMPORTING
OUTPUT = high.
ENDIF.

option = 'BT'.
sign = 'I'.




ENDFUNCTION.

Program for updating TVARVC with FISCPER Range

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


*& Report ZBW_TVARVC_FISCPER_UPDATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZBW_TVARVC_FISCPER_UPDATE.

include ZBW_TVARVC_FISCPER_UPDATE_TOP.
include ZBW_TVARVC_FISCPER_UPDATE_SEL.
include ZBW_TVARVC_FISCPER_UPDATE_f01.



START-OF-SELECTION.

* Get error request in selected DSO
perform get_data_and_update_variable.

*&---------------------------------------------------------------------*
*& Include ZBW_TVARVC_FISCPER_UPDATE_SEL
*&---------------------------------------------------------------------*

PARAMETERS: p_pname TYPE TVARVC-NAME.

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


*& Include ZBW_TVARVC_FISCPER_UPDATE_TOP
*&---------------------------------------------------------------------*

DATA :
gs_tvarvc TYPE tvarvc.

CONSTANTS: c_s TYPE rsscr_kind VALUE 'S'.

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


*& Include ZBW_TVARVC_FISCPER_UPDATE_F01
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form GET_DATA_AND_UPDATE_VARIABLE
*&---------------------------------------------------------------------*
* calculates the fiscper range for selective deletion
* and fills it into TVARVC.
* see
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f05b0f0a-db27-2e10-b4a4-a0272a80f...
* ABAP: Dynamic Variant Processing with STVARV
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM get_data_and_update_variable.
CALL FUNCTION 'Z_BW_GET_FISCPER_DATA'
EXPORTING
NAME = p_pname
PERI7
= ''
IMPORTING
LOW = gs_tvarvc-low
HIGH
= gs_tvarvc-high
SIGN = gs_tvarvc-sign
OPTION = gs_tvarvc-opti.

gs_tvarvc
-name = p_pname.
gs_tvarvc
-type = c_s.
gs_tvarvc
-numb = space.
UPDATE tvarvc FROM gs_tvarvc.
FREE: gs_tvarvc.

ENDFORM. " GET_DATA_AND_UPDATE_VARIABLE

 
 

Infopackage Routine for setting the fiscper range for 0co_om_nwa_2 infopackage

program

conversion_routine.
* Type pools used by conversion program
type-pools: rsarc, rsarr, rssm.
tables: rssdlrange.
* Global code used by conversion rules
*$*$ begin of global - insert your declaration only below this line *-*
* TABLES: ...
CONSTANTS: c_pname TYPE ZBW_PARAM-pname VALUE 'ZBW_LAST_X_MONTHS_CCA'.
* DATA: ...
*$*$ end of global - insert your declaration only before this line *-*
* -------------------------------------------------------------------
* InfoObject =
* Fieldname = FISCPER
* data type = NUMC
* length = 000007
* convexit = PERI7
* -------------------------------------------------------------------

form compute_FISCPER
tables l_t_range structure rssdlrange
using p_infopackage type rslogdpid
p_fieldname
type rsfnm
changing p_subrc like sy-subrc.
* Insert source code to current selection field
*$*$ begin of routine - insert your code only below this line *-*
*brings the last x month where x is value of parameter c_pname in ZBW_PARAM
**
data: l_idx like sy-tabix.


read table l_t_range with key
fieldname = 'FISCPER'.
l_idx = sy-tabix.
***** Begin period range calculation *****
CALL FUNCTION 'Z_BW_GET_FISCPER_DATA'
EXPORTING
NAME = c_pname
PERI7
= 'X'
IMPORTING
LOW = l_t_range-low
HIGH
= l_t_range-high
SIGN = l_t_range-sign
OPTION = l_t_range-option.

***** End period range calculation *****

modify l_t_range index l_idx.

p_subrc
= 0.

*$*$ end of routine - insert your code only before this line *-*
endform. "

Labels in this area