lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed digit ValuePICStored 0Z(4)(spaces) 0ZZZ90 87ZZZ987 +2,319ZZ,ZZZ-2, ZZ,ZZZ ,933Z,ZZZ.99-5, Z,ZZZ
lecture 32 PROCEDURE DIVISION Contains instructions to read, process, and output data I/O operations (OPEN, CLOSE, READ, WRITE), MOVE, DISPLAY, ACCEPT, Arithmetic (ADD, SUBSTRACT, MULTIPLY, DIVIDE), STOP RUN, …
lecture 33 Coding the Procedure Division Divide into paragraphs Each paragraph represents one procedure The first procedure should represent the function of the entire program The procedures called by the first procedure should represent the functions performed by those procedures
lecture 34 PERFORM/PERFORM UNTIL PERFORM procedure-name. Skips to the named procedure, executes it, and returns to the statement after the PERFORM. PERFORM procedure-name UNTIL condition. Execute the procedure until the condition is true. It’s a loop statement The condition is tested first Execution continues after PERFORM when condition is true.
lecture 35 STOP RUN statement STOP RUN. Terminates the program Should appear only once in your program All files should be closed prior to executing this statement
lecture 36 MOVE - Assignment MOVE {data-name | literal } TO data-name-2 …. Copies data from a sending field to one or more receiving fields MOVE NUMBER-ENTERED TO PAY-RATE. MOVE “Y” TO END-OF-SESSION-SWITCH. MOVE 1 TO PAGE-NUMBER. Move data to multiple locations MOVE 15 TO NUM-1 NUM-2 NUM-3
lecture 37 MOVE The original data is retained in the sending field (only a copy operation) If the sending field is numeric and the receiving field is numeric edited, the MOVE converts from one form to the other If (receiving field size > sending field size) then –filled out with trailing blanks in an alphanumeric move, or –leading zeros in a numeric move If (receiving field size < sending field size) then moved data is truncated
lecture 38 SENDING FIELDRECEIVING FIELD Alphabetic Alphanumeric Numeric Numeric Edited ALPHABETIC ALPHANUMERIC NUMERIC NUMERIC EDITED Valid Invalid Valid Integer Valid Invalid Integer Valid Invalid Integer Valid Invalid MOVE Rules
lecture 39 Examples Alphanumeric Alphanumeric PIC SendingContentsPIC Rec.Contents X(5)‘ABCDE’X(5)‘ABCDE’ X(5)‘ABCDE’X(4)‘ABCD’ X(5)‘ABCDE’X(6)‘ABCDE ‘ Data is copied from left to right with space filling or truncation on the right The contents of the receiving item are completely replaced
lecture 310 Examples Numeric Numeric PIC SendingContentsPIC Rec.Contents 9(5)123459(5) (5)123459(4)2345 9(5)123459(6) (3)V99123^459(3)123 9(3)V99123^459V993^45 9(3)1239(3)V99123^00 Data is aligned at the decimal point with zero filling or truncation as necessary When the decimal point is not explicitly specified, an assumed decimal point is implied immediately after its rightmost character
lecture 311 OPEN Read/Write Close OPEN –Only the files you declared in a SELECT and corresponding FD statements CLOSE –You should close a file when either : it will not be read/written anymore before the program ends File I/O
lecture 312 OPEN and CLOSE OPENINPUT filename-1... OUTPUTfilename-2 … CLOSEfilename … INPUT is a file you read into the program OUTPUT is a file the program writes into OPEN/CLOSE many files on the same line Call OPEN before any READ/WRITE After CLOSE you cannot READ/WRITE. If you OPEN an input file again, you can read the records starting from the first record
lecture 313 READ READ filename AT END statement END-READ. The filename is defined with FD Reads a single record Each successive call reads the next record AT END (optional) executes the statement if the EOF has been reached END-READ is optional (don’t forget period).
lecture 314 Priming Read Pseudocode Read input record Priming Read Loop if not EOF Calculate information Read input next record End-loop
lecture 315 Priming Read … MOVE ‘N’ TO INPUT-EOF. READ INPUT-FILE AT END MOVE ‘Y’ TO INPUT-EOF. … PERFORM PROCESS-RECORDS UNTIL INPUT-EOF = ‘Y’. … PROCESS RECORDS … READ INPUT-FILE AT-END MOVE ‘Y’ TO INPUT-EOF.
lecture 316 WRITE WRITE record-name AFTER/BEFORE ADVANCING more. more is PAGE integer [LINE | LINES] data-name [LINE | LINES] One record is written to the file AFTER/BEFORE ADVANCING (optional) –Printer usage to advance to the top of the next page or advance a number of lines
lecture 317 DISPLAY DISPLAY (data-name-1 | literal-1) … WITH NO ADVANCING. Display literals or data values on the screen A single DISPLAY can display several items (separated by spaces) and then a carriage return The WITH NO ADVANCING clause (optional) suppresses the carriage return Handy tool to debug your program
lecture 318 Examples DISPLAY “ “. DISPLAY DISPLAY “ ” DISPLAY “End of Session.”. DISPLAY SALES-AMOUNT. DISPLAY “THE SALES AMOUNT IS “ SALES-AMOUNT “.”.
lecture 319 ACCEPT ACCEPT data-name FROM reserve-word. Waits for input from the user Input is stored in the variable data-name and the cursor moves to the next line Input should be consistent with the PIC of the data-name. If not, it may be truncated or adjusted. FROM reserve word (optional) : DATEPIC 9(6)YYMMDD DAYPIC 9(5)YYDDD DAY-OF-WEEKPIC 91 = Monday TIMEPIC 9(8)HHMMSSss ss = S/100 military time
lecture 320 ADD DATA NAMEA BC Value before execution Value after execution of: ADD A TO C ADD A B TO C ADD A TO B GIVING C ADD A 18 B GIVING C ADD A 18 B TO C ADD 1 TO B C
lecture 321 DATA NAMEA BCD Value before execution Value after execution of: SUBTRACT A FROM C SUBTRACT A B FROM C SUBTRACT A B FROM C GIVING D SUBTRACT 10 FROM C D SUBTRACT
lecture 322 DATA NAMEA BC Value before execution Value after execution of: MULTIPLY B BY A GIVING C MULTIPLY A BY B GIVING C MULTIPLY A BY B MULTIPLY B BY A MULTIPLY A BY 3 GIVING B C MULTIPLY
lecture 323 DATA NAMEA BC Value before execution Value after execution of: DIVIDE 2 INTO B DIVIDE 2 INTO B GIVING C DIVIDE B BY 5 GIVING A DIVIDE A INTO B C DIVIDE A INTO B GIVING C DIVIDE 3 INTO A GIVING B REMAINDER C DIVIDE
lecture 324 Conditions Format : {variable|literal|reserve-const} symbol {variable|literal|reserve-const} Symbol = <>>=<= Reserve-const ZERO, ZEROS, SPACE, SPACES