Problem :
The customer creates a UTF8 file and want to print it with a Cobol application .
What does he do
Solution:
It is necessary to use the Operating system commands or functions .
The generic name is iconv .
The follow Cobol program is a subprogram to convert a UTF8 buffer to a CP864 buffer , with four parameters :
The UTF8 buffer (input)
The CP864 buffer ( output )
The size of the UTF8 buffer
The size of the CP864 buffer
The operating system is a Linux operating system :
WORKING-STORAGE SECTION.
78 pfx value " *--> ".
78 OK value " <OK> ".
78 KO value " <KO> ".
01 int pic s9(9) comp-5 is typedef.
78 iconv_open value "iconv_open".
78 iconv_close value "iconv_close".
78 iconv value "iconv".
78 CodeSetLength value 20.
01 CodeSet_UTF-16 pic x(CodeSetLength) value z"CP864".
01 CodeSet_UTF-8 pic x(CodeSetLength) value z"UTF-8".
01 iconv_tPtr pointer.
01 iconv_tint int redefines iconv_tPtr.
88 iconv_tPtrKO value -1.
01 anInt int.
01 InBufPtr pointer.
01 OutBufPtr pointer.
01 InBytesLeft int.
01 OutBytesLeft int.
78 testStrLenNat value 200.
78 testStrLenAsc value testStrLenNat * 2.
01 ascOriLen int.
01 NatUTF16 PIC x(testStrLenNat).
01 NatUTF16sav PIC x(testStrLenNat).
01 NatUTF16len int.
01 NatUTF8 PIC X(testStrLenAsc).
01 NatUTF8len int.
01 ascDest PIC X(testStrLenAsc) value spaces.
LINKAGE SECTION.
01 ls-CodeSet_ToCode pic x(CodeSetLength).
01 ls-CodeSet_FromCode pic x(CodeSetLength).
01 ls-InBufPtr pic x any length.
01 ls-OutBufPtr pic x any length.
01 ls-InBufLen int.
01 ls-OutBufLen int.
01 lnk1 pic x(500).
01 lnk2 pic x(500).
01 lnk3 pic 9(5).
01 lnk4 pic 9(5).
PROCEDURE DIVISION using lnk1 lnk2 lnk3 lnk4.
perform testCONV.
EXIT PROGRAM.
testCONV.
call iconv_open using
CodeSet_UTF-16
CodeSet_UTF-8
returning iconv_tPtr
move lnk3 to NatUTF16len NatUTF8len
initialize NatUTF16
move lnk1 to natutf8
call "strlen" using NatUTF8 returning NatUTF8len
set InBufPtr to address of lnk1
set OutBufPtr to address of natutf16
call iconv using by value iconv_tPtr
by reference InBufPtr
natutf8len
OutBufPtr
natutf16len
returning anInt.
call iconv_close using
by value iconv_tPtr
returning anInt.
move natutf16 ( 1 : natutf16len ) to lnk2 .
move natutf16len to lnk4.
.

