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

Write a data into a file in UTF-16 format

Former Member
0 Likes
3,302

Hello Experts,

I want to create a datafile in UTF-16 format.

OPEN DATASET does not support a UTF-16 format.

How can i create a file in such a format.

Thanks in advance.....

fract

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
2,477

OPEN DATASET will support but a UTF-16 file can only be opened as a binary file.

Check this

http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_MODE.htm#!ABAP_ALTERNATIVE_3@3@

11 REPLIES 11
Read only

Former Member
0 Likes
2,477

you can convert the data with these objects

CL_ABAP_CONV_OUT_CE Code Page and Endian Conversion (System Format -> External


      TRY.
            CALL METHOD cl_abap_conv_out_ce=>create
              EXPORTING
                encoding = 'UTF-16'
              RECEIVING
                conv     = yourstring_sap.

*         get result
          CALL METHOD l_convout->get_buffer
            RECEIVING
              buffer = yourbinarystring_utf16

        CATCH cx_root.
* Your error handling
* Check if you have an error and UTF-16 realy works
      ENDTRY.

and then write the data binary in a file the same way only as binary

Rene

Code Formatted by: Alvaro Tejada Galindo on Jan 4, 2010 5:38 PM

Read only

former_member194669
Active Contributor
0 Likes
2,478

OPEN DATASET will support but a UTF-16 file can only be opened as a binary file.

Check this

http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_MODE.htm#!ABAP_ALTERNATIVE_3@3@

Read only

0 Likes
2,477

I am extracting data from Japanese system and i want to write that data into a file in UTF-16 LITTLE ENDIAN format .

Do i need to use Code Page with LITTLE ENDIAN or LITTLE ENDIAN is enough or both?

OPEN DATASET V_FILE FOR OUTPUT IN LEGACY BINARY MODE LITTLE ENDIAN CODE PAGE '4103'.

Thanks,

fract

Read only

0 Likes
2,477

Only CODEPAGE is necessary


OPEN DATASET V_FILE FOR OUTPUT IN LEGACY BINARY MODE CODE PAGE '4103'.

Read only

0 Likes
2,477

I am getting this short dump. Where is the problem?

Runtime Errors CONVT_CODEPAGE_INIT

Except. CX_SY_CODEPAGE_CONVERTER_INIT

Short text

The conversion of certain code pages is not supported.

What happened?

The conversion of texts in code page '4103' to code page '4103' is not

supported here.

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_CODEPAGE_CONVERTER_INIT', was

not caught in procedure "DOWNLOAD_DATA" "(FORM)", nor was it propagated by a

RAISING clause.

Since the caller of the procedure could not have anticipated that the

exception would occur, the current program is terminated.

The reason for the exception is:

Possibly, one of the codepages '4103' or '4103' - needed for the

conversion - is unknown to the system. Another option is, that a Unicode

codepage was specified for a file in LEGACY MODE, which is not allowed.

Additional parameters for the codepage conversion (as , for example, the

replacement character) might have invalid values. You can find further

information under 'Inernal notes'.

If the problem occurred at opening, reading, or writing of a file, then

the file name was '
SAPT01\DATA\DEV\t001-20091231.dat'. (Further

information about this file: " 쬞")

>>>>>     OPEN DATASET V_FILE FOR OUTPUT IN LEGACY BINARY MODE CODE PAGE '4103'.
   IF SY-SUBRC NE 0.
     CONCATENATE 'File open error' V_FILE INTO WA_ERR_LOG.
    ENDIF.
 
 CLEAR WA_DATA.
    LOOP AT ITAB INTO WA_DATA.
 
     TRANSFER WA_DATA TO V_FILE.
    ENDLOOP.
    CLOSE DATASET V_FILE.

Read only

0 Likes
2,477

Hi,

Try with the addition IGNORING CONVERSION ERRORS with the OPEN DATASET statement


OPEN DATASET V_FILE FOR OUTPUT IN LEGACY BINARY MODE CODE PAGE '4103' IGNORING CONVERSION ERRORS.
   IF SY-SUBRC NE 0.
     CONCATENATE 'File open error' V_FILE INTO WA_ERR_LOG.
    ENDIF.
 
 CLEAR WA_DATA.
    LOOP AT ITAB INTO WA_DATA.
 
     TRANSFER WA_DATA TO V_FILE.
    ENDLOOP.
    CLOSE DATASET V_FILE.

Vikranth

Read only

0 Likes
2,477

Hi,

I tried with the following statement but same short dump.

OPEN DATASET V_FILE FOR OUTPUT IN LEGACY BINARY MODE CODE PAGE '4103' IGNORING CONVERSION ERRORS.

Read only

0 Likes
2,477

Hi

Your shortdump looks to me as your system uses 4103 code page and therefor a conversion is not needed.

If you write directly in text mode this should be fine. If this is not what you want; try:

open DATASET vfile for OUTPUT in LEGACY TEXT MODE BIG ENDIAN CODE PAGE '4103'.

Happy new year.

Read only

0 Likes
2,477

I tried but still short dump. Is there any other solutions....

Read only

0 Likes
2,477

So if the short dump is the same, this emans you are in a 4103 encoded system?

What is your default codepage?

Read only

0 Likes
2,477

You can also check if 4103 is even an option in your system.

Use transaction SCP to see what is there.

Rene