Wednesday 28 March 2012

Set Extractor Parameters Dynamically

In some scenarios when we launch data extraction from BW we may want to have extractor selection parameters to be defined dynamically. 

For example, for a certain extraction we may want to select a particular Period and Versions based on data currently available in the source system. In the post below I will review an example of how to organize stock planning data load based on Period and Version submitted from the source system. I will describe a model for loading transactional data to BW and specify configuration required for automating data loads based on data availability in the source.

Business Task Description:

Several times per month business users generate stock planning versions in the source system for certain stock categories. This information can be gathered via a generic extractor with selection parameters (Period, Version). Unfortunately, the extractor is working in a FULL mode only and BW does not know when to extract data and which version to extract. On the other hand, users maintain a table in the source system (ZCONTROL) where they specify parameters for new planning versions that have been generated. Therefore by reading entries in this table we can identify what needs to be loaded in BW.
Our goal is to build a solution in SAP BW that would automate loads of Stock Planning Versions and will eliminate manual involvement.

Extract Selection Parameters:

As a first step we want to load Stock version selection parameters to BW. This is possible to do in a delta mode, as there is a “Modified On” (AEDAT) field available in the table ZCONTROL.

We have to create a generic extractor ZAG_CONTR (Transaction Code: RSO2) based on the table ZCONTROL. In the Generic Delta screen we specify field AEDAT as Delta specific field, and check “Calendar Day” in the selections:

image002.jpg

After the replication of datasources in BW our newly created datasource (ZAG_CONTR) can be connected to a DSO (O_SELP). I suggest having three fields in this DSO:
  • Period
  • Version
  • Calendar Day – filled in the transformation with the date of the load.
The following data flow can be used for this model:

image004.jpg

Load Stock Planning Versions with Dynamic Selections

In the next step we have to select data in the Transactional datasource (Z_STVERS) based on the delta records received in the “Selection Parameters” DSO. This can be done by comparing the value of the Calendar Day field to the Current date.

We have to specify ABAP routines in the Infopackage Data Selection screen. This should be done both for Period and Version selection objects:

image006.jpg

I suggest using the following code in the Period selection ABAP Routine:

DATA: selt TYPE STANDARD TABLE OF /BIC/AO_SELP00.FIELD-SYMBOLS: <selt> TYPE /BIC/AO_SELP00.
SELECT * FROM /BIC/AO_SELP00 INTO TABLE
 seltWHERE CALDAY = sy-datum.
DATA: cper TYPE /BIC/OIZPERD. cper = ' '
.
IF sy-subrc = 0
.
  p_subrc = 
0
.
  
LOOP AT selt ASSIGNING
 <selt>.* Fill Period
    
read table l_t_range with key
    fieldname = 
'POSTING_DATE'
.
    l_idx = sy-tabix.
    l_t_range-LOW = <selt>-/BIC/ZPERD.
    
modify l_t_range index
 l_idx.
    
IF cper = ' '
.
      cper = <selt>-/BIC/ZPERD.
    
ELSEIF
 cper <> <selt>-/BIC/ZPERD.
      p_subrc = 
2
.
      
exit
.
    
ENDIF
.
  
ENDLOOP
.ELSE.
  p_subrc = 
1
.ENDIF.

In the code above we check if there are two different periods arriving with Delta from the Control table. If this is the case we identify it as an error and stop further processing. This is done because according to business rules during the same day we can get multiple Stock Plan versions for the same Period, not for multiple periods.

For the Version selection I suggest applying the following ABAP code:

DATA: selt TYPE STANDARD TABLE OF /BIC/AO_SELP00.FIELD-SYMBOLS: <selt> TYPE /BIC/AO_SELP00.
SELECT * FROM /BIC/AO_SELP00 INTO TABLE
 seltWHERE CALDAY = sy-datum.
DATA: mv TYPE C. mv = 'n'
.
IF sy-subrc = 0
.
  
LOOP AT selt ASSIGNING
 <selt>.* Fill version
    
read table l_t_range with key
    fieldname = 
'VERSION'
.
    l_idx = sy-tabix.
    l_t_range-LOW = <selt>-/BIC/ZVERS.
    
IF mv = 'n'
.
      
modify l_t_range index
 l_idx.
      mv = 
'y'
.
    
ELSE
.
      
append
 l_t_range.
    
ENDIF
.
  
ENDLOOP
.
  p_subrc = 
0
.ELSE.
  p_subrc = 
1.
ENDIF.

The dynamically generated output for the infopackage selections can look as follows:

image008.jpg

Entire process automation will be done by running DELTA loads for “Selection Parameters” DSO daily, and subsequently running a FULL extraction of the stock planned versions (extractor Z_STVERS) with the dynamic parameter selection as described above.

No comments:

Post a Comment