Batch Input Session Dec-2008 Data Interfaces |
Nov 07, 2014
Batch Input Session
Dec-2008 Data Interfaces |
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
Overview
Dec-2008 Data Interfaces | 3
SAPSAPDatabaseDatabase
TableTable
BatchInput
Session
BDCProgram
ExternalData
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.
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
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-SUBRCCHECK
BDC_INSERT
Dec-2008 Data Interfaces | 6
CALL FUNCTION ‘BDC_INSERT’
EXPORTING
TCODE = <transaction code>
POST_LOCAL = <local update>
TABLES
DYNPROTAB = <bdc internal table>
EXCEPTIONS
INTERNAL_ERROR = 1
. . .
OTHERS = 5.
SY-SUBRCCHECK
BDC_INSERT (Contd.)
Dec-2008 Data Interfaces | 7
CALL FUNCTION ‘BDC_INSERT’
EXPORTING
TCODE = <transaction code>
POST_LOCAL = <local update>
TABLES
DYNPROTAB = <bdc internal table>
EXCEPTIONS
INTERNAL_ERROR = 1
. . .
OTHERS = 5.
SY-SUBRCCHECK
BDC_CLOSE_GROUP
Dec-2008 Data Interfaces | 8
CALL FUNCTION ‘BDC_CLOSE_GROUP’
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.SY-SUBRC
CHECK
Batch Input Session - Structure
Dec-2008 Data Interfaces | 9
BatchInput
Session
Data Section
Transaction Data
Header Section
Creator
Client
Session Name
Authorization User
Hold Date
Keep or Delete
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”.
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_GRPNVALUE 'DEMO#8'.
Step #1
** This program is continued on the next slide **
Example #1 - Main Program
Dec-2008 Data Interfaces | 12
START-OF-SELECTION.CALL FUNCTION ‘BDC_OPEN_GROUP’
EXPORTINGCLIENT = SY-MANDTGROUP = SESSIONUSER = SY-UNAME
EXCEPTIONS. . . .PERFORM FILL_BDC_TAB.CALL FUNCTION ‘BDC_INSERT’
EXPORTINGTCODE = ‘FK02’
TABLESDYNPROTAB = 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 **
Example #1 - Subroutines
Dec-2008 Data Interfaces | 13
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TABUSING:
‘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 USINGFLAG 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.
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.
CityBoston
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.
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
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 **
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’
EXPORTINGTCODE = ‘FK02’
TABLESDYNPROTAB = BDC_TAB. . . .
ENDDO.CALL FUNCTION ‘BDC_CLOSE_GROUP’. . . .CLOSE DATASET INFILE.
SY-SUBRCCHECKStep #3
Step #4
Step #5
Step #6
Step #7
Step #8
Step #9
Step #10
** This program is continued on the next slide **
Example #2 - Subroutines
Dec-2008 Data Interfaces | 18
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TABUSING:
‘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 USINGFLAG 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.
Demonstration
• Creation of a custom batch input session program for transaction XD02 (Change Customer).
Dec-2008 Data Interfaces | 19
Practice
• Creation of a custom batch input session program for transaction XD02 (Change Customer).
Dec-2008 Data Interfaces | 20
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
Questions
• What are the function modules required to create a batch input session ?
• In what sequence are they called ?
Dec-2008 Data Interfaces | 22