Batch Data

Download as pdf or txt
Download as pdf or txt
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 Background

Step #1

Step #2

Defining a
background job.
Phases of Background Processing

Job
Scheduling

Job
Processing

Job
Overview
Scheduling a Background Job
Transaction Job
SM36 Scheduling
Creating Step for Background Job
Steps
Job
Scheduling
Start Criteria for Background Job

Job
Start date Scheduling

Immediate Date/Time After Job After Event

Jobs can be Jobs can be


Jobs can be scheduled to
scheduled to run scheduled to run after
run immediately or at a
after another job has an event has been
particular date/time.
been completed. “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
Start date Scheduling
Period values

X Periodic job Hourly With the ‘Period


Values’ pushbutton,
Daily you can schedule
the job to run hourly,
daily, weekly,
By checking the Weekly monthly, etc.
‘Periodic Job’ option,
you can specify
that the job run at
Monthly
regular intervals.
Other period
Scheduling Job after Another Job

Job
Start date After 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

Job
Start date After Event 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
EVENTID_DOES_NOT_EXIST = 2 The only required
EVENTID_MISSING =3 exporting parameter is the
RAISE_FAILED =4 name of the event to raise.
OTHERS = 5.
Phases of Background Processing

Job
Scheduling

Job
Processing

Job
Overview
Processing a Background Job

Scheduler Job Dispatcher

Job
Background
Job
Processing
Processing a Background Job
Application Server Job
Work Processes Processing
8 Online 1 Spool 3 Background
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
PRINT SPOOL
Job Step #1
Job
Job Step #2
Processing
List
Job Step #3 All “WRITE”
statement output
from job step.
End Module
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 Job


Program Overview
Messages

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 Background Job


Memory
Step #1
...
EXPORT <data> TO
<data> MEMORY.
...

Step #2
...
IMPORT <data> FROM
MEMORY.
...
Passing Data to Subsequent Job Steps

Global ABAP/4 Background Job


Memory
Step #1
...
EXPORT <data2> TO
<id1>
MEMORY ID <id2>.
...
<data>

Step #2
<id2> ...
IMPORT <data2> FROM
<data2> MEMORY ID <id2>.
...
Scheduling Job within
ABAP/4 Program

Open Background Job

JOB_OPEN

JOB_SUBMIT
is called for
Insert Job Step
each step that
is to be added
to the job. JOB_SUBMIT

Close Background Job

JOB_CLOSE
JOB_OPEN

JOB_OPEN Background Job

Exporting: <job name>


jobname = <job name>
<job #>

Importing:
jobcount = <job #>
JOB_SUBMIT

JOB_SUBMIT Background Job

Exporting: <job name>


authcknam = <user>
jobcount = <job #> <job #>
jobname = <job name>
report = <report>
variant = <variant> Step #1

Step #2
JOB_CLOSE

JOB_CLOSE Background Job

Exporting: <job name>


jobcount = <job #>
jobname = <job name> <job #>
sdlstrtdt = <start date>
sdlstrttm = <start time>
strtimmed = <flag1> Step #1

Importing:
job_was_released = Step #2
<flag2>
ABAP/4 Program Example

REPORT Y180DM01.
DATA: JOBNUM LIKE TBTCJOB-JOBCOUNT.
PARAMETERS: JOBNAME LIKE TBTCJOB-JOBNAME,
PROGRAM LIKE SY-REPID,
VARIANT LIKE RALDB-VARIANT,
USER LIKE SY-UNAME.
Open Job CALL FUNCTION ‘JOB_OPEN’
EXPORTING JOBNAME = JOBNAME
IMPORTING JOBCOUNT = JOBNUM.
Submit Step CALL FUNCTION ‘JOB_SUBMIT’
EXPORTING AUTHCKNAM = USER
JOBCOUNT = JOBNUM
JOBNAME = JOBNAME
REPORT = PROGRAM
VARIANT = VARIANT.
WRITE: / JOBNAME, JOBCOUNT, REPORT, VARIANT,
BTCHUSER.
Close Job CALL FUNCTION ‘JOB_CLOSE’
EXPORTING JOBCOUNT = JOBCOUNT
JOBNAME = JOBNAME.
Summary of Background Processing

Job Job Job


Scheduling Processing 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
Database
files on an Server
application server

Application
Servers

Presentation
Servers
Processing Files

Open File

Create File or Read File

Close File
Open File

“OPEN DATASET” statement

“FOR”
“IN”
INPUT
BINARY MODE
OUTPUT
TEXT MODE
APPENDING

“AT POSITION” “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

REPORT Y180DM02.
TABLES: KNA1.
PARAMETERS:
OUTFILE(20) DEFAULT ‘/tmp/bc180_file1’
LOWER CASE,
STATE LIKE KNA1-REGIO DEFAULT ‘MA’.
Step #1 DATA: BEGIN OF OUTREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF OUTREC.

Step #2 OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE.


SELECT * FROM KNA1 WHERE REGIO = STATE.
Step #3 MOVE-CORRESPONDING KNA1 TO OUTREC.
Step #4 TRANSFER OUTREC TO OUTFILE.
ENDSELECT.
Step #5 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,
The only change from the KUNNR LIKE KNA1-KUNNR,
previous example is “FOR REGIO LIKE KNA1-REGIO,
APPENDING” instead of TELF1 LIKE KNA1-TELF1,
“FOR OUTPUT”. END OF OUTREC.

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.

PARAMETERS:
INFILE(20) DEFAULT ‘/tmp/bc180_file1’
LOWER CASE.
Step #1 DATA: BEGIN OF INREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF INREC.

Step #2 OPEN DATASET INFILE FOR INPUT IN TEXT MODE.


DO.
Step #3 READ DATASET INFILE INTO INREC.
Step #4 IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE: INREC-KUNNR, INREC-REGIO, INREC-TELF1.
ENDDO.
Step #5 CLOSE DATASET INFILE.
Text Mode versus Binary Mode

File structured File structured


in lines byte-by-byte
ABC “READ DATASET” into ABCDEF
DEFGH field string that is four GHIJK
characters in length
IJKL

A B C 1 A B C D
D E F G 2 E F G H
I J K L 3 I J K
CHAPTER 3
FILE HANDLING AT
PRESENTATION
SERVER
Overview

In this chapter, we
will learn how to
process sequential Database
files on a Server
presentation 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>
The only required FILETYPE = <default file type>
parameter is the MODE = <create new or extend>
internal table. IMPORTING
FILESIZE = <size of file in bytes>
TABLES
DATA_TAB = <internal table to transfer>
EXCEPTIONS. . . .
Example - Create Local File
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.
Step #1 DATA: OUT_ITAB TYPE OUTREC
OCCURS 10 WITH HEADER LINE.

SELECT * FROM KNA1 WHERE REGIO = STATE.


Step #2 MOVE-CORRESPONDING KNA1 TO OUT_ITAB.
APPEND OUT_ITAB.
CLEAR OUT_ITAB.
ENDSELECT.

Step #3 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

REPORT Y180DM06.
TYPES: BEGIN OF INREC,
KUNNR LIKE KNA1-KUNNR,
REGIO LIKE KNA1-REGIO,
TELF1 LIKE KNA1-TELF1,
END OF INREC.
Step #1 DATA: IN_ITAB TYPE INREC
OCCURS 10 WITH HEADER LINE.

Step #2 CALL FUNCTION ‘UPLOAD’


EXPORTING
FILENAME= ‘c:\bc180_file2’
TABLES
DATA_TAB = IN_ITAB.
Step #3 LOOP AT IN_ITAB.
WRITE: / IN_ITAB-KUNNR,
IN_ITAB-REGIO,
IN_ITAB-TELF1.
ENDLOOP.
Download/Upload Program Code

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

To upload a local file into


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

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


CHAPTER 4
BDC CONCEPTS
Overview

External System SAP System

Data Batch Input


Data Transfer Rules

External
Data

X Checks &
SAP
Database
Validations
Table

External
Data
Online Program

To check and validate the external Vendor TEST1


data, user dialog is simulated
through an SAP transaction Company Code
(i.e., an online program).
X Address

Name Computers, Inc.

Street
City Philadelphia
BDCDATA Structure

To simulate user dialog,


ABAP/4 Dictionary
you must know the
following information:
(1) online program name,
(2) screen numbers, “BDCDATA”
(3) field names, and
(4) field values.

The “BDCDATA” ABAP/4 PROGRAM


Dictionary structure is used DYNPRO
in a batch input program to DYNBEGIN
collect this information for FNAM
an entire transaction. FVAL
Example - Change Vendor

Vendor TEST1
Company Code
For our example, we
will use the “Change X Address

Vendor” transaction
(“FK02”) to add a street
address to an already
existing vendor. Name Computers, Inc.

Street 123 Main St.


City Philadelphia
Researching Transaction - 1st Screen

Step #1 Step #2
Use “System > Status” Use ‘F1’ key and “Technical
menu path to determine Info” pushbutton in each
online program name screen field to be filled to
(SAPMF02K), screen determine the field name.
number (0106), and
transaction code (FK02). Step #3
Determine how to proceed
Vendor TEST1 in the transaction
Company Code (go to the next screen by
pressing the ‘Enter’ key).
X Address
Field name = RF02K-LIFNR
Field name = RF02K-D0110
Researching Transaction - 2nd Screen

Step #1 Step #2
Use “System > Status” Use ‘F1’ key and “Technical
menu path to determine Info” pushbutton in each
online program name screen field to be filled to
(SAPMF02K) and screen determine the field name.
number (0110).
Step #3
Determine how to proceed
in the transaction (save the
Name Computers, Inc. record by clicking on the
‘Save’ pushbutton or
Street 123 Main St. pressing the ‘F11’ key).
City Philadelphia
Field name = LFA1-STRAS
BDC Table Contents

After researching the transaction,


we can determine the contents of
the BDC table.

PROGRAM DYNPRO DYNBEGIN FNAM FVAL


SAPMF02K 0106 X
RF02K-LIFNR TEST1
RF02K-D0110 X
SAPMF02K 0110 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


transaction’s information must be
declared “LIKE BDCDATA”.
Filling BDC Table - Method #1

FORM FILL_BDC_TAB.
CLEAR BDC_TAB.
REFRESH BDC_TAB. BDC_TAB-PROGRAM = ‘SAPMF02K’.
BDC_TAB-DYNPRO = ‘0110’.
CLEAR BDC_TAB. BDC_TAB-DYNBEGIN = ‘X’.
BDC_TAB-PROGRAM = ‘SAPMF02K’. APPEND BDC_TAB.
BDC_TAB-DYNPRO = ‘0106’.
BDC_TAB-DYNBEGIN = ‘X’. CLEAR BDC_TAB.
APPEND BDC_TAB. BDC_TAB-FNAM = ‘LFA1-STRAS’.
BDC_TAB-FVAL = ‘123 Main St.’.
CLEAR BDC_TAB. APPEND BDC_TAB.
BDC_TAB-FNAM = ‘RF02K-LIFNR’.
BDC_TAB-FVAL = ‘TEST1’. CLEAR BDC_TAB.
APPEND BDC_TAB. BDC_TAB-FNAM = ‘BDC_OKCODE’.
BDC_TAB-FVAL = ‘/11’.
CLEAR BDC_TAB. APPEND BDC_TAB.
BDC_TAB-FNAM = ‘RF02K-D0110’.
BDC_TAB-FVAL = ‘X’. ENDFORM.
APPEND BDC_TAB.
Filling BDC Table - Method #2

FORM FILL_BDC_TAB. FORM POPULATE_BDC_TAB USING


FLAG VAR1 VAR2.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING: IF FLAG = ‘1’.
BDC_TAB-PROGRAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0106’, BDC_TAB-DYNPRO = VAR2.
‘ ’ ‘RF02K-LIFNR’ ‘TEST1’, BDC_TAB-DYNBEGIN = ‘X’.
‘ ’ ‘RF02K-D0110’ ‘X’, ELSE.
BDC_TAB-FNAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0110’, BDC_TAB-FVAL = VAR2.
‘ ’ ‘LFA1-STRAS’ ‘123 Main St.’, ENDIF.
‘ ’ ‘BDC_OKCODE’ ‘/11’.
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

“CALL TRANSACTION
Method #2 USING” Statement

Method #3 “CALL DIALOG” Statement


CHAPTER 5
BATCH INPUT
METHODS
Overview

BDC The first batch input method is to create


Program a batch input session. It is the
processing of this batch input session
External that updates the database, not the
Data execution of the batch input program.

Batch
SAP
Input
Database
Session
Table
Creating Batch Input Sessions

Open Batch Input Session

BDC_OPEN_GROUP

“BDC_INSERT” is
called for each
transaction Insert Transaction Data into Session
entered into the
batch input BDC_INSERT
session.

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
Creator
Client
Session Name
Authorization User
Hold Date
Batch Keep or Delete
Input
Session
Data Section
Transaction Data
Example #1 - Change Vendor

In this example, we will Vendor TEST1


create a batch input Company Code
session to add a street
address to an already X Address
existing vendor (TEST1).

Name Computers, Inc.

The “Change Vendor” Street 123 Main St.


transaction is “FK02”. City Philadelphia
Example #1 - Declaration Section

REPORT Y180DM08.
DATA: BDC_TAB LIKE BDCDATA
OCCURS 6 WITH HEADER LINE,
Step #1
SESSION LIKE APQI-GROUPID
VALUE ‘DEMO #8’.

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


Example #1 - Main Program

START-OF-SELECTION.
Step #2 CALL FUNCTION ‘BDC_OPEN_GROUP’
EXPORTING
CLIENT = SY-MANDT
GROUP = SESSION
USER = SY-UNAME
EXCEPTIONS. . . .
Step #3 PERFORM FILL_BDC_TAB.
Step #4 CALL FUNCTION ‘BDC_INSERT’
EXPORTING
TCODE = ‘FK02’
TABLES
DYNPROTAB = BDC_TAB
EXCEPTIONS. . . .
Step #5 CALL FUNCTION ‘BDC_CLOSE_GROUP’
EXCEPTIONS. . . .

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


Example #1 - Subroutines

FORM FILL_BDC_TAB. FORM POPULATE_BDC_TAB USING


FLAG VAR1 VAR2.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING: IF FLAG = ‘1’.
BDC_TAB-PROGRAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0106’, BDC_TAB-DYNPRO = VAR2.
‘ ’ ‘RF02K-LIFNR’ ‘TEST1’, BDC_TAB-DYNBEGIN = ‘X’.
‘ ’ ‘RF02K-D0110’ ‘X’, ELSE.
BDC_TAB-FNAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0110’, BDC_TAB-FVAL = VAR2.
‘ ’ ‘LFA1-STRAS’ ‘123 Main St.’, ENDIF.
‘ ’ ‘BDC_OKCODE’ ‘/11’.
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.

Vendor TEST1 Vendor TEST2

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
Sequential File

TEST1 123 Main St.


TEST2 10 Walnut St.
TEST3 32 Chestnut St.
TEST4 30 Market St.
TEST5 17 S. 30th St. The sequential file we will
read is set up in records.
Each record has two fields
File name:
with the following formats:
‘/tmp/bc180_file3’
<Field1> LIKE LFA1-LIFNR
<Field2> LIKE LFA1-STRAS
Example #2 - Declaration Section

REPORT Y180DM09.

DATA: BDC_TAB LIKE BDCDATA


Step #1 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,
Step #2
STREET LIKE LFA1-STRAS,
END OF INREC.

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


Example #2 - Main Program

START-OF-SELECTION.
Step #3 OPEN DATASET INFILE
FOR INPUT IN TEXT MODE.
Step #4 CALL FUNCTION ‘BDC_OPEN_GROUP’. . . .
DO.
Step #5 READ DATASET INFILE INTO INREC.
Step #6 IF SY-SUBRC <> 0. EXIT. ENDIF.
Step #7 PERFORM FILL_BDC_TAB.
Step #8 CALL FUNCTION ‘BDC_INSERT’
EXPORTING
TCODE = ‘FK02’
TABLES
DYNPROTAB = BDC_TAB. . . .
ENDDO.
Step #9 CALL FUNCTION ‘BDC_CLOSE_GROUP’. . . .
Step #10 CLOSE DATASET INFILE.

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


Example #2 - Subroutines

FORM FILL_BDC_TAB. FORM POPULATE_BDC_TAB USING


FLAG VAR1 VAR2.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING: IF FLAG = ‘1’.
BDC_TAB-PROGRAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0106’, BDC_TAB-DYNPRO = VAR2.
‘ ’ ‘RF02K-LIFNR’ INREC-VENDNUM, BDC_TAB-DYNBEGIN = ‘X’.
‘ ’ ‘RF02K-D0110’ ‘X’, ELSE.
BDC_TAB-FNAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0110’, BDC_TAB-FVAL = VAR2.
‘ ’ ‘LFA1-STRAS’ INREC-STREET, ENDIF.
‘ ’ ‘BDC_OKCODE’ ‘/11’.
APPEND BDC_TAB.
ENDFORM.
ENDFORM.

Notice that the vendor number and street values are coming
from the file’s 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 In this chapter, we will


Program learn how to process
External batch input sessions.
Data

Process
Batch Batch
Input SAP
Input
Session Database
Session
Table
Process
Batch
Session Overview
Transaction Code “SM35”
Input OR
Session “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 Delete
Input
Session 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

Remember: A batch input


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

Time1 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 FNAM FVAL


SAPMF02K 0106 X
RF02K-LIFNR TEST1
RF02K-D0110 X
SAPMF02K 0110 X
LFA1-STRAS 123 Main St.
BDC_OKCODE /11

BDC Table

Create Batch Input Use in “CALL Use in “CALL


Session TRANSACTION” DIALOG”
(BDC Program) statement statement
Differences in Batch Input Methods

When is the
How are errors
SAP database
handled?
updated?

Automatically by the
Create batch During the processing
system during the
input session of the batch input
processing of the
(BDC Program): session
batch input session

During the execution Must be handled in


CALL TRANSACTION:
of the batch input the batch input
CALL DIALOG: program 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.

Vendor TEST1 Vendor TEST2

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 S: synchronous
E: display errors only A: asynchronous
N: no display
Example #1 - Declaration Section

REPORT Y180DM10.

DATA: BDC_TAB LIKE BDCDATA


Step #1 OCCURS 6 WITH HEADER LINE,
INFILE(20) VALUE ‘/tmp/bc180_file4’.

DATA: BEGIN OF INREC,


VENDNUM LIKE LFA1-LIFNR,
Step #2
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

START-OF-SELECTION.
Step #3 OPEN DATASET INFILE
FOR INPUT IN TEXT MODE.
DO.
Step #4 READ DATASET INFILE INTO INREC.
Step #5 IF SY-SUBRC <> 0. EXIT. ENDIF.
Step #6 PERFORM FILL_BDC_TAB.
Step #7 CALL TRANSACTION ‘FK02’
USING BDC_TAB
MODE DISPMODE
UPDATE UPDAMODE.
Step #8 IF SY-SUBRC <> 0.
WRITE: / ‘Error’.
ENDIF.
ENDDO.
Step #9 CLOSE DATASET INFILE.

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


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

Notice that the vendor number and street values are coming
from the file’s 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. DO.
... ...
PERFORM FILL_BDC_TAB. PERFORM FILL_BDC_TAB.
CALL TRANSACTION ‘FK02’ CALL TRANSACTION ‘FK02’
USING BDC_TAB USING BDC_TAB
MODE ‘N’ MODE ‘N’
UPDATE ‘S’. UPDATE ‘A’.
IF SY-SUBRC <> 0. IF SY-SUBRC <> 0.
WRITE: / ‘Error’. WRITE: / ‘Transaction error’.
ENDIF. ENDIF.
ENDDO. ENDDO.

With synchronous updating, we With asynchronous updating,


can check SY-SUBRC to we can check SY-SUBRC to
determine the success of the determine the success of the
transaction and the actual transaction only, not the actual
update to the database. 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 Notice that an update
E: display errors only mode is not specified.
N: no display
Example #2 - Declaration Section

REPORT Y180DM11.

DATA: BDC_TAB LIKE BDCDATA


Step #1 OCCURS 6 WITH HEADER LINE,
INFILE(20) VALUE ‘/tmp/bc180_file5’.

DATA: BEGIN OF INREC,


VENDNUM LIKE LFA1-LIFNR,
Step #2
STREET LIKE LFA1-STRAS,
END OF INREC.

PARAMETERS: DISPMODE DEFAULT ‘A’.

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


Example #2 - Main Program
START-OF-SELECTION.
Step #3 OPEN DATASET INFILE
FOR INPUT IN TEXT MODE.
DO.
Step #4 READ DATASET INFILE INTO INREC.
Step #5 IF SY-SUBRC <> 0. EXIT. ENDIF.
Step #6 PERFORM FILL_BDC_TAB.
Step #7 CALL DIALOG ‘Z_DIALOG_FK02’
USING BDC_TAB
MODE DISPMODE.
Step #8 IF SY-SUBRC <> 0.
WRITE: / ‘Transaction error’.
STOP.
ENDIF.
ENDDO.
Step #9 COMMIT WORK.
Step #10 CLOSE DATASET INFILE.
** This program is continued on the next slide **
Example #2 - Subroutines
FORM FILL_BDC_TAB. FORM POPULATE_BDC_TAB USING
FLAG VAR1 VAR2.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING: IF FLAG = ‘1’.
BDC_TAB-PROGRAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0106’, BDC_TAB-DYNPRO = VAR2.
‘ ’ ‘RF02K-LIFNR’ INREC-VENDNUM, BDC_TAB-DYNBEGIN = ‘X’.
‘ ’ ‘RF02K-D0110’ ‘X’, ELSE.
BDC_TAB-FNAM = VAR1.
‘1’ ‘SAPMF02K’ ‘0110’, BDC_TAB-FVAL = VAR2.
‘ ’ ‘LFA1-STRAS’ INREC-STREET, ENDIF.
‘ ’ ‘BDC_OKCODE’ ‘/11’.
APPEND BDC_TAB.
ENDFORM.
ENDFORM.

Notice that the vendor number and street values are coming
from the file’s records read into the “INREC” field string.
“CALL TRANSACTION”
versus “CALL DIALOG”

CALL
Update occurs after
TRANSACTION
each transaction is
completed.
Timing of
Update

Update occurs on
“COMMIT WORK”
CALL statement.
DIALOG

You might also like