Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

file interfaces

Former Member
0 Likes
2,570

Hi,

I am new to SAP ABAP. i have some queries:

i have a comma delimited file with me(6 fields).

i want to read this file and then update a database table in sap using file interfaces.also can you please explain how to read the data correctly from the flat file for each field.

My email id Is anandkk99@gmail.com if you hav any good example codes or good tutorials or materials related to file interfaces.

Thanks in advance.

I will reward points for each reply.

1 ACCEPTED SOLUTION
9 REPLIES 9
Read only

Former Member
0 Likes
1,141

Batch Data Communication (BDC) is the oldest one. BDC is not bi-directional; it is an integration tool in its typical form. It can only be used for uploading data into RJ3. BDC works through an ABAP program and works on the principle of simulating user input for transactional screen.

The purpose of the Batch Data Communication is to transfer data. The BDC can transfer data from one SAP System to another SAP System or can transfer data from non-SAP System to SAP System too. To transfer data BDC uses normal transaction codes. Two methods are provided to BDC to do this work.

SAP has provided two different types of methods for BDC to do its work. Among these, the first one is called the classical method or session method. Through this method the data can be read by the BDC program from a sequential dataset file. This sequential dataset file is stored in batch-input session. In order to .run the transaction in this session, what one needs is to execute the session. For this, follow these few steps: you can start and subsequently monitor the session firstly from – System à Services à Batch Input or have the session run in the background. In this method to generate the required session, you have to use the function module BDC _ NSERT and BDC _CLOSE.

In the second method the BDC has to use the ABAP statement CALL TRANSACTION USING statement to run a transaction. In the second method, unlike in the first type, you do not need BDC to create a session.

During the process of data transfer, data is transferred into the SAP R/3 System. This transfer is from an external system to SAP R/3 system. Whenever you transfer data from an external system into an R/3 System, you can use data transfer because it is installed and regularly transfers data from an external system into an R/3 System.

Direct Input: In this method the SAP function modules execute the consistency checks. However, there are other means of checking with the help of screens. The Direct Input Method has considerable performance advantages.

Call Transaction: In this method you can check the data consistency with the help of screen logic.

Batch Input Session: In this method data consistency is checked with the help of screen logic.

please refer the following site,it will be very helpful.

http://aspalliance.com/1130_Batch_Data_Communication_BDC_in_SAP_R3.7

http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm

http://sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html

http://help.sap.com/saphelp_erp2005/helpdata/en/fa/097119543b11d1898e0000e8322d00/frameset.htm

http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html

http://www.sap-img.com/abap/learning-bdc-programming.htm

http://www.sap-img.com/bdc.htm

http://www.sappoint.com/abap/bdcconcept.pdf

http://www.sap-img.com/abap/learning-bdc-programming.htm

http://www.sapdevelopment.co.uk/bdc/bdchome.htm

http://www.planetsap.com/bdc_main_page.htm

Reward points if useful.

Read only

Former Member
0 Likes
1,141

hey guys,

thanks for your replies but could you please send me according to file interfaces(i.i.opendataset,closedataset etc.) and not BDC.

Thanks in advance,

Anand.

Read only

Former Member
0 Likes
1,141

hey guys,

thanks for your replies but could you please send me according to file interfaces(i.i.opendataset,closedataset etc.) and not BDC.

Thanks in advance,

Anand.

Read only

0 Likes
1,141

First i will explain the procedure step by step and will send a sample code plz check it once ok..And also i will attach a flat file at the end of SAMPLE CODE CHECK IT ONCE OK..

Steps:

1.Bulid an internal table first according to ur flat file fields.

2.select the flat file by using PARAMETER.

3.And assign that file path to GUI_UPLOAD function module.

4.Call BDC_OPEN_GROUP is used to open the session.

5.loop that flat file data and palce BDC_INSERT funtion module in that loop for uploading data into database table

6.After loop call BDC_CLOSE_GROUP to close the session.

SAMPLE CODE:

REPORT ybdc_session_mm01 NO STANDARD PAGE HEADING LINE-SIZE 255.

-


Global Structure for BDC Data

-


DATA: it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

-


Internal Table

-


DATA: BEGIN OF itab OCCURS 0,

mbrsh LIKE rmmg1-mbrsh,

mtart LIKE rmmg1-mtart,

maktx LIKE makt-maktx,

meins LIKE mara-meins,

END OF itab.

-


Upload the flat file

-


CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename =

'C:\Documents and Settings\Compaq_Owner\Desktop\satish\mm01.txt'

filetype = 'ASC'

has_field_separator = 'X'

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

DAT_MODE = ' '

IMPORTING

FILELENGTH =

HEADER =

TABLES

data_tab = itab.

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

-


Session Method Starts

BDC_OPEN_GROUP

-


CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

DEST = FILLER8

GROUP = 'ychinnu'

HOLDDATE = FILLER8

KEEP = 'X'

USER = SY-UNAME

RECORD = FILLER1

PROG = SY-CPROG

IMPORTING

QID =

EXCEPTIONS

CLIENT_INVALID = 1

DESTINATION_INVALID = 2

GROUP_INVALID = 3

GROUP_IS_LOCKED = 4

HOLDDATE_INVALID = 5

INTERNAL_ERROR = 6

QUEUE_ERROR = 7

RUNNING = 8

SYSTEM_LOCK_ERROR = 9

USER_INVALID = 10

OTHERS = 11

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

-


Create BDCDATA Structure

-


*include bdcrecx1.

START-OF-SELECTION.

PERFORM open_group.

loop at itab.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MTART'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MBRSH'

itab-mbrsh.

PERFORM bdc_field USING 'RMMG1-MTART'

itab-mtart.

-


After enterning MBRSH,MTART we press enter

-


PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'. "press Enter

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

-


View selection (Basic data1)

-


PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'"view selection

'X'.

-


Select Tick Mark (ok)

-


PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'MAKT-MAKTX'

itab-maktx.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-MEINS'.

PERFORM bdc_field USING 'MARA-MEINS'

itab-meins.

-


Finally after filling the data we save the data.

-


PERFORM bdc_field USING 'MARA-MTPOS_MARA' "For saving

'NORM'.

PERFORM bdc_transaction USING 'MM01'.

*

PERFORM close_group.

-


BDC_INSERT

-


CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'MM01'

POST_LOCAL = NOVBLOCAL

PRINTING = NOPRINT

SIMUBATCH = ' '

CTUPARAMS = ' '

TABLES

dynprotab = it_bdcdata

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

-


Refresh BDCDATA

-


refresh it_bdcdata.

endloop.

-


Closing BDC Group

-


CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

-


Start new screen *

-


FORM bdc_dynpro USING program dynpro.

CLEAR it_bdcdata.

it_bdcdata-program = program.

it_bdcdata-dynpro = dynpro.

it_bdcdata-dynbegin = 'X'.

APPEND it_bdcdata.

ENDFORM. "BDC_DYNPRO

-


Insert field *

-


FORM bdc_field USING fnam fval.

IF FVAL NODATA.

CLEAR it_bdcdata.

it_bdcdata-fnam = fnam.

it_bdcdata-fval = fval.

APPEND it_bdcdata.

ENDIF.

ENDFORM. "BDC_FIELD

-


Flat File

-


*M FERT IRON KG

*M ROH STEEL KG

*M HALB IRON KG

-


Award points if helpful.

Read only

0 Likes
1,141

BDC:

Batch Data Communication (BDC) is the process of transferring data from one SAP System to another SAP system or from a non-SAP system to SAP System.

Features :

BDC is an automatic procedure.

This method is used to transfer large amount of data that is available in electronic medium.

BDC can be used primarily when installing the SAP system and when transferring data from a legacy system (external system).

BDC uses normal transaction codes to transfer data.

Types of BDC :

CLASSICAL BATCH INPUT (Session Method)

CALL TRANSACTION

Session method.

1) synchronous processing.

2) can tranfer large amount of data.

3) processing is slower.

4) error log is created

5) data is not updated until session is processed.

Call transaction.

1) asynchronous processing

2) can transfer small amount of data

3) processing is faster.

4) errors need to be handled explicitly

5) data is updated automatically

Reward points if useful.

Read only

Former Member
0 Likes
1,141

hey guys,

thanks for your replies but could you please send me according to file interfaces(i.i.opendataset,closedataset etc.) and NOT BDC.

Thanks in advance,

Anand.

Read only

0 Likes
1,141

ABAP/4 provides the following statements for handling files on the application server

OPEN DATASET

CLOSE DATASET

DELETE DATASET

READ DATASET

TRANSFER

To open a sequential file on the application server, use the OPEN DATASET <file name> options statement .

Use the “FOR” options to specify the access mode:

FOR INPUT (default) opens an existing file for reading.

FOR OUTPUT opens a file for writing. If the file does not exist, it is created. If the file already exists, its contents are deleted.

FOR APPENDING opens a file for writing. If the file does not exist, it is created. If the file already exists, the system goes to the end of the file to add to it.

Use the “IN” options to specify the structure of the file:

IN BINARY MODE (default) indicates that the file is not structured in lines (i.e., it is set up byte-by-byte).

IN TEXT MODE indicates that the file is structured in lines.

If you use the “MESSAGE <field>” addition, a system message issued when opening the file will be placed in the character-type <field>.

The “AT POSITION <position>” addition opens the file at a specific <position>, indicated in bytes from the beginning of the file.

To read a sequential file on the application server, use the “READ DATASET” statement. The basic syntax of this statement is:

READ DATASET <file name> INTO <structure>.

To write to a sequential file on the application server, use the “TRANSFER” statement. The basic syntax of this statement is:

TRANSFER <structure> TO <file name>.

To close a sequential file on the application server, use the “CLOSE DATASET” statement. The basic syntax of this statement is:

CLOSE DATASET <file name>.

To delete a sequential file on the application server, use the “DELETE DATASET” statement. The basic syntax of this statement is:

DELETE DATASET <file name>.

Sample Code:

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.

In the example above, we are creating a file with customer information. Specifically, we are transferring the customer number, state, and telephone number (for all customers in a particular state) from the KNA1 table to the ‘/tmp/bc180_file1’ file on the application server.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/content.htm.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d42358411d1829f0000e829fbfe/content.htm