000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. COMMCARB.
000300* ASK USER FOR THE NUMBER OF UNITS SOLD AND THE UNIT PRICE.
000400* DISPLAY THE PRICE AND UNITS ENTERED. 
000500* CALCULATE THE GROSS SALES AMOUNT (UNITS X PRICE).  
000600* DISPLAY GROSS SALES.
000700* CALCULATE THE COMMISSION (GROSS * COMM-RATE).
000800* DISPLAY THE COMMISSION.
000900* CALCULATE THE NET PROFIT FOR THE ITEM 
001000 
001100 DATA DIVISION.
001200 WORKING-STORAGE SECTION.
001300  
001400 01  WS-TODAYS-DATE          pic ZZZZ/ZZ/ZZ.
001500 01  WS-TIME.
001600     05 WS-TIME-HH           pic 9(02).
001700     05 WS-TIME-MM           PIC 9(02).
001800     05 WS-TIME-SS           PIC 9(02).
001900 01  WS-END                  pic X(01).
002000 
002100 01  WS-UNITS-IN             PIC 9(03).
002200 01  WS-UNITS-NUMERIC        PIC 9(03).
002300 
002400 01  WS-UNIT-RATE-IN.
002500     05 WS-UNIT-RATE-DOLLARS  PIC X(03).
002600     05 WS-UNIT-RATE-DECIMAL  PIC X(01).
002700     05 WS-UNIT-RATE-CENTS    PIC X(02).
002800 
002900 01  WS-NUMERIC-UNIT-PARTS.
003000     05 WS-NUMERIC-UNIT-DOLLARS  PIC 9(03).
003100     05 WS-NUMERIC-UNIT-CENTS PIC 9(02).
003200 01  WS-NUMERIC-UNIT-WHOLE    pic 9(03)v99.           
003300 
003400 01  WS-COMM-RATE            PIC 9(03)V99 VALUE .09.
003500
003600 01  WS-GROSS-AMOUNT         PIC 9(06)V99 VALUE 0.
003700 01  WS-COMM-AMOUNT          PIC 9(06)V99 VALUE 0.
003800 01  WS-NET-PROFIT           PIC 9(06)V99 VALUE 0.
003900 
004000 01  WS-FORMATTED-AMOUNT-Z   PIC $ZZZ,ZZZ,ZZZ.99.
004100 01  WS-FORMATTED-AMOUNT     PIC $ZZZ,ZZZ,ZZZ.99.       
004200 01  WS-FORMATTED-UNITS      PIC ZZZ,ZZZ,ZZZ,ZZZ.
004300 01  WS-FORMATTED-COMM       PIC Z(14).
004400 
004500 PROCEDURE DIVISION.
004600 0000-MAINLINE.
004700     
004800     DISPLAY 'START COMMCARB BY RYAN BROOKS'.
004900     perform 1000-get-date-time.
005000  
005100* PROMPT THE USER FOR RATE UNTIL NUMERIC RATE ENTERED: 
005200     PERFORM UNTIL WS-UNIT-RATE-DOLLARS IS NUMERIC
005300                   AND WS-UNIT-RATE-CENTS IS NUMERIC
005400               AND WS-UNIT-RATE-DECIMAL = '.'
005500       DISPLAY "ENTER THE UNIT PRICE FROM 000.00 TO 999.99"
005600               " AND PRESS ENTER"
005700       ACCEPT WS-UNIT-RATE-IN
005800     END-PERFORM
005900     
006000* PROMPT THE USER FOR UNITS UNTIL NUMERIC UNITS ENTERED:          
006100     PERFORM UNTIL WS-UNITS-IN IS NUMERIC
006200       DISPLAY "ENTER THE UNITS SOLD FROM 000 TO 999"
006300               " AND PRESS ENTER"
006400       ACCEPT WS-UNITS-IN
006500     END-PERFORM           
006600* CONVERT THE STRING DATA ENTERED INTO NUMERIC FIELD:
006700     move WS-UNIT-RATE-DOLLARS to WS-NUMERIC-UNIT-DOLLARS.
006800     MOVE WS-UNIT-RATE-CENTS to WS-NUMERIC-UNIT-CENTS.
006900     move WS-UNITS-IN to WS-UNITS-NUMERIC.
007000     move WS-NUMERIC-UNIT-PARTS to WS-NUMERIC-UNIT-WHOLE.
007100     display "______________________________".
007200     
007300* FORMAT UNITS IN AND DISPLAY:
007400     MOVE WS-UNITS-IN to WS-FORMATTED-UNITS.
007500     display "UNITS SOLD   : " WS-FORMATTED-UNITS.       
007600     
007700* FORMAT AND DISPLAY UNIT PRICE:            
007800     MOVE WS-NUMERIC-UNIT-WHOLE to WS-FORMATTED-AMOUNT.
007900     DISPLAY "RATE ENTERED : " WS-FORMATTED-AMOUNT.
008000  
008100* COMPUTE, FORMAT AND DISPLAY GROSS SALES:             
008200     COMPUTE WS-GROSS-AMOUNT = WS-UNITS-IN * WS-NUMERIC-UNIT-WHOLE
008300     .
008400     MOVE WS-GROSS-AMOUNT   TO WS-FORMATTED-AMOUNT-Z.
008500     DISPLAY "GROSS SALES  : " WS-FORMATTED-AMOUNT-Z.  
008600     
008700* COMPUTE, FORMAT AND DISPLAY COMMISSION:             
008800     COMPUTE WS-COMM-AMOUNT = WS-COMM-RATE * WS-GROSS-AMOUNT.
008900     MOVE WS-COMM-AMOUNT   TO  WS-FORMATTED-AMOUNT-Z.
009000     compute WS-FORMATTED-COMM = WS-COMM-RATE * 100.
009100     display "COMMISSION % : " WS-FORMATTED-COMM "%".
009200     DISPLAY "COMMISSION   : " WS-FORMATTED-AMOUNT-Z.
009300    
009400* COMPUTE, FORMAT AND DISPLAY NET PROFIT:          
009500     COMPUTE WS-NET-PROFIT = WS-GROSS-AMOUNT -
009600                             WS-COMM-AMOUNT.
009700     MOVE    WS-NET-PROFIT TO WS-FORMATTED-AMOUNT.
009800     DISPLAY "PROFIT AMOUNT: " WS-FORMATTED-AMOUNT.
009900     
010000     display "______________________________".           
010100     DISPLAY "PROGRAM ENDS" WITH no advancing.
010200     perform 1000-get-date-time.
010300     
010400     display "PRESS ANY KEY TO EXIT"
010500     accept WS-END.
010600     GOBACK.
010700 
010800 1000-get-date-time.
010900     ACCEPT WS-TODAYS-DATE from date yyyymmdd.
011000     ACCEPT WS-TIME        from time.
011100     DISPLAY " ON " WS-TODAYS-DATE
011200             " AT " WS-TIME-HH ":" WS-TIME-MM ":" WS-TIME-SS.