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 problem with UTF-8

Former Member
0 Likes
8,138

Hi frnds,

Problem details: We have to read file from applicaitn server, In the file data its having special characters like "Uherské Hradiu0161te". when i m trying to read the file, Data is comming but the special character are not comming, inthe place of special characters its giving spcae r #..

Below is the code i m trying

************************************************************************************************

DATA: lw_filepath TYPE rlgrap-filename value '/011/test.txt', " application server path.

lw_empty TYPE flag,

lw_lineno(8) TYPE c,

index TYPE i,

infile(1500) TYPE C.

*Read the file from the application server and put the records into the INFILE internal table

  • Open File

OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING UTF-8 REPLACEMENT CHARACTER space.

*OPEN DATASET lw_filepath IN legacy text MODE for INPUT.

*OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING DEFAULT.

  • OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING DEFAULT REPLACEMENT CHARACTER space.

  • OPEN DATASET lw_filepath IN TEXT MODE ENCODING UTF-8 set-loacal lange iwth countery key FOR INPUT REPLACEMENT CHARACTER space.

IF sy-subrc <> 0.

RAISE open_failure.

ENDIF.

  • Initialize empty file flag

lw_empty = 'X'.

  • Read the rest of the records until EOF

DO.

CLEAR infile.

TRY.

READ DATASET lw_filepath INTO infile.

CATCH cx_sy_conversion_codepage.

ENDTRY.

WRITE: / infile.

if infile is initial.

exit.

endif.

ENDDO.

  • Close file

CLOSE DATASET lw_filepath.

***************************************************************************************

Below is the applicaiton server file data: test.txt having some special characters

Velký Velký Hložkova Nádražní Želechovice Uherské Hradiu0161teZlín Mládí

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,568

Hi,

Incase you need the special characters you will have to use ENCODING as UTF-8.

if you use the encoding as NON-UNICODE; then you special characters will be converted into #.

This is because as per UNICODE standards special charaters require 2 byte of memory space.

Regards,

Ankur Parab

Hi frnds,

Problem details: We have to read file from applicaitn server, In the file data its having special characters like "Uherské Hradiu0161te". when i m trying to read the file, Data is comming but the special character are not comming, inthe place of special characters its giving spcae r #..

Below is the code i m trying

************************************************************************************************

DATA: lw_filepath TYPE rlgrap-filename value '/011/test.txt', " application server path.

lw_empty TYPE flag,

lw_lineno(8) TYPE c,

index TYPE i,

infile(1500) TYPE C.

*Read the file from the application server and put the records into the INFILE internal table

  • Open File

OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING UTF-8 REPLACEMENT CHARACTER space.

*OPEN DATASET lw_filepath IN legacy text MODE for INPUT.

*OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING DEFAULT.

  • OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING DEFAULT REPLACEMENT CHARACTER space.

  • OPEN DATASET lw_filepath IN TEXT MODE ENCODING UTF-8 set-loacal lange iwth countery key FOR INPUT REPLACEMENT CHARACTER space.

IF sy-subrc <> 0.

RAISE open_failure.

ENDIF.

  • Initialize empty file flag

lw_empty = 'X'.

  • Read the rest of the records until EOF

DO.

CLEAR infile.

TRY.

READ DATASET lw_filepath INTO infile.

CATCH cx_sy_conversion_codepage.

ENDTRY.

WRITE: / infile.

if infile is initial.

exit.

endif.

ENDDO.

  • Close file

CLOSE DATASET lw_filepath.

***************************************************************************************

Below is the applicaiton server file data: test.txt having some special characters

Velký Velký Hložkova Nádražní Želechovice Uherské Hradiu0161teZlín Mládí

16 REPLIES 16
Read only

Former Member
0 Likes
4,568

try this

OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING NON-UNICODE

Read only

0 Likes
4,568

Thanks for responding krishna murty,

I tried that also, still i m getting # in place of some spl characters.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,568

Hello,

I tried using

OPEN DATASET lw_filepath FOR INPUT IN TEXT MODE ENCODING DEFAULT.

And i have the data after READ DATASET. Can you plz clarify why you need ENCODING UTF-8?

BR,

Suhas

Read only

Former Member
0 Likes
4,568

Hi

I tried with OPEN DATASET lw_filepath FOR INPUT IN TEXT MODE ENCODING DEFAULT this also.

but its now roking.

we need to read UNICODE data. can u check the test data, above i provided

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,568

Hello,

I tried with your test data only & it is working fine for me. BTW what do you mean by :

we need to read UNICODE data

Plz revert back.

Read only

Former Member
0 Likes
4,568

can you suggest me i need changes setting in SAP logoin or any properties

In my system logon -> change item-> in that Code page tab.

Language is Default and Unicode off check box is unchecked.

upload/download Encoding is "default - ANSI for Unicode system"

can you tel me u r settings

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,568

Hello,

You hit the nail right on the head ) The encoding must be "Default - ANSI for Uinicode systems".

Hope this helps.

BR,

Suhas

Read only

Former Member
0 Likes
4,568

HI,

SAP offers F1 help too.. just press F1 on OPEN DATASET !

then on ENCODING DEFAULT..... should work for you.

for more info, F1.

Regards, Bin

Read only

Former Member
0 Likes
4,569

Hi,

Incase you need the special characters you will have to use ENCODING as UTF-8.

if you use the encoding as NON-UNICODE; then you special characters will be converted into #.

This is because as per UNICODE standards special charaters require 2 byte of memory space.

Regards,

Ankur Parab

Read only

0 Likes
4,568

Hi Ankur Parab ,

s i m using UTF-8, but its not working. In the place of spl character its comming space or # symbol.

below is the stmt

OPEN DATASET l_filepath IN TEXT MODE FOR INPUT ENCODING UTF-8 REPLACEMENT CHARACTER space.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,568

>

> Hi,

> Incase you need the special characters you will have to use ENCODING as UTF-8.

> if you use the encoding as NON-UNICODE; then you special characters will be converted into #.

>

> This is because as per UNICODE standards special charaters require 2 byte of memory space.

>

> Regards,

> Ankur Parab

Hello Ankur,

And on what basis are you claiming this?

BR,

Suhas

Read only

0 Likes
4,568

Hi,

Please do F1 on UTF-8

UTF-8

8 bit Unicode character representation. ASCII characters are represented by one byte. Other European characters are represented in 2 bytes. Most Asian characters are represented in 3 bytes. The characters in the surrogate area are addressed directly using 4 bytes.

Regards,

Ankur Parab

Read only

0 Likes
4,568

Thanks Ankur Parab,

we have to use UTF-16 for this problem. but can u plz explain me how can i use this formate in my ABAP program.

below one i m using.

OPEN DATASET lw_filepath IN TEXT MODE FOR INPUT ENCODING UTF-8 REPLACEMENT CHARACTER space.

UTF-8 because of this the spl character are not comming. how can i use UTF-16 in my program.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,568

Hello Ankur,

You may be aware of something called Code Page. This is where code-page comes into picture. Differenet character sets have different Code Page representations.

I think what you are talking about is Code Page & not encoding.

Hope i am clear.

BR,

Suhas

Read only

Former Member
0 Likes
4,568

Some of the languages "Code pages" are not supported in "EN" login. Try loggin in into corresponding language log in (RU for Russia, RO for Romania etc..).

Read only

Former Member
0 Likes
4,568

To avoid # use,

REPLACE ALL OCCURRENCES OF '#' IN infile WITH 'Special Character'.

Thanks and Regards