The document describes the batch input session method for processing batch input in SAP. It discusses creating a batch input session by opening and closing the session and inserting transaction data using BDC function modules. It provides examples of creating batch input sessions to update vendor records from sequential files and individual transactions.
2. Objectives
• The participants will be able to:
– Create the Batch Input part of an Inbound
Interface.
– Describe the Batch Input Session Method for
Batch Input.
Dec-2008 Data Interfaces | 2
3. Overview
Dec-2008 Data Interfaces | 3
SAPSAP
DatabaseDatabase
TableTable
Batch
Input
Session
BDC
Program
External
Data
The first batch input method is to create a batch input
session. It is the processing of this batch input
session that updates the database, not the execution
of the batch input program.
4. Creating Batch Input Sessions
Dec-2008 Data Interfaces | 4
“BDC_INSERT” is
called for each
transaction
entered into the
batch input
session.
Open Batch Input SessionOpen Batch Input Session
Close Batch Input SessionClose Batch Input Session
Insert Transaction Data into Session
BDC_OPEN_GROUP
BDC_INSERT
BDC_CLOSE_GROUP
5. BDC_OPEN_GROUP
Dec-2008 Data Interfaces | 5
CALL FUNCTION ‘BDC_OPEN_GROUP’
EXPORTING
CLIENT = <client>
GROUP = <session name>
HOLDDATE = <lock session until date>
KEEP= <keep or delete session>
USER= <user name>
EXCEPTIONS
CLIENT_INVALID = 1
. . .
OTHERS = 11.
SY-SUBRC
CHECK
9. Batch Input Session - Structure
Dec-2008 Data Interfaces | 9
Batch
Input
Session
Data Section
Transaction Data
Header Section
Creator
Client
Session Name
Authorization User
Hold Date
Keep or Delete
10. Example #1 - Change Vendor
Dec-2008 Data Interfaces | 10
Vendor
Company Code
ABAPXX-002
AddressX
Name
Street
Computers, Inc.
Buyer, Inc.1
City Philadelphia
In this example, we will create a
batch input session to add a street
address to an already existing
vendor (TEST1).
The “Change Vendor” transaction is
“FK02”.
11. Example #1 - Declaration Section
Dec-2008 Data Interfaces | 11
REPORT YDIXX5_2.
DATA: BDC_TAB TYPE STANDARD TABLE OF BDCDATA
INITIAL SIZE 6 WITH HEADER LINE,
WA_BDC_TAB TYPE BDCDATA,
SESSION TYPE APQ_GRPN
VALUE 'DEMO#8'.
Step #1
** This program is continued on the next slide **
12. Example #1 - Main Program
Dec-2008 Data Interfaces | 12
START-OF-SELECTION.
CALL FUNCTION ‘BDC_OPEN_GROUP’
EXPORTING
CLIENT = SY-MANDT
GROUP = SESSION
USER = SY-UNAME
EXCEPTIONS. . . .
PERFORM FILL_BDC_TAB.
CALL FUNCTION ‘BDC_INSERT’
EXPORTING
TCODE = ‘FK02’
TABLES
DYNPROTAB = BDC_TAB
EXCEPTIONS. . . .
CALL FUNCTION ‘BDC_CLOSE_GROUP’
EXCEPTIONS. . . .
Step #2
Step #3
Step #4
Step #5
** This program is continued on the next slide **
13. Example #1 - Subroutines
Dec-2008 Data Interfaces | 13
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
‘1’‘SAPMF02K’ ‘0106’,
‘ ’‘RF02K-LIFNR’ ‘ABAPXX-002’,
‘ ’‘RF02K-D0110’ ‘X’,
‘1’‘SAPMF02K’ ‘0110’,
‘ ’‘LFA1-STRAS’ ‘Buyer, Inc.1’,
‘ ’‘BDC_OKCODE’ ‘=UPDA’.
ENDFORM.
FORM POPULATE_BDC_TAB USING
FLAG TYPE C
VAR1 TYPE C
VAR2 TYPE C.
CLEAR WA_BDC_TAB.
IF FLAG = ‘1’.
WA_BDC_TAB-PROGRAM = VAR1.
WA_ BDC_TAB-DYNPRO= VAR2.
WA_BDC_TAB-DYNBEGIN= ‘X’.
ELSE.
WA_BDC_TAB-FNAM = VAR1.
WA_BDC_TAB-FVAL = VAR2.
ENDIF.
APPEND WA_BDC_TAB TO BDC_TAB.
ENDFORM.
14. Example #2 - Change Vendors
Dec-2008 Data Interfaces | 14
Vendor
Company Code
TEST1
AddressX
Name
Street
Computers, Inc.
123 Main St.
City Philadelphia
Vendor
Company Code
TEST2
AddressX
Name
Street
Computer Land
10 Walnut St.
City
Boston
In this example, we will read records from a sequential file on
the application server to create a batch input session that
updates multiple vendors.
15. Example #2 - Sequential File
Dec-2008 Data Interfaces | 15
TEST1 123 Main St.
TEST2 10 Walnut St.
TEST3 32 Chestnut St.
TEST4 30 Market St.
TEST5 17 S. 30th St.
File name:
‘/tmp/bc180_file3’
The sequential file we will read is set up in
records. Each record has two fields with
the following formats:
<Field1> LIKE LFA1-LIFNR
<Field2> LIKE LFA1-STRAS
16. Example #2 - Declaration Section
Dec-2008 Data Interfaces | 16
REPORT YDIXX5_02.
DATA: BDC_TAB TYPE STANDARD TABLE OF BDCDATA
INITIAL SIZE 6 ,
SESSION TYPE APQ_GRPN
VALUE 'DEMO#9',
INFILE(20) VALUE '/tmp/bc180_file3'.
DATA: BEGIN OF INREC,
VENDNUM TYPE LIFNR,
STREET TYPE STRAS_GP,
END OF INREC.
Step #1
Step #2
** This program is continued on the next slide **
17. Example #2 - Main Program
Dec-2008 Data Interfaces | 17
START-OF-SELECTION.
OPEN DATASET INFILE
FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
CALL FUNCTION ‘BDC_OPEN_GROUP’. . . .
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0. EXIT. ENDIF.
PERFORM FILL_BDC_TAB.
CALL FUNCTION ‘BDC_INSERT’
EXPORTING
TCODE = ‘FK02’
TABLES
DYNPROTAB = BDC_TAB. . . .
ENDDO.
CALL FUNCTION ‘BDC_CLOSE_GROUP’. . . .
CLOSE DATASET INFILE.
SY-SUBRC
CHECKStep #3
Step #4
Step #5
Step #6
Step #7
Step #8
Step #9
Step #10
** This program is continued on the next slide **
18. Example #2 - Subroutines
Dec-2008 Data Interfaces | 18
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
‘1’‘SAPMF02K’ ‘0106’,
‘ ’‘RF02K-LIFNR’ INREC-VENDNUM,
‘ ’‘RF02K-D0110’ ‘X’,
‘1’‘SAPMF02K’ ‘0110’,
‘ ’‘LFA1-STRAS’ INREC-STREET,
‘ ’‘BDC_OKCODE’ ‘=UPDA’.
ENDFORM.
FORM POPULATE_BDC_TAB USING
FLAG TYPE C
VAR1 TYPE C
VAR2 TYPE C.
CLEAR WA_BDC_TAB.
IF FLAG = ‘1’.
WA_BDC_TAB-PROGRAM = VAR1.
WA_BDC_TAB-DYNPRO = VAR2.
WA_BDC_TAB-DYNBEGIN = ‘X’.
ELSE.
WA_BDC_TAB-FNAM = VAR1.
WA_BDC_TAB-FVAL = VAR2.
ENDIF.
APPEND WA_BDC_TAB TO BDC_TAB.
ENDFORM.
Notice that the vendor number and street values are coming from the file’s
records read into the “INREC” structure.
19. Demonstration
• Creation of a custom batch input session
program for transaction XD02 (Change
Customer).
Dec-2008 Data Interfaces | 19
20. Practice
• Creation of a custom batch input session
program for transaction XD02 (Change
Customer).
Dec-2008 Data Interfaces | 20
21. Summary
Dec-2008 Data Interfaces | 21
Research Transaction
Code BDC Program
Execute BDC Program
Batch Input Session Created
Process Batch Input Session
SAP Database Updated
22. Questions
• What are the function modules required to
create a batch input session ?
• In what sequence are they called ?
Dec-2008 Data Interfaces | 22
Editor's Notes
In this chapter, we will cover the batch input method to create a batch input session.
In this case, the batch input program is often called a BDC program.
With this method, the execution of the batch input program only creates a batch input session; it does not update the SAP database. The transaction data entered into the BDC table is inserted in the batch input session. Processing (or executing) this batch input session updates the SAP database.
Batch input sessions are collected and maintained by the system in the “batch input queue” (also called the “queue file”).
In a BDC program, you create a batch input session.
To create a batch input session, you must:
Open the batch input session with the “BDC_OPEN_GROUP” function module.
Insert transaction data (collected in the BDC table) into the batch input session with the “BDC_INSERT” function module.
This subroutine is “called” for each transaction entered into the batch input session.
Close the batch input session with the “BDC_CLOSE_GROUP” function module.
The next three slides cover these function modules in detail.
The “BDC_OPEN_GROUP” function module opens a batch input session.
The main exporting parameters are:
Client - The client in which the batch input session is to be processed. The default is the client in which the BDC program was executed.
Group - The name of the batch input session. This name does not have to be unique.
Hold date - The batch input session cannot be processed until this “lock date”. The default is no date, so the batch input session can be processed immediately.
Keep - Flag to indicate whether the batch input session should be kept (‘X’) or deleted (‘ ’) after successful processing. The default is to delete the batch input session.
User - User whose authorisations will be checked if the batch input session is processed in the background.
The “BDC_INSERT” function module inserts transaction data into a batch input session.
The exporting parameters are:
TCODE - The transaction code that is to be executed. In other words, the information in the BDC table refers to this transaction.
POST_LOCAL - if you set this parameter to ‘X’ the update will run in asynchronous mode instead of the default synchronous one (for the differences between the two update types see the chapter on CALL TRANSACTION)
The only tables parameter is:
DYNPROTAB (required) - The BDC table with the transaction data.
The “BDC_INSERT” function module is “called” for each transaction entered into the batch input session.
In our simple example where we update one vendor, we will only “call” this function module once.
In a more realistic example where we will read multiple records from a sequential file, we will “call” this function module for each record.
A batch input session can include data for different transactions. The “TCODE” parameter indicates the appropriate transaction code. The BDC table contents must mimic the transaction code specified or an error will occur when the batch input session is processed.
For example, if you read vendor information from a sequential file, you will use the “Change Vendor” transaction (“FK02”) if the vendor already exists or the “Create Vendor” transaction (“FK01”) if the vendor does not exist. The BDC table for each of these transactions will be different because different screens are encountered and different fields must be filled.
The “BDC_CLOSE_GROUP” function module closes a batch input session.
There are no parameters for this function module, only exceptions.
In both the “BDC_CLOSE_GROUP” and “BDC_INSERT” function modules, the batch input session name is not specified. This fact indicates that only one batch input session can be open at any given time.
Depending on the number of records to be processed, you may want to split the records into multiple batch input sessions. In this case, you would close one batch input session and then open a new one before entering more transaction data.
A batch input session is comprised of two sections:
The heading section consists of general information about the batch input session. This information is contained in the APQI table.
This general information includes:
The creator of the batch input session
The creation date
Parameters specified in the “BDC_OPEN_GROUP” function module:
Client
Session name
Authorisation user
Hold date
Keep or delete flag
The data section consists of the transaction data. Information about this transaction data is contained in the APQD table.
We will continue our example from the previous chapter to create a batch input session.
Recall that we are using the “Change Vendor” transaction (“FK02”) to update one vendor’s record (“ABAPXX-002”) by adding a street address (“Buyer, Inc.1”).
To create a batch input session, perform the following steps in a BDC program:
Step #1: Create the BDC table.
This internal table must be declared “TYPE BDCDATA”.
These steps are continued on the next page.
If you create a variable or constant for the batch input session name, it must be declared “LIKE APQI-GROUPID”; otherwise, you will encounter an error when the “BDC_OPEN_GROUP” function module is executed.
This example program can be found in development class “YTRABAP46X” with the name “YDIXX5_01”.
Executing this program creates a batch input session. We have to process the session to update the SAP database.
Use the “System Services Batch input Sessions” menu path to process batch input sessions (we will cover this topic in greater detail in the next chapter).
Steps to create a batch input session (continued from previous page):
Step #2: Open the batch input session by calling the “BDC_OPEN_GROUP” function module.
Step #3: Fill the BDC table with the appropriate data for the transaction (see next page).
We learned how to fill the BDC table in the previous chapter.
Step #4: Insert a transaction’s data (from the BDC table) into the batch input session by calling the “BDC_INSERT” function module.
Step #5: Close the batch input session by calling the “BDC_CLOSE_GROUP” function module.
The two subroutines above are used to fill the BDC table. These two subroutines are executed just before the BDC table’s contents are inserted into the batch input session.
You should get in the habit of using this two-subroutine method of filling the BDC table. For this simple example and others we will cover, it might seem harder and longer to use this two-subroutine method. However, when you code a more complicated batch input program (i.e.one that involves many screens and many fields), you will notice a time savings and increased maintainability by using the two-subroutine method.
It is also a good habit to put comments on each entry entered into the BDC table. For example:
PERFORM POPULATE_BDC_TAB USING:
‘1’‘SAPMF02K’ ‘0106’, “initial screen of change vendor
‘ ’‘RF02K-LIFNR’ ‘ABAPXX-002’, “vendor number field
‘ ’‘RF02K-D0110’ ‘X’, “address check box
‘1’‘SAPMF02K’ ‘0110’,“address screen of change vendor
‘ ’‘LFA1-STRAS’ ‘Buyer, Inc.1’, “street address field
‘ ’‘BDC_OKCODE’‘=UPDA’. “save the record
The next example we will cover is more realistic to what you will be doing in the “real world”. You would never code a BDC program to update one record – it would be faster to manually go through the transaction online.
In this example, we will read vendor records from a sequential file on the application server.
Let’s assume that we are on an SAP project. ABC Inc. is the client installing SAP. We know that our client has a sequential file with vendor information that must be updated in the new SAP system (we have already inserted vendors into the system via batch input).
This sequential file is located on the application server.
We must determine the format of the sequential file (see next page).
The sequential file on the application server (‘/tmp/bc180_file3’) is set up in lines (or records).
This fact determines that we will open the file “IN TEXT MODE”.
Each record on the file has two fields. These two fields have the following formats:
&lt;Field1&gt; LIKE LFA1-LIFNR
&lt;Field2&gt; LIKE LFA1-STRAS
Once we determine the fields coming from the file, we can research the appropriate transaction.
We have already performed this research in the previous chapter, so we’ll skip ahead to coding the BDC program (see next page).
To create a batch input session with multiple records from a sequential file on the application server, perform the following steps in a BDC program:
Step #1: Create the BDC table.
This internal table must be declared “TYPE BDCDATA”.
Step #2: Define the structure in which the file’s records will be read.
The structure of the structure should match the structure of the file’s records.
These steps are continued on the next page.
If you create a variable or constant for the batch input session name, it must be declared “LIKE APQI-GROUPID”; otherwise, you will encounter an error when the “BDC_OPEN_GROUP” function module is executed.
This example program can be found in development class “YTRABAP46X” with the name “YDIXX5_02”.
Executing this program creates a batch input session. We have to process the session to update the SAP database.
Use the “System Services Batch input Sessions” menu path to process batch input sessions (we will cover this topic in greater detail in the next chapter).
Steps to create a batch input session with multiple records from a sequential file on the application server (continued from previous page):
Step #3: Open the file “FOR INPUT”.
Step #4: Open the batch input session by calling the “BDC_OPEN_GROUP” function module.
Step #5: Read a record from the file into the structure.
To read the complete file, you must code the “READ DATASET” statement in a DO loop.
Step #6: Code a way out (EXIT) of the DO loop.
If SY-SUBRC is not 0, the end of the file has already been reached.
Step #7: Fill the BDC table with the appropriate data for the transaction (see next page)This step will be executed for each record in the sequential file.
We learned how to fill the BDC table in the previous chapter.
Step #8: Insert a transaction’s data (from the BDC table) into the batch input session by calling the “BDC_INSERT” function module.
This step will be executed for each record in the sequential file.
Step #9: Close the batch input session by calling the “BDC_CLOSE_GROUP” function module.
Step #10: Close the file.
The two subroutines above are used to fill the BDC table. These two subroutines are executed just before the BDC table’s contents are inserted into the batch input session.
The main difference in this example and our previous one-vendor example is the values used to fill the vendor number and street address fields.
In our previous example, these values were hard-coded as ‘TEST1’ and 123 Main St.’.
Because we are now reading this information from a sequential file, the values change for each vendor and cannot be hard-coded.
In this case, we will use the values read into the “INREC” structure for each record.
When we learned how to fill the BDC table, the first step was to delete all table entries with the “REFRESH” statement. This action is important now because the “FILL_BDC_TAB” subroutine will be executed for each record.
Without the “REFRESH” statement, the BDC table contents would be accumulating with each new record and the same transaction data would be inserted into the batch input session multiple times.
There is no difference in the second subroutine.
Throughout the last two chapters we have learned the basics of batch input and one batch input method – to create a batch input session.
In the last chapter, we learned how to research a transaction and fill the BDC table. This process will be used for all batch input methods.
In this chapter, we learned how to code a BDC program to create a batch input session.
An important point to remember is that executing a BDC program does not update the SAP database; instead, it creates a batch input session. The SAP database is updated when the batch input session is processed. We will cover the topic of processing batch input sessions in the next chapter.