Hi All! When I started to work with BW it was very difficult to me to create extractors. Thats why I've decided to do step-by-step instruction. I hope it will be usefull for somebody. Let's start!
ps sorry for my english :smile:
Every extractor has : the structure and functional module
1. We must create a structure of our extractor. Go to se11, choose Data type - ZST1_TEST2 - create - Structure
On the table - parameters of structure (of course it's only sample)
COMP_CODE | /BI0/OICOMP_CODE |
CALMONTH | /BI0/OICALMONTH |
CALYEAR | /BI0/OICALYEAR |
FISCPER3 | /BI0/OIFISCPER3 |
AMOUNT | RSBCTMA_OD_MONET_AMOUNT |
CUR | BAPIBP_BAL_CUR |
2. Create fm ( more detail about fm I'll write later)
FM - it's very important and specific step. My skills in ABAP are near the zero an absolutely zero :smile: I'll try to describe in detail
ATTENTION: I must create fucnction group and include with data types in se80 for fm import parameters. se80 - Function Group -Enter - Yes
Change the include LZ_ZLOBINTOP
FUNCTION-POOL Z_ZLOBIN. "MESSAGE-ID ..
TYPE-pools SBIWA.
TYPE-pools SRSC.
TYPE-pools ZBCST.
TYPE-pools RSD.
2.1 se37 - ZST1_TEST
Import parameters
I_REQUNR | SBIWA_S_INTERFACE-REQUNR | Request number |
I_DSOURCE | SBIWA_S_INTERFACE-ISOURCE | Source name |
I_MAXSIZE | SBIWA_S_INTERFACE-MAXSIZE | Max size of the package |
I_INITFLAG | SBIWA_S_INTERFACE-INITFLAG | Initial flag |
Tables
I_T_SELECT | SBIWA_T_SELECT | Data for processing |
I_T_FIELDS | SBIWA_T_FIELDS | Field restrictions |
E_T_DATA | ZST1_TEST2 | Out table (type of our structure (look 1) |
ABAP code we will view later.
3. The create of data sourse. Go to rso2 and fill the fields as in picture
Now press Save and mark the selections ( I_T_FIELDS in fm)
Press Save - goto rsa1 - DataSources and in the required system Replicate metadata
Ofcourse you need to create FM to get real data.
Imagine, that we have table ZST1_TEST
№ | CALMONTH | COMPCODE | CUR | AMOUNT |
1 | 201301 | 2014 | RUB | 1 000,0000 |
2 | 201301 | 4011 | RUB | 6 000,0000 |
3 | 201301 | 5011 | RUB | 1 000,0000 |
4 | 201301 | 7007 | USD | 5 600,0000 |
5 | 201302 | 2014 | RUB | 2 000,0000 |
6 | 201302 | 5011 | RUB | 44 000,0000 |
7 | 201303 | 2014 | RUB | 3 000,0000 |
8 | 201303 | 6010 | RUB | 6 000,0000 |
9 | 201304 | 2014 | RUB | 4 000,0000 |
10 | 201304 | 3011 | RUB | 5 000,0000 |
11 | 201305 | 6987 | 987 654,0000 |
we need to exctract data as
CALMONTH | COMPCODE | CUR | AMOUNT | FISCPER3 | CALYEAR |
if space then USD | YYYYMM->0MM | YYYYMM->YYYY |
In FM- extractor I single out 3 steps:
1. Initialization infosousre and define the limits
2. Data processing - the work with data for extract
3. Work with out table
This is my FM ( i'm the greatest ABAP master :lol: ) with comments
************************************************************************************
FUNCTION ZST1_TEST.
*"----------------------------------------------------------------------
*"*"Локальный интерфейс:
*" IMPORTING
*" REFERENCE(I_REQUNR) TYPE SBIWA_S_INTERFACE-REQUNR
*" REFERENCE(I_DSOURCE) TYPE SBIWA_S_INTERFACE-ISOURCE
*" REFERENCE(I_MAXSIZE) TYPE SBIWA_S_INTERFACE-MAXSIZE
*" REFERENCE(I_INITFLAG) TYPE SBIWA_S_INTERFACE-INITFLAG
*" TABLES
*" I_T_SELECT TYPE SBIWA_T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SBIWA_T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZST1_TEST2 OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
* Structure for request parameters
* Структура для хранения данных запроса между вызовами
STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE.
* Statics variables counter and table for storage data between calls
* Счетчик и таблица. Статические переменные для хранения данных между вызовами
STATICS: S_COUNTER_DATAPAKID LIKE SY-TABIX,
t_data_temp like ZST1_TEST occurs 0 with header line,
tab type ZST1_TEST occurs 0.
* Ranges for selections
* Диапазоны для критериев выбора
RANGES: L_R_CALMONTH FOR ZST1_TEST-CALMONTH,
L_R_COMPCODE FOR ZST1_TEST-COMPCODE.
DATA: L_S_SELECT LIKE I_T_SELECT,
idx LIKE sy-tabix,
wa_E_T_DATA LIKE E_T_DATA,
n TYPE I,
calmonth type /BI0/OTCALMONTH.
* >>>>>>>>>> 1. Initialisation and identifying restrictions
* Инициализация экстрактора и определение ограничени
if I_INITFLAG = 'X'.
CLEAR S_COUNTER_DATAPAKID.
* Check DataSource validity
CASE I_DSOURCE.
WHEN 'ZST1_TEST'.
WHEN OTHERS.
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDCASE.
ELSE.
* >> Read data only in first call
* считаем данные только при первом вызове экстрактора
IF S_COUNTER_DATAPAKID = 0.
* >>>>>> Select data
* >>>>>> Выборка данных согласно ограничениям
LOOP AT I_T_SELECT INTO L_S_SELECT
WHERE FIELDNM = 'CALMONTH'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_CALMONTH.
APPEND L_R_CALMONTH.
ENDLOOP.
LOOP AT I_T_SELECT INTO L_S_SELECT
WHERE FIELDNM = 'COMP_CODE'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_COMPCODE.
APPEND L_R_COMPCODE.
ENDLOOP.
* <<<<<< Select data
*>>>>> 2.Operations with selected data restrictions
* From table ZST1_TEST select data according restrictions to the table (L_R_COMPCODE and L_R_CALMONTH)
* Считаем данные из таблицы согласно определенным ограничениям во внутреннюю таблицу
select * into corresponding fields of table tab from ZST1_TEST where CALMONTH in L_R_CALMONTH and COMPCODE in L_R_COMPCODE.
endif.
*<<< IF S_COUNTER_DATAPAKID = 0.
*<<<<< 2. Operations with selected data restrictions
*>>>>> 3. Data processing
* Refresh table between calls
Refresh E_T_DATA.
* Начинаем работать с данными
DO I_MAXSIZE TIMES. " reading in the amount of maxsize of records
idx = S_COUNTER_DATAPAKID * I_MAXSIZE + sy-index. " set index to the untreated record in table
* each call of extractor idx increases on S_COUNTER_DATAPAKID * I_MAXSIZE
READ TABLE tab INTO t_data_temp INDEX idx. " read record from table to the hader line
IF SY-SUBRC <> 0. " index NOT table - exit!
EXIT.
ELSE.
* write line of out table
wa_E_T_DATA-COMP_CODE = t_data_temp-COMPCODE.
wa_E_T_DATA-CALMONTH = t_data_temp-CALMONTH.
CONCATENATE '0' t_data_temp-CALMONTH+4(2) into wa_E_T_DATA-FISCPER3.
wa_E_T_DATA-CALYEAR = t_data_temp-CALMONTH(4).
if t_data_temp-cur is INITIAL.
wa_E_T_DATA-cur = 'USD'.
else.
wa_E_T_DATA-cur = t_data_temp-cur.
ENDIF.
wa_E_T_DATA-amount = t_data_temp-amount.
* append line to out table
APPEND wa_E_T_DATA TO E_T_DATA.
ENDIF.
ENDDO.
DESCRIBE TABLE E_T_DATA LINES N. " Count records in out table. If n = 0 - NO MORE DATA!
IF SY-SUBRC <> 0 AND N = 0.
RAISE NO_MORE_DATA.
ENDIF.
* Increase the counte befor next call
* увеличим счетчик
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
endif.
ENDFUNCTION.
************************************************************************************
Let's debug this process. Goto rsa3. In table ZST1_TEST we have only 11 records , that's why set this parameters of extractor
(3 calls on 2 records)
Data Records / Calls | 2 |
Display Extr. Calls | 3 |
Set the limits
1. Initialization infosousre and define the limits
2. Data processing
FIRST CALL
I_INITFLAG = ' '
* * >>>>>> Select data l_r_calmonth and l_r_compcode
* From table ZST1_TEST select data according limits to the table (L_R_COMPCODE and L_R_CALMONTH)
select * into corresponding fields of table tab from ZST1_TEST where CALMONTH in L_R_CALMONTH and COMPCODE in L_R_COMPCODE.
S_COUNTER_DATAPAKID = 0
DO I_MAXSIZE TIMES. " reading in the amount of maxsize of records
idx = S_COUNTER_DATAPAKID * I_MAXSIZE + sy-index
* append line to out table
APPEND wa_E_T_DATA TO E_T_DATA.
DESCRIBE TABLE E_T_DATA LINES N.
N=2
SECOND CALL
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1 = 2
index start value = 3 . ( and there are 3 records in tab)
When index =4 ,
SY-SUBRC =4 - >
DESCRIBE TABLE E_T_DATA LINES N.
N=1
S_COUNTER_DATAPAKID = 3 ->
Next call
THIRD CALL
index start value = 4
SY-SUBRC =4 - >
DESCRIBE TABLE E_T_DATA LINES N.
N = 0
- >>> NO MORE DATA!!!!
SUMMARY
In result we have 3 records in 2 data processings
*__________________________________________________________________________________________________________________________
Thank you very much for your attention! Leave comments! Good luck!
With best regards , Alexander!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |