home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / loan / loan.cbv next >
Text File  |  1998-03-02  |  8KB  |  184 lines

  1.  
  2.       * Feature source code generation begins here...
  3.       * METHOD
  4.        IDENTIFICATION DIVISION.
  5.        METHOD-ID. "figureLoan".
  6.        DATA DIVISION.
  7.        WORKING-STORAGE SECTION.
  8.       * --------------------------------------------
  9.       * Data declarations for the message box
  10.       * --------------------------------------------
  11.        01  MessageTitle.
  12.             03  MessageTitle-Length      PIC 9(9) COMP-5.
  13.             03  MessageTitle-String.
  14.                  05  MessageTitle-Chars  PIC X
  15.                         OCCURS 1 TO 255 TIMES
  16.                         DEPENDING ON  MessageTitle-Length.
  17.        01  MsgText.
  18.             03  MsgText-Length      PIC 9(9) COMP-5.
  19.             03  MsgText-String.
  20.                  05  MsgText-Chars  PIC X
  21.                         OCCURS 1 TO 255 TIMES
  22.                         DEPENDING ON MsgText-Length.
  23.        01 MsgSeverityIcon PIC 9(9) COMP-5 VALUE 2.
  24.            88  MsgSeverityIcon-None  VALUE  1.
  25.            88  MsgSeverityIcon-Information  VALUE  2.
  26.            88  MsgSeverityIcon-Query  VALUE  3.
  27.            88  MsgSeverityIcon-Warning  VALUE  4.
  28.            88  MsgSeverityIcon-Error  VALUE  5.
  29.        01 MsgButtons PIC 9(9) COMP-5 VALUE 1.
  30.            88  MsgButtons-Ok  VALUE  1.
  31.            88  MsgButtons-OkCancel  VALUE  2.
  32.            88  MsgButtons-Cancel  VALUE  3.
  33.            88  MsgButtons-Enter  VALUE  4.
  34.            88  MsgButtons-EnterCancel  VALUE  5.
  35.            88  MsgButtons-RetryCancel  VALUE  6.
  36.            88  MsgButtons-AbortRetryIgnore  VALUE  7.
  37.            88  MsgButtons-YesNo  VALUE  8.
  38.            88  MsgButtons-YesNoCancel  VALUE  9.
  39.        01 MsgDefaultButton PIC 9(9) COMP-5 VALUE 1.
  40.            88  MsgDefaultButton-Button1  VALUE  1.
  41.            88  MsgDefaultButton-Button2  VALUE  2.
  42.            88  MsgDefaultButton-Button3  VALUE  3.
  43.        01 MsgModality PIC 9(9) COMP-5 VALUE 1.
  44.            88  MsgModality-Application  VALUE  1.
  45.            88  MsgModality-System  VALUE  2.
  46.        01 MsgMoveable PIC 9(9) COMP-5 VALUE 0.
  47.           88 MsgMoveable-False    VALUE 0.
  48.           88 MsgMoveable-True    VALUE 1.
  49.        01 MsgHelpId PIC 9(9) COMP-5 VALUE 0.
  50.        01 MsgResponse      PIC 9(9) COMP-5.
  51.             88  MsgResponse-OK          VALUE 1.
  52.             88  MsgResponse-Cancel      VALUE 2.
  53.             88  MsgResponse-Retry       VALUE 4.
  54.             88  MsgResponse-Abort       VALUE 8.
  55.             88  MsgResponse-Ignore      VALUE 16.
  56.             88  MsgResponse-Yes         VALUE 32.
  57.             88  MsgResponse-No          VALUE 64.
  58.             88  MsgResponse-Enter       VALUE 128.
  59.        01  errorCodeRc PIC 9(9) COMP-5.
  60.  
  61.        LOCAL-STORAGE SECTION.
  62.       * --------------------------------------------
  63.       * Data declarations
  64.       *   Note that the year data has the DATE FORMAT.
  65.       *   A temporaty 4-digit date is used to accept
  66.       *   the two-digit year; Year-Due is a numeric
  67.       *   used to hold the date for use by the user-
  68.       *   interface.  A numeric is needed to display
  69.       *   in the window.
  70.       * --------------------------------------------
  71.        01 The-Date          DATE FORMAT YYXXXX.
  72.           05 Year-Part        PIC 99 DATE FORMAT YY.
  73.           05 Month-Part       PIC 99.
  74.           05 Day-Part         PIC 99.
  75.        01 Temp-Year           PIC 9(4) DATE FORMAT YYYY.
  76.        01 Year-Due            PIC 9(4).
  77.        01 Rate                pic 9(9)V99.
  78.        01 Month-Rate          pic 9(9)V9999.
  79.        01 LPayment            pic 9(9)V99.
  80.        01 num-of-payments     pic 9(3).
  81.        01 Total-Interest      Pic 9(9)V99.
  82.       * --------------------------------------------
  83.       * A reference to the visual part.
  84.        01 aLoan USAGE OBJECT REFERENCE loan.
  85.       * --------------------------------------------
  86.        LINKAGE SECTION.
  87.        01 lsLoanAmt PIC 9(9) COMP-5.
  88.        01 lsRate PIC 9(9) COMP-5.
  89.        01 lsTerm PIC 9(9) COMP-5.
  90.        PROCEDURE DIVISION USING lsLoanAmt lsRate lsTerm.
  91.       * Enter your code here..........
  92.  
  93.       * --------------------------------------------
  94.       * Initiaze the error return code.
  95.       * --------------------------------------------
  96.            Initialize errorCodeRc.
  97.       * --------------------------------------------
  98.       * Check the values and catch a potential problem.
  99.       *   If a value is not valid, set the return
  100.       *   code; in the Composition edito, connect the
  101.       *   errorOccured event to a message window part
  102.       *   to display an error message for this condition.
  103.       * --------------------------------------------
  104.            If lsLoanAmt is < 0 or
  105.               lsRate is < 1 or
  106.               lsRate is > 25 or
  107.               lsTerm is < 1 or
  108.               lsTerm is > 30
  109.            Then
  110.              Move 37 to errorCodeRc
  111.              Move 0 to LPayment
  112.                        Total-Interest
  113.                        Year-Due
  114.  
  115.              Move 22 to MessageTitle-Length
  116.              Move "Oh, no ... an Error !!" to MessageTitle-String
  117.       *    inserted by code assistant
  118.            INVOKE InterfaceManager "setMessageTitle"
  119.               USING CMessageBox2
  120.                  MessageTitle
  121.       *       end of inserted code
  122.  
  123.              Move 82 TO MsgText-Length
  124.              Move "An error occurred in figuring the loan.  Check that
  125.       -             "the loan information is valid."
  126.                  To MsgText-String
  127.              Move 4 to MsgSeverityIcon
  128.              Move 130 TO MsgHelpId
  129.  
  130.              Invoke InterfaceManager "showMessage"
  131.                 Using CMessageBox2
  132.                    MsgText
  133.                    MsgSeverityIcon
  134.                    MsgButtons
  135.                    MsgDefaultButton
  136.                    MsgModality
  137.                    MsgMoveable
  138.                    MsgHelpId
  139.                 Returning MsgResponse
  140.  
  141.            End-If.
  142.       * --------------------------------------------
  143.       * Check the return code and if it is zero, compute
  144.       *   the loan data.
  145.       * --------------------------------------------
  146.            If errorCodeRc is = 0
  147.               Move lsRate to Rate
  148.               Compute Rate = Rate / 100
  149.               Compute num-of-payments = 12 * lsTerm
  150.  
  151.               Compute LPayment =
  152.                  lsLoanAmt *
  153.                    function Annuity ((Rate / 12) Num-of-payments)
  154.  
  155.               Compute Total-Interest = LPayment * Num-of-payments
  156.               Subtract lsLoanAmt from Total-Interest
  157.       *----------------------------------------------
  158.       * Compute the year the loan is due using a two-digit
  159.       *   year; a temporary date data item hold the four-digit
  160.       *   value and is used to set the four-digit numeric for
  161.       *   use in the data part.  The MLE Undate function converts
  162.       *   the data item to a numeric.
  163.       *----------------------------------------------
  164.               Accept The-Date from Date
  165.               Add lsTerm to Year-Part
  166.               Move Year-Part to Temp-Year
  167.               Compute Year-Due = Function Undate(Temp-Year)
  168.            End-If.
  169.       * --------------------------------------------
  170.       * Set the computed values in the data part.
  171.       * --------------------------------------------
  172.            Invoke Loandata2 "setPayment"
  173.               Using LPayment
  174.            Invoke Loandata2 "setTotalInterest"
  175.               UsinG Total-Interest
  176.            Invoke Loandata2 "setDueYear"
  177.               Using Year-Due.
  178.       * --------------------------------------------
  179.            GOBACK.
  180.  
  181.        END METHOD "figureLoan".
  182.  
  183.       * Feature source code generation ends here.
  184.