Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / BW / BW ABAP Development

BW ABAP Development

BW · Data & Analytics ·

Open the interactive lesson →
  1. Where ABAP plugs into BW: t-codes and tables
  2. Generic DataSource with a function module
  3. DataSource enhancement: append, RSA6, RSA3, exit or BAdI
  4. Transformation routines in ABAP
  5. AMDP routines on BW/4HANA (HANA push-down)
  6. Variable exits: customer exit and BAdI
  7. DTP routines, InfoPackage routines and APD
  8. BW ABAP best practices
  9. Interview questions

Where an ABAP developer works in SAP BW: generic extractors written as function modules, DataSource enhancements (customer exit RSAP0001 or BAdI RSU5_SAPI_BADI), transformation routines (start, field, end and expert routines in ABAP or AMDP), variable exits for queries (customer exit RSR00001 or the BAdI RSROA_VARIABLES_EXIT_BADI), DTP and InfoPackage routines and the legacy APD. DataSources, ODP, transformations and DTPs as concepts are on page 03, queries and variables on page 04. General enhancement techniques (SMOD / CMOD, SE18 / SE19): CORE ABAP › 10 Enhancements; AMDP and SQLScript: ABAP on HANA › 06 AMDP & SQLScript.

Part 1 – Where ABAP plugs into BW: t-codes and tables

ABAP hooks along the BW data flow: generic extractor and DataSource enhancement in the source system, start / field / end / expert routines and DTP filter routines in BW, variable exits when the query runs

Where

ABAP object

Typical requirement

Part

Source system (ECC / S/4HANA)

Function module extractor (generic DataSource)

Data that no standard DataSource and no table / view delivers, logic during extraction

2

Source system

Customer exit RSAP0001 or BAdI RSU5_SAPI_BADI

Fill ZZ fields appended to a standard DataSource

3

BW – transformation

Start, field, end, expert routine (ABAP or AMDP)

Complex filters, derivations, lookups, record splitting

4, 5

BW – DTP / InfoPackage

Filter routine / file name routine

Dynamic selections (last 30 days), dynamic file path

7

BW – query runtime

Variable exit RSR00001 or BAdI RSROA_VARIABLES_EXIT_BADI

Default values, derived values, validations, authorization values

6

1.1 Transactions

T-code

System

What it does

RSA1

BW

Data Warehousing Workbench (formerly Administrator Workbench): modelling, source systems, DataSources, Business Content, transport connection

RSA2

Source

DataSource Repository: displays a DataSource's metadata – extractor, extract structure, fields, delta process

RSO2

Source

Create, change and display generic DataSources (table / view, InfoSet query or function module), including the generic delta settings

RSA3

Source

Extractor checker: test extraction without BW (full, delta simulation, debug mode, number of records and packages)

RSA5

Source

Install (activate) SAP-delivered Business Content DataSources – copies the delivered D version to the active A version

RSA6

Source

Post-process (maintain) active DataSources: selection fields, hide / unhide fields, enhance the extract structure (append), field only known in exit

RSDS

BW

Maintain a DataSource in the BW system (BW 7.x DataSource): create, change, display, activate after replication

RSA7 / ODQMON

Source

Classic BW delta queue / monitor of the ODP delta queues (ODQ)

LBWE

Source

Logistics extraction (LO) cockpit for the 2LIS_* DataSources

SMOD / CMOD, SE18 / SE19

Both

Customer exits (RSAP0001, RSR00001) / BAdIs (RSU5_SAPI_BADI, RSROA_VARIABLES_EXIT_BADI)

RSRT

BW

Query monitor: run and debug a query, also the variable exit (page 04)

1.2 Tables

Table

Content

ROOSOURCE

Header table of the source system DataSources (SAP BW OLTP sources): DataSource name, extraction method (e.g. V view, F1 / F2 function module, Q InfoSet query), extractor, extract structure, delta process

ROOSFIELD

Fields of each DataSource with their selection and hide flags

Useful trick: when you do not know which program fills a DataSource, read its ROOSOURCE entry (or RSA2) – the EXTRACTOR field names the function module or view.

Part 2 – Generic DataSource with a function module

A generic DataSource is created by the customer in RSO2 when no Business Content DataSource fits. It can be based on a table or database view, on an InfoSet query, or on a function module. Choose the function module when the data needs logic: several tables that a view cannot join, calculations, authorisation-free reads of cluster data, or a delta that a single timestamp cannot express.

Template FM (function group RSAX)

Interface

Delta

RSAX_BIW_GET_DATA_SIMPLE

Simple interface (extraction method F2) – the template you copy for an RSO2 DataSource

The template itself reads everything (full load). Delta works through the RSO2 generic delta: the API passes the delta range of the delta field in I_T_SELECT and your code must use it in the SELECT

RSAX_BIW_GET_DATA

Complete interface (extraction method F1) with more parameters, e.g. the update mode

Template for delta-capable extractors that handle the update mode themselves

Call cycle of a function module extractor: one initialization call that stores the selections, then data calls that open a cursor once and return one package per call until NO_MORE_DATA

2.1 Development steps

  • 1. Gather the requirement: fields, source tables, selections, full or delta, volume.
  • 2. Create the extract structure in SE11, e.g. ZST_NA_DS_SALES. For a delta, include the delta field (here ZZ_CHDATE).
  • 3. Create a function group for the DataSource, e.g. ZFG_NA_SALES (global data in its TOP include).
  • 4. Copy RSAX_BIW_GET_DATA_SIMPLE to your function module, e.g. Z_NA_BW_GET_SALES, in that function group.
  • 5. Adapt the code:
    • Tables tab: set the associated type of E_T_DATA to your extract structure.
    • Replace the template's table declaration (SFLIGHT) with your own tables.
    • Replace the template's ranges (CARRID, CONNID) with ranges for your selection fields.
    • Fill those ranges from the selection table (I_T_SELECT, stored at the first call).
    • Replace the SELECT under the OPEN CURSOR statement with your own SELECT.
  • 6. Create the DataSource in RSO2: transaction data / master data attributes / texts, application component, Extraction by function module with the FM name and the extract structure; then mark selection fields and hide fields.
  • 7. Enter the DataSource name in the FM in the CASE statement of the initialization call (below CASE i_dsource).
  • 8. Delta (optional): RSO2 → Generic Delta → delta-specific field (calendar day, timestamp or numeric pointer), safety interval, and whether a changed record is a new status (overwrite in the ADSO) or additive.
  • 9. Test in RSA3, then replicate the DataSource in BW and build the data flow (page 03).

2.2 The function module

The extraction API calls the FM several times: once with I_INITFLAG = 'X' (store the selections, no data) and then repeatedly for data. Everything that must survive between calls (selections, cursor, package counter) lives in the TOP include of the function group.

* TOP include of function group ZFG_NA_SALES – data kept between the calls
DATA gs_if      TYPE srsc_s_if_simple.                " request, package size, selections
DATA gv_cursor  TYPE cursor.
DATA gv_packets TYPE i.
DATA gr_vkorg   TYPE RANGE OF vkorg.
DATA gr_chdate  TYPE RANGE OF erdat.
FUNCTION z_na_bw_get_sales.
*"----------------------------------------------------------------------
*" Interface copied from RSAX_BIW_GET_DATA_SIMPLE
*"  IMPORTING
*"     VALUE(I_REQUNR)    TYPE  SRSC_S_IF_SIMPLE-REQUNR
*"     VALUE(I_DSOURCE)   TYPE  SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*"     VALUE(I_MAXSIZE)   TYPE  SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*"     VALUE(I_INITFLAG)  TYPE  SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*"     VALUE(I_READ_ONLY) TYPE  SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*"     VALUE(I_REMOTE_CALL) TYPE  SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
*"  TABLES
*"      I_T_SELECT TYPE  SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*"      I_T_FIELDS TYPE  SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*"      E_T_DATA STRUCTURE  ZST_NA_DS_SALES OPTIONAL
*"  EXCEPTIONS
*"      NO_MORE_DATA
*"      ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
IF i_initflag = sbiwa_c_flag_on.
" Initialization call: check the DataSource and remember the request
CASE i_dsource.
WHEN 'ZNA_DS_SALES'.                           " the DataSource created in RSO2
WHEN OTHERS.
MESSAGE e009(r3) WITH i_dsource RAISING error_passed_to_mess_handler.
ENDCASE.
gs_if = VALUE #( requnr   = i_requnr
dsource  = i_dsource
maxsize  = i_maxsize
t_select = i_t_select[]
t_fields = i_t_fields[] ).
CLEAR gv_packets.
RETURN.
ENDIF.

" Data calls: open the cursor in the first call, then one package per call
IF gv_packets = 0.
" Ranges from the selections – ZZ_CHDATE carries the generic delta range
gr_vkorg  = VALUE #( FOR s IN gs_if-t_select WHERE ( fieldnm = 'VKORG' )
( sign = s-sign option = s-option low = s-low high = s-high ) ).
gr_chdate = VALUE #( FOR s IN gs_if-t_select WHERE ( fieldnm = 'ZZ_CHDATE' )
( sign = s-sign option = s-option low = s-low high = s-high ) ).

OPEN CURSOR WITH HOLD gv_cursor FOR
SELECT p~vbeln, p~posnr, a~vkorg, a~kunnr, p~matnr, p~kwmeng, p~vrkme,
p~netwr, p~waerk, p~erdat, p~aedat
FROM vbak AS a
INNER JOIN vbap AS p ON p~vbeln = a~vbeln
WHERE a~vkorg IN @gr_vkorg
AND ( p~erdat IN @gr_chdate OR p~aedat IN @gr_chdate ).
ENDIF.

FETCH NEXT CURSOR gv_cursor
APPENDING CORRESPONDING FIELDS OF TABLE @e_t_data
PACKAGE SIZE @gs_if-maxsize.
IF sy-subrc <> 0.
CLOSE CURSOR gv_cursor.
RAISE no_more_data.                              " ends the extraction
ENDIF.

" Delta field = the later of creation date and change date
LOOP AT e_t_data ASSIGNING FIELD-SYMBOL(<ls_data>).
<ls_data>-zz_chdate = COND #( WHEN <ls_data>-aedat > <ls_data>-erdat
THEN <ls_data>-aedat
ELSE <ls_data>-erdat ).
ENDLOOP.
gv_packets += 1.
ENDFUNCTION.
  • NO_MORE_DATA must be raised when the cursor is empty – without it the API calls the FM forever.
  • WITH HOLD keeps the cursor open across the database commits that happen between two calls.
  • I_MAXSIZE is the package size the API asks for; the FETCH returns at most that many rows.
  • ERROR_PASSED_TO_MESS_HANDLER is raised after writing an error message; it ends the request with that message in the monitor.
  • Empty ranges select everything, so the same code serves full loads (no ZZ_CHDATE selection) and delta loads (the API fills the ZZ_CHDATE range from the last delta pointer).

Part 3 – DataSource enhancement: append, RSA6, RSA3, exit or BAdI

A standard DataSource lacks a field the business needs. You add it to the extract structure and fill it with ABAP. When a load starts (InfoPackage in classic BW, DTP via ODP in BW/4HANA), BW calls the extraction API in the source system; the API calls the standard extractor and then the enhancement – customer exit and / or BAdI – once per data package, before the package is sent to BW.

First check whether you need code at all: for LO DataSources (2LIS_*) many fields of the communication structures can be added in LBWE without ABAP.

3.1 Development steps

  • 1. Append structure: in RSA6 (Enhance extraction structure) or SE11, create an append on the extract structure (e.g. MC11VA0ITM of 2LIS_11_VAITM) with fields starting ZZ.
  • 2. Unhide the new fields in RSA6: new append fields are hidden; clear Hide field (and set Field only known in exit where appropriate) and save – this regenerates the DataSource.
  • 3. Write the code that fills the fields: customer exit RSAP0001 (3.2) or BAdI RSU5_SAPI_BADI (3.3).
  • 4. Test in RSA3: the enhanced fields appear as new columns and must be filled.
  • 5. Replicate the DataSource in BW, add the fields to the transformation and target.

3.2 Customer exit RSAP0001 (classic)

Function exit (SMOD RSAP0001)

Include (CMOD)

Called for

Data table

EXIT_SAPLRSAP_001

ZXRSAU01

Transaction data

C_T_DATA

EXIT_SAPLRSAP_002

ZXRSAU02

Master data attributes

I_T_DATA

EXIT_SAPLRSAP_003

ZXRSAU03

Texts

I_T_DATA

EXIT_SAPLRSAP_004

ZXRSAU04

Hierarchies

Hierarchy tables (nodes, texts, intervals)

All DataSources of a type share one include, so a big CASE i_datasource grows into an unreadable, risky include where one syntax error stops every extraction. The common pattern: the include only dispatches to one program per DataSource, named ZBW_<DataSource>, and each program has a FORM execute_user_exit. A DataSource without a program is simply skipped (IF FOUND).

* Include ZXRSAU01 (EXIT_SAPLRSAP_001 – transaction data): dispatcher only
DATA lv_program TYPE progname.

lv_program = |ZBW_{ i_datasource }|.               " e.g. ZBW_2LIS_11_VAITM
PERFORM execute_user_exit IN PROGRAM (lv_program)
TABLES i_t_select
i_t_fields
c_t_data
c_t_messages
IF FOUND.                                        " no program = DataSource not enhanced
REPORT zbw_2lis_11_vaitm.
* Enhancement of DataSource 2LIS_11_VAITM – called from ZXRSAU01

TYPES: BEGIN OF ty_info,
vbeln   TYPE vbeln_va,
channel TYPE zz_channel,
END OF ty_info.

FORM execute_user_exit
TABLES i_t_select   TYPE sbiwa_t_select
i_t_fields   TYPE sbiwa_t_fields
c_t_data     STRUCTURE mc11va0itm          " extract structure incl. the ZZ append
c_t_messages STRUCTURE balmi.

DATA lt_info TYPE HASHED TABLE OF ty_info WITH UNIQUE KEY vbeln.

IF c_t_data[] IS INITIAL.
RETURN.
ENDIF.

" One SELECT for the whole package – never a SELECT SINGLE inside the loop
SELECT vbeln, channel
FROM zsd_order_info
FOR ALL ENTRIES IN @c_t_data
WHERE vbeln = @c_t_data-vbeln
INTO TABLE @lt_info.

LOOP AT c_t_data ASSIGNING FIELD-SYMBOL(<ls_data>).
<ls_data>-zzchannel = VALUE #( lt_info[ vbeln = <ls_data>-vbeln ]-channel OPTIONAL ).
ENDLOOP.
ENDFORM.
  • For master data (ZXRSAU02) and texts (ZXRSAU03) the dispatcher passes i_t_data instead of c_t_data, and the FORM's data parameter uses that DataSource's extract structure, e.g. i_t_data STRUCTURE biw_t001ws for a plant attribute DataSource.
  • Activate the CMOD project that contains RSAP0001 – without an active project no exit runs.

3.3 BAdI RSU5_SAPI_BADI (recommended)

The classic BAdI RSU5_SAPI_BADI (SE18 / SE19) does the same job in ABAP Objects and is SAP's recommended replacement for RSAP0001. Method DATA_TRANSFORM is called for transaction data, master data attributes and texts; HIER_TRANSFORM for hierarchies. It is multiple-use, so several teams can have their own implementations.

CLASS zcl_im_bw_sapi DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_ex_rsu5_sapi_badi.
ENDCLASS.

CLASS zcl_im_bw_sapi IMPLEMENTATION.
METHOD if_ex_rsu5_sapi_badi~data_transform.
" Dispatcher: one class per enhanced DataSource
CASE i_datasource.
WHEN '2LIS_11_VAITM'.
zcl_bw_enh_2lis_11_vaitm=>enhance( CHANGING ct_data = c_t_data ).
ENDCASE.
ENDMETHOD.

METHOD if_ex_rsu5_sapi_badi~hier_transform.
ENDMETHOD.
ENDCLASS.
CLASS zcl_bw_enh_2lis_11_vaitm DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
CLASS-METHODS enhance CHANGING ct_data TYPE ANY TABLE.   " C_T_DATA of the BAdI
ENDCLASS.

CLASS zcl_bw_enh_2lis_11_vaitm IMPLEMENTATION.
METHOD enhance.
TYPES: BEGIN OF ty_info,
vbeln   TYPE vbeln_va,
channel TYPE zz_channel,
END OF ty_info.
DATA lt_data TYPE STANDARD TABLE OF mc11va0itm WITH DEFAULT KEY.
DATA lt_info TYPE HASHED TABLE OF ty_info WITH UNIQUE KEY vbeln.

lt_data = ct_data.                             " typed copy of the generic table
IF lt_data IS INITIAL.
RETURN.
ENDIF.

SELECT vbeln, channel
FROM zsd_order_info
FOR ALL ENTRIES IN @lt_data
WHERE vbeln = @lt_data-vbeln
INTO TABLE @lt_info.

LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<ls_data>).
<ls_data>-zzchannel = VALUE #( lt_info[ vbeln = <ls_data>-vbeln ]-channel OPTIONAL ).
ENDLOOP.
ct_data = lt_data.                             " hand the enriched package back
ENDMETHOD.
ENDCLASS.

Customer exit RSAP0001

BAdI RSU5_SAPI_BADI

Technique

Function exits + includes ZXRSAU01–04 (CMOD project)

Classic BAdI, class implementation (SE19)

Implementations

One include per data type for all DataSources

Several implementations possible (multiple use)

Data types

Four exits: transaction, attributes, texts, hierarchies

Two methods: DATA_TRANSFORM, HIER_TRANSFORM

Risk

One syntax error stops all extractions of that type

Separate classes, easier to test and transport

Status

Legacy – still works in ECC and S/4HANA on-premise

Recommended for new SAPI enhancements

S/4HANA: for new extraction prefer released CDS extraction views (page 03, page 06) – custom fields reach them through key-user extensibility or CDS view extensions instead of an append plus ABAP exit.

Part 4 – Transformation routines in ABAP

A transformation maps a source (DataSource or InfoProvider) to a target with rules; routines add ABAP where the rule types (direct assignment, formula, constant, read master data / read from ADSO) are not enough. The DTP executes the transformation package by package.

DTP flow: extract source data into SOURCE_PACKAGE, start routine, rules with field routines, RESULT_PACKAGE, end routine, write to the target ADSO; the expert routine replaces everything between source and target

4.1 What happens when a DTP runs

  • 1. The DTP extracts a package of data from the source.
  • 2. The data is placed in SOURCE_PACKAGE (source structure).
    • 2.1 The start routine runs on the whole SOURCE_PACKAGE.
  • 3. Each record is transformed from the source structure into the target structure; field (characteristic / key figure) routines run per record and field.
  • 4. The transformed records are saved in RESULT_PACKAGE (target structure).
    • 4.1 The end routine runs on the whole RESULT_PACKAGE.
  • 5. The data is written to the target (ADSO, InfoObject; DSO / InfoCube in classic BW).

Routine

Works on

Use it for

Start routine

SOURCE_PACKAGE, once per package

Filters the DTP filter cannot express (DTP selections are only ANDed, no OR across fields), deleting records on conditions that need other data, filling internal tables with lookup data for later use

Field routine

One field of one record (SOURCE_FIELDS → RESULT)

A target field that does not exist in the source and needs logic; skip a record

End routine

RESULT_PACKAGE, once per package

Lookups and derivations on target fields, deleting or adding result records, final checks

Expert routine

Whole package: SOURCE_PACKAGE → RESULT_PACKAGE

Replaces all rules – full control, e.g. splitting one record into many; you must map every field yourself

4.2 Examples

BW generates a local class with the routine methods; you write only between the begin / end of routine comments. Global declarations go into the global section and are shared by all routines of the transformation.

METHOD start_routine.
*$*$ begin of routine - insert your code only below this line        *-*
" OR across fields is not possible in the DTP filter
DELETE source_package WHERE doc_type = 'ZT'                       " test documents
OR ( comp_code = '9999' AND amount = 0 ).
*$*$ end of routine - insert your code only before this line         *-*
ENDMETHOD.
METHOD compute_amount_signed.                       " field routine, generated method name
*$*$ begin of routine - insert your code only below this line        *-*
IF source_fields-doc_type IS INITIAL.
RAISE EXCEPTION TYPE cx_rsrout_skip_record.     " record is not loaded
ENDIF.
" Credit memos are loaded with a negative sign
result = COND #( WHEN source_fields-doc_type = 'G2'
THEN - source_fields-amount
ELSE source_fields-amount ).
*$*$ end of routine - insert your code only before this line         *-*
ENDMETHOD.
METHOD end_routine.
*$*$ begin of routine - insert your code only below this line        *-*
TYPES: BEGIN OF ty_cust,
customer TYPE /bi0/oicustomer,
country  TYPE /bi0/oicountry,
END OF ty_cust.
DATA lt_cust TYPE HASHED TABLE OF ty_cust WITH UNIQUE KEY customer.

IF result_package IS INITIAL.
RETURN.
ENDIF.
" Read the master data of 0CUSTOMER once for the whole package
SELECT customer, country
FROM /bi0/pcustomer
FOR ALL ENTRIES IN @result_package
WHERE customer = @result_package-customer
AND objvers  = 'A'
INTO TABLE @lt_cust.

LOOP AT result_package ASSIGNING <result_fields>.    " field symbol declared by BW
ASSIGN lt_cust[ customer = <result_fields>-customer ] TO FIELD-SYMBOL(<ls_cust>).
IF sy-subrc = 0.
<result_fields>-country = <ls_cust>-country.
ELSE.
" Warning in the DTP monitor
APPEND VALUE #( msgid = 'ZBW' msgty = 'W' msgno = '001'
msgv1 = <result_fields>-customer ) TO monitor.
ENDIF.
ENDLOOP.
*$*$ end of routine - insert your code only before this line         *-*
ENDMETHOD.
  • Simple master data lookups do not need code: use the rule type Read master data (or Read from DataStore object in BW/4HANA).
  • Fields filled only in the end routine must be enabled for update: in the end routine settings choose that all target fields are updated, not only those with active rules.
  • Exceptions: CX_RSROUT_ABORT stops the whole request, CX_RSROUT_SKIP_RECORD skips one record, messages in MONITOR appear in the DTP monitor; with error handling switched on, wrong records go to the error stack (error DTP).
  • Move bigger logic into a global class (e.g. ZCL_BW_SALES_RULES) and call it from the routine – reusable across transformations and unit-testable.

Part 5 – AMDP routines on BW/4HANA (HANA push-down)

On BW 7.5 on HANA and BW/4HANA a transformation can run in the HANA runtime: the whole transformation is executed in the database instead of moving every package to the ABAP server. Rules without routines are pushed down automatically; routines must then be written as AMDP script (SQLScript) instead of ABAP. The routine is an AMDP method of a generated class that you edit in ADT (BW Modeling Tools).

ABAP routine

AMDP routine

Runs in

ABAP application server, record / package loop

SAP HANA, set-based SQLScript

Runtime of the transformation

ABAP runtime

HANA runtime – only if every routine and rule of the transformation can run in HANA

Mixing

–

BW 7.5: one runtime per transformation – ABAP and AMDP routines cannot be mixed · BW/4HANA: an ABAP end routine is possible (partial HANA runtime); ABAP start / field / expert routines force the ABAP runtime

Input / output

SOURCE_PACKAGE, RESULT_PACKAGE, RESULT, MONITOR

inTab → outTab; errorTab for error handling

Strengths

Calling function modules, BAPIs, complex procedural logic

Large volumes, joins and aggregations, lookups as joins

Where

BW 7.x and BW/4HANA

BW 7.5 on HANA and BW/4HANA

  • outTab must be returned with the columns in the order of its definition, including the technical columns RECORD and SQL__PROCEDURE__SOURCE__RECORD that link each row to its source record.
  • errorTab has the columns ERROR_TEXT and SQL__PROCEDURE__SOURCE__RECORD; it is used only when error handling for HANA routines is switched on in the transformation, otherwise return it empty.
  • Every table the method reads must be listed in the USING clause.
* End routine as AMDP: add the customer's country from the 0CUSTOMER master data
METHOD global_end BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING /bi0/pcustomer.
-- *** begin of routine - insert your code only below this line ***
outTab = SELECT it.comp_code,
it.customer,
it.calmonth,
COALESCE( md.country, '' ) AS country,   -- lookup as a join
it.amount,
it.currency,
it."RECORD",
it.sql__procedure__source__record
FROM :inTab AS it
LEFT OUTER JOIN "/BI0/PCUSTOMER" AS md
ON  md.customer = it.customer
AND md.objvers  = 'A';

errorTab = SELECT '' AS error_text,
'' AS sql__procedure__source__record
FROM dummy
WHERE dummy <> 'X';                            -- no error handling: empty
-- *** end of routine - insert your code only before this line ***
ENDMETHOD.

The generated method names follow the routine type (e.g. GLOBAL_START, GLOBAL_END, PROCEDURE for the expert routine) – keep the generated signature and write only inside the markers. AMDP syntax and debugging: ABAP on HANA › 06 AMDP & SQLScript.

Part 6 – Variable exits: customer exit and BAdI

A query variable with processing type customer exit gets its values from ABAP (variable types and processing types: page 04). Typical uses: default the current month before the variable screen, derive a range from another variable after it, check the entries, and return a user's authorized values for an authorization variable.

When the variable exit is called: I_STEP 1 before the variable screen, 2 after it, 3 check of all values, 0 outside the variable screen (authorization check, monitor)

I_STEP

When

Typical use

1

Directly before the variable screen

Default values for input-ready variables

2

Directly after the variable screen – only for variables that are not input-ready and were not filled in step 1

Derive values from the entered variables (read I_T_VAR_RANGE)

3

After step 2, once for all variables

Validate the combination of entries; an exception shows the variable screen again

0

Not called from the variable screen: the call comes from the authorization check or the monitor

Authorization variables: return the values the user is authorized for

6.1 Customer exit RSR00001 (BW 3.x – 7.5, also BW on HANA)

Enhancement RSR00001 (SMOD) with function exit EXIT_SAPLRRS0_001, code in include ZXRSRU01 of a CMOD project. Main parameters: I_VNAM (variable name), I_STEP, I_T_VAR_RANGE (values of the other variables, type RRS0_T_VAR_RANGE), E_T_RANGE (result, type RSR_T_RANGESID). As with the DataSource exit, the include usually only dispatches to one program per variable, ZBW_<variable>.

* Include ZXRSRU01 (EXIT_SAPLRRS0_001): dispatcher only
DATA lv_program TYPE progname.

lv_program = |ZBW_{ i_vnam }|.                      " e.g. ZBW_ZV_CALMONTH_CUR
PERFORM execute_user_exit IN PROGRAM (lv_program)
TABLES e_t_range
USING  i_t_var_range
i_step
i_vnam
IF FOUND.
REPORT zbw_zv_calmonth_cur.
* Variable ZV_CALMONTH_CUR on 0CALMONTH: current month as default

FORM execute_user_exit
TABLES e_t_range     TYPE rsr_t_rangesid
USING  i_t_var_range TYPE rrs0_t_var_range
i_step        TYPE i
i_vnam        TYPE rszglobv-vnam.

DATA ls_range TYPE rrrangesid.

IF i_step = 1.                                    " before the variable screen
ls_range = VALUE #( sign = 'I' opt = 'EQ' low = sy-datum(6) ).
APPEND ls_range TO e_t_range.
ENDIF.
ENDFORM.

6.2 BAdI RSROA_VARIABLES_EXIT_BADI (BW 7.3 and later; the only option in BW/4HANA)

Enhancement spot RSROA_VARIABLES_EXIT contains the BAdI RSROA_VARIABLES_EXIT_BADI (implement in SE19 or ADT). The method IF_RSROA_VARIABLES_EXIT_BADI~PROCESS receives the same input as EXIT_SAPLRRS0_001 (I_VNAM, I_IOBJNM, I_STEP, I_T_VAR_RANGE …) but returns the values in the changing table C_T_RANGE (type RSR_T_RANGESID) and signals errors with exception CX_RS_ERROR. It is multiple-use and filter-dependent: the filter is the InfoObject of the variable (IOBJNM), so each implementation handles only its own InfoObject; step 3 is called with an empty InfoObject filter. The default implementation (SMOD_EXIT_CALL) still calls ZXRSRU01, so the old exit keeps working in BW 7.x. BW/4HANA does not support the CMOD exit: existing code must move into BAdI implementations.

CLASS zcl_bw_var_calmonth DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_badi_interface.
INTERFACES if_rsroa_variables_exit_badi.
ENDCLASS.

CLASS zcl_bw_var_calmonth IMPLEMENTATION.
" BAdI implementation with filter IOBJNM = '0CALMONTH'
METHOD if_rsroa_variables_exit_badi~process.
CASE i_vnam.
WHEN 'ZV_CALMONTH_CUR'.                        " default: current month
IF i_step = 1.
c_t_range = VALUE #( ( sign = 'I' opt = 'EQ' low = sy-datum(6) ) ).
ENDIF.

WHEN 'ZV_CALMONTH_PREV'.                       " not input-ready: month before the entry
IF i_step = 2.
READ TABLE i_t_var_range INTO DATA(ls_in) WITH KEY vnam = 'ZV_CALMONTH_IN'.
IF sy-subrc = 0.
DATA(lv_date) = CONV d( substring( val = ls_in-low len = 6 ) && '01' ).
lv_date = lv_date - 1.                   " last day of the previous month
c_t_range = VALUE #( ( sign = 'I' opt = 'EQ' low = lv_date(6) ) ).
ENDIF.
ENDIF.
ENDCASE.
ENDMETHOD.
ENDCLASS.
" Second implementation, empty IOBJNM filter: step 3 validation
METHOD if_rsroa_variables_exit_badi~process.
IF i_step <> 3.
RETURN.
ENDIF.
READ TABLE i_t_var_range INTO DATA(ls_in) WITH KEY vnam = 'ZV_CALMONTH_IN'.
IF sy-subrc = 0 AND ls_in-low(6) > sy-datum(6).      " month in the future
CALL FUNCTION 'RRMS_MESSAGE_HANDLING'              " message on the variable screen
EXPORTING
i_class  = 'ZBW'
i_type   = 'E'
i_number = '010'
i_msgv1  = ls_in-low.
RAISE EXCEPTION TYPE cx_rs_error.                 " variable screen appears again
ENDIF.
ENDMETHOD.
  • Authorization variable (I_STEP = 0): return, for example, the company codes of the user (sy-uname) read from a Z mapping table as ranges in C_T_RANGE (E_T_RANGE in the customer exit). Query-specific attributes are not filled in this step.
  • Test: run the query in RSRT with a breakpoint in the BAdI method or in ZXRSRU01.

Part 7 – DTP routines, InfoPackage routines and APD

7.1 DTP filter routine

A routine on a field of the DTP filter computes the selection dynamically at runtime – e.g. always the last 30 days or the current fiscal period. BW generates a FORM routine with the selection table l_t_range (structure RSSDLRANGE: FIELDNAME, SIGN, OPTION, LOW, HIGH) and the return code p_subrc; you write only the body. An OLAP variable (e.g. a customer exit variable) can be used in the filter instead.

* Body of the generated DTP filter routine for field CALDAY: last 30 days
DATA(lv_from) = CONV d( sy-datum - 30 ).

DELETE l_t_range WHERE fieldname = 'CALDAY'.
APPEND VALUE rssdlrange( fieldname = 'CALDAY'
sign      = 'I'
option    = 'BT'
low       = lv_from
high      = sy-datum ) TO l_t_range.
p_subrc = 0.                                      " 0 = filter is valid

7.2 InfoPackage routine (classic BW – legacy)

InfoPackages load data from the source into the PSA in classic BW (in BW/4HANA there are no InfoPackages and no PSA – the DTP reads directly from the DataSource). Routines in the InfoPackage compute selections or, for flat files, the file name and path on the application server dynamically (routine form compute_flat_file_filename). Background loads need the file on the application server, not on the PC.

* Body of the InfoPackage file name routine: file of the day via a logical file name
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = 'ZBW_SALES_IN'              " FILE: e.g. sales_<DATE>.csv
IMPORTING
file_name        = p_filename
EXCEPTIONS
file_not_found   = 1
OTHERS           = 2.
p_subrc = sy-subrc.
  • A logical file name (transaction FILE) keeps the physical path out of the code, so the same routine works in DEV, QAS and PRD; the placeholder <DATE> in the physical file name is replaced by today's date.

7.3 APD – Analysis Process Designer (legacy)

APD (transaction RSANWB) built graphical analysis processes in classic BW: read from queries or InfoProviders, transform (join, filter, ABAP routine, data mining), write to a DSO or file. It is not available in BW/4HANA; the transfer tool RSB4HAPD converts supported APDs into data flows with DTPs and transformations. Details and successors: page 04 Part 9.

Part 8 – BW ABAP best practices

Topic

Do

Avoid

Lookups

Read once per package (FOR ALL ENTRIES with a non-empty check, or a join), store in HASHED / SORTED tables

SELECT SINGLE inside the LOOP over the package

Loops

Field symbols or references, binary / hashed reads

Copying work areas and MODIFY inside large loops

Rule types

Standard rules (read master data / ADSO, formulas) before code

Routines for what a rule type can do

Structure

Dispatcher include + one program / class per object; logic in global classes

One huge CASE in ZXRSAU01 or ZXRSRU01

Push-down

AMDP routines and HANA runtime for large volumes on BW/4HANA

ABAP routines that force the whole transformation into the ABAP runtime without need

Errors

MONITOR messages, error handling with error stack and semantic groups, CX_RSROUT_ABORT for fatal cases

Silent skips, COMMIT WORK or screen messages in routines

Configuration

Z control tables, logical file names, TVARVC entries

Hard-coded company codes, dates and paths

Testing

RSA3 (extractors, debug mode), DTP in debugging / simulation mode, RSRT for variables

Testing only with full production loads

S/4HANA source

Released CDS extraction views via ODP; RSU5_SAPI_BADI if you must enhance SAPI DataSources

New Z function module extractors on application tables

Part 9 – Interview questions

Q1. When do you build a generic DataSource with a function module instead of a table or view?

When the data needs logic: tables a view cannot join, calculations, reading data through function modules, or a delta that one field of one table cannot express. Table / view DataSources are simpler and should be the first choice.

Q2. What is the difference between RSAX_BIW_GET_DATA_SIMPLE and RSAX_BIW_GET_DATA?

Both are templates in function group RSAX. RSAX_BIW_GET_DATA_SIMPLE has the simple interface (F2) and is the template copied for RSO2 DataSources; it reads everything, delta comes from the RSO2 generic delta whose range your code must evaluate in I_T_SELECT. RSAX_BIW_GET_DATA has the complete interface (F1) including the update mode, for extractors that handle delta themselves.

Q3. Walk me through the code of a function module extractor.

The first call (I_INITFLAG = X) checks the DataSource name and stores the selections and package size in global data. The first data call builds ranges from the selections and opens a cursor WITH HOLD; every data call FETCHes one package of I_MAXSIZE rows into E_T_DATA; when FETCH finds nothing the cursor is closed and NO_MORE_DATA is raised.

Q4. How do you enhance a standard DataSource?

Append ZZ fields to the extract structure, unhide them in RSA6, fill them in customer exit RSAP0001 (EXIT_SAPLRSAP_001 – 004, includes ZXRSAU01 – 04) or in BAdI RSU5_SAPI_BADI, test in RSA3, replicate and map the fields in BW. For LO DataSources check LBWE first.

Q5. Why use ZBW_<DataSource> programs or one class per DataSource?

All DataSources share one exit include. A dispatcher that calls a separate program or class per DataSource keeps the include tiny, isolates errors and transports, and lets several developers work in parallel.

Q6. Customer exit RSAP0001 or BAdI RSU5_SAPI_BADI?

Same purpose. The BAdI is object-oriented, multiple-use (several implementations) and SAP's recommended replacement; the exit is legacy but still runs. In S/4HANA prefer released CDS extraction views over enhancing SAPI DataSources.

Q7. Explain start, field, end and expert routines and their order.

Start routine on SOURCE_PACKAGE before the rules (filters, lookup preparation); field routines per record and field; end routine on RESULT_PACKAGE after the rules (lookups on target fields, deletions); the expert routine replaces all rules and maps the whole package itself.

Q8. ABAP or AMDP routine – and when does a transformation run in HANA?

AMDP routines are SQLScript methods working set-based on inTab / outTab inside HANA. A transformation runs in the HANA runtime only if all its rules and routines are HANA-capable; in BW 7.5 one ABAP routine forces the ABAP runtime and the two kinds cannot be mixed; in BW/4HANA an ABAP start, field or expert routine forces the ABAP runtime, while an ABAP end routine gives a partial HANA runtime.

Q9. What are the I_STEP values of the variable exit?

1 before the variable screen (defaults), 2 after it for non-input-ready variables (derivations), 3 check of all entries (exception shows the screen again), 0 called outside the variable screen – from the authorization check or the monitor, used for authorization variables.

Q10. How do you implement variable exits on BW/4HANA?

With BAdI RSROA_VARIABLES_EXIT_BADI in enhancement spot RSROA_VARIABLES_EXIT, method IF_RSROA_VARIABLES_EXIT_BADI~PROCESS, filtered by InfoObject. The CMOD exit RSR00001 / ZXRSRU01 is not supported in BW/4HANA.

Q11. What are DTP and InfoPackage routines used for?

A DTP filter routine sets the selection dynamically (last 30 days, current period). An InfoPackage routine (classic BW only) sets selections or the flat-file name and path on the application server dynamically, e.g. one file per day.

Q12. Your end routine is slow. What do you check?

SELECTs inside the loop (replace with one read per package into a hashed table), missing field symbols, linear reads on standard tables, package size, and whether standard rule types or an AMDP routine with HANA push-down could replace the ABAP.

🏠 Start Here · ◀ 04 · Reporting · 06 · BW/4HANA & Architect ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP