Utilisation des API iconv pour chgt CCSID

BoTTom |
       * iconv() demo
     H DFTACTGRP(*NO) ACTGRP(*NEW)
     H BNDDIR('QC2LE')
 
     d iconv_t         DS                  based(prototype_only)
     d   return_value                10I 0
     d   cd                          10I 0 dim(12)
 
     d from            DS
     d  from_CCSID                   10I 0
     d  from_ConvAlt                 10I 0 inz(0)
     d  from_SubsAlt                 10I 0 inz(0)
     d  from_ShiftAlt                10I 0 inz(1)
     d  from_InpLenOp                10I 0 inz(0)
     d  from_ErrorOpt                10I 0 inz(1)
     D  from_Reserved                 8A   inz(*ALLx'00')
 
     d to              DS
     d  to_CCSID                     10I 0
     d  to_ConvAlt                   10I 0 inz(0)
     d  to_SubsAlt                   10I 0 inz(0)
     d  to_ShiftAlt                  10I 0 inz(1)
     d  to_InpLenOp                  10I 0 inz(0)
     d  to_ErrorOpt                  10I 0 inz(1)
     D  to_Reserved                   8A   inz(*ALLx'00')
 
     d QtqIconvOpen    PR                  extproc('QtqIconvOpen')
     d                                     like(iconv_t)
     d    tocode                           like(to) const
     d    fromcode                         like(from) const
 
     d iconv           PR            10U 0 extproc('iconv')
     d   cd                                like(iconv_t) value
     d   inbuf                         *
     d   inbytesleft                 10U 0
     d   outbuf                        *
     d   outbytesleft                10U 0
 
     D iconv_close     PR            10I 0 extproc('iconv_close')
     D   cd                                like(iconv_t) value
 
     D ic              ds                  likeds(iconv_t)
     D Data            s             12A
     D p_Data          s               *


|
     D DataLen         s             10U 0
     D UTF8_Data       s             72A
     D p_UTF8_Data     s               *
     D UTF8DataLen     s             10U 0
 
      *
      *  1208 = Unicode, UTF-8
      *     0 = special value meaning "current job's CCSID"
      *   819 = ISO-8859-1 ASCII
      *  1252 = Windows Latin-1 ASCII
      *
     c                   eval      to_CCSID = 1208
     c                   eval      from_CCSID = 0
 
 
      *
      *  initialize iconv() API
      *
     c                   eval      ic = QtqIconvOpen(to: from)
     c                   if        ic.return_value = -1
      **       ... FIXME: handle error ...
     c                   endif
 
 
      *
      *  Input string is "Hello World!"
      *
      *
     c                   eval      Data = 'Hello World!'
     c                   eval      p_Data = %addr(Data)
     c                   eval      DataLen = %len(Data)
 
      *
      *  Get output string ready.
      *
     c                   eval      p_UTF8_Data = %addr(UTF8_data)
     c                   eval      UTF8DataLen = %len(UTF8_data)
 
      *
      *  Convert string to UTF8.  Note that this changes the values of
      *  p_Data, DataLen, p_UTF8_Data and UTF8DataLen as it processes
      *  each character.
      *
     c                   if        iconv(ic: p_Data:      DataLen:


|
     c                                       p_UTF8_Data: UTF8DataLen) = -1
      **       ... FIXME: handle error ...
     c                   endif
 
      *
      *  UTF8DataLen will now contain the data converted to the UTF8 CCSID
      *
 
      *
      * call iconv_close() to free up resources when done
      *
     c                   callp     iconv_close(ic)
     c                   eval      *inlr = *on




©AF400