Skip to main content

Problem:

How to convert to UTF-8 format in Cobol?

Resolution:

This documented in a Microsoft SQL article (Q232580):-

Translate to and from UCS-2 or UTF-8 as appropriate within the application. Sample code for this type of conversion is located at the Unicode Consortium's site:

<http://www.unicode.org/Public/PROGRAMS/CVTUTF>

A high-level description of the algorithm to convert UCS-2 to UTF-8 can be found in the Internet Request For Comments document RFC2279.

On Windows NT or Windows 2000, you may use the Win32 functions MultiByteToWideChar and WideCharToMultiByte to convert UTF-8 to and from UCS-2 by passing the constant CP_UTF8 (65001) as the first parameter to the functions.

If you can live with a Win32 only solution the api calls will give you the easiest solution.

Old KB# 3852