You are on page 1of 108

CHAPTER 1

INTRODUCTION

Background Processing

Phases

of Background Processing
Passing Data to Subsequent Job
Steps
Scheduling Job within ABAP/4
Program

Work Processes

Dispatcher

Online

Update

Enqueue

Spool

Background

The Background Work Process

Background Job A
Step #1
Step #2
Defining a
background job.

Background

Phases of Background Processing

Job
Scheduling
Job
Processing
Job
Overview

Scheduling a Background Job


Transaction
SM36

Job
Scheduling

Creating Step for Background Job


Steps
Job
Scheduling

Start Criteria for Background Job


Job
Scheduling

Start date

Immediate

Date/Time

Jobs can be scheduled to


run immediately or at a
particular date/time.

After Job

Jobs can be
scheduled to run
after another job has
been completed.

After Event
Jobs can be
scheduled to run after
an event has been
triggered/raised.

If you start a job based on a date/time or an event, you


can schedule the job to run at regular intervals, not just
at a particular time.

Scheduling a Periodic Job


Job
Scheduling

Start date
Period values

X Periodic job

Hourly
Daily

By checking the
Periodic Job option,
you can specify
that the job run at
regular intervals.

Weekly
Monthly
Other period

With the Period


Values pushbutton,
you can schedule
the job to run hourly,
daily, weekly,
monthly, etc.

Scheduling Job after Another Job


Start date

After Job

Job
Scheduling

After clicking on the After


Job pushbutton, you
must specify the name of
the job that must be
completed before this job
will run.

If you check the Start status-depend.


option, this job will run only if the
specified job ends successfully.

Scheduling Job After an Event


Start date

After Event

Job
Scheduling

After clicking on the After Event


pushbutton, you must specify the
name of the event that must be
raised before this job will run. You
can distinguish between different
occurrences of a particular event
by specifying a parameter.

If you check the Periodic Job option, the


system starts a new job each time the
specified event is raised.

SCREENSHOT: SM62 TRANSACTION, CREATE EVENT

Triggering/Raising Events
To trigger/raise an event from within an ABAP/4 program, you must
call the BP_EVENT_RAISE function module.

CALL FUNCTION BP_EVENT_RAISE


EXPORTING
EVENTID
= <event name>
EVENTPARM
=
TARGET_INSTANCE =
EXCEPTIONS
BAD_EVENTID
=1
The only required
EVENTID_DOES_NOT_EXIST = 2
exporting parameter is the
EVENTID_MISSING
=3
name of the event to raise.
RAISE_FAILED
=4
OTHERS
= 5.

Phases of Background Processing


Job
Scheduling

Job
Processing

Job
Overview

Processing a Background Job

Scheduler

Job

Background
Job
Processing

Dispatcher

Job

Processing a Background Job


Application Server
Work Processes
8 Online

1 Spool

3 Background

Job
Processing
Transaction
SM50

Processing a Background Job


Job Log
Scheduler

Entries from start and end


modules.
All messages issued by
job steps and system.

Start Module
Job Step #1
Job Step #2
Job Step #3
End Module

PRINT SPOOL
Job
Processing

List
All WRITE
statement output
from job step.

Phases of Background Processing


Job
Scheduling

Job
Processing

Job
Overview

Job Overview
Transaction
SM37

Job Status

Job
Overview

Job Analysis using Job Log


System and
Program
Messages

Job
Overview

You can use this Job Log to analyze each step of a


finished or cancelled background job.

Other Background Processing Topics

Passing Data to Subsequent Job Steps


Scheduling Job within ABAP/4 Program

Passing Data to Subsequent Job Steps


Global ABAP/4
Memory

<data>

Background Job
Step #1
...
EXPORT <data> TO
MEMORY.
...
Step #2
...
IMPORT <data> FROM
MEMORY.
...

Passing Data to Subsequent Job Steps


Global ABAP/4
Memory

<id1>
<data>

<id2>
<data2>

Background Job
Step #1
...
EXPORT <data2> TO
MEMORY ID <id2>.
...
Step #2
...
IMPORT <data2> FROM
MEMORY ID <id2>.
...

Scheduling Job within


ABAP/4 Program
Open Background Job
JOB_OPEN
JOB_SUBMIT
is called for
each step that
is to be added
to the job.

Insert Job Step


JOB_SUBMIT

Close Background Job


JOB_CLOSE

JOB_OPEN
JOB_OPEN
Exporting:
jobname = <job name>

Background Job
<job name>
<job #>

Importing:
jobcount = <job #>

JOB_SUBMIT
JOB_SUBMIT

Background Job

Exporting:
authcknam = <user>
jobcount = <job #>
jobname = <job name>
report = <report>
variant = <variant>

<job name>
<job #>
Step #1

Step #2

JOB_CLOSE
JOB_CLOSE

Background Job

Exporting:
jobcount = <job #>
jobname = <job name>
sdlstrtdt = <start date>
sdlstrttm = <start time>
strtimmed = <flag1>

<job name>

Importing:
job_was_released =
<flag2>

<job #>
Step #1

Step #2

ABAP/4 Program Example

Open Job
Submit Step

Close Job

REPORT Y180DM01.
DATA: JOBNUM LIKE TBTCJOB-JOBCOUNT.
PARAMETERS: JOBNAME LIKE TBTCJOB-JOBNAME,
PROGRAM LIKE SY-REPID,
VARIANT LIKE RALDB-VARIANT,
USER LIKE SY-UNAME.
CALL FUNCTION JOB_OPEN
EXPORTING JOBNAME = JOBNAME
IMPORTING
JOBCOUNT = JOBNUM.
CALL FUNCTION JOB_SUBMIT
EXPORTING AUTHCKNAM = USER
JOBCOUNT = JOBNUM
JOBNAME = JOBNAME
REPORT = PROGRAM
VARIANT = VARIANT.
WRITE: / JOBNAME, JOBCOUNT, REPORT, VARIANT,
BTCHUSER.
CALL FUNCTION JOB_CLOSE
EXPORTING JOBCOUNT = JOBCOUNT
JOBNAME = JOBNAME.

Summary of Background Processing


Job
Scheduling

Job
Processing

Job
Overview
Job Log

Step #1

Spool List

Step #2

Background

CHAPTER 2
FILE HANDLING AT
APPLICATION SERVER

Overview
In this chapter, we
will learn how to
process sequential
files on an
application server

Database
Server

Application
Servers

Presentation
Servers

Processing Files

Open File

Create File or Read File

Close File

Open File
OPEN DATASET statement

FOR
INPUT
OUTPUT
APPENDING

AT POSITION

IN
BINARY MODE
TEXT MODE

MESSAGE

Close File or Delete File

CLOSE DATASET statement

DELETE DATASET statement

Create File or Read File

TRANSFER statement

READ DATASET statement

Example - Create New File

Step #1

Step #2
Step #3
Step #4
Step #5

REPORT Y180DM02.
TABLES: KNA1.
PARAMETERS:
OUTFILE(20) DEFAULT /tmp/bc180_file1
LOWER CASE,
STATE LIKE KNA1-REGIO DEFAULT MA.
DATA: BEGIN OF OUTREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF OUTREC.
OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE.
SELECT * FROM KNA1 WHERE REGIO = STATE.
MOVE-CORRESPONDING KNA1 TO OUTREC.
TRANSFER OUTREC TO OUTFILE.
ENDSELECT.
CLOSE DATASET OUTFILE.

Example - Extend File


REPORT Y180DM03.
TABLES: KNA1.
PARAMETERS:
OUTFILE(20) DEFAULT /tmp/bc180_file1
LOWER CASE,
STATE LIKE KNA1-REGIO DEFAULT MA.
DATA: BEGIN OF OUTREC,
KUNNR LIKE KNA1-KUNNR,
The only change from the
REGIO LIKE KNA1-REGIO,
previous example is FOR
TELF1 LIKE KNA1-TELF1,
APPENDING instead of
END OF OUTREC.
FOR OUTPUT.
OPEN DATASET OUTFILE FOR APPENDING IN TEXT MODE.
SELECT * FROM KNA1 WHERE REGIO = STATE.
MOVE-CORRESPONDING KNA1 TO OUTREC.
TRANSFER OUTREC TO OUTFILE.
ENDSELECT.
CLOSE DATASET OUTFILE.

Example - Read File


REPORT Y180DM04.

Step #1

Step #2
Step #3
Step #4
Step #5

PARAMETERS:
INFILE(20) DEFAULT /tmp/bc180_file1
LOWER CASE.
DATA: BEGIN OF INREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF INREC.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE: INREC-KUNNR, INREC-REGIO, INREC-TELF1.
ENDDO.
CLOSE DATASET INFILE.

Text Mode versus Binary Mode


File structured
byte-by-byte

File structured
in lines

ABC
DEFGH
IJKL

READ DATASET into


field string that is four
characters in length

ABCDEF
GHIJK

A B C

A B C D

D E F G

E F G H

I J K L

I J K

CHAPTER 3
FILE HANDLING AT
PRESENTATION
SERVER

Overview
In this chapter, we
will learn how to
process sequential
files on a
presentation server

Database
Server

Application
Servers

Presentation
Servers

Use of an Internal Table


Internal Table

To create a local file,


you must transfer the
contents of an
internal table.
Internal Table

To read a local file,


you must read the
contents into an
internal table.

Create Local File

DOWNLOAD function module

CALL FUNCTION DOWNLOAD


EXPORTING
FILENAME = <default file name>
FILETYPE = <default file type>
The only required
MODE
= <create new or extend>
parameter is the
IMPORTING
internal table.
FILESIZE
= <size of file in bytes>
TABLES
DATA_TAB = <internal table to transfer>
EXCEPTIONS. . . .

Example - Create Local File

Step #1
Step #2

Step #3

REPORT Y180DM05.
TABLES: KNA1.
PARAMETERS: STATE LIKE KNA1-REGIO DEFAULT MA.
TYPES: BEGIN OF OUTREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF OUTREC.
DATA:
OUT_ITAB TYPE OUTREC
OCCURS 10 WITH HEADER LINE.
SELECT * FROM KNA1 WHERE REGIO = STATE.
MOVE-CORRESPONDING KNA1 TO OUT_ITAB.
APPEND OUT_ITAB.
CLEAR OUT_ITAB.
ENDSELECT.
CALL FUNCTION DOWNLOAD
EXPORTING
FILENAME= c:\bc180_file2
TABLES
DATA_TAB
= OUT_ITAB.

Read Local File

UPLOAD function module

CALL FUNCTION UPLOAD


EXPORTING
The only required
FILENAME = <default file name>
parameter is the
FILETYPE = <default file type>
internal table.
IMPORTING
FILESIZE
= <size of file in bytes>
TABLES
DATA_TAB = <internal table to transfer>
EXCEPTIONS. . . .

Example - Read Local File

Step #1
Step #2

Step #3

REPORT Y180DM06.
TYPES: BEGIN OF INREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF INREC.
DATA:
IN_ITAB TYPE INREC
OCCURS 10 WITH HEADER LINE.
CALL FUNCTION UPLOAD
EXPORTING
FILENAME= c:\bc180_file2
TABLES
DATA_TAB
= IN_ITAB.
LOOP AT IN_ITAB.
WRITE: / IN_ITAB-KUNNR,
IN_ITAB-REGIO,
IN_ITAB-TELF1.
ENDLOOP.

Download/Upload Program Code

ABAP/4
Program

To download an ABAP/4
program to a local file,
use the Utilities >
Download menu path.

To upload a local file into


an ABAP/4 program, use
the Utilities > Upload
menu path.

ABAP/4
Program

** Uploading into an ABAP/4 program will overwrite any existing code **

CHAPTER 4
BDC CONCEPTS

Overview

External System

Data

SAP System

Batch Input

Data Transfer Rules


External
Data

X
External
Data

Checks &
Validations

SAP
Database
Table

Online Program
To check and validate the external
data, user dialog is simulated
through an SAP transaction
(i.e., an online program).

TEST1

Vendor
Company Code
X Address

Name Computers, Inc.


Street
City

Philadelphia

BDCDATA Structure
To simulate user dialog,
you must know the
following information:
(1) online program name,
(2) screen numbers,
(3) field names, and
(4) field values.
The BDCDATA ABAP/4
Dictionary structure is used
in a batch input program to
collect this information for
an entire transaction.

ABAP/4 Dictionary

BDCDATA

PROGRAM
DYNPRO
DYNBEGIN
FNAM
FVAL

Example - Change Vendor


Vendor

TEST1

Company Code

For our example, we


will use the Change
Vendor transaction
(FK02) to add a street
address to an already
existing vendor.

X Address

Name Computers, Inc.


Street 123 Main St.
City

Philadelphia

Researching Transaction - 1st Screen


Step #1

Step #2

Use System > Status


menu path to determine
online program name
(SAPMF02K), screen
number (0106), and
transaction code (FK02).

Use F1 key and Technical


Info pushbutton in each
screen field to be filled to
determine the field name.

Vendor
Company Code
X

Address

TEST1

Step #3
Determine how to proceed
in the transaction
(go to the next screen by
pressing the Enter key).
Field name = RF02K-LIFNR
Field name = RF02K-D0110

Researching Transaction - 2nd Screen


Step #1

Step #2

Use System > Status


menu path to determine
online program name
(SAPMF02K) and screen
number (0110).

Use F1 key and Technical


Info pushbutton in each
screen field to be filled to
determine the field name.

Step #3

Name Computers, Inc.


Street 123 Main St.
City

Philadelphia

Determine how to proceed


in the transaction (save the
record by clicking on the
Save pushbutton or
pressing the F11 key).
Field name = LFA1-STRAS

BDC Table Contents


After researching the transaction,
we can determine the contents of
the BDC table.

PROGRAM DYNPRO DYNBEGIN


SAPMF02K
0106
X
SAPMF02K

0110

FNAM

FVAL

RF02K-LIFNR
RF02K-D0110

TEST1
X

X
LFA1-STRAS 123 Main St.
BDC_OKCODE
/11

Declaring BDC Table

DATA:

BDC_TAB LIKE BDCDATA


OCCURS 6 WITH HEADER LINE.

The internal table used to collect the


transactions information must be
declared LIKE BDCDATA.

Filling BDC Table - Method #1


FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = SAPMF02K.
BDC_TAB-DYNPRO = 0106.
BDC_TAB-DYNBEGIN = X.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = RF02K-LIFNR.
BDC_TAB-FVAL = TEST1.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = RF02K-D0110.
BDC_TAB-FVAL = X.
APPEND BDC_TAB.

CLEAR BDC_TAB.
BDC_TAB-PROGRAM = SAPMF02K.
BDC_TAB-DYNPRO = 0110.
BDC_TAB-DYNBEGIN = X.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = LFA1-STRAS.
BDC_TAB-FVAL = 123 Main St..
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = BDC_OKCODE.
BDC_TAB-FVAL = /11.
APPEND BDC_TAB.
ENDFORM.

Filling BDC Table - Method #2


FORM POPULATE_BDC_TAB USING
FLAG VAR1 VAR2.

FORM FILL_BDC_TAB.
REFRESH BDC_TAB.

CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
1

SAPMF02K
RF02K-LIFNR
RF02K-D0110

0106,
TEST1,
X,

SAPMF02K
0110,
LFA1-STRAS
123 Main St.,
BDC_OKCODE /11.

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.
This two-subroutine method to fill the BDC table is preferable because the
POPULATE_BDC_TAB subroutine is reusable throughout all batch input programs.

Batch Input Methods

Method #1

Batch Input Session

Method #2

CALL TRANSACTION
USING Statement

Method #3

CALL DIALOG Statement

CHAPTER 5
BATCH INPUT
METHODS

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

Batch
Input
Session

SAP
Database
Table

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

BDC_OPEN_GROUP
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.

BDC_INSERT

CALL FUNCTION BDC_INSERT


EXPORTING
TCODE

= <transaction code>

TABLES
DYNPROTAB = <bdc internal table>
EXCEPTIONS
INTERNAL_ERROR = 1
...
OTHERS

= 5.

BDC_CLOSE_GROUP

CALL FUNCTION BDC_CLOSE_GROUP


EXCEPTIONS
NOT_OPEN

=1

QUEUE_ERROR

=2

OTHERS

= 3.

Batch Input Session

Header Section

Batch
Input
Session

Creator
Client
Session Name
Authorization User
Hold Date
Keep or Delete

Data Section
Transaction Data

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).

TEST1

Vendor
Company Code
X Address

Name Computers, Inc.

The Change Vendor


transaction is FK02.

Street

123 Main St.

City

Philadelphia

Example #1 - Declaration Section

REPORT Y180DM08.

Step #1

DATA: BDC_TAB LIKE BDCDATA


OCCURS 6 WITH HEADER LINE,
SESSION LIKE APQI-GROUPID
VALUE DEMO #8.

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

Example #1 - Main Program


Step #2

Step #3
Step #4

Step #5

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. . . .
** This program is continued on the next slide **

Example #1 - Subroutines
FORM POPULATE_BDC_TAB USING
FLAG VAR1 VAR2.

FORM FILL_BDC_TAB.
REFRESH BDC_TAB.

CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
1

SAPMF02K
RF02K-LIFNR
RF02K-D0110

0106,
TEST1,
X,

SAPMF02K
0110,
LFA1-STRAS
123 Main St.,
BDC_OKCODE /11.

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.

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.
TEST1

Vendor

TEST2

Vendor

Company Code

Company Code

X Address

X Address

Name Computers, Inc.

Name Computer Land

Street 123 Main St.

Street 10 Walnut St.

City

City

Philadelphia

Boston

Sequential File

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


REPORT Y180DM09.
Step #1

Step #2

DATA: BDC_TAB LIKE BDCDATA


OCCURS 6 WITH HEADER LINE,
SESSION LIKE APQI-GROUPID
VALUE DEMO #9,
INFILE(20) VALUE /tmp/bc180_file3.
DATA: BEGIN OF INREC,
VENDNUM LIKE LFA1-LIFNR,
STREET LIKE LFA1-STRAS,
END OF INREC.
** This program is continued on the next slide **

Example #2 - Main Program


Step #3
Step #4
Step #5
Step #6
Step #7
Step #8

Step #9
Step #10

START-OF-SELECTION.
OPEN DATASET INFILE
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.
** This program is continued on the next slide **

Example #2 - Subroutines
FORM POPULATE_BDC_TAB USING
FLAG VAR1 VAR2.

FORM FILL_BDC_TAB.
REFRESH BDC_TAB.

CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
1

SAPMF02K
RF02K-LIFNR
RF02K-D0110

0106,
INREC-VENDNUM,
X,

SAPMF02K
LFA1-STRAS
BDC_OKCODE

0110,
INREC-STREET,
/11.

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 field string.

Summary
Research Transaction
Code BDC Program
Execute BDC Program
Batch Input Session Created

Process Batch Input Session


SAP Database Updated

CHAPTER 6
SESSION HANDLING

Overview
BDC
Program
External
Data

Batch
Input
Session

In this chapter, we will


learn how to process
batch input sessions.

Process
Batch
Input
Session

SAP
Database
Table

Process
Batch
Input
Session

Session Overview
Transaction Code SM35
OR

System Services Batch input Sessions menu path

Processing Modes
Process batch input session
in the FOREGROUND.

DISPLAY ERRORS ONLY when


processing batch input session.

Process batch input session


in the BACKGROUND.

Processing Options

/bdel
/n
/bda
/bde
/bend

Session Overview Options

Process
Select block

Batch
Input
Session

Delete
Session
Statistics
Log

Session Status
Sessions still to be processed
Sessions processed with errors
Sessions processed successfully
Background sessions
Sessions being processed
Sessions being created

Log

Session Log

Session Analysis
Session

** This is not an analysis of the batch input session from the previous page **

Timing Issue

BDC program
executed Batch input
session created
Time1

Remember: A batch input


session is created when you
execute a BDC program
(time1), but it is processed at
a different time (time2).
Time2

Batch input
session processed SAP database updated

Program RSBDCSUB
Execute
program
RSBDCSUB

Specify batch input session to process.

Batch input session


scheduled to be processed
in the background.

CHAPTER 7
CALL TRANSACTION
CALL DIALOG

Overview
PROGRAM

DYNPRO

DYNBEGIN

SAPMF02K

0106

SAPMF02K

0110

FNAM

FVAL

RF02K-LIFNR
RF02K-D0110

TEST1
X

LFA1-STRAS
BDC_OKCODE

123 Main St.


/11

BDC Table

Create Batch Input


Session
(BDC Program)

Use in CALL
TRANSACTION
statement

Use in CALL
DIALOG
statement

Differences in Batch Input Methods


When is the
SAP database
updated?

How are errors


handled?

Create batch
input session
(BDC Program):

During the processing


of the batch input
session

Automatically by the
system during the
processing of the
batch input session

CALL TRANSACTION:
CALL DIALOG:

During the execution


of the batch input
program

Must be handled in
the batch input
program

Example - Change Vendors


To illustrate the CALL TRANSACTION and CALL
DIALOG methods, we will use the example to change
vendors coming from a sequential file.
TEST1

Vendor

TEST2

Vendor

Company Code

Company Code

X Address

X Address

Name Computers, Inc.

Name Computer Land

Street

123 Main St.

Street

10 Walnut St.

City

Philadelphia

City

Boston

CALL TRANSACTION
USING Statement
CALL TRANSACTION <transaction code>
USING
<bdc internal table>
MODE
<display mode>
UPDATE <update mode>
MESSAGES INTO <mssg int. table>.
<display mode>

<update mode>

A: display all
E: display errors only
N: no display

S: synchronous
A: asynchronous

Example #1 - Declaration Section


REPORT Y180DM10.
Step #1

DATA: BDC_TAB LIKE BDCDATA


OCCURS 6 WITH HEADER LINE,
INFILE(20) VALUE /tmp/bc180_file4.

Step #2

DATA: BEGIN OF INREC,


VENDNUM LIKE LFA1-LIFNR,
STREET LIKE LFA1-STRAS,
END OF INREC.
PARAMETERS:

DISPMODE DEFAULT A,
UPDAMODE DEFAULT S.

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

Example #1 - Main Program


Step #3
Step #4
Step #5
Step #6
Step #7

Step #8

Step #9

START-OF-SELECTION.
OPEN DATASET INFILE
FOR INPUT IN TEXT MODE.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0. EXIT. ENDIF.
PERFORM FILL_BDC_TAB.
CALL TRANSACTION FK02
USING
BDC_TAB
MODE
DISPMODE
UPDATE
UPDAMODE.
IF SY-SUBRC <> 0.
WRITE: / Error.
ENDIF.
ENDDO.
CLOSE DATASET INFILE.
** This program is continued on the next slide **

Example #1 - Subroutines
FORM POPULATE_BDC_TAB USING
FLAG VAR1 VAR2.

FORM FILL_BDC_TAB.
REFRESH BDC_TAB.

CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
1

SAPMF02K
RF02K-LIFNR
RF02K-D0110

0106,
INREC-VENDNUM,
X,

SAPMF02K
LFA1-STRAS
BDC_OKCODE

0110,
INREC-STREET,
/11.

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 field string.

Error Handling
Write an error report.

Send the record(s) in


error to an error file.

Create a batch input


session with the
record(s) in error.

Synchronous versus Asynchronous


DO.
...
PERFORM FILL_BDC_TAB.
CALL TRANSACTION FK02
USING
BDC_TAB
MODE
N
UPDATE
S.
IF SY-SUBRC <> 0.
WRITE: / Error.
ENDIF.
ENDDO.

With synchronous updating, we


can check SY-SUBRC to
determine the success of the
transaction and the actual
update to the database.

DO.
...
PERFORM FILL_BDC_TAB.
CALL TRANSACTION FK02
USING
BDC_TAB
MODE
N
UPDATE
A.
IF SY-SUBRC <> 0.
WRITE: / Transaction error.
ENDIF.
ENDDO.

With asynchronous updating,


we can check SY-SUBRC to
determine the success of the
transaction only, not the actual
update to the database.

CALL DIALOG Statement

CALL DIALOG <dialog module>


USING
<bdc internal table>
MODE
<display mode>.
<display mode>

<update mode>

A: display all
E: display errors only
N: no display

Notice that an update


mode is not specified.

Example #2 - Declaration Section


REPORT Y180DM11.
Step #1

DATA: BDC_TAB LIKE BDCDATA


OCCURS 6 WITH HEADER LINE,
INFILE(20) VALUE /tmp/bc180_file5.

Step #2

DATA: BEGIN OF INREC,


VENDNUM LIKE LFA1-LIFNR,
STREET LIKE LFA1-STRAS,
END OF INREC.
PARAMETERS:

DISPMODE DEFAULT A.

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

Example #2 - Main Program


Step #3
Step #4
Step #5
Step #6
Step #7
Step #8

Step #9
Step #10

START-OF-SELECTION.
OPEN DATASET INFILE
FOR INPUT IN TEXT MODE.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0. EXIT. ENDIF.
PERFORM FILL_BDC_TAB.
CALL DIALOG Z_DIALOG_FK02
USING
BDC_TAB
MODE
DISPMODE.
IF SY-SUBRC <> 0.
WRITE: / Transaction error.
STOP.
ENDIF.
ENDDO.
COMMIT WORK.
CLOSE DATASET INFILE.
** This program is continued on the next slide **

Example #2 - Subroutines
FORM POPULATE_BDC_TAB USING
FLAG VAR1 VAR2.

FORM FILL_BDC_TAB.
REFRESH BDC_TAB.

CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
1

SAPMF02K
RF02K-LIFNR
RF02K-D0110

0106,
INREC-VENDNUM,
X,

SAPMF02K
LFA1-STRAS
BDC_OKCODE

0110,
INREC-STREET,
/11.

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 field string.

CALL TRANSACTION
versus CALL DIALOG
CALL
TRANSACTION
Timing of
Update

CALL
DIALOG

Update occurs after


each transaction is
completed.

Update occurs on
COMMIT WORK
statement.

You might also like