Application Development 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: 

Validate File is of type utf-8 ??

former_member194669
Active Contributor
0 Kudos

Hi,

I have file is in appl server . before reading this file i need to validate whether the file is utf-8 or not.

ie

Before calling OPEN DATASET

Any Info?

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello

Please have a look at the following sources:

[Unicode File Handling in ABAP|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2194] [original link is broken] [original link is broken] [original link is broken];

[Unicode Interface|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10fe20ed-b611-2a10-a2ba-d5665779c10c]

[Unicode Interfaces (TechED)|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e0928b44-b811-2a10-7599-cc4bb6585c46]

Regards

Uwe

5 REPLIES 5

Former Member
0 Kudos

hi check this...

fgetc is an C function to read your file bytes and is detecting a problem with charset encoding.

Check your profile file =/usr/sap/PRD/SYS/profile/PRD_DVEBMGS00_ap-s-sap is encoded with UTF-8 charset. You can use "file" command (see man file) or your text editor (Are you on unix or linux?).

You may also check the default encoding for your system with command "locale charmap" (maybe it is iso-8859-1 or ASCII if you are using unix). Check also whether your system has UTF-8 locale support enabled (command "locale -a"). Check the contents of the env valiable LANG, because you are using the locale informed in this variable.

C libraries use the encoding specified in env variable LC_CTYPE or LANG (In that order)

Your SAP system expects UTF-8 because your SAP installation may be Unicode.

regards,

venkat

0 Kudos

Any Info?

a®s.

uwe_schieferstein
Active Contributor
0 Kudos

Hello

Please have a look at the following sources:

[Unicode File Handling in ABAP|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2194] [original link is broken] [original link is broken] [original link is broken];

[Unicode Interface|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10fe20ed-b611-2a10-a2ba-d5665779c10c]

[Unicode Interfaces (TechED)|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e0928b44-b811-2a10-7599-cc4bb6585c46]

Regards

Uwe

0 Kudos

Uwe,

Your reply got solution for my issue.

please find below is code for my sulution.


  cl_abap_file_utilities=>check_utf8(
        exporting file_name = p_file
        importing encoding = lv_encoding ).

  if lv_encoding = cl_abap_file_utilities=>encoding_utf8.
     open dataset p_file for input in text mode          
            encoding utf-8 skipping byte-order mark.           
  else.                                                  
     open dataset p_file for input in text mode
            encoding default.
  endif.               

Former Member
0 Kudos

HI,

Try using the fallowing simple code,it will determine the file is UTF-8 or not.

cl_abap_file_utilities=>check_for_bom( <File Name> ) = cl_abap_file_utilities=>bom_utf8.

BR,

Rajani Kanth