12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL...

10
12 Batch Input 12.1 C ncept The term batch input sometimes causes confusion with Rl3 users and consultants. Does this re- fer'to the processing of input data that were created in batch? Or is it the batch processing of in- put data? Or do both apply? Batch input is used for the reliable import of large, usually computer-generated, data volumes into the Rl3 system. The input data procedure makes use of the normal dialog transactions of the system. The main difference to normal dialog operation is that the input data for the dialog transactions does not come from user inputs (mouse, keyboard) but is read from specially pre- pared data files. These data files are called batch input sessions. They are usually populated manually, stored in the appropriate tables and then processed. During the processing of a batch input session, their data are passed to the dynpro fields of the transactions in the same manner as for dialog operation. Simulated user inputs (continue, save, back) pass the data to the system after performing the usual field validations. Thus, the batch input process can be understood as being input rerouting for dialog transactions. The classic batch input process consists of two parts: Data acceptance and creation of session Session processing The two steps can be performed independent of each other directly in background (batch). One of the variants will be used depending on the data quantity or processing time involved. Typical situations for the use of batch input are: • Acceptance of large data volumes using a file from non-SAP systems Session creation: batch Session processing: batch Acceptance of mid-sized data volumes using a file or RFC from non-SAP systems Session creation: direct Session processing: batch Acceptance of small data volumes within Rl3 (customizing) Session creation: direct Session processing: direct The last example shows that batch input is possible without using batch. If this seldom applica- tion situation is ignored, batch input can be designated as being "batch execution of dialog pro- grams using computer-generated input data". Batch input can be compared with the background execution of reports with variant. Variants also represent an input rerouting for the report pa- U. Mende, Software Development for SAP R/3 ® © Springer-Verlag Berlin Heidelberg 2000

Transcript of 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL...

Page 1: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

12 Batch Input

12.1 Concept The term batch input sometimes causes confusion with Rl3 users and consultants. Does this re­fer'to the processing of input data that were created in batch? Or is it the batch processing of in­put data? Or do both apply?

Batch input is used for the reliable import of large, usually computer-generated, data volumes into the Rl3 system. The input data procedure makes use of the normal dialog transactions of the system. The main difference to normal dialog operation is that the input data for the dialog transactions does not come from user inputs (mouse, keyboard) but is read from specially pre­pared data files. These data files are called batch input sessions. They are usually populated manually, stored in the appropriate tables and then processed. During the processing of a batch input session, their data are passed to the dynpro fields of the transactions in the same manner as for dialog operation. Simulated user inputs (continue, save, back) pass the data to the system after performing the usual field validations. Thus, the batch input process can be understood as being input rerouting for dialog transactions. The classic batch input process consists of two parts:

Data acceptance and creation of session Session processing

The two steps can be performed independent of each other directly in background (batch). One of the variants will be used depending on the data quantity or processing time involved. Typical situations for the use of batch input are:

• Acceptance of large data volumes using a file from non-SAP systems Session creation: batch Session processing: batch Acceptance of mid-sized data volumes using a file or RFC from non-SAP systems Session creation: direct Session processing: batch Acceptance of small data volumes within Rl3 (customizing) Session creation: direct Session processing: direct

The last example shows that batch input is possible without using batch. If this seldom applica­tion situation is ignored, batch input can be designated as being "batch execution of dialog pro­grams using computer-generated input data". Batch input can be compared with the background execution of reports with variant. Variants also represent an input rerouting for the report pa-

U. Mende, Software Development for SAP R/3 ®© Springer-Verlag Berlin Heidelberg 2000

Page 2: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

286 12 Batch Input

rameters. Rather than specifying just a few parameters in the report variant, batch input popu­lates a complete session with input data.

Because of the comprehensive field validations performed on the dynpros, it can normally be assumed that the session processing runs much longer than the session creation.

In addition to the classic batch input using sessions, there is also a variant with CALL TRANSACTION in which batch input data are passed directly using an internal table.

The following DDIC structures are used for the creation and processing of batch input data:

Table 12.1: Important structures for batch input

Structure Field Type, Meaning Length

BDCDATA Batch input new table field structure PROGRAM CHAR8 Program name DYNPRO NUM4 Dynpro number DYNBEGIN CHARI Flag whether new dynpro FNAM CHAR35 Field name on the dynpro FVAL CHAR 132 Field value in external format

BDCTH Batch input transaction header MTYPE CHARI Message type STATE CHARI Status TCODE CHAR4 Transaction code

The actual batch input data are stored in an internal table having the structure BDCDATA. The DYNBEGIN switch controls whether the first two fields or last two fields of a table entry apply. DYNBEGIN = "X" always applies in the first line of a table; the program name and dynpro number are specified. The lines that follow with DYNBEGIN = SPACE contain the field name and field values for fields of the associated dynpro. A new line with DYNBEGIN = "X" identi­fies a new dynpro orland a new program.

The simulated function code or key code adopts a special role; the BDC_OKCODE value is entered in FNAM. The associated field value contains either the required key code (/11, 15 or 13) or the assigned function code (EDIT, SA VE, BACK, END, etc.). Field names and codes can be determined from the running transaction. The right mouse button displays the function keys permitted for the dynpro; Fl and then the Technical Help key provides the field name.

The table fields in table views also have a special feature. In addition to the name, these fields are specified with an index in parentheses suffixed to the field name.

Page 3: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

12.2 Classic Batch Input Using Sessions 287

12.2 Classic Batch Input Using Sessions

12.2.1 Creation of Sessions

Several transaction invocations for the session creation are saved in the database with a common name as a so-called session or group. Every transaction call contains a transaction header with the structure BDCTH. The following function modules are used for the program-controlled creation of sessions

BDC_OPEN_GROUP BDC_INSERT BDC_CLOSE_GROUP

Open a new session Insert a transaction call (multiple) Close a session

These functions are explained using the ZR_12_01 program that takes the batch input data from a file. This program uses the ZBF logical file interface that describes the hierarchical interrela­tionship between sessions, transactions and dynpros. The top structure ZBDCSESS contains the clients, the sessions and the user names. The two subordinate structures correspond to the above BDC structures. The file structure corresponds to the structure of the logical database. Two ses­sions are to be created.

* Textfile for logical file interface ZBF: * * ZBDCSESS

: I----BDCTH

: I-------BDCDATA * * Report ZR 12 01 reads the file and creates the given * batch input sessions. * * * 10 20 30 40 50 60 *234567891123456789112345678911234567891123456789112345678911234561 * * Batch input data for the view of ZPOSTKEY and ZPOSTKEYT using SM30 ZBDCSESS 999ZPOSTKEY MENDE BDCTH M1SM30 ZBDCDATA SAPMSVMA0100X ZBDCDATA VIEWNAME ZPOSTKEY ZBDCDATA BDC OKCODE /5 ZBDCDATA SAPLZGEN0001X ZBDCDATA BDC OKCODE /5 ZBDCDATA SAPLZGEN0001X ZBDCDATA ZPOSTKEY-PSTKY(l) 10 ZBDCDATA ZPOSTKEYT-PSTKYTXT(l) net premo ZBDCDATA ZPOSTKEY-PSTKY(2) 20

Page 4: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

288

ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA

SAPLZGEN0001X

ZPOSTKEYT-PSTKYTXT(2) ZPOSTKEY-PSTKY(3) ZPOSTKEYT-PSTKYTXT(3) BDC OKCODE

BDC OKCODE SAPLZGEN0001X

BDC OKCODE

* Batch input data for posting transaction ZDOC (ZM 09 03) ZBDCSESS BDCTH ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA ZBDCDATA

999Posting MENDE M1ZDOC ZM 09 030100X

ZM 09 030100X

ZDOCHD- COMCODE ZDOCHD - CONTNO ZDOCHD-CURRKY ZDOCHD-PSTDAT ZDOCHD-DOCTEXT ZDOCHD-DOCTYPE ZDOClTEM-PSTKY(1) ZDOClTEM-AMOUNT(1) ZDOClTEM-lTEMTEXT(1) ZDOClTEM-PSTKY(2) ZDOClTEM-AMOUNT(2) ZDOClTEM-lTEMTEXT(2) BDC OKCODE

BDC OKCODE

12 Batch Input

refund 30 interest /11

/3

ENDE

0001 3013 USD 25.06.1998 Batch lnp. FB 1 1024,00 net prem o 2 12,10 refund /13

BUCH

The first session with the name ZPOSTKEY should pass the posting reasons with the descrip­tive texts to the ZPOSTKEY and ZPOSTKEYT tables. The extended table maintenance update SM30 with the update view previously generated for the table should be used here. The SAPMSVMA-OlOO dynpro sets the value ZPOSTKEY for the VIEWNAME field. /5 is the function code for the "Update" key. SAPLYCNV-OOOI is then invoked and BDC_OKCODE /5 used to release new fields. The values are set in these fields. The numbers specified in paren­theses correspond to the line numbers of the table control. BDC_OKCODE /11 saves the new entries and BDC_OKCODE /3 performs the return.

The second session contains posting data for the posting transaction ZDOC of the examples. A document consisting of header and three items is accepted. Note that because ZDOCHD­ACCNO field is not an input field, it cannot be entered using batch input. This field is filled af­ter a contract number is entered (directly or using match-code). BDC_OKCODE /13 in the batch input initiates a data release to fill the field. The "BUCH" function code posts the data.

ZR_l C04 from YBF is used to generate the SAPDBYBF interface program. The ZR_12_01 report processes the file. GET ZBDCSESS opens a new session. A new transaction header BDCTH clears the internal table BDCTAB. Every new BDCDATA inserts a line in BDCTAB; the first line always represents a new dynpro and all continuation lines contain pairs with field and value.

Page 5: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

12.2 Classic Batch Input Using Sessions 289

A BDC_INSERT is invoked after the last BDCDATA record of a transaction. The forms used in the program encapsulate the function modules. Because they make no use of global data (also no internal tables), they can be called from any other programs.

REPORT ZR 12 01 MESSAGE-ID ZO LINE-SIZE 70. NODES: ZBDCSESS, BDCTH, ZBDCDATA.

DATA BDCTAB LIKE BDCDATA OCCURS 100 WITH HEADER LINE.

GET ZBDCSESS. WRITE:/ 'Session opened :', ZBDCSESS - GROUPID. PERFORM BDC OPEN GROUP

USING ZBDCSESS-CLIENT ZBDCSESS-GROUPID ZBDCSESS-USERID.

GET BDCTH. CLEAR BDCTAB. REFRESH BDCTAB.

GET ZBDCDATA. IF ZBDCDATA-DYNBEGIN = 'X'.

PERFORM BDC DYNPRO TABLES BDCTAB USING ZBDCDATA- PROGRAM ZBDCDATA- DYNPRO.

ELSE. PERFORM BDC FIELD TABLES BDCTAB

USING ZBDCDATA- FNAM ZBDCDATA- FVAL. ENDIF.

GET BDCTH LATE. PERFORM BDC INSERT TABLES BDCTAB

USING BDCTH- TCODE.

GET ZBDCSESS LATE. PERFORM BDC CLOSE GROUP. WRITE: / 'Session created:', ZBDCSESS-GROUPI D.

END - OF- SELECTION. COMMIT WORK. *-------------- ----------------------------- ------- --- -- ------------FORM BDC OPEN GROUP USING

CALL FUNCTION 'BDC OPEN EXPORTING CLIENT

GROUP USER KEEP

ENDFORM.

CLIENT GROUP USER. GROUP'

= CLIENT GROUP USER

= 'X'.

*------------------------------- ---- ------- -------------------------FORM BDC INSERT TABLES BDCTAB US I NG TCODE.

CALL FUNCTION 'BDC I NSERT' EXPORTING TCODE = TCODE TABLES DYNPROTAB = BDCTAB.

ENDFORM. *----------------- ---- ---- ------------------------------------------

Page 6: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

290 12 Batch Input

FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' .

ENDFORM. *-------------------------------------------------------------------FORM BDC DYNPRO TABLES BDCTAB STRUCTURE BDCDATA

USING PROGRAM DYNPRO. CLEAR BDCTAB. BDCTAB- PROGRAM '" PROGRAM. BDCTAB-DYNPRO DYNPRO . BDCTAB-DYNBEGIN 'X' . APPEND BDCTAB.

ENDFORM. *------------ ----- ------------------- ------------- ------------------FORM BDC FIELD TABLES BDCTAB STRUCTURE BDCDATA USING FNAM FVAL .

CLEAR BDCTAB . BDCTAB - FNAM = FNAM . BDCTAB - FVAL = FVAL . APPEND BDCTAB.

ENDFORM.

26 . 06.98 Chapter 12 : Create batch input folders from a file 1

Session opened : ZPOSTKEY Session created : ZPOSTKEY Session opened : posting Session created: Posting

The ZR_12_01 program together with the ZBF logical file interface can be used in many dif­ferent ways. It can reliably accept any data (transaction data, master data, customizing and ODIC data) using the associated transactions.

12.2.2 Session Management and Session Processing

System/Services/Batch Input or SM35 provide the session management. The status of the cre­ated sessions can be shown. The ZR_12_01 program created both the above sessions.

Page 7: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

12.2 Classic Batch Input Using Sessions 291

iii Batc h Input Sess ion Uvelvlew "(i] £J

1.--·: ... · .~i====-1L~~~::1~~ ... ~~~ "'111. __ '26.06.98 16 :17 :00 'IHENDE 1i 2 MENDlj 26 . 06 . 98 16 :16 : 49 MENDE 1i 2 KENDE

126 . 06 . 98 16 :16 : 49 MENDE 11 1 51 MENDE

~~== ____ ~.~2~6~. 0~6~. ~98~1~1~6~:0~5~: ~04~-=====~_~HEN==~D~E __ ~~=-~L-____ 2~i~ME=N~DE

Errors in sessions

I· .. · ... POSTIHG

Pux:esseci sesslOns

l!--lal iZPOSTKEY iZPOSTKEY !ZPOSTKEY

Figure 12.1: Session overview sorted according to session status

MENDE

...

The selection of a session initially displays its transaction calls. The selection of a transaction call displays its dynpros with all associated data.

The sessions can be processed in several ways. At the beginning, in particular during the program test, it is desirable to trace the processing of the sessions. In this case, the dynpros are filled with batch input data and displayed. The BDC_OKCODE is placed in the command field and executed only when the ENTER key is pressed. This enables the individual steps to be traced. A log exists for every processed session.

Page 8: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

292

.. Senjon Edt lim S~

I 1 a w: • rsm- _mr

~ld ~ __________ ~ ________ i=Qm===teD==t=.====~====~==================~ IZlI 09 03 I ztOCHD-cOMCODE 00 01 IZOOCHD-CONTNO 3013 , ZOOCHD-CURRICY usn ZDOCHD-PSTD.T 25 . 06 .1998 ZOOCHD-DCX:TlIT Batc h Inpu t ZOOClTEM-PSTJ(Y( 1) 1 ZOOClTEM-UOUNT( 1) 102( . 00 ZIXX:lTEM-lTEMTEXT(l) t net preuUJl ZOOC lTEM-l'STI<Y ( 2 ) I 2

ZOOClTEM-ITElfTEXT(2) refund ZOOClTEM-UOllNT( 2) 1 12, 10

BDC OKCODE / 13 __ -___ .________ _ _____ _ ===========::il

Figure 12.2: Data display of a session

Ruo aode

~ Process/foregrouDd DlSplA, errore Oft 1 ,

BAclt9J"OllDd DestilUlhon

Add1t10Dal fUDCt1CGS

r £SteDded log

r Eapert aode

P Dynpro atandArd au.

""-" I Carall

Figure 12.3: Processing capabilities for a session

BS2OJC1991

12 Batch Input

Page 9: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

12.3 Batch Input Using CALL TRANSACTION

Iii B"lch Inpul DlSp ldY Log "[iii E)

EaIde! Eel Golo Sl/IIem

MENDE BlaarsOO r~' ""'-' l~ r;-4-;;j--~ 1"''''''1 1--- ISOO~=i~ P06TI'G i. bei •• ,- by "~. MElIOE i._.

15 : 57 : 59IZDODIZX 09 03 0100 1500349 Field ZDOCHD-DOCTXT . does not exist in the screen ZN O~ ' 15 : 59 :18 ZDOO SA;L~ 01001500344 No botch input aata for screen SAPLGRAP 0100 - -15 : 59 :18 ZDOC SAPlGRAP 01001500344 No batch input data for screen 5APLGRAP 0100 15 : 59 :18 ZDOO SAPLGR1P 0100 500344 No batch input data for screen SAPlGRAP 0100 15 : 59 :18 ZDOC 5APlGRAP 0100\500344 No batch input data for screen 5APlGRAP 0100 15 : 59 :18 ZDOO SAPLGRAP 0100 5003 •• No batch input data for screen 5APlGR1P 0100 15 : 59 :19 ZDOO ISAPlGRAP 0100 500344 No botch input aata for $Creen 5APlGRAP 0100 15 :59 :19 ZDOC 1500104 Transaction vas exited vith function key F3 . F12 or F15

15 :59 : 30 ZDCO

115 : 59 : 31

115 : 59 : 31 15 : 59 : 31

115 : 59 : 31 15 : 59 : 31 ~ : 59 : 31

S00357 Transaction error

500370 Processing statistics 500363 1 transactions read 500364 0 transactions processed 500365 1 transactions vith errors 500366 a transactions deleted 500382 Batch in ut processi~ enaeQ

Figure 12.4: Processing log for a session

12.3 Batch Input Using CALL TRANSACTION

293

The saving of data in sessions can be avoided if the BDCTAB internal table of the invoked transaction BDCTH-TCODE is passed directly in a CALL TRANSACTION. The general form of this command, which corresponds to the SUBMIT for reports, has the form:

CALL TRANCACTION trans USING BDCTab [MODE mode MESSAGES INTO messtab].

Trans is the transaction code, BDCTab is an internal table of BDCDATA type. The mode speci­fies whether or not the processing of the transaction is to be shown. All messages initiated in the transactions can be stored in an internal table MessTab for subsequent processing.

Page 10: 12 Batch Input - Springer names and codes can be ... 290 12 Batch Input FORM BDC CLOSE GROUP. CALL FUNCTION 'BDC CLOSE GROUP' . ... 12.3 Batch Input Using CALL TRANSACTION ...

294 12 Batch Input

CALL TRANSACTION is faster than the session variant. The ZR_12_02 program processes the same input data as ZR_12_01. As with these, it uses the ZBF logical file interface for batch input data. Because there are no sessions, the BDC_OPEN_GROUP and BDC_CLOSE_­GROUP function calls and the corresponding GET events are not required. The preparation of the dynpro and field data is performed in exactly the same manner as for the session creation. The forms from ZR_12_01 are invoked. Rather than BDC_INSERT, CALL TRANSACTION is called directly. The result is the same as for the ZR_12_01 report.

REPORT ZR 12 02 MESSAGE-ID ZO LINE-SIZE 70. NODES: ZBDCSESS, BDCTH, ZBDCDATA.

DATA BDCTAB LIKE BDCDATA OCCURS 100 WITH HEADER LINE. DATA MSGTAB LIKE BDCMSGCOLL OCCURS 100 WITH HEADER LINE. DATA MSGTXT (70) .

GET BDCTH. CLEAR BDCTAB. REFRESH BDCTAB.

GET ZBDCDATA. IF ZBDCDATA-DYNBEGIN = 'X'.

PERFORM BDC DYNPRO(ZR 12 01) TABLES BDCTAB USING ZBDCDATA-PROGRAM ZBDCDATA-DYNPRO.

ELSE. PERFORM BDC FIELD(ZR 12 01)

TABLES BDCTAB USING ZBDCDATA-FNAM ZBDCDATA-FVAL. ENDIF.

GET BDCTH LATE. CLEAR MSGTAB. REFRESH MSGTAB.

CALL TRANSACTION BDCTH-TCODE USING BDCTAB MODE 'A'. WRITE: / 'Transaction called:', BDCTH-TCODE.

END-OF - SELECTION.

21.07.98 Chapter 12: Batch input with CALL TRANSACTION

Transaction called: SM30 Transaction called: ZDOC

"'N' .

1