Return to the RPG Tips
Code Page API
We have a situation where some folks out of the country send data in thru a web application. When the data arrives here it has upper ascii characters "mit der umlaut" etc... I believe that the code page would help here, but do not know if the sender is responsible or not. Actually it does not matter if the sender is or is not, we need to convert this stuff to our code set. Anyone have any ideas on how to do this? *********************** CODE PAGE API ********************************** *------------------------------------------------------------------ * Prototype for Code Conversion - Open *------------------------------------------------------------------ d IConvOpen PR 52A ExtProc('QtqIconvOpen') d * Value options(*string) To Code d * Value options(*string) Fr Code *------------------------------------------------------------------ * Prototype for Code Conversion *------------------------------------------------------------------ d IConv PR 10i 0 ExtProc('iconv') d 52a Value Code Discripter d * Value ptr to InBuffer Ptr d * Value ptr to InSize ptr d * Value ptr to OutBuffer Ptr d * Value ptr to OutSize ptr **************************************************************** * Code Page Conversions (iconv_t) ***************************************************************** d ToAscii DS d ICORV_A 1 4b 0 * return value to indicate if error occurred d ICOC_A 5 52b 0 DIM(00012) * cd * d ToEbcdic DS d ICORV_E 1 4b 0 * return value to indicate if error occurred d ICOC_E 5 52b 0 DIM(00012) * cd * * d p_Qascii S * inz(%addr(Qascii)) d Qascii DS 32 d asciiCP 1 4b 0 inz(00813) Code page ID d asciiCA 5 8b 0 inz(0) d asciiSA 9 12b 0 inz(0) d asciiSS 13 16b 0 inz(1) d asciiIL 17 20b 0 inz(0) d asciiEO 21 24b 0 inz(1) d asciiR 25 32a inz(*allx'00') * d p_Qebcdic S * inz(%addr(Qebcdic)) d Qebcdic DS 32 d ebcdicCP 1 4b 0 inz(00037) Code page ID d ebcdicCA 5 8b 0 inz(0) d ebcdicSA 9 12b 0 inz(0) d ebcdicSS 13 16b 0 inz(1) d ebcdicIL 17 20b 0 inz(0) d ebcdicEO 21 24b 0 inz(1) d ebcdicR 25 32a inz(*allx'00') * * translate response to ASCII c eval p_InBuff = %addr(TXTIN) c eval p_OutBuff = %addr(TXTOUT) c eval InBytesLeft = %len(%trim(TXTIN)) c eval OutBytesLeft = %len(TXTOUT) c eval rc = IConv(ToAscii: c %addr(p_InBuff): c p_InBytes: c %addr(p_OutBuff): c p_OutBytes) c if ICORV_A > 0 c eval MsgToDsply = 'Error in Translate' c MsgToDsply dsply c endif * translate to ebcdic c eval p_InBuff = %addr(TXTIN) c eval p_OutBuff = %addr(TXTOUT) c eval InBytesLeft = %len(%trim(TXTIN)) c eval OutBytesLeft = %len(TXTOUT) c eval rc = IConv(ToEbcdic: c %addr(p_InBuff): c p_InBytes: c %addr(p_OutBuff): c p_OutBytes) c if ICORV_E > 0 c eval MsgToDsply = 'Error in Translate' c MsgToDsply dsply c endif * ************************************************************************** * FIRST PASS ************************************************************************** csr *INZSR begsr * setup code page conversion ebcdic - ascii c eval ToAscii = IConvOpen(p_Qascii: c p_Qebcdic) c if ICORV_A = -1 * error processing here c endif * setup code page conversion ascii - ebcdic c eval ToEbcdic = IConvOpen(p_Qebcdic: c p_Qascii) c if ICORV_E = -1 * error processing here c endif * csr #INZSR endsr
[report a broken link by clicking here]