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: 

Checking a file for Unicode errors

former_member201275
Active Contributor

Hi,

I apologise in advance for the dumb questions I post here.

I would like to test a file on the SAP server for unicode errors, and replace the faulty characters with a default character. For example, we might have 'iński' where the ń is not recognized in our system. What we see in AL11 is in fact 'iE#ski' i.e. the string become longer by 1 character. I am thinking of doing this as per the code below.

  DATA: ltext(340).
  OPEN DATASET sp_filei FOR INPUT IN TEXT MODE ENCODING UTF-8.
  DO.
    READ DATASET sp_filei INTO ltext.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    TRY.
        conv = cl_abap_conv_x2x_ce=>create(
             in_encoding  = '4102'
             out_encoding = '4110'
             input = gv_xstring ).
      CATCH cx_sy_codepage_converter_init.
        MESSAGE a218(fz) WITH in_encoding '4110'.
    ENDTRY.

This of course doesn't work because I am reading the values into a text field and not xstring, however when I use xstring the program dumps.

I need somehow to pick up that that there is a faulty character, in this case 'ń' and replace it with the value available in our mapping table i.e. 'n' (a normal n).

All help greatly appreciated.

1 REPLY 1

cris_hansen
Advisor
Advisor
0 Kudos

Hi Glen,

I'm not sure about programming from scratch, but have you consider the existing tools:

747615 – Tool for converting files from one code page to another
752859 – sapiconv – a tool for converting the encoding of files

Regards,
Cris