You are on page 1of 106

Data source

Enhancements in
SAP BW
Essential Guide for a BW developer
1 COPYRIGHT
NOTICE

© @how2bw.com, 2016. Unauthorized


use and/or duplication of this material

without express and written permission

from this book’s author and/or owner is

strictly prohibited. Excerpts and links

may be used, provided that full and clear

credit is given to the author with


appropriate and specific direction to the

original content. SAP and SAP logo are

registered trademarks of SAP AG.

How2BW is not associated with SAP


AG. We have made every effort to

provide accurate information, use the


content of this book at your own risk.
2 ABOUT THE AUTHOR
AK Verma, the author of How2bw series
of books and founder of website
how2bw.com is working in BI industry
since more than six years. She graduated
in chemical engineering from IIT Kanpur
in 2006. She decided to pursue her
career in software rather than in
chemical industry and joined a
consultancy via campus recruitment. She
started her career as SAP BW consultant
and got trained in SAP BW 3.5, PL/SQL,
RDBMS and Data warehousing concepts
in her first company. There she worked
on many implementation projects of SAP
BW travelling to client offices and
gathering requirements.
She then joined another leading MNC
where she worked for support projects
of SAP BW facing harsh clients and
meeting tight schedules and deadlines.
She gained valuable experience in
domains like sales, material
management, customer relationship
management and finance working in then
version of SAP BW which was 7.0
After that she worked on implementation
projects in versions 7.3, 7.4 and
attended SAP HANA training and
Qlikview training.
Her major achievements were accolades
and awards from client as well as hiring
company.
ABOUT THE BOOK
This book is brief information on how to
use ABAP programming in enhancement
of Data sources used for extraction.
Standard Data sources provided by SAP
can be enhanced for adding extra fields
and also custom / generic data sources
can be created which are based on
function modules.
Enhancing your data source in SAP BW
requires couple of steps to be performed
and writing ABAP code in the source
code of the function module. This book
helps in filling the gap by providing
sample ABAP program snippets to help
the BW developer work quickly rather
than spending time on the syntax.
The book includes screenshots of the
SAP software which are copyright of
SAP AG.
3 CONTENTS
1 COPYRIGHT notice
2 About the Author
About the book
4 Custom Data source for Sales Order
Header Data
4.1 Creating Extract Structure
4.2 Creating Extract Function
Module without source code from
standard FM
RSAX_BIW_GET_DATA-
4.3 Copy the standard Function
Module RSAX_BIW_GET_DATA into
your custom Function module. Ex.
RSAX_BIW_GET_DATA_SALES01
4.4 Create custom Data source in
RSO2
4.5 Preparing code in Extraction
Function module to extract data from
database tables into Datasource based
on the selection fields data-
5 SAP’s Enhancement Techniques
5.1 User exits
5.2 Customer exits
5.3 BADIs (Business Add-Ins)
6 Enhancements and Customer
Projects
7 Steps for Customer Exit
Enhancement
7.1 Adding extra fields of the extract
structure
7.1.1 Goal: Add field STARS
(House number and street) and LAND1
(Country key) of standard table KNA1
to the custom data source.
8 Steps for Enhancement of the Data
source by BADI
9 Generic Delta Extraction by
Function Module
9.1 Step 1: Create an Extract
Structure
9.2 Step 2: Create the function
module
9.3 Step 3: Create the Data source
9.4 Step 4: Change the source code
of the function module
9.5 Step 5: Go to transaction RSA3
to test the data source
4 CUSTOM DATA
SOURCE FOR SALES
ORDER HEADER DATA
This example illustrates how to create a
custom Data source in ECC system
which extracts the data from a standard
SAP table like VBAK. This step by step
approach will help you in creating a
Generic Data source based on function
module. The advantage of using a
function module based Data source is
that you can do some modifications to
the data after it is extracted from the
table.
4.1 CREATING EXTRACT
STRUCTURE

Goto tcode SE11.


Select radio button ‘Data Type’.
Enter the name of the extract structure
Ex. ZES_SALES01
Click on the create button.
From popup window, select structure
radio button and click on Continue.
Enter short description for the Data
source. Enter required fields as
Components. Enter the Data element
names of the fields as Component types
(Verify the Standard DB table like
VBAK).

For Currency and Quantity fields of your


Extract Structure, you have to specify the
corresponding key fields as Reference
fields.
For this, go to Currency/Quantity fields
tab and specify Reference table/
Structure and field.
Finally, save and activate the extract
structure.
4.2 CREATING EXTRACT
FUNCTION MODULE WITHOUT
SOURCE CODE FROM STANDARD
FM
RSAX_BIW_GET_DATA-

Create a function group Ex:


ZMYGROUP01 in SE80 and activate it.
In its top include, attach the Type group
SBIWA by the following statement and
activate it.
TYPE-POOLS SBIWA.
4.3 COPY THE STANDARD
FUNCTION MODULE
RSAX_BIW_GET_DATA
INTO YOUR CUSTOM FUNCTION
MODULE. EX.
RSAX_BIW_GET_DATA_SA

Goto SE37. Enter standard FM name


RSAX_BIW_GET_DATA into your
custom Function module and copy it as
your custom FM Ex:
RSAX_BIW_GET_DATA_SALES01
Also enter name of your Function Group
ex: ZMYGROUP01 and click on
Continue button.
Open your Custom Function Module in
SE37 in Change mode.
Goto Source code tab,
Select the entire source code and delete
it.
Finally activate the function module.
4.4 CREATE CUSTOM DATA
SOURCE IN RSO2

Go to RSO2.
Enter name of your custom data source
Ex: ZDS_SALES01
Click on Create button.
Enter Application Component eg. 0CRM
Enter Descriptions
Click on Extraction by FM button.
Enter your FM name and your extract
structure name and finally save it.
Select required fields as selection fields
to filter the records in future and save
the Data source. Ex. Only two fields
VBELN and ERDAT are selected as
Selection Fields.
4.5 PREPARING CODE IN
EXTRACTION FUNCTION
MODULE TO EXTRACT DATA
FROM DATABASE TABLES INTO
DATASOURCE BASED ON THE
SELECTION FIELDS DATA-

Goto SE37.
Open your FM -
RSAX_BIW_GET_DATA_SALES01 in
change mode.
Go to its ‘Tables’ tab and provide the
name of Extract structure as associated
type for the table parameter E_T_DATA.
Ignore any errors occurred by pushing
the Enter key.
Go to Source code tab of the function
module, and enter the following code.
STATICS C1 TYPE CURSOR.
RANGES R_VBELN FOR VBAK-
VBELN.
RANGES R_ERDAT FOR VBAK-
ERDAT.
IF I_INITFLAG = SPACE.
IF C1 IS INITIAL.
“Select Sales order numbers
LOOP AT I_T_SELECT WHERE
FIELDNM = ‘VBELN’.
R_VBELN-SIGN = I_T_SELECT-
SIGN.
R_VBELN-OPTION =
I_T_SELECT-OPTION.
R_VBELN-HIGH = I_T_SELECT-
HIGH.
R_VBELN-LOW = I_T_SELECT-
LOW.

“for adding leading zeroes to the sales


order number VBELN
CALL FUNCTION
‘NUMERIC_CHECK’
EXPORTING
STRING_IN = I_T_SELECT-LOW
IMPORTING
STRING_OUT = R_VBELN-
LOW.
CALL FUNCTION
‘NUMERIC_CHECK’
EXPORTING
STRING_IN = I_T_SELECT-
HIGH
IMPORTING
STRING_OUT = R_VBELN-
HIGH.
APPEND R_VBELN.
CLEAR R_VBELN.
ENDLOOP.
“Select sales document creation date
ERDAT
LOOP AT I_T_SELECT WHERE
FIELDNM = ‘ERDAT’.
R_ERDAT-SIGN = I_T_SELECT-
SIGN.
R_ ERDAT-OPTION =
I_T_SELECT-OPTION.
R_ERDAT-HIGH =
I_T_SELECT-HIGH.
R_ ERDAT-LOW =
I_T_SELECT-LOW.
APPEND R_ERDAT.
CLEAR R_ERDAT.
ENDLOOP.
OPEN CURSOR WITH HOLD C1
FOR
SELECT VBELN
ERDAT
VKORG
KUNNR
NETWR
WAERK
FROM VBAK
WHERE VBELN IN
R_VBELN AND
ERDAT IN
R_ERDAT.
ENDIF.
FETCH NEXT CURSOR C1
INTO CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE I_MAZSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR C1.
RAISE NO_MORE_DATA.
ENDIF.
LOOP AT E_T_DATA INTO WA.
“extra calculations after fetching
data into data source
WA-NETWR = WA-NETWR + 500.
“Add 500 to the net value extracted
from table VBAK
MODIFY E_T_DATA FROM WA.
ENDLOOP.
ENDIF.
ENDFUNCTION.

FINALLY save and activate the function


module.
Test if by extracting the data into your
Data source in tcode RSA3.
5 SAP’S
ENHANCEMENT
TECHNIQUES
SAP delivers standard applications like
VA01 for its customer. Based on the
local business requirement, the customer
or client tries to modify this standard
application.
There are 2 ways for modifying standard
functionality of the standard application.
1. Directly going into the source code
of the standard application and start
modifying the standard logic. This
comes under Source code
Modification. This process is not
recommended as SAP object change
is a system wide effect and needs
Access Key. Only highly advanced
programmers should go for this
option.
2. Doing modification to source code of
standard application without
disturbing the existing code. This
comes under source code
enhancement. Here ordinary user can
attach his custom logic for the
existing standard code of SAP at
predefined places within the standard
source code.
Enhancements can be defined as
predefined points (Hooks) within the
source code of a standard SAP
application where end users (business
people) can add their custom logic
without disturbing the existing code.
In general these predefined points can be
considered as EXITS. When the program
control reaches one of these points, it
will come out of the source code,
executes the customer logic and returns
back to the standard source code. That is
why these are called as EXITS.
There are 3 types of EXITS-
1. User exits
2. Customer exits
3. BADIs (Business Add-Ins)
5.1 USER EXITS

In old versions of SAP, these exits are


implemented with the Subroutines
concept. Those are known as User
exits.
They are local to the standard source
code. Locating these exits and
maintaining custom logic in them is
difficult.
5.2 CUSTOMER EXITS
In later versions of SAP, these exits are
implemented with the Function Module
concept. These are known as Customer
exits or Function exits.
These are maintained as global items
outside the standard source code.
Locating these exits and maintaining the
custom logic in them is much easier than
user exits.

The common disadvantage with the


above 2 types of exits is that, they can be
implemented only once. If a person has
already implemented these exits and if
another person wants to implement the
same exit, he has to prepare his custom
logic along with the logic of the first
person. Implementations cannot be
maintained independently.
5.3 BADIS (BUSINESS ADD-
INS)

In the latest versions of SAP, the exits


are implemented with the methods of
Object Oriented Programming concepts.
These are known as BADIs.
These exits also can be maintained as
global items outside the standard source
code. Maintaining the custom logic is
much easier and efficient than the other
exits.
The major advantage with BADIs is,
multiple implementation can be
maintained independent of each other.
6 ENHANCEMENTS AND
CUSTOMER PROJECTS
Several customer exits are combined
into a single object called as
Enhancement object.
Several Enhancements are combined
into a single object called as Customer
Project.
Ex: RSAP0001 is an enhancement
object for the Data Source
enhancements. It contains 4 customer
exits-
EXIT_SAPLRSAP_001
EXIT_SAPLRSAP_002
EXIT_SAPLRSAP_003
EXIT_SAPLRSAP_004
Ex: RSR00001 is an enhancement object
for BEx report variables. It contains
only one customer exit-
EXIT_SAPLRRS0_001
SMOD is the tcode to look at the
components of an enhancement object.
For implementing an enhancement
object, it must be attached to a
customer project using the tcode
CMOD.
One customer project can be
attached with several enhancement
objects.
Enhancements can be implemented
only once. That is, if an enhancement
is attached to customer project it
cannot be attached to another
customer project.
In case of BADIs, several BADI
methods are combined into an object
called BADI definition.
The tcode SE18 is for maintaining
the BADIs definition.
BADI definition is same as the
enhancement Object. BADI method is
same as customer exit. SE18 is same
as SMOD.
A BADI definition can be
implemented several times by the
BADI implementation classes. These
classes are same as customer exits.
The relevant tcode is SE19. It is same
as CMOD.
Ex: The BADI definition for the
Data Source enhancement is
RSU5_SAPI_BADI
The methods of this BADI
definition are

DATA_TRANSFORM and
HIER_TRANSFORM
When the existing Data Sources are not
providing the complete data according to
the current requirement, extra data fields
can be added to the existing fields and
data can be fetched for those fields by
Enhancement Process.
For Data source Enhancement, SAP has
provided two techniques.
1. Enhancement by Customer exits
2. Enhancement by BADIs
The repository object for Customer Exit
is called as Enhancement Object and its
name is RSAP0001. Its components can
be observed using the tcode SMOD.
They can be implemented using the tcode
CMOD.
The repository object for BADI
enhancements is called as BADI
definition and its name is RSU5-
SAPI_BADI. Its components can be
observed using the tcode SE18. They
can implemented using the tcode SE19.
Customer Exit can be implemented only
once, whereas BADIs can be
implemented multiple times and those
Implementation are independent of each
other.
7 STEPS FOR
CUSTOMER EXIT
ENHANCEMENT
7.1 ADDING EXTRA FIELDS
OF THE EXTRACT STRUCTURE

7.1.1 Goal: Add field STARS


(House number and street) and
LAND1 (Country key) of standard
table KNA1 to the custom data
source.

Go to RSA6 tcode in the SAP ECC


system. Expand the node SAP R/3,
expand the relevant application
component e.g. SD.
Keep the cursor on the selected data
source e.g. ZDS_SALES01
Click on Change button in
application toolbar

Take name of the Extract Structure


e.g. ZES_SALES01
Go to SE11, provide name of the
structure and click on Display button.
To add extra fields for the Data
source, click on Append Structure
button
Provide name for the append
structure e.g. ZAPPEND1
Provide short description for the
append structure and mention the
required fields and their fields under
the heading component e.g. STARS
and LAND1.
Specify Data elements under the
heading component type e.g. STARS
and LAND1
Finally activate the append structure and
come back. Observe the extra fields
added to your data source.
You can see that the fields LAND1 and
STARS is added to your extract
structure.
To activate these fields in the data
source, goto RSA6 transaction, open
your data source in change mode and
unselect the hide check boxes
corresponding to the newly added fields.
Finally save the Data source.

To provide the data for the newly added


fields, we have to enhance the customer
exit corresponding to the enhancement
RSAP0001.
Goto CMOD transaction. Enter a name
for Customer Project. Example:
Project1.
Click on create button. Enter the short
description and click on enhancement
assignment button and enter the name of
your enhancement RSAP0001 and save
it.
If the enhancement is not already
implemented, then the system will create
a Customer project, otherwise an error
message appears in the status bar, which
specifies the name of the Customer
Project example: ZBW110 has already
implemented the enhancement. Take the
name of the existing customer project
and completely come out of the current
transaction.
Again enter into CMOD transaction with
the Customer Project which is already
existed e.g. ZBW110. Click on the
components button inside ZBW110
project and observe the four standard
customer exits. These are the Function
modules.
Double click on the first customer exit
and observe the parameters of this
function module.
Double click on the name of the include
file and change the include file into Edit
mode. Keep cursor in an empty line
anywhere after the CASE statement.
CASE i_datasource.
You can find empty line usually before
WHEN keyword.
Finally click on Insert button from
application tool bar.
Observe the presence of a pair of braces
with the word insert. In the middle of
them you can prepare the logic of your
enhancement.
CASE i_datasource.
*{ insert
WHEN ‘ZDS_SALES01’.
DATA WA2 TYPE
ZES_SALES01. “define a
work area like your extract structure
DATA C_T_DATA2 TYPE TABLE
OF ZES_SALES01. “define an
internal table like your extract
structure
DATA IT_KNA1 TYPE TABLE OF
KNA1. “define an internal
table like standard table KNA1
DATA IS_KNA1 TYPE
KNA1. “define a work
area type KNA1 table structure
IF NOT C_T_DATA [ ] IS INITIAL.
C_T_DATA2 [ ] = C_T_DATA [
]. “Read all data
of data source into internal table
C_T_DATA2 [ ]
SELECT * FROM KNA1 INTO
TABLE IT_KNA1 FOR ALL ENTRIES
IN C_T_DATA2
WHERE KUNNR = C_T_DATA2-
KUNNR.
LOOP AT C_T_DATA2 INTO WA2.
READ TABLE IT_KNA1 INTO
IS_KNA1 WITH KEY KUNNR = WA2-
KUNNR.
WA2-STARS = IS_KNA1-
STARS. “Read values of house
street number for all customers in data
source from KNA1
WA2-LAND1 = IS_KNA1-LAND1.
“Read values of country key for all
customers in data source from KNA1
MODIFY C_T_DATA2 FROM WA2.
CLEAR WA2.
ENDLOOP.
C_T_DATA [ ] = C_T_DATA2 [
]. “Update the data source
data
ENDIF.
*} insert
Finally activate the include and extract
the data for the data source in RSA3
transaction. Observe the data of the
newly added fields.
8 STEPS FOR
ENHANCEMENT OF THE
DATA SOURCE BY BADI
BADI stands for Business Add-In
These are Object oriented methods for
enhancing the data sources.
Every BADI definition contains an
interface with empty methods. We
implement these methods with our logic.
BADI definition is same as enhancement
object. BADI methods are same as
Customer exits of Enhancement Object.
A BADI method can be implemented
several times.
BADI methods are implemented in the
transaction SE19.
The standard BADI definition for Data
source enhancement is
RSU5_SAPI_BADI.
In ECC 6.0 this BADI comes under the
category of Classic BADIs.
Go to the transaction SE19. Select radio
button Classic BADI, enter name of
BADI and click on create button.
Enter description and activate the
implementation

Click on the Interface tab and observe


two methods of this BADI definition.
Double click on 1st method
DATA_TRANSFORM to implement the
logic.
If importing parameters of this method
are not visible, click on Signature
button. Observe the parameters
I_DATASOURCE, C_T_DATA etc. and
prepare your logic inside the method.
Prepare the logic same as the customer
exit logic.
CASE i_datasource.
WHEN ‘ZDS_SALES01’.
DATA WA2 TYPE
ZES_SALES01. “define a
work area like your extract structure
DATA C_T_DATA2 TYPE TABLE
OF ZES_SALES01. “define an
internal table like your extract
structure
DATA IT_KNA1 TYPE TABLE OF
KNA1. “define an internal
table like standard table KNA1
DATA IS_KNA1 TYPE
KNA1. “define a work
area type KNA1 table structure
IF NOT C_T_DATA [ ] IS INITIAL.
C_T_DATA2 [ ] = C_T_DATA [
]. “Read all data
of data source into internal table
C_T_DATA2 [ ]
SELECT * FROM KNA1 INTO
TABLE IT_KNA1 FOR ALL ENTRIES
IN C_T_DATA2
WHERE KUNNR = C_T_DATA2-
KUNNR.
LOOP AT C_T_DATA2 INTO WA2.
READ TABLE IT_KNA1 INTO
IS_KNA1 WITH KEY KUNNR = WA2-
KUNNR.
WA2-STARS = IS_KNA1-
STARS. “Read values of house
street number for all customers in data
source from KNA1
WA2-LAND1 = IS_KNA1-LAND1.
“Read values of country key for all
customers in data source from KNA1
MODIFY C_T_DATA2 FROM WA2.
CLEAR WA2.
ENDLOOP.
C_T_DATA [ ] = C_T_DATA2 [
]. “Update the data source
data
ENDIF.
Finally activate the implementation and
extract the data for the data source in
RSA3 transaction. Observe the data of
the newly added fields.
9 GENERIC DELTA
EXTRACTION BY
FUNCTION MODULE
For delta functionality you need a delta
field. Some tables like VBAK (Sales
Document: Header Data) don’t have a
timestamp field for creation/change that
we can use as a unique delta field in
Data source. But they have separate
fields for Sales Order creation date
(ERDAT), creation time (ERZET) and
Sales order changed date (AEDAT). To
get the data of the VBAK table by using
delta functionality we will create a
generic Data source using a custom
function module which implements the
necessary logic.
We will create an extraction structure
that has a timestamp field and we will
use this field to implement the delta
functionality.
There are two template function modules
which you can copy and use:
RSAX_BIW_GET_DATA_SIMPLE: A
function module with simple interface
for Full Load with no support of delta
loads.
RSAX_BIW_GET_DATA: A function
module with complete interface that
supports delta load. We will use this
FM.
9.1 STEP 1: CREATE AN
EXTRACT STRUCTURE

Go to transaction SE11 and create an


extract structure ZES_SALES01 for the
data source.
Add a field TIMSTMP (Data element:
TZNTSTMPS). This field will hold the
timestamp and allow us to use the
extraction for delta purposes.
Save and activate the structure.
9.2 STEP 2: CREATE THE
FUNCTION MODULE
Go to the transaction SE80 and create a
function group for the function module if
it is not existed. Attach the type group
SBIWA to the TOP include by the
statement TYPE_POOLS SBIWA.
Go to the transaction SE37 and copy the
function module
RSAX_BIW_GET_DATA to
RSAX_BIW_GET_DATA_SALES01.
Open your FM
RSAX_BIW_GET_DATA_SALES01
in change mode.
Select entire source code and delete it.
Go to tables tab and mention the name of
extract structure ZES_SALES01 as
associated type for the table parameter
E_T_DATA with LIKE keyword.

Save and activate the function module.


9.3 STEP 3: CREATE THE
DATA SOURCE
Go to the transaction RSO2 and create a
new data source for transaction data and
name it to ZDS_SALES01.
Set the application component and the
description texts.
Click on Generic Delta button. Select the
timestamp field TIMSTMP (Time Stamp
field of your extract structure) and set
the option Timestamp.
Optionally set the safely interval lower
limit.
Click Save and click save again. In the
following screen, you can set the
selection fields.
The timestamp field is disabled because
it will be automatically populated as
part of the delta process.

Now go to transaction RSA2 to see the


details of our data source
ZDS_SALES01. The extraction method
is set to F2 (Simple Interface).
To change it to F1 (Complete Interface)
execute the following ABAP code (You
can go to SE38 and create a new report
with this ABAP code)
REPORT.
UPDATE roosource.
SET delta = ‘E’.
exmethod = ‘F1’
WHERE oltpsource = ‘ZDS_SALES01’.
Go to RSA2 and check the status of the
data source ZDS_SALES01 (just to
confirm that it is set to F1)
9.4 STEP 4: CHANGE THE
SOURCE CODE OF THE
FUNCTION MODULE

Go to the function module


ZRSAX_BIW_GET_DATA_SALES01
and populate the source code as below-

FUNCTION ZRSAX_BIW_GET_DATA_SALES0
*"---------------------------------------------------
-------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SBIWA_S_INTE
REQUNR
*" VALUE(I_ISOURCE) TYPE SBIWA_S_INTE
ISOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SBIWA_S_INTE
MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SBIWA_S_INT
INITFLAG OPTIONAL
*" VALUE(I_UPDMODE) TYPE SBIWA_S_IN
UPDMODE OPTIONAL
*" VALUE(I_DATAPAKID) TYPE SBIWA_S_IN
DATAPAKID OPTIONAL
*" VALUE(I_PRIVATE_MODE) OPTIONAL
*" VALUE(I_CALLMODE) LIKE ROARCHD2
CALLMODE OPTIONAL
*" VALUE(I_REMOTE_CALL) TYPE SBIWA_F
*" TABLES
*" I_T_SELECT TYPE SBIWA_T_SELECT OP
*" I_T_FIELDS TYPE SBIWA_T_FIELDS OP
*" E_T_DATA STRUCTURE ZES_SALES01 O
*" E_T_SOURCE_STRUCTURE_NAME OPT
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"---------------------------------------------------
-------------------
STATICS C1 TYPE CURSOR.
RANGES R_VBELN FOR VBAK-
VBELN.
RANGES R_ERDAT FOR VBAK-
ERDAT.
RANGES R_KUNNR FOR VBAK-
KUNNR.
DATA K(10) TYPE N.
DATA TS1 TYPE TZNTSTMPS.
DATA STARTDATE TYPE D.
DATA STARTTIME TYPE T.
DATA ENDDATE TYPE D.
DATA ENDTIME TYPE T.
IF I_INITFLAG = SPACE.
IF C1 IS INITIAL.
“Select Sales order numbers
LOOP AT I_T_SELECT WHERE
FIELDNM = ‘VBELN’.
R_VBELN-SIGN = I_T_SELECT-
SIGN.
R_VBELN-OPTION =
I_T_SELECT-OPTION.
“for adding leading zeroes to the
sales order number VBELN
CALL FUNCTION
‘NUMERIC_CHECK’
EXPORTING
STRING_IN = I_T_SELECT-
LOW
IMPORTING
STRING_OUT = R_VBELN-
LOW.
CALL FUNCTION
‘NUMERIC_CHECK’
EXPORTING
STRING_IN = I_T_SELECT-
HIGH
IMPORTING
STRING_OUT = R_VBELN-
HIGH.
APPEND R_VBELN.
CLEAR R_VBELN.
ENDLOOP.
“Select sales organization
LOOP AT I_T_SELECT WHERE
FIELDNM = ‘VKORG’.
R_VKORG-SIGN =
I_T_SELECT-SIGN.
R_ VKORG-OPTION =
I_T_SELECT-OPTION.
CALL FUNCTION
‘NUMERIC_CHECK’ “for
adding leading zeroes
EXPORTING
STRING_IN = I_T_SELECT-
LOW
IMPORTING
STRING_OUT = R_VKORG-
LOW.
CALL FUNCTION
‘NUMERIC_CHECK’
EXPORTING
STRING_IN = I_T_SELECT-
HIGH
IMPORTING
STRING_OUT = R_VKORG-
HIGH.
APPEND R_VKORG.
CLEAR R_VKORG.
ENDLOOP.
LOOP AT I_T_SELECT WHERE
FIELDNM = ‘KUNNR’.
R_VKORG-SIGN =
I_T_SELECT-SIGN.
R_ VKORG-OPTION =
I_T_SELECT-OPTION.
CALL FUNCTION
‘NUMERIC_CHECK’ “for
adding leading zeroes
EXPORTING
STRING_IN = I_T_SELECT-
LOW
IMPORTING
STRING_OUT = R_KUNNR-
LOW.
CALL FUNCTION
‘NUMERIC_CHECK’
EXPORTING
STRING_IN = I_T_SELECT-
HIGH
IMPORTING
STRING_OUT = R_KUNNR-
HIGH.
APPEND R_KUNNR.
CLEAR R_KUNNR.
ENDLOOP.
LOOP AT I_T_SELECT WHERE
FIELDNM =
‘TIMSTMP’. “Time
stamp field
TS1 = I_T_SELECT-LOW.
ENDLOOP.
IF TS1 IS INITIAL. “1st time
perform full load
OPEN CURSOR WITH HOLD C1
FOR
SELECT VBELN
VKORG
KUNNR
NETWR
WAERK
FROM VBAK
WHERE VBELN IN
R_VBELN AND
VKORG IN
R_VKORG AND
KUNNR IN
R_KUNNR.
ELSE. “2nd time perform delta
load
CONVERT TIME STAMP TS1
TIME ZONE SY-ZONLO
INTO DATA STARTDATE
TIME STARTTIME.
OPEN CURSOR WITH HOLD C1
FOR
SELECT VBELN
VKORG
KUNNR
NETWR
WAERK
FROM VBAK
WHERE VBELN IN
R_VBELN AND
VKORG IN
R_VKORG AND
KUNNR IN
R_KUNNR AND
( ( ERDAT >=
STARTDATE AND ERZET >=
STARTTIME ) OR (AEDAT >=
STARTDATE).
ENDIF.
ENDIF.
FETCH NEXT CURSOR C1
INTO CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE I_MAZSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR C1.
RAISE NO_MORE_DATA.
ENDIF.
ENDIF.
ENDFUNCTION.
Save and activate your function module.
This is an optional step: To test the
function module go to SE37 and call it
two times in succession- one call for
initialization and the second to read
data. This is actually no necessary but
it’s a good way to check.
9.5 STEP 5: GO TO
TRANSACTION RSA3 TO TEST
THE DATA SOURCE

The data source supports the Full and


Update Delta mode. To use the Update
Delta mode, the first call must have the
update type C (Delta Initialization). All
following calls must have the update
type D (Delta update). The delta
process of the data source can be
mentioned and maintained in RSA7
(Delta queue).

You might also like