You are on page 1of 72

Batch Data

Communication
BY ----Arjun
Overview

It is the technique of transferring in data from legacy system (NON-


SAP) to SAP is called BDC.

There are two techniques available for transferring data.


Outbound process
Inbound process
OUTBOUND PROCESS:

The process of transferring the data from SAP to NON-SAP or


another SAP server is called Outbound Process.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 2
INBOUND PROCESS

The process of receiving the data from NON-SAP to SAP


server is called as Inbound Process.

BDC is an Inbound Process.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 3
DIFFERENT METHODS OF BDC:

Call transaction (Screen Level Processing)

Session method (Screen Level Processing)

Direct input method->(Standard SAP Programs)

LSMW -> (A tool)

BAPI method -> (Advanced Technique, which is very Good)

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 4
CALL TRANSACTION METHOD:

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 5
CALL TRANSACTION METHOD:

CALL TRANSACTION METHOD:

It is the process of transferring the data from flat file into SAP by
calling a transaction through a series of sequence of steps.

Properties:
This method is used for transferring less amount of data(<10,000
records).
This method uses Synchronous and Asynchronous updates.
This method will update the DB immediately.
We need to handle the errors and the success messages by
declaring an internal table of type BDCMSGCOLL.
This method is very fast.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 6
Syntax:

Call Transaction <Tcode>

Using <BDC DATA>

UPDATE <A/S>

MODE <A/E/N>

MESSAGES INTO <Message Internal Table>

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 7
BDC DATA

BDC Data:

It is a structure defined in a data dictionary with the below fields.

Program -> Name of the program of a screen

Dynpro -> Screen number

Dynbegin -> Start the Process

Fnam -> Field name on the SAP screen

Fval -> Field value on to the field name of SAP screen

USE OF BDC DATA:

It is a structure which holds the information related to each screen


i.e. program name, screen no, field name, field values, information of
that particular screen to be transferred into the SAP.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 8
BDC DATA

In simple words, it holds all the screen related information and field
information to be transferred into corresponding SAP transaction.

Program Dynpro Dynbegin Fnam Fval

SAPLGMM 0060 X

RMMG1-MATNR 1011

RMMG1-MBRSH FOOD

RMMG1-MTART FERT

SAPLGMM 0070 X
RZSEL X

- - - - -

- - - - -

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 9
BDC DATA

To find the above information for each field, press F1 on particular


field

It will display help information.

Click on the button technical information

It will show the entire technical information of a screen.

Please note down the program name, screen number, screen field
name.

This procedure has to be repeated for each field on a SAP screen.

Since, it is very difficult to note down the technical information for


each field, we have an alternate and easy method called as
RECORDING METHOD.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 10
Update:

Update: There are two types of updates are available.


Asynchronous update (COMMIT)
Synchronous update (COMMIT & WAIT)

DIAL0G WORK PROCESS: A work process which is dedicated to


process screen information is called Dialog work process.

There will be 6 to 7 dialog work processes.

These dialog work processes are defined by basis consultant.

UPDATE WORK PROCESS: This work process is responsible for


updating the data into the database.

There will be always only 1 update work process.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 11
ASYNCHRONOUS UPDATE

ASYNCHRONOUS UPDATE (COMMIT):

In this type the call transaction screens will communicate with the
update work process to update the data into database.

It doesnt wait for the update to be finished.

It immediately starts to process the next record without waiting for


the update to be finished.

Thats why this process is very fast.

It is generally not recommended for the large amount of data,


because the called transaction doesnt return any success or error
messages.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 12
SYNCHRONOUS UPDATE

SYNCHRONOUS UPDATE (COMMIT & WAIT):

In this mode, the called transaction communicates with the update


work process to update the data into database.

It will wait for the update to be finished.

Once the update is finished, then it continues to process the next


record.

Thats why this process is very slow.

It is generally recommended for large amount of data because it


returns success and error messages.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 13
MODE:

It specifies the type of the mode to execute the transaction.

There are 3 options for mode

___________________________________________________________

MODE DESCRIPTION

___________________________________________________________

A All screen mode(Foreground)

E Error screen mode (only error screens will be


displayed)

N No screen mode (Background)

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 14
MESSAGES:
MESSAGES:

In the called transaction, we need to handle the messages by


declaring an internal table of type BDCMSGCOLL.

All the messages will be stored in the above internal table.

The structure of BDCMSGCOLL is as below:

MSGTYP Message type(E-error, S-success W Warning etc..)

MSGID Message ID

MSGNR Message number

MSGV1 Variable part of a message

MSGV2 Variable part of a message

MSGV3 Variable part of a message

MSGV4 Variable part of a message


SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 15
The variable BDCMSGCOLL MSGV1 will contain the created
material number or vendor number whenever the message type is
success (S).

Whenever the message type is error, we need to use the function


module FORMAT_MESSAGE to display the meaningful message.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 16
RECORDING METHOD:

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 17
RECORDING METHOD:

RECORDING METHOD:

Since, it is very difficult to find technical information of each field on


the screen, we go for a method called as Recording method.

The recording method is going to record all the fields in the


transaction and it generated the technical information such as
program name, screen no, field name, field value for each field on the
SAP screen.

By using the recording method, it is very easy to create a BDC


program.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 18
Steps to create a Material:

Go to MM01

Give the industry sector as Pharmaceuticals.

Give the material type as coupons.

Click on the button select views

Select the checkbox Basic Data1

Click on continue button.

Give the description as Test material.

Give the units as Kgs.

Click on save.

A message will be displayed with text as Material 1427 is created.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 19
Steps for Recording :

Steps for the Recording:

Go to SHDB

Click on new recording

Give the recording name. eg:YMM01

Give the transaction code. Eg: MM01

Click on the button start recording.

MM01 will be displayed.

Enter the industry sector as Pharmaceuticals

Enter the material type as coupons.

Click on select view button.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 20
Select the checkbox Basic Data1.

Click on continue button.

Give the description as Test material.

Give the units as Kgs and click on Save.

The recording will display all the technical information.

Click on save

Click on back

Select the recording

Click on the button create program

Give the program name

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 21
Select the button transfer from recording.

Press enter

Give the title

Click on the button Source Code.

The code will be generated as below.

Perform BDC-Dynpro using SAPLGMM 0060.

Perform BDC-Field using BDC_CURSOR

RMMG1-MRART.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 22
FORM bdc_dynpro using program dynpro.

Clear BDCDATA.

BDCDATA-program = program.

BDCDATA-dynpro = dynpro.

BDCDATA-dynbegin = x.

Append BDCDATA.

ENDFORM.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 23
*INSERT FIELD.

FORM bdc_field using FNAM FVAL.

Clear BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

Append BDCDATA.

ENDFORM.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 24
Assignment:

Create a customer and also recording for the transaction XD01.

Hint: Use XD03 for reference.

Create a vendor and also recording for the transaction XK01.

Hint: Use XK03 for reference.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 25
Steps to create a BDC program:

Create the recording for the transaction

Create an internal table of type flat file structure

Upload the data from flat file into the internal table using
GUI_UPLOAD

Loop at I_FILE into WA_FILE

***Copy the code generated from Recording and paste it here

Perform BDC-Dynpro using <Prg name> <Scrn No>

Perform BDC-Field using <fnam> <fval>

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 26
Call transaction tcode Call the transaction

Using BDCDATA

Update A/S

Mode A/E/N

Message into MESSTAB.

If SY-SUBRC = 0.

Perform display_success_rec. Subroutine for SUCCES recs

Else

Perform display_error_rec. Subroutine for ERROR recs

Endif.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 27
Form display_success_rec.

Read table MESSTAB

With key MSGTYP = S.

Endform.

Form display_error_rec.

Loop at MESSTAB where MSGTYP = E.

Call function FORMAT_MESSAGE.

..

Endloop.

Endform.
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 28
Example program on Call transaction

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 29
BReq : Upload material master data from flat file given as below

FLAT FILE SHOULD BE AS BELOW

*****************************************************************

Indsector Mattype desc units

P COUP DESC5 KGS

P COUP DESC6 KGS

P COUP DESC7 KGx

P COUP DESC8 KGS

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 30
TYPES : BEGIN OF TY_FILE,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF TY_FILE.
DATA : I_FILE TYPE TABLE OF TY_FILE .
DATA : WA_FILE TYPE TY_FILE .
DATA : LV_MSG TYPE STRING .
**********************BDC DATA DECLARARATIONS
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 31
BREAK-POINT .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\MARADATA.TXT'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = I_FILE.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 32
LOOP AT I_FILE INTO WA_FILE .

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MTART'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MBRSH'

WA_FILE-MBRSH.

perform bdc_field using 'RMMG1-MTART'

WA_FILE-MTART.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 33
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
WA_FILE-MAKTX.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 34
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
WA_FILE-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
CALL TRANSACTION 'MM01'
USING bdcdata
UPDATE 'A'
MODE 'N'
MESSAGES INTO MESSTAB .
If SY-SUBRC = 0.
Perform display_success_rec.
Else .
Perform display_error_rec.
Endif.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 35
CLEAR WA_FILE .

REFRESH BDCDATA.

CLEAR BDCDATA.

REFRESH MESSTAB .

CLEAR MESSTAB.

ENDLOOP .

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 36
*----------------------------------------------------------------------*

* Start new screen *

*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM. "BDC_DYNPRO

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 37
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM. "BDC_FIELD

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 38
*&---------------------------------------------------------------------*
*& Form display_success_rec
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_success_rec .
READ TABLE MESSTAB WITH KEY MSGTYP = 'S' .
WRITE : / 'material is created with no:' , messtab-msgv1 COLOR 5.
ENDFORM.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 39
FORM display_error_rec .
LOOP AT MESSTAB WHERE MSGTYP = 'E' .
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = MESSTAB-MSGID
LANG = 'E'
NO = MESSTAB-MSGNR
V1 = MESSTAB-MSGV1
V2 = MESSTAB-MSGV2
V3 = MESSTAB-MSGV3
V4 = MESSTAB-MSGV4
IMPORTING
MSG = LV_MSG.
WRITE / lv_msg COLOR 6.
ENDLOOP .
ENDFORM. " display_error_rec

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 40
Assignments

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 41
Steps to create Vendors:

Go to XK01

Give the vendor no. eg: 9887

Give the account group as 0001.

Press enter

Give the name as Reliance

Give the search term as name

Give the country as IN

Click on save, the vendor will be created.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 42
Steps to create the Customer:

Go to XD01

Give the account group as SOLD-TO-PARTY-0001

Give the customer no. eg: 9888

Give the name

Give the search term as name

Give the postal code as 509001

Give the city as HYD, country as IN, transport zone as 0000000001

Click on save.

Customer will be created.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 43
SESSION METHOD

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 44
SESSION METHOD

SESSION METHOD:

This method is used to transfer large amount of data (eg: >10,000 to


10 lakhs)

It is basically a 2 step process


Create a session
Process a session

Session: a session contains a group of records, which have to be


transferred into SAP.

To create a session, we use the below function modules.


BDC_Opengroup
BDC_Insert
BDC_Closegroup

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 45
BDC_OPENGROUP: This function module is used to create a
session with the below parameters.

client no = client no

user name = user name

group name = Session Name

Keep = X

hold Date = session is locked until the specified date

Keep = X , specifies the session to be available in the session


queue for processing at a later point of time.

Just call the function module and provide the above parameters.

The session will be created

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 46
BDC_INSERT:

This function module is used to transfer the data from BDCDATA


structure into the session.

Just call the function module and provide the transaction code name
and BDCDATA internal table name.

BDC_CLOSEGROUP:

This function module is used to close the session which is created


by function module BDC_OPENGROUP.

Once the session is created, we need to process the session.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 47
Processing the session:

SM35 is the transaction code for processing the session.

Go to SM35

Select the session name. eg:ZSESS1

Click on process button.

Select either foreground or background or error mode, click on the


process button.

The session will be processed.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 48
Status of session:

To know the status or to know how many records are


successfully processed, follow the below steps.

select the session name. eg:ZSESS1

click on the button Analysis

click on the tap Log.

it will clearly display all the messages whether each record is


successful or error with clear meaningful messages.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 49
Difference between call transaction and session:

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 50
Ex on Session Method

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 51
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 52
TYPES : BEGIN OF TY_FILE,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF TY_FILE.
DATA : I_FILE TYPE TABLE OF TY_FILE .
DATA : WA_FILE TYPE TY_FILE .
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE
. BREAK-POINT .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\MARA.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FILE.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 53
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'ZARJUN'
KEEP = 'X'
USER = SY-UNAME.

LOOP AT I_FILE INTO WA_FILE .


perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MBRSH'

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 54
*****CONTINUE ALL THE RECORDED STMTS UNITL LAST STMT

perform bdc_field using 'MARA-MTPOS_MARA'


'NORM'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
TABLES
DYNPROTAB = BDCDATA.

CLEAR WA_FILE .
REFRESH BDCDATA.
CLEAR BDCDATA.

ENDLOOP .

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 55
CALL FUNCTION 'BDC_CLOSE_GROUP'.

WRITE : / 'SESSION IS SUCCESSFULLY CREATED AND CLOSED' .

UNIT TESTING :

Execute the program

Goto SM35 and check the status of session

Process the session

Ceck for any errors

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 56
Direct Input Method

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 57
Direct Input Method:

Direct Input Method:

These are standard SAP programs which are used to update / upload
the data from flat file into SAP

we rarely use direct input programs in the real time, because of


below limitations.

The file structure should be created as per the structure of an


standard internal table declared in the standard program.

Here, we cant catch all types of errors because direct input


programs works directly on open SQL statements, where as call
transaction and session method uses Screen level processing (data
is transferred through the screens) where we can catch all type of
errors.
RMDATIND is a standard direct input program for uploading
material master data.
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 58
LSMW

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 59
LSMW (Legacy System Migration Workbench):

It is a SAP tool which is used to transfer the data fro legacy system
to SAP.

It is mainly used to transfer very less amount of data. (<5000)

LSMW contains very little coding

It is mainly designed for consultants who doesnt have any


programming language. i.e. functional consultants.

There are 4 methods available in LSMW.

direct input method

recording method

BAPI method

ALE/IDOC method.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 60
Difference between LSMW and BDC:

LSMW is a more user friendly tool, through which one can do the
same work as the BDC. One just has to follow the 14 steps.

BDC is basically a program which is either generated by SAP after a


recording or programmed by a abaper. Its like running the
transaction manually but all the data is populated in the screens
automatically.

LSMW provides various methods for migration of data, namely those


of direct input, batch input recording and IDOC. BDC however simply
makes use of reccroding. There are 2 ways of implementing BDC, the
call transaction method and the session method.

In LSMW, mapping is taken care of with the help of SAP, where as in


BDC one has to provide explicit mapping directions.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 61
In BDC, we can schedule the job, so the uploading can be done at
the same time or later periodically while in LSMW. It has to be done
at once only. So through LSMW, one cant upload large amount of
data. Hence we use LSMW for updating or inserting below 5000
records and we use BDC to upload records more than 5000.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 62
Application Server Files

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 63
Working with Files:

In SAP, a file can be located either in presentation server or


application server.

If the file is located in presentation server, we can use GUI_UPLOAD,


GUI_DOWNLOAD function modules to read or write the data in files.

If the file is located in application server, we use the below syntaxes


to read or write the data into files.

OPEN DATASET<filename>FOR<input/output/append>IN TEXT


MODE ENCODING DEFAULT

READ DATASET <filename> INTO <variable>

TRANSFER <variable/wa> to <fname>.

CLOSE DATASET<filename>

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 64
Open dataset: This statement is used to open a file in application
server for

INPUT : means, the file is opened for reading the data from file

OUTPUT : means, the file is opened for writing the data into file.

APPEND : means, the file is opened for appending new records


into the file.

Close dataset: This statement is used to close the file which is


opened by OPEN DATASET.

Note: AL11 is the transaction code for directories in application


server.

The default directories which are generally used are

DIR_HOME,DIR_TEMP,DIR_NAME .

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 65
Reading data from file:

Reading data from file:

we use the below statement to read the data from application server
file.

Syntax: READ DATASET <filename> INTO <variable>

Eg: READ DATASET mara.txt INTO v_str

(where, v_str is a type string)

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 66
Writing data into application server:

Writing data into application server:

We use the below statement for writing the data into application
server file.

Syntax: TRANSFER <variable/wa> to <fname>.

Eg: TRANSFER wa_mara to mara.txt.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 67
Eg: for writing the data into file.

Types : begin of ty_mara,

Matnr type mara-matnr,

Mtart type mara-mtart,

Mbrsh type mara-mbrsh,

Meins type mara-meins,

End of ty_mara.

Data : I_mara type table of ty_mara.

Data : wa_mara type ty_mara.

Data : fname(30) type c.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 68
Fname = mara.txt.stored in default directory DIR_HOME.

Select matnnr mtart mbrsh meins

From mara

Into table i_mara

Up to 10 rows.

Open data set fnaame for output in text mode encoding default.

If SY-SUBRC <> 0.

MESSAGE file could not be opened type E.

ELSE.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 69
Loop at i_mara into wa_mara.

Transfer wa_mara to fname.

Endloop.

Close dataset fname.

Write : / the data is written successfully into file.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 70
Eg: For reading the data from file.

Data : fname(30) type c.

Data : v_str type string.

Fname = mara.txt.

Open dataset fname for input in text mode encoding default.

If SY-SUBRC <> 0.

Message file could not be opened type E.

ELSE.

DO.

Read dataset fname into v_str.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 71
If SY-SUBRC <> 0.

EXIT.

ELSE.

Write : / v_str.

ENDIF.

ENDDO.

ENDIF.

SAP AG 2001, Smart Forms - the Form Printing Solution,


Claudia Binder / Jens Stumpe 72

You might also like