midrange.com code scratchpad
Name:
SETSIGN service program
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/30/2007 06:26:19 pm
IP:
Logged
Description:
SETSIGN converts a numeric field to character and places the sign on the left or right as specified.
Code:
  1. SETSIGNPR:
  2.  
  3.      D SetSign         PR
  4.      D  InputNum                     12S 2
  5.      D  SignLoc                       1A
  6.      D  OutString                    12A
  7.  
  8.  
  9. SETSIGN:
  10.  
  11.       *=================================================================*
  12.       * SetSign - Set the sign for a numeric to character conversion
  13.       *=================================================================*
  14.      H
  15.       *=================================================================*
  16.       * Parameters
  17.       * 1. Input: numeric value
  18.       * 2. Output: signed numeric string
  19.       *=================================================================*
  20.      D/copy qsrvsrc,setsignpr
  21.       *-----------------------------------------------------------------*
  22.       * Main entry parameters
  23.       * 1. Input: numeric value
  24.       * 2. Output: signed numeric string
  25.       *-----------------------------------------------------------------*
  26.      D SetSign         PI
  27.      D  InputNum                     12S 2
  28.      D  SignLoc                       1A
  29.      D  OutString                    12A
  30.      D
  31.  
  32.       *-----------------------------------------------------------------*
  33.       * Other fields used by the program
  34.       *-----------------------------------------------------------------*
  35.      D                 DS
  36.      D work1                         11s 2
  37.      D work2                         11a   overlay(work1)
  38.  
  39.      D Pos             c                   ' '
  40.      D Neg             c                   '-'
  41.      D Left            c                   'L'
  42.      D Right           c                   'R'
  43.  
  44.       /free
  45.        work1 = %abs(InputNum);
  46.  
  47.        // for Negative numbers
  48.        if InputNum < *zero;
  49.          // Sign on the Right
  50.          if SignLoc = Right;
  51.            OutString = work2 + Neg;
  52.          endif;
  53.          // Sign on the Left
  54.          if SignLoc = Left;
  55.            OutString = Neg + work2;
  56.          endif;
  57.  
  58.        // Positive numbers
  59.        else;
  60.          // Sign on the Right
  61.          if SignLoc = Right;
  62.            OutString = work2 + Pos;
  63.          endif;
  64.          // Sign on the Left
  65.          if SignLoc = Left;
  66.            OutString = Pos + work2;
  67.          endif;
  68.        endif;
  69.  
  70.        Return;
  71.       /end-free 
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css