ABAP-Bdcs

27
Batch Data Communications (BDCs)

Transcript of ABAP-Bdcs

Page 1: ABAP-Bdcs

Batch Data Communications (BDCs)

Page 2: ABAP-Bdcs

Introduction to BDCs

Let us assume that we have installed SAP R/3 in a company.

This company has data pertaining to different modules in legacy system (other systems like Oracle, sybase databases etc.,).

This data has to be transferred in to R/3 system.

Page 3: ABAP-Bdcs

Introduction to BDCs contd.

Transfer of data from legacy system to R/3 is possible through BDC.

There are 2 steps involved in this data transfer. Conversion SAP data transfer

Page 4: ABAP-Bdcs

Conversion

Data is first converted from legacy system into required flat file format.

Page 5: ABAP-Bdcs

Conversion contd.

There is no specific tool in SAP to do this conversion. C, COBOL > Conversion programs. Oracle or Sybase > Export utilities. Format editors or code generators. You can write ABAP/4 programs to do

this job.

Page 6: ABAP-Bdcs

SAP data transfer

SAP Data transfer program reads flat file and moves it into R/3 system.

Page 7: ABAP-Bdcs

SAP data transfer contd.

Data purging :Before transferring data from flat file, remove all the old and obsolete records to save time and disk space.

Data cleansing :Correction of data inconsistencies. mistakes to be rectified before data transfer.

Page 8: ABAP-Bdcs

File Handling

Sequential files ( data sets) Local files

Page 9: ABAP-Bdcs

Sequential files

Stored in application server.Handling of sequential files is of 3

tier process. Open Process Close

Page 10: ABAP-Bdcs

1) OPEN

Syntax:open dataset <data set>. for < input / output / appending >in < text mode / binary mode >.

This statement returns sy-subrc.Defaults: For Input and Binary mode.

Page 11: ABAP-Bdcs

For Input

Opens the data set for reading and places the cursor at the beginning of the file.

If the data set does not exist, then sy-subrc is not equal to zero.

Page 12: ABAP-Bdcs

For Output

Opens the data set and places the cursor at the beginning of the file.

If the data set is already existing, then it is over written.

If the data set do not exist, then a new file is created.

Page 13: ABAP-Bdcs

For Appending

Opens the data set and places the cursor at the end of the file.

If the data set do not exist, then a new file is created.

Page 14: ABAP-Bdcs

In text mode

Reading and writing will be line by line.

If the destination is shorter than source, then truncated else padded with spaces.

Page 15: ABAP-Bdcs

In Binary mode

Reading and writing will be character by character. Each time ‘n’ characters are read or written.

Format is changed.

Page 16: ABAP-Bdcs

2) Process

Writing on to the data set (TRANSFER) or Reading a data set (READ) is nothing but Processing.

Page 17: ABAP-Bdcs

Transfer

Transfer <field> to <data set>.

If <field> is an internal table itab then,loop at itab.Transfer itab to <data set>.Endloop.

Page 18: ABAP-Bdcs

Transfer contd.

If the data set is not already open, ‘TRANSFER’ tries to open the file ‘FOR OUTPUT’ in ‘BINARY MODE’ or using the last ‘OPEN DATASET’ statement for this data set.

In file handling, transfer is the only statement which do not return sy-subrc.

Page 19: ABAP-Bdcs

READ

Read dataset <data set> into <field>. If <field> is an internal table itab then,

Do.Read dataset <data set> into itab.If sy-subrc = 4. exit. endif. append itab.Enddo.

Page 20: ABAP-Bdcs

3) Close

All data sets, which are still open at the end of the program will be closed by the system. How ever it is good programming practice to explicitly close all the data sets that were opened.

Syntax:close dataset <dataset>.

Page 21: ABAP-Bdcs

Delete

Delete dataset <data set>.

Page 22: ABAP-Bdcs

Pseudo logic for handling sequential files

Task : To store a file in application server.

1) Declare an Internal table (itab) with h/l.2) Populate itab.3) open dataset ‘seq.txt’ for output in text

mode.4) transfer itab to ‘seq.txt’.5) close dataset ‘seq.txt’.

Page 23: ABAP-Bdcs

Pseudo logic contd.

6) refresh itab.7) open dataset ‘seq.txt’ for input in

text mode.8) read dataset ‘seq.txt’ into itab.9) close dataset ‘seq.txt’.10) Process itab.

Page 24: ABAP-Bdcs

Local files

Stored in presentation server.For handling we use upload

(ws_upload) and download (ws_download) function modules.

Page 25: ABAP-Bdcs

Differences (SQH & LFH)

Sequential files Local filesApplication Ser. Presentation

Ser.Open/process/close. Upload/

downloadfunction

modules.Transfer rec by rec. At one step

Page 26: ABAP-Bdcs

Pseudo logic for LFH

For uploading ( note pad to itab)1) Create data in a note pad ‘lf1.txt’

and save it.2) declare itab structure similar to

data file structure with header line.3) upload data from note pad into itab

using function modules ‘upload’ (ws_upload).

Page 27: ABAP-Bdcs

Pseudo logic contd.

Down load (itab to another note pad)4) down load itab into another note

pad say ‘lf2.txt’ using function module ‘download’ (ws_download).

[ upload = inbound download = outbound]