MF Sign

 

 

NOTE - Use your Browsers BACK Button to return to prior page or CLICK here.

   Mainframe Signed Number Conversion - INBOUND/OUTBOUND
ftlob01.jpg (12490 bytes) SQR Interfaces To/From a mainframe may require special sign conversion on the last digit. The routine below performs Inbound & Outbound Sign Conversion. See program notes for more detail.

   TDNUMMF.SQC - Mainframe Signed Number Conversion
!**********************************************************************
!*                                                                    *
!*       MODULE:  TDNUMMF.SQC                                         *
!*       AUTHOR:  TONY DELIA.                                         *
!*         DATE:  02/02/1999.                                         *
!*       SYSTEM:  TD SQR UTILITY SERIES.                              *
!*         DESC:  MAINFRAME SIGNED NUMBER CONVERSION (IN/OUT).        *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*         NOTE:  Outbound only requires conversion of negative       *
!*                results. There are two possible values for each     *
!*                negative number (digit). We'll use D0 - D9 because  *
!*                it is the most common. Also the B0 - B9 character   *
!*                set is more cumbersome. Positive numbers do not     *
!*                require a special signed character. F0 - F9 are     *
!*                positive numbers. Translating to any other signed   *
!*                equivalent (A0-A9, C0-C9, E0-E9) produces no gain.  *
!*                                                                    *
!*                Verify that the ascii/ebcdic conversion for your    *
!*                Operating system is identical to that used in the   *
!*                MF-Signed-IN routine.                               *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*        USAGE:  OUTBOUND / INBOUND EXAMPLES                         *
!*                                                                    *
!*       OUT #1:  let #w-amt = 100.25                                 *
!*                let #w-dec = 3                                      *
!*                let #w-len = 10                                     *
!*                do MF-Signed-OUT(#w-amt, #w-dec, #w-len, $w-out)    *
!*                .                                                   *
!*       OUT #2:  let #w-amt = -865.123                               *
!*                let #w-dec = 3                                      *
!*                let #w-len = 7                                      *
!*                do MF-Signed-OUT(#w-amt, #w-dec, #w-len, $w-out)    *
!*                .                                                   *
!*       OUT #3:  let #w-amt = -865.123                               *
!*                do MF-Signed-OUT(#w-amt, 6, 10, $w-out)             *
!*                .                                                   *
!*        IN #4:  do MF-Signed-IN('0000100250', 3, #w-out)            *
!*                .                                                   *
!*        IN #5:  do MF-Signed-IN('086512L', 3, #w-out)               *
!*                .                                                   *
!*        IN #6:  do MF-Signed-IN('086512300}', 6, #w-out)            *
!*                .                                                   *
!*                .                                                   *
!*                #Include 'tdnummf.sqc'                              *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*      RESULTS:  Example 1 returns '0000100250'      in $w-out       *
!*                Example 2 returns '086512L'         in $w-out       *
!*                Example 3 returns '086512300}'      in $w-out       *
!*                Example 4 returns 100.25            in #w-out       *
!*                Example 5 returns -865.123          in #w-out       *
!*                Example 6 returns -865.123          in #w-out       *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*        LEGAL:  CONFIDENTIALITY INFORMATION.                        *
!*                                                                    *
!*                This module is the original work of Tony DeLia. It  *
!*                can be considered ShareWare under the following     *
!*                conditions.                                         *
!*                                                                    *
!*                A - The author's name (Tony DeLia) remains on any   *
!*                    and all versions of this module.                *
!*                B - Any modifications must be clearly identified.   *
!*                C - A "vanilla" copy of this module must be kept    *
!*                    alongside any revised versions.                 *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*      WEBSITE:  http://www.sqrtools.com                             *
!*                                                                    *
!*                Questions/Comments: tdelia@erols.com                *
!*                                                                    *
!**********************************************************************

!**********************************************************************
!*       MF Signed OUTBOUND                                           *
!**********************************************************************

begin-procedure MF-Signed-OUT(#NUMin, #NUMdec, #NUMlen, :$NUMout)

!   Set Implied Decimal Multiplier
let #w_mult      = power(10, #NUMdec)

!   Set Implied Decimal Positions (Remove Decimals)
let #w_amt       = #NUMin * #w_mult

!   Set Sign (Positive/Negative) - Set Absolute Value
let $w_sign      = '+'
if  #w_amt       < 0
    let $w_sign  = '-'
    let #w_amt   = #w_amt * -1
end-if

!   Convert to Character Format
let $w_amt       = edit(#w_amt,'0999999999999999999999999')

!   If Negative convert last digit to ASCII/EBCDIC Equivalent
if  $w_sign      = '-'
    let #len     = length($w_amt)
    let $w_amt1  = substr($w_amt, 1, #len - 1)
    let $w_old   = substr($w_amt, #len, 1)
    let #pos     = to_number($w_old) + 1
    let $w_new   = substr('}JKLMNOPQR', #pos, 1)
    let $w_amt   = $w_amt1 || $w_new
end-if

!   Return Converted Amount
if  #NUMlen      = 0
or  #NUMlen      > length($w_amt)
    let #NUMlen  = length($w_amt)
end-if

let #pos         = length($w_amt) - #NUMlen + 1
let $NUMout      = substr($w_amt, #pos, #NUMlen)

end-procedure

!**********************************************************************
!*       MF Signed INBOUND                                            *
!**********************************************************************

begin-procedure MF-Signed-IN($NUMin, #NUMdec, :#NUMout)

!   Identify/Arrange converted EBCDIC to ASCII character set...
if  $_MF_cnv     = ''
    let $MF_A    = chr(209) || chr(126) || 'stuvwxyz'
    let $MF_B    = chr(216) || chr(217) || chr(218) || chr(219) ||
                   chr(220) || chr(221) || chr(222) || chr(223) ||
                   chr(224) || chr(225)
    let $MF_C    = '{ABCDEFGHI'
    let $MF_D    = '}JKLMNOPQR'
    let $MF_E    = '\'      || chr(159) || 'STUVWXYZ'
    let $MF_F    = '0123456789'
    let $_MF_cnv = $MF_B || $MF_D ||                  ! (-) Pos  1-20
                   $MF_A || $MF_C || $MF_E || $MF_F   ! (+) Pos 21-60
end-if

!   Set Implied Decimal Divisor
let #w_div       = power(10, #NUMdec)

!   Set Sign Multiplier (Positive)
let #w_sign      = 1

!   Isolate Last Digit (EBCDIC Signed Number)
let #len         = length($NUMin)
let $w_last      = substr($NUMin, #len, 1)

!   Evaluate Last Digit - Convert to Sign/Ascii Equivalent
let #pos         = instr($_MF_cnv, $w_last, 1)
if  #pos         > 0
    if #pos     <= 20
       let #w_sign = -1
    end-if
    let $w_last  = to_char(mod(#pos+9,10))
end-if

!   Reassemble converted string
let $NUMout      = substr($NUMin, 1, #len - 1) || $w_last

!   Convert to Numeric Format
let #NUMout      = ( to_number($NUMout) / #w_div ) * #w_sign
let #NUMout      = round(#NUMout, #NUMdec)

end-procedure

!**********************************************************************
!*       End of Program                                               *
!**********************************************************************
                                                                          

   Feedback
ftoct01.jpg (12389 bytes) I would appreciate any feedback you may have on this site. Send mail to tdelia@erols.com or click on the Octopus.
   Technical difficulties?
pg013.jpg (40439 bytes) Please report any technical difficulties you may encounter to the address above OR click on the Octopus. Thanks.

By the way... this is what my cat TJ looks like... and he also has the same attitude!

NOTE - Use your Browsers BACK Button to return to prior page.

Tony DeLia - Updated June 02, 1999