Entering content frameThis graphic is explained in the accompanying text File Interface Locate the document in its SAP Library structure

 

This example deals with the opening and closing of files.

 

Before Unicode conversion

 

data:

  begin of STRUC,

    F1 type c,

    F2 type p,

  end of STRUC,

 

  DSN(30) type c value 'TEMPFILE'.

 

STRUC-F1 = 'X'.

STRUC-F2 = 42.

 

* Write data to file

open dataset DSN in text mode. ß Unicode error

transfer STRUC to DSN.

close dataset DSN.

* Read data from file

clear STRUC.

open dataset DSN in text mode. ß Unicode error

read dataset DSN into STRUC.

close dataset DSN.

write: / STRUC-F1, STRUC-F2.

 

This example program cannot be executed in Unicode for two reasons. Firstly, in Unicode programs, the file format must be specified more precisely for OPEN DATASET and, secondly, only purely character-type structures can still be written to text files.

 

Depending on whether the old file format still has to be read or whether it is possible to store the data in a new format, there are various possible conversion variants, two of which are introduced here.

 

After Unicode conversion
Case 1: New textual storage in UTF-8 format

....

data:

  begin of STRUC2,

    F1 type c,

    F2(20) type c,

  end of STRUC2.

 

* Put data into text format

move-corresponding STRUC to STRUC2.

 

* Write data to file

open dataset DSN in text mode for output encoding utf-8.

transfer STRUC2 to DSN.

close dataset DSN.

 

* Read data from file

clear STRUC.

open dataset DSN in text mode for input encoding utf-8.

read dataset DSN into STRUC2.

close dataset DSN.

 

move-corresponding STRUC2 to STRUC.

write: / STRUC-F1, STRUC-F2.

 

The textual storage in UTF-8 format ensures that the created files are platform-independent.

 

After Unicode conversion
Case 2: Old non-Unicode format must be retained

...

* Write data to file

open dataset DSN in legacy text mode for output.

transfer STRUC to DSN.

close dataset DSN.

 

* read from file

clear STRUC.

open dataset DSN in legacy text mode for input.

read dataset DSN into STRUC.

close dataset DSN.

write: / STRUC-F1, STRUC-F2.

 

Using the LEGACY TEXT MODE ensures that the data is stored and read in the old non-Unicode format. In this mode, it is also possible to read or write non-character-type structures. However, be aware that data loss and conversion errors can occur in Unicode systems if there are characters in the structure that cannot be represented in the non-Unicode codepage.

Leaving content frame