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

Open Dataset Character Encoding Error with binary file preparation.

Former Member
0 Likes
2,803

Hi Team,

We have UNIX & LINUX application servers in our system.

I am writing binay files on application servers. If I am using same set of application servers while reading and writing binary files, I am able to access the data as expected. If I have written file using UNIX application server and while reading If i use Linux platform character encoding error happen as a result JUNK characters are displaying.

Reason for the error is unix server uses big endian format while preparing binary file, where as linux server uses little endian format for accessing binary file format.

If I tried restristing data written format as big endian/little endian addition the open dataset statement, special characters are getting converted into '#' character.

Could you advice further how to proceed .

Thanks in advance.

Regards.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,690

Hi Bysani,

I assume you have Unicode systems, right?

I don't understand why you write the dataset as being a binary file, while it really contains characters. Did you make a code page conversion before writing the file? In which code page?

Here is an example what might happen : Let's say the "writer" application server (AS) is big endian (BE), it writes the file in BE ("&" = 2 bytes 00 and 26 in hexadecimal). If the "reader" AS is LE, and you make it read in binary, it will transfer the BE bytes of the file into memory that will be incorrectly interpreted in LE format (0026 will be interpreted as Unicode U+2600, which is ਨ).

If you tell the reader AS (LE) to read the file, saying that the characters are BE, the system will convert from BE to LE (though I don't understand why you have #, there's probably something to investigate about what was initially written), but what happens now if the writer ABAP program runs on the AS in LE, and the reader ABAP program runs on the AS in BE : the reader program says the file is BE, which is wrong, so it will not convert (from BE to BE), and the byte order will be incorrect again.

The best way to write text files is to write them in text mode, not binary mode, in an exact code page (for example, UTF-8 for occidental (it is the defaut for OPEN DATASET IN TEXT MODE, in a Unicode system), and UTF-16, let's say LE, for CJK), so that the program can decode it without any problem.

BR

Sandra

6 REPLIES 6
Read only

Former Member
0 Likes
1,690

Hi,

Can you try adding IGNORING CONVERSION ERRORS & let us know if it works.

OPEN DATASET ............... IGNORING CONVERSION ERRORS

Thanks,

Best regards,

Prashant

Read only

0 Likes
1,690

Hi,

When I use this addition special characters like grrek and france characters are converted into '#'.

I can use this addition only with Legacy Binary Big Endian addition only.

Regards,

Bysani.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,691

Hi Bysani,

I assume you have Unicode systems, right?

I don't understand why you write the dataset as being a binary file, while it really contains characters. Did you make a code page conversion before writing the file? In which code page?

Here is an example what might happen : Let's say the "writer" application server (AS) is big endian (BE), it writes the file in BE ("&" = 2 bytes 00 and 26 in hexadecimal). If the "reader" AS is LE, and you make it read in binary, it will transfer the BE bytes of the file into memory that will be incorrectly interpreted in LE format (0026 will be interpreted as Unicode U+2600, which is ਨ).

If you tell the reader AS (LE) to read the file, saying that the characters are BE, the system will convert from BE to LE (though I don't understand why you have #, there's probably something to investigate about what was initially written), but what happens now if the writer ABAP program runs on the AS in LE, and the reader ABAP program runs on the AS in BE : the reader program says the file is BE, which is wrong, so it will not convert (from BE to BE), and the byte order will be incorrect again.

The best way to write text files is to write them in text mode, not binary mode, in an exact code page (for example, UTF-8 for occidental (it is the defaut for OPEN DATASET IN TEXT MODE, in a Unicode system), and UTF-16, let's say LE, for CJK), so that the program can decode it without any problem.

BR

Sandra

Read only

0 Likes
1,690

Hi,

I need to prepare binary files only, I can't change it to TEXT mode.

Could you guide me how to do code page conversion, multiple languages are installed on my system.

Regards.

Read only

0 Likes
1,690

Hi,

I recently had a similar issue with one of our programs because we are upgrading our systems from non-unicode to unicode and I was able to correct the problem by changing the previous code like so:

old - OPEN DATASET ... IN BINARY MODE

new - OPEN DATASET ... IN LEGACY BINARY MODE (the previous error character was a newline and this addition allowed the system to ignore the problem)

Hope it helps... Regards

Read only

nils_buerckel
Product and Topic Expert
Product and Topic Expert
0 Likes
1,690

Hi,

please use TEXT mode with UTF8 (in all cases). As far as I know, this is the only easy solution for this problem, as UTF-8 is platform independent.

Please also have a look at SAP note 1310720.

Best regards,

Nils Buerckel