midrange.com code scratchpad |
Name:
Dennis Lovelady
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
04/16/2010 03:21:49 am
|
IP:
Logged
|
|
Description:
Issue with cvtch
|
Code:
- H DftActGrp(*NO) Option(*SRCSTMT)
- H BNDDIR('QC2LE')
-
- // Convert string of hex characters representing ASCII data to
- // EBCDIC values. Vendor is supplying a file that contains data
- // like '414243303132' which needs to be interpreted as ABC012.
- // The entire string received from the vendor is hex representation
- // of ASCII characters.
-
- D EBCDIC_CCSID C 37
- // 1208 is the common UTF-8 CCSID
- D ASCII_CCSID C 1208
-
-
- D asciiHexToEBCDIC...
- D PR 32767 Varying extProc('ascHexToBCD')
- D hexIn 65534 Value
- D hexLen 10I 0 Value
-
- D hexInput S 32767 Varying
- D result S 32767 Varying
-
- D valueToConvert...
- D C '532f2d7052252e252229757320+
- D 2f2220592c2c292e2f29732020+
- D 2020202032303020572e205a21+
- D 232b732f2e2020202020202020+
- D 20202020202039752820522c2f+
- D 2f722020202020202020532829+
- D 2321272f202020202020202059+
- D 5c323032303220202020203830+
- D 302d3833372d3233353115aac2+
- D e1333035303031737979797922+
- D 00520050005a00057920202020+
- D 20202020202020202020202020+
- D 20202020202020202020203230+
- D 2e79202e332e3330202e2e2e22+
- D 2130302e2e2e2e2e2e2e202020+
- D 20202020202020202020202020+
- D 20202020202020202020202030+
- D 3030302e2e2f30312e2e2e2e2e20'
-
- /Free
-
- hexInput = valueToConvert ;
- result = asciiHexToEBCDIC(hexInput: %Len(hexInput)) ;
- *INLR = *On ;
-
- /End-free
-
-
-
- P asciiHexToEBCDIC...
- P B
-
- D PI 32767 Varying
- D hexIn 65534 Value
- D hexLen 10I 0 Value
-
-
- D cvtch PR ExtProc('cvtch')
- D ptrcharOut 32767 Options(*VarSize)
- D ptrHexIn 65534 Const
- D charLength 10I 0 Value
-
- D ASCII S 32767
- D EBCDIC S 32767
- D resultLen S 5U 0
-
- /Free
-
- cvtch(ASCII: hexIn: hexLen) ;
- resultLen = hexLen / 2 ;
- // Insert iconv() stuff here
- Return %Subst(EBCDIC: 1: resultLen) ;
-
- /End-free
-
- P E
-
|
|
|