|
Mel's service program includes several
data conversion functions
you may take advantage from.
You may find examples about these functions
by scanning through PDM the source file QRPGLESRC
in library CGIDEV2.
Conversion procedures from module
XXXDATA
- Subprocedure char2hex
converts a character string to its hexadecimal
representation.
- Subprocedure hex2char
converts a character string in hexadecimal format to its
character representation.
- Subprocedure chknbr
accepts a character string and an optional parameter
specifying the maximum number of digits to the left of the decimal point.
Additional optional parameters are available to request that any errors
found should be formatted as messages and added to the service program's
message arrays, the text that should be used to describe the field in the messages,
and whether a message should be sent if the field's value is less than zero.
Chknbr returns a structure containing seven indicators. The indicators and
their meaning when *on are:
- one or more errors occurred
- non-numeric characters (includes minus sign in wrong place)
- multiple decimal points
- multiple signs (both leading and trailing)
- zero length input or no numeric characters
- too many digits to the left of the decimal point
- no errors, but value is less than 0.
Note 1. Indicator 7 *on does not set indicator 1 *on.
- Subprocedure c2n
converts a character string to a floating point number. It is
recommended that you check the string with chknbr before calling c2n.
- Subprocedurec2n2
converts a character string to a packed 30.9 number. c2n2
performs faster than c2n and has none of c2n's floating point precision problems.
Therefore, it is recommended that you use c2n2 instead of c2n. It is recommended that
you check the string with chknbr before calling c2n2.
- SubprocedurexlatWCCSIDs
uses CCSIDs to translate variable length strings up to 32767 characters in
length.
If optional parameters fromCCSID and toCCSID are specified, they are used
for the translation.
Otherwise, translation between ASCII and EBCDIC
is performed using the CCSIDs found in the CGI_EBCDIC_CCSID and
CGI_ASCII_CCSID environment variables. Input parameter, toebcdic,
is used to determine whether translation is from ASCII to EBCDIC (*on) or
from EBCDIC to ASCII (*off).
- Subprocedure uppify
converts all the characters in a string to upper case.
An optional CCSID parameter may be used to support non-english language characters.
Examples:
D ccsid 10i 0
* If you want the best possible performance and the
* English language characters are sufficient, do
* not use the CCSID parameter.
C eval charstring = uppify(charstring)
* To convert to uppercase a non-english language
* character string, you must pass the correct CCSID
* as second parameter.
* This takes 2 times as long as using no CCSID.
* For instance, if the character string is in swedish language:
C eval ccsid = 278
C eval charstring = uppify(charstring:ccsid)
* A value 0 for the CCSID parameter instructs the uppify
* procedure to use the job CCSID.
* This takes 3 times as long as using no CCSID.
C eval charstring = uppify(charstring:0) |
|
|
- Subprocedure lowfy
converts all the characters in a string to lower case.
An optional CCSID parameter may be used to support non-english language characters.
Examples:
D ccsid 10i 0
* If you want the best possible performance and the
* English language characters are sufficient, do
* not use the CCSID parameter.
C eval charstring = lowfy(charstring)
* To convert to uppercase a non-english language
* character string, you must pass the correct CCSID
* as second parameter.
* This takes 2 times as long as using no CCSID.
* For instance, if the character string is in swedish language:
C eval ccsid = 278
C eval charstring = lowfy(charstring:ccsid)
* A value 0 for the CCSID parameter instructs the uppify
* procedure to use the job CCSID.
* This takes 3 times as long as using no CCSID.
C eval charstring = lowfy(charstring:0) |
Conversion procedures from module
XXXDATA1
Conversion procedures from module
XXXWRKHTML
- When displaying database fields in a HTML page,
it may happen that some data containing special HTML characters
are interpreted as HTML tag delimiters thus generating
ununderstandable strings.
On the other way, multiple consecutive blanks in a field
are displayed as a single space, which in some cases
may be unappropriate.
The following three subprocedures allow to convert special
characters and blanks into their corresponding HTML
character entities, in order to display field data
exactly as they are on databases.
All procedures require
- the input and the ouput fields be defined with
varying length not exceeding 32767
- Subprocedure encode
converts the following special characters to
their HTML entity equivalents:
| " | is converted to |
" |
| & | is converted to |
& |
| < | is converted to |
< |
| > | is converted to |
> |
- Subprocedure encodeBlanks
converts blanks to non-breaking spaces ( ).
This procedure is an alternative to use the traditional
HTML tags <pre> and </pre>.
Examples:
-
D VarOutput s 1000 varying
................
C read record
C dow not %eof
C read record
C eval VarOutput = %trimr(recordField)
C eval VarOutput = Encode(VarOutput)
C eval VarOutput = EncodeBlanks(VarOutput)
C callp updhtmlvar('htmlvar':VarOutput)
C callp wrtsection('TableRow')
C enddo
|
|
-
C read record
C dow not %eof
C read record
C callp updHtmlVar('htmlvar':EncodeBlanks(
C Encode(%trimr(recordField))))
C callp wrtsection('TableRow')
C enddo
|
|
- Subprocedure encode2
allows to translate special characters to their corresponding named entities as documented in a user
specified stream file.
If not provided, the stream file defaults to
/cgidevexthml/encod2arr.txt .
Required parameter group:
| returned value: |
65528 char max, |
input string with special characters converted to HTML named entities |
| inputs: |
1891 char max, |
input string with special characters to be converted to HTML named entities |
|
10i 0, |
return code: |
| 0 = | successful |
| -1 = |
file error.
Could be any of the following:
- file not found
- file not accessible (authority, etc.)
- file empty
- file contains no valid records
(at run time, a detailed message is sent to the CGIDEBUG
debugging file) |
|
|
256 char max, (optional) |
"entities" stream file, the file that contains the arrays of characters and character entities.
If omitted, file /cgidevexthtml/encode2fil.txt is used.
|
|
|
Note 2. Click here
to display stream file /cgidevexthtml/encode2fil.txt .
Note 3. Click here
to run CGI dspencode2. This program uses procedure
encode2 to test an "entity" stream file.
Note 4. To customize the arrays:
- Never modify, move, or rename the default stream file /cgidevexthtml/encode2fil.txt .
- Copy the default stream file to an IFS file of your own.
- Make sure QTMHHTP1 has *RX authority to your file.
- Modify your file:
- Record format, one record per line
- Comment records:
- positions 1 -2 must be //
- Data records:
- Position 1 = the character to be encoded
- Positions 2 - 9 = the character entity to be substituted for
the character. If these positions are blank,
the record is ignored.
- Remainder of record = blanks or comments
- Use your file in the EntitiesFile parameter.
Coding examples:
-
D inputString s 1891 varying
D outputString s 65528 varying
D dftFile s 256 inz('/cgidevexthtml/encode2fil.txt')
D rc s 10i 0 inz(0)
C eval outputString = encode2(inputString:
C rc:dftFile)
|
|
|
-
* Passing a literal
C eval result = encode2('':rc)
* Passing a varying field.
C eval vfield = ''
C eval result = encode2(vfield:rc)
* Passing from a fixed length field
C eval ffield = ''
C eval result = encode2(%trimr(ffield):rc)
* Passing an expression
C eval result = encode2('abc' + %trimr(ffield) +
C vfield + 'xyz':rc) |
|
|
|