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 transfer using Code page

0 Likes
475

Hi friends,

Please provide me some sample program how to use "code page" statement in "READ OPENDATASET" command to create/modify the application server files.

Thanks & Regards,

Thayalan

1 REPLY 1
Read only

christian_wohlfahrt
Active Contributor
0 Likes
353

Hi!

In general you can make something like the following(extend SAP-help):


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.

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.

Instead of legacy text mode you can define a specific codepage. Have a look in table TCP00 for available codepages in SAP.

Regards,

Christian