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

data transfer

Former Member
0 Likes
721

Hi ,

to get file from application server and store the data in the r/3 system custom table.

Can anybody give idea.

cheers

Bab

5 REPLIES 5
Read only

Former Member
0 Likes
682

Hi,

Get the path of the data to be read,

Perform the open dataset operation and afterwards perform read dataset operation.and at the end perform the close dataset operation.

Syntax:

OPEN DATASET P_DATASET

FOR INPUT IN TEXT MODE

ENCODING DEFAULT.

do.

read dataset dataset into record.

APPEND record.

enddo.

CLOSE DATASET P_DATASET.

now you will have the data in the record internal table. Use Insert statement to update the data into the table.

Reward me if it is helpful.

Thanks,

Prasnanna

Read only

Former Member
0 Likes
682

Hi,

FORM write_applserv.

CLEAR: wa_output,

wf_path.

  • Function to get the file name and path

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

client = sy-mandt

logical_filename =

operating_system = sy-opsys

IMPORTING

file_name = wf_path

EXCEPTIONS

file_not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

wf_empty_flag = 1.

  • If file path does not exist then Exit.

EXIT.

ENDIF.

  • Convert the date to short-time-stamp.

CLEAR: wf_time.

TRANSLATE wf_path TO LOWER CASE.

TRANSLATE wf_filename TO LOWER CASE.

OPEN DATASET wf_filename FOR OUTPUT IN TEXT MODE.

IF sy-subrc <> 0.

wf_empty_flag = 3.

EXIT.

ENDIF.

IF NOT tb_output[] IS INITIAL.

LOOP AT tb_output INTO wa_output.

TRANSFER wa_output1 TO wf_filename.

CLEAR : wa_output1,

wa_output.

ENDLOOP.

CLOSE DATASET wf_filename.

ELSE.

  • If output internal table is not filled.

  • Pass an empty record.

TRANSFER wa_output1 TO wf_filename.

wf_empty_flag = 2.

ENDIF.

CLOSE DATASET wf_filename.

ENDFORM. " write_applserv

Check this peace of code in which change accordinlgy to ur requirement,

Then go to T-code AL11 check the path name

Thanks

Mohinder Singh Chauhan

Read only

Former Member
0 Likes
682

try this:

OPEN DATASET filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

READ DATASET filename INTO string.

APPEND records of string TO it_record.

CLOSE DATASET file.

Open Dataset is used to read or write on to application server ... other than that i am not sure that there exists any way to do the same ... here is a short description for that

FILE HANDLING IN SAP

Introduction

• Files on application server are sequential files.

• Files on presentation server / workstation are local files.

• A sequential file is also called a dataset.

Handling of Sequential file

Three steps are involved in sequential file handling

• OPEN

• PROCESS

• CLOSE

Here processing of file can be READING a file or WRITING on to a file.

OPEN FILE

Before data can be processed, a file needs to be opened.

After processing file is closed.

Syntax:

OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}

IN {TEXT/BINARY} MODE

This statement returns SY_SUBRC as 0 for successful opening of file or 8, if unsuccessful.

OUTPUT: Opens the file for writing. If the dataset already exists, this will place the cursor at the start of the dataset, the old contents get deleted at the end of the program or when the CLOSE DATASET is encountered.

INPUT: Opens a file for READ and places the cursor at the beginning of the file.

FOR APPENDING: Opens the file for writing and places the cursor at the end of file. If the file does not exist, it is generated.

BINARY MODE: The READ or TRANSFER will be character wise. Each time ‘n’’ characters are READ or transferred. The next READ or TRANSFER will start from the next character position and not on the next line.

IN TEXT MODE: The READ or TRANSFER will start at the beginning of a new line each time. If for READ, the destination is shorter than the source, it gets truncated. If destination is longer, then it is padded with spaces.

Defaults: If nothing is mentioned, then defaults are FOR INPUT and in BINARY MODE.

PROCESS FILE:

Processing a file involves READing the file or Writing on to file TRANSFER.

TRANSFER Statement

Syntax:

TRANSFER <field> TO <file name>.

<Field> can also be a field string / work area / DDIC structure.

Each transfer statement writes a statement to the dataset. In binary mode, it writes the length of the field to the dataset. In text mode, it writes one line to the dataset.

If the file is not already open, TRANSFER tries to OPEN file FOR OUTPUT (IN BINARY MODE) or using the last OPEN DATASET statement for this file.

IF FILE HANDLING, TRANSFER IS THE ONLY STATEMENT WHICH DOES NOT RETURN SY-SUBRC

READ Statement

Syntax:

READ DATASET <file name> INTO <field>.

<Field> can also be a field string / work area / DDIC structure.

Each READ will get one record from the dataset. In binary mode it reads the length of the field and in text mode it reads each line.

CLOSE FILE:

The program will close all sequential files, which are open at the end of the program. However, it is a good programming practice to explicitly close all the datasets that were opened.

Syntax:

CLOSE DATASET <file name>.

SY-SUBRC will be set to 0 or 8 depending on whether the CLOSE is successful or not.

DELETE FILE:

A dataset can be deleted.

Syntax:

DELETE DATASET <file name>.

SY-SUBRC will be set to 0 or 8 depending on whether the DELETE is successful or not.

Pseudo logic for processing the sequential files:

For reading:

Open dataset for input in a particular mode.

Start DO loop.

Read dataset into a field.

If READ is not successful.

Exit the loop.

Endif.

Do relevant processing for that record.

End the do loop.

Close the dataset.

For writing:

Open dataset for output / Appending in a particular mode.

Populate the field that is to be transferred.

TRANSFER the filed to a dataset.

Close the dataset.

chk a sampel

parameters: p_file like rlgrap-filename obligatory

default '/usr/sap/upload.xls'.

types: begin of t_data,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

werks like vbap-werks,

megne like vbap-zmeng,

end of t_data.

data: it_data type standard table of t_data,

wa_data type t_data.

open dataset p_file for output in text mode encoding default.

if sy-subrc ne 0.

write:/ 'Unable to open file:', p_file.

else.

do.

read dataset p_file into wa_data.

if sy-subrc ne 0.

exit.

else.

append wa_data to it_data.

endif.

enddo.

close dataset p_file.

endif.

And if you want to write on the file.

open UNIX file

open dataset unixfile for output in text mode message w_msg.

if sy-subrc ne 0.

write: / 'Cannot open for writing:', unixfile, w_msg.

exit.

endif.

write UNIX file

loop at it_file.

transfer it_file to unixfile.

endloop.

close UNIX file

close dataset unixfile.

Read only

Former Member
0 Likes
682

bab,

1 First get the records from file into internal table.:

DATA: ld_file LIKE rlgrap-filename.

    • Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 like pa0002-VORNA,

name2 like pa0002-name2,

age type i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Text version of data table

TYPES: begin of t_uploadtxt,

name1(10) type c,

name2(15) type c,

age(5) type c,

end of t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) type c.

OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

ELSE.

DO.

CLEAR: wa_string, wa_uploadtxt.

READ DATASET ld_file INTO wa_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

wa_uploadtxt-name2

wa_uploadtxt-age.

MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.

APPEND wa_upload TO it_record.

ENDIF.

ENDDO.

CLOSE DATASET ld_file.

2.Based on table insert the data into table.

UPDATE dbtab FROM TABLE itab. or UPDATE (dbtabname) FROM TABLE itab.

Note: itab should have the same structure of database table

otherwise use another syntax to store the data into database table....

*UPDATE dbtab SET f1 ... fn. *

Read only

Former Member
0 Likes
682

>

> Hi ,

>

> to get file from application server and store the data in the r/3 system custom table.

> Can anybody give idea.

>

>

> cheers

> Bab

Hi,

Using data sets we can read file from application server and we can load data into r/3 data base.

for this we have to follow the steps...

open_data_set <file_name>.

with this the will identify and it is in open mode to read data.

read data_set

with this the data is reading from file and the data is stored in internal table.

transfer file to internal table.

with this statement the data is transfered from flat file in application server to internal table.

*note : the only key word which does not returns sy-subrc is transfer keyword.'*

regards,

swami.