ABAP-Bdcs

Post on 24-Oct-2014

21 views 0 download

Tags:

Transcript of ABAP-Bdcs

Batch Data Communications (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.

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

Conversion

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

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.

SAP data transfer

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

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.

File Handling

Sequential files ( data sets) Local files

Sequential files

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

tier process. Open Process Close

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.

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.

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.

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.

In text mode

Reading and writing will be line by line.

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

In Binary mode

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

Format is changed.

2) Process

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

Transfer

Transfer <field> to <data set>.

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

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.

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.

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

Delete

Delete dataset <data set>.

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

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.

Local files

Stored in presentation server.For handling we use upload

(ws_upload) and download (ws_download) function modules.

Differences (SQH & LFH)

Sequential files Local filesApplication Ser. Presentation

Ser.Open/process/close. Upload/

downloadfunction

modules.Transfer rec by rec. At one step

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

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]