Vous êtes sur la page 1sur 22

IBM Global Services

Batch Input Session

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

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.

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Overview
BDC Program 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.

External Data

Batch Input Session

SAP Database Table

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Creating Batch Input Sessions


Open Batch Input Session

BDC_OPEN_GROUP

BDC_INSERT is called for each transaction entered into the batch input session.

Insert Transaction Data into Session


BDC_INSERT

Close Batch Input Session


BDC_CLOSE_GROUP
4 Data Interfaces | 7.05 March-2005

2005 IBM Corporation

IBM Global Services

BDC_OPEN_GROUP

CALL FUNCTION BDC_OPEN_GROUP

EXPORTING
CLIENT GROUP HOLDDATE = <client> = <session name> = <lock session until date>

KEEP = <keep or delete session>


USER = <user name> EXCEPTIONS CLIENT_INVALID =1
CHECK SY-SUBRC

...
OTHERS = 11.

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

BDC_INSERT

CALL FUNCTION BDC_INSERT EXPORTING TCODE TABLES DYNPROTAB EXCEPTIONS INTERNAL_ERROR ... OTHERS = 5. =1
CHECK SY-SUBRC

= <transaction code>

= <bdc internal table>

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

BDC_INSERT (Contd.)

CALL FUNCTION BDC_INSERT EXPORTING TCODE TABLES DYNPROTAB EXCEPTIONS INTERNAL_ERROR ... OTHERS = 5. =1
CHECK SY-SUBRC

= <transaction code>

= <bdc internal table>

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

BDC_CLOSE_GROUP

CALL FUNCTION BDC_CLOSE_GROUP EXCEPTIONS NOT_OPEN QUEUE_ERROR = 2 OTHERS = 3. =1


CHECK SY-SUBRC

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Batch Input Session - Structure

Header Section Creator Client Session Name Authorization User

Hold Date
Keep or Delete Batch Input Session

Data Section

Transaction Data

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Example #1 - Change Vendor

In this example, we will create a batch input session to add a street address to an already existing vendor (TEST1).

Vendor Company Code X Address

ABAPXX-002

Name The Change Vendor transaction is FK02. Street

Computers, Inc.

Buyer, Inc.1
Philadelphia

City

10

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Example #1 - Declaration Section

REPORT YDIXX5_2. DATA: BDC_TAB LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 6 WITH HEADER LINE, SESSION LIKE APQI-GROUPID VALUE 'DEMO#8'.

Step #1

** This program is continued on the next slide **

11

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Example #1 - Main Program


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 **


12 Data Interfaces | 7.05 March-2005

2005 IBM Corporation

IBM Global Services

Example #1 - Subroutines
FORM FILL_BDC_TAB. REFRESH BDC_TAB. FORM POPULATE_BDC_TAB USING FLAG TYPE C VAR1 TYPE C VAR2 TYPE C. CLEAR BDC_TAB. IF FLAG = 1. BDC_TAB-PROGRAM = VAR1. BDC_TAB-DYNPRO = VAR2. BDC_TAB-DYNBEGIN = X. ELSE. BDC_TAB-FNAM = VAR1. BDC_TAB-FVAL = VAR2. ENDIF. APPEND BDC_TAB. ENDFORM. ENDFORM.

PERFORM POPULATE_BDC_TAB USING:


1 SAPMF02K RF02K-LIFNR RF02K-D0110 1 SAPMF02K LFA1-STRAS BDC_OKCODE 0106, ABAPXX-002, X, 0110, Buyer, Inc.1, =UPDA.

13

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Example #2 - Change Vendors


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.

Vendor Company Code

TEST1

Vendor Company Code

TEST2

Address

Address

Name Computers, Inc. Street 123 Main St. City


14

Name Computer Land Street 10 Walnut St. City Boston

Philadelphia
Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Example #2 - Sequential File

TEST1 TEST2 TEST3 TEST4 TEST5

123 Main St. 10 Walnut St. 32 Chestnut St. 30 Market St. 17 S. 30th St. The sequential file we will read is set up in records. Each record has two fields with the following formats:

<Field1> LIKE LFA1-LIFNR


File name: /tmp/bc180_file3 <Field2> LIKE LFA1-STRAS

15

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Example #2 - Declaration Section


REPORT YDIXX5_02. DATA: BDC_TAB LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 6 WITH HEADER LINE, SESSION LIKE APQI-GROUPID VALUE 'DEMO#9', INFILE(20) VALUE '/tmp/bc180_file3'. DATA: Step #2 BEGIN OF INREC, VENDNUM LIKE LFA1-LIFNR, STREET LIKE LFA1-STRAS, END OF INREC.

Step #1

** This program is continued on the next slide **


16 Data Interfaces | 7.05 March-2005

2005 IBM Corporation

IBM Global Services

Example #2 - Main Program


Step #3 Step #4 Step #5 START-OF-SELECTION. CHECK OPEN DATASET INFILE SY-SUBRC FOR INPUT IN TEXT MODE. 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.

Step #6
Step #7 Step #8

Step #9 Step #10

** This program is continued on the next slide **


17 Data Interfaces | 7.05 March-2005

2005 IBM Corporation

IBM Global Services

Example #2 - Subroutines
FORM FILL_BDC_TAB. REFRESH BDC_TAB. PERFORM POPULATE_BDC_TAB USING: 1 SAPMF02K RF02K-LIFNR RF02K-D0110 1 SAPMF02K LFA1-STRAS BDC_OKCODE 0106, INREC-VENDNUM, X, 0110, INREC-STREET, =UPDA. FORM POPULATE_BDC_TAB USING FLAG TYPE C VAR1 TYPE C VAR2 TYPE C. CLEAR BDC_TAB. IF FLAG = 1. BDC_TAB-PROGRAM = VAR1. BDC_TAB-DYNPRO = VAR2. BDC_TAB-DYNBEGIN = X. ELSE. BDC_TAB-FNAM = VAR1. BDC_TAB-FVAL = VAR2. ENDIF. APPEND BDC_TAB. ENDFORM.

ENDFORM.

Notice that the vendor number and street values are coming from the files records read into the INREC structure.
18 Data Interfaces | 7.05 March-2005

2005 IBM Corporation

IBM Global Services

Demonstration
Creation of a custom batch input session program for transaction XD02 (Change Customer).

19

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Practice
Creation of a custom batch input session program for transaction XD02 (Change Customer).

20

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Summary
Research Transaction

Code BDC Program

Execute BDC Program

Batch Input Session Created

Process Batch Input Session

SAP Database Updated

21

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

IBM Global Services

Questions
What are the function modules required to create a batch input session ?

In what sequence are they called ?

22

Data Interfaces | 7.05

March-2005

2005 IBM Corporation

Vous aimerez peut-être aussi