Skip to main content

[archive] Create UTF16 text file

  • October 21, 2010
  • 3 replies
  • 0 views

[Migrated content. Thread originally posted on 20 October 2010]

Hi All,

Text files created in Acucobol are typically ASCII.

How do I create a UTF16 text file ?

Any advice/experience would be appreciated.

Thanks in advance.

Juls

3 replies

[Migrated content. Thread originally posted on 20 October 2010]

Hi All,

Text files created in Acucobol are typically ASCII.

How do I create a UTF16 text file ?

Any advice/experience would be appreciated.

Thanks in advance.

Juls
Assuming you are doing this on Windows, here is an example from the Advanced Windows programming training.

In the zip file attached are the following files:


    • config
    • ReadAnsi.txt
    • WriteUnicode.cbl

    config contain the following options:
    [INDENT]SHARED-LIBRARY-LIST Kernel32.DLL
    STRIP-TRAILING-SPACES 1
    CODE-MAPPING 1
    MultiByteToWideChar MultiByteToWideChar@WINAPI
    [/INDENT]
    SHARED-LIBRARY-LIST preloads the Windows DLL Kernel32.dll which has the data conversion API.

    STRIP-TRAILING-SPACES set to 1 inhibits trailing spaces to be written to file.

    CODE-MAPPING set to 1 allow us to call the function by an alias, leaving the decoration in the configuration file

    MultiByteToWideChar set to MultiByteToWideChar@WINAPI allow us to use just MultiByteToWideChar in the call statement, the calling convention is picked in the alias assignment.

    ReadAnsi.txt is just a template file, you can put anything you want in there, alternatively use another file, just remember to change the filename to be opened for input in WriteUnicode.cbl.

    WriteUnicode.cbl is the program that does the translation. The one thing to observe here is that the pic x used for storage of the string is set to 1036. This number is bytes, not code units. If you expect to handle strings longer than 512 UTF-16 code units you should extend this buffer.

    Also take into account that this code does not consider the possibility of surrogate pairs.

    To compile:
    ccbl32 WriteUnicode.cbl
    To run:
    wrun32 -c config WriteUnicode

[Migrated content. Thread originally posted on 20 October 2010]

Hi All,

Text files created in Acucobol are typically ASCII.

How do I create a UTF16 text file ?

Any advice/experience would be appreciated.

Thanks in advance.

Juls
Looks great. WIll give it a go.

Thanks a lot.

[Migrated content. Thread originally posted on 20 October 2010]

Hi All,

Text files created in Acucobol are typically ASCII.

How do I create a UTF16 text file ?

Any advice/experience would be appreciated.

Thanks in advance.

Juls
Looks great. WIll give it a go.

Thanks a lot.