cancel
Showing results for 
Search instead for 
Did you mean: 

report

Former Member
0 Kudos

hi

how to Sending the file to Application Server.

i used this:

OPEN DATASET P_FIL_AS fOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC ne 0.

MESSAGE E001. "Unable to open the file

else.

LOOP AT I_FINAL_TABLE INTO WA_FINAL.

LV_FILE = WA_FINAL.

TRANSFER LV_FILE TO P_FIL_AS.

ENDLOOP.

ENDIF.

CLOSE DATASET P_FIL_AS.

plse guide me.

thanks with regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

Take a look at the SAP Help. It gives you information with exmaples.

Writing Data to Files

To write data to a file on the application server, use the TRANSFER statement:

Syntax

TRANSFER <f> to <dsn> [LENGTH <len>].

This statement writes the values of the field <f> into the file <dsn>. You can specify the transfer mode in the OPEN DATASET statement. If you have not already opened the file for writing, the system tries to open it either in binary mode, or using the additions from the last OPEN DATASET statement. However, it is good practice only to open files using the OPEN DATASET statement. For further information about the OPEN DATASET statement and the naming conventions for files, refer to Opening a File. <f> can have an elementary data type, but may also be a structure, as long as it does not contain an internal table. You cannot write internal tables into files in a single step.

You can specify the length of the data you want to transfer using the LENGTH addition. The system then transfers the first <len> bytes into the file. If <len> is too short, excess bytes are truncated. If <len> is greater than the length of the field, the system adds trailing blanks.

The following program shows how you can write internal tables into a file:

DATA FNAME(60) VALUE 'myfile'.

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

DATA: LIN TYPE LINE,

TAB TYPE ITAB.

DO 5 TIMES.

LIN-COL1 = SY-INDEX.

LIN-COL2 = SY-INDEX ** 2.

APPEND LIN TO TAB.

ENDDO.

OPEN DATASET FNAME FOR OUTPUT.

LOOP AT TAB INTO LIN.

TRANSFER LIN TO FNAME.

ENDLOOP.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO LIN.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE: / LIN-COL1, LIN-COL2.

ENDDO.

CLOSE DATASET FNAME.

The output is:

1 1

2 4

3 9

4 16

5 25

In this example, a structure LIN and an internal table TAB with line type LINE are created. Once the internal table TAB has been filled, it is written line by line into the file "myfile". The file is then read into the structure LIN, whose contents are displayed on the screen.

The following example works in R/3 Systems that are running on UNIX systems using ASCII.

DATA FNAME(60) VALUE 'myfile'.

DATA: TEXT1(4) VALUE '1234',

TEXT2(8) VALUE '12345678',

HEX TYPE X.

OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.

TRANSFER: TEXT1 TO FNAME LENGTH 6,

TEXT2 TO FNAME LENGTH 6.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO HEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE HEX.

ENDDO.

CLOSE DATASET FNAME.

The output is:

31 32 33 34 20 20 0A 31 32 33 34 35 36 0A

This example writes the strings TEXT1 and TEXT2 to the file "myfile" in text mode. The output length is set to 6. By reading the file byte by byte into the hexadecimal field, you can see how it is stored. The numbers 31 to 36 are the ASCII codes for the digits 1 to 6. 20 is a space, and 0A marks the end of the line. TEXT1 is filled with two trailing spaces. Two characters are truncated from TEXT2.

Cheers

VJ

Answers (3)

Answers (3)

vinod_gunaware2
Active Contributor
0 Kudos

Reading and Writing a text file from and to the application server

  • sy-subrc = 0 Record read from file

  • sy-subrc = 4 End of file reached

data: w_dataset1(27) value '/var/textfile.txt',

w_dataset2(27) value '/var/outfile.txt'.

data:begin of itab1 occurs 0, "Text file format

matnr(18), "MATERIAL NUMBER

bwkrs(4), "PLANT

end of itab1.

*Uploading of text file from Application server.

open dataset w_dataset1 for input in text mode.

do.

if sy-subrc <> 0.

exit.

endif.

read dataset w_dataset1 into itab1.

append itab1.

clear itab1.

enddo.

close dataset w_dataset1.

*Downloading of text file to Application server.

open dataset w_dataset2 for output in text mode.

loop at itable.

transfer itable to w_dataset2.

endloop.

close dataset w_dataset2.

<b>USe CG3X,CG3Y,CG3Z and AL11</b>regards

vinod

Former Member
0 Kudos

USE TRANSACTION...

1. CG3Z

2. we can use the above tcode for this purpose.

3. Internall it calls this FM.

C13Z_FRONT_END_TO_APPL

Former Member
0 Kudos

Hi,

This looks fine.

What is the problem you are facing?

Regards,

Ravi

Note : Please mark the helpful answers