| 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:
 
        Note 1. Indicator 7 *on does not set indicator 1 *on.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.
      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 encodeconverts the following special characters to
            their HTML entity equivalents:
 
            | " | is converted to | " |  | & | is converted to | & |  | < | is converted to | < |  | > | is converted to | > | Subprocedure encodeBlanksconverts 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
   ................
 /free
      read record;
      dow not %eof;
          VarOutput=%trimr(recordField);
          VarOutput=Encode(VarOutput);
          VarOutput=EncodeBlanks(VarOutput);
          updhtmlvar('htmlvar':VarOutput);
          wrtsection('TableRow');
          read record;
      enddo;
 /end-free | 
 
 |  /free
      read record;
      dow not %eof;
          updHtmlVar('htmlvar':EncodeBlanks(
              Encode(%trimr(recordField))));
          wrtsection('TableRow');
          read record;
      enddo;
 /end-free | 
 
Subprocedure encode2allows to translate special characters to their corresponding
            entities
            as documented in a user specified "entity" stream file.
 CGIDEV2 provides two "entity" stream files:
 
            /cgidevexthtml/encode2Fil.txtThis is a named entity conversion table, by which, for instance,
 character < is translated to <
 This "entity" stream file is the default value for subprocedure encode2
/cgidevexthtml/encode2Fil2.txtThis is a decimal entity conversion table, by which, for instance,
 character < is translated to <
 
 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 named entities
            stream file /cgidevexthtml/encode2fil.txt
        here to display decimal entities
            stream file /cgidevexthtml/encode2fil2.txt
         Note 3. Click here
        to run CGI dspencode2. This program may be used to validate
        an "entity" stream files used by encode2.
         Note 4. To customize the arrays:
         
        Never modify, move, or rename the CGIDEV2-provided stream files
            
            /cgidevexthtml/encode2fil.txt (named entities)
            /cgidevexthtml/encode2fil2.txt (decimal entities)
            Copy a CGIDEV2-provided 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 commentsUse your file in the EntitiesFile parameter.
         Coding examples:
         
         
 | D inputString     s           1891    varying
D outputString    s          65528    varying
D numberEntFile   s            256
D rc              s             10i 0 inz(0)
 /free
      // Convert inputString to named entities
      outputString=encode2(inputString:rc);
      // Convert inputString to decimal entities
      numberEntFile='/cgidevexthtml/encode2fil2.txt';
      outputString=encode2(inputString:rc:numberEntFile);
 /end-free | 
 
 
* 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' +
C                             %trimr(ffield) +
C                             vfield + 'xyz':rc)
             
 
Conversion procedures from module
    XXXDECODE2
    
    Subprocedure Decode2 can be used to convert a string containing HTML named or number
        entities
        to a string containing their corresponding special characters.
        The conversion is performed through a special user specified stream file (the same stream file used for
        subprocedure encode2).CGIDEV2 provides two "entity" stream files:
 
        In other words, subprocedure decode2 is exactly the opposite of subprocedure
        encode2./cgidevexthtml/encode2Fil.txtThis is a named entity conversion table, by which, for instance,
 character < is translated to <
 This "entity" stream file is the default value for subprocedure encode2
/cgidevexthtml/encode2Fil2.txtThis is a decimal entity conversion table, by which, for instance,
 character < is translated to <
 
 Required parameter group:
         
        | returned value:
 | 65528 char max, fixed or variable length
 | input string with HTML named entities converted to special characters
 |  | inputs: | 65528 char max, fixed or variable length
 | input string with HTML named entities to be converted to special characters
 |  |  | 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 5. Variables inputString and outputString
        can be fixed or varying length. Their lengths must not exceed 65528.
 Note 6. Third parameter dftFile of decode2() can be omitted,
        thus defaulting to stream file /cgidevexthtml/encode2fil.txt .See also notes 2 to 4 for encode2.
 Coding example:
         
         
 | D inputString     s          65528    varying
D outputString    s          65528    varying
D outputString2   s          65528    varying
D numberEntFile   s            256
D rc              s             10i 0 inz(0)
 /free
      // Convert named entities from inputString
      outputString=decode2(inputString:rc);
      // Convert decimal entities from inputString
      numberEntFile='/cgidevexthtml/encode2fil2.txt';
      outputString=decode2(inputString:rc:numberEntFile);
      // Convert named AND decimal entities from inputString
      outputString=decode2(inputString:rc);
      numberEntFile='/cgidevexthtml/encode2fil2.txt';
      outputString2=decode2(outputString:rc:numberEntFile);
 /end-free | 
 
 
    Conversion procedures from module
    XXXCVTSTG
    
    Subprocedure CvtStg (Convert String) can be used to convert a memory string
    from one CCSID to another CCSID. For instance you could convert a memory string from CCSID 1208 (Unicode, UTF-8 Level 3)
    to CCSID 37 (EBCDIC USA, Canada, Netherlands, Portugal, Brazil, Australia, New Zealand).This is how you use it:
 
    |  * "InpCCSID" is the CCSID of the input string
 *            (the string to be converted)
 * "InpBufP" is a pointer to the input string
 * "InpBufLen" is the length on the input string
 * "OutCCSID" is the CCSID of the output string
 *            (the string to receive the converted value)
 * "OutBufP" is a pointer to the output string
 * "OutBufLen" is the length of the output string
 *            (this length must be large enough
 *             to contain the converted value)
 * "OutDtaLen" is the length of the converted value
 *             once it is converted in the output string
D  InpCCSID       s             10u 0
D  InpBufP        s               *
D  InpBufLen      s             10u 0
D  OutCCSID       s             10u 0
D  OutBufP        s               *
D  OutBufLen      s             10u 0
D  OutDtaLen      s             10u 0
 /free
      // Convert a memory string from CCSID 1208 to CCSID 37
      InpCCSID=1208;
      OutCCSID=37;
      CvtStg(InpCCSID:InpBufP:InpBufLen;
             OutCCSID:OutBufP:OutBufLen:OutDtaLen); |  |