Absent Member.
Absent Member.

[archive] Create UTF16 text file

[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.

2 Replies
Absent Member.
Absent Member.

RE: [archive] Create UTF16 text file

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:
    MultiByteToWideChar MultiByteToWideChar@WINAPI
    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
Absent Member.
Absent Member.

RE: [archive] Create UTF16 text file

Looks great. WIll give it a go.

Thanks a lot.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.