Using Text Mode Locate the document in its SAP Library structure

To open a file in text mode, use the IN TEXT MODE addition to the OPEN DATASET statement.

Syntax

OPEN DATASET <dsn> FOR .... IN TEXT MODE.

If you read from or write to a file that is open in text mode, the data is transferred line by line. The system assumes that the file has a line structure.

You should always use text mode if you want to write strings to files or where you know that an existing file has a line construction. You can, for example, use text mode to read files that you have created using any editor on your application server.

Example

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

DATA FNAME(60) VALUE 'myfile'.

DATA: TEXT(4),
      HEX TYPE X.

OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.

TRANSFER '12        ' TO FNAME.
TRANSFER '123456  9 ' TO FNAME.
TRANSFER '1234      ' TO FNAME.

OPEN DATASET FNAME FOR INPUT IN TEXT MODE.

READ DATASET FNAME INTO TEXT.
WRITE / TEXT.
READ DATASET FNAME INTO TEXT.
WRITE  TEXT.
READ DATASET FNAME INTO TEXT.
WRITE  TEXT.

OPEN DATASET FNAME FOR INPUT IN BINARY MODE.

SKIP.
DO.
  READ DATASET FNAME INTO HEX.
  If SY-SUBRC <> 0.
    EXIT.
  ENDIF.
  WRITE HEX.
ENDDO.

The output appears as follows:

12 1234 1234

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

This example opens a file "myfile" for writing in text mode. Three literals with length 10 characters are written to it. After the file has been opened for reading in text mode, the lines are read into the field TEXT (length 4). The first line is filled with two trailing spaces. The last five characters of the second line are truncated. The structure of the file is displayed by opening it in binary mode and reading its contents into the hexadecimal field HEX. The numbers 31 - 36 are the ASCII codes for the digits 1 - 6. 20 is the code for the space character. The end of each line is marked by 0A. Note that any spaces at the end of strings are not written to the file.

 

 

 

Leaving content frame