200 likes | 320 Vues
Computation & Display Data. DT266/2 Information System COBOL. Used to inform the program of its environment files special devices special characters Configuration Section configures the program to its hardware Special-names - paragraph name. Environment Division.
E N D
Computation & Display Data DT266/2 Information System COBOL
Used to inform the program of its environment files special devices special characters Configuration Section configures the program to its hardware Special-names - paragraph name Environment Division. Configuration Section. Special-names. Currency sign is “£”. This allows the program to use a “£” as a currency symbol - otherwise, a $ is used. Environment Division
Data Division • Pictures • 9 => digit at the position in the picture • A => alphabetic character at the position in the picture • X => alpha numeric at the position in the picture • Decimals points => v and . • Signs s, -, +, CR, DB.
Pictures 01 YOUR-NAME PIC A(10). 01 AGE PIC 999. • A picture describes the number of characters in a data item and the type of characters allowed • Character / alphabetic values are surrounded by “”. 01 message-string pic x(6) value “Hello!”.
Computational vs Display • Numeric pictures are divided into:- • Computational data types • Display data types • Display Data Types • Floating leading characters “-”, “£”, “$”, “z” • Commas and currency symbols.
Computational data types • Can be packed using the COMPUTATIONAL suffix. • Can only include 9, v and s. • v is a VIRTUAL decimal point - it takes up no space • s is an unprintable sign - usually superimposed on the first or last numeric digit. • Computation can be done on these fields (I.e. add, subtract, multiply, divide). • Example s9(7)v99 or s9(7)v99 comp.
Numeric move • Integer • Movement is left justified • Non-filled high-order positions are replaced with zeros • Truncation of high-order digits occurs if the receiving field is not large enough to hold the results • Non-Integer • Decimal alignment is maintained • Movement is from left to right, beginning at the decimal point • Non-filled low-order positions are replaced with zeros
Move • When data is moved into a data item its contents are completely replaced • If source data is too small to fill the item, the remainder is zero or space filled • E.g. • Data Item person-name pic x(15) • Move “Jacinta” to person-name. • Move “Supercalifragalistic” to person-name. • First assignment will leave spaces to right • Second will be truncated on right
Moving Computational Data Types • Example #1 • AMOUNT-A PIC 9999 VALUE 1000. • AMOUNT-B PIC 999 VALUE 999. • After command • MOVE AMOUNT-A TO AMOUNT-B • AMOUNTB=000 (Lost leftmost digit)
Moving Computational Data Types • Example #2 • AMOUNT-A PIC 99v99 VALUE 1234. • AMOUNT-B PIC 99v999 VALUE 56789. • (Implied decimal point 56.789) • After command • MOVE AMOUNT-A TO AMOUNT-B • AMOUNTB=12340 • (Implied decimal point 12.340)
Display data types Each character takes up 1 byte Each character must be defined decimal point sign punctuation (e.g. “£”, “$”, “,”) Any data items with extra display symbols cannot be used in computation
Sample display types • 01 Display-amount pic ££,£££,££9.99CR • This will display any positive or negative number, between +9,999,999.99 and -9,999,999.99 • If the number is negative, CR will be shown • If the number is positive, two blanks will replace CR • The £ is floating - a £ will precede the most significant digit. It will be preceded by blanks to fill the area. • The comma will be displayed only if there is a significant digit preceding it.
Pic ---,---.99 12.34 -1,234.56 More display types Z shows blanks for leading zeros pic zzz,zzz.zz. 1,234.56 23.44 123,456.70 pic zzz,999.99+ 012.34+ 1,234.56- pic zzz,999.99- 012.34 1,234.56-
Moredata.cbl Identification Division. Program-Id. moredata initial. *Introducing the Environment Division, more data types and conditions. Environment Division. Configuration Section. Special-names. Currency sign is "£".
Moredata.cbl Data Division. Working-Storage Section. 01 Item-cost pic 99v99 value 0. 01 No-of-items pic 99 value 0. 88 valid-no value 8 through 15. 01 Amount-proferred pic 9(4)v99 value 0. 01 Amount-of-change pic s9(4)v99 value 0. 01 total-cost pic 9(4)v99 value 0. 01 Display-cost pic ££9.99. 01 Display-total-cost pic £(4)9.99. 01 Display-change pic £(4)9.99-.
Moredata.cbl Procedure Division. Perform Transaction-item-info until valid-no. Perform calculate-and-display-change. Stop Run. Transaction-item-info. Display "Item purchase transaction". Display " ". Display "Enter item cost (99.99 format):" with no advancing. Accept item-cost. Display "Enter number of items (08 to 15):” with no advancing. Accept No-of-items.
Moredata.cbl If valid-no Display "Enter amount proferred (9999.99 format):" with no advancing Accept Amount-proferred else Display "Number of items 08 to 15 - try again!" end-if.
Moredata.cbl Calculate-and-display-change. Multiply Item-cost by No-of-items giving total-cost. Move total-cost to display-total-cost. Display "Total cost of transaction is", display-total-cost. Subtract total-cost from amount-proferred giving display-change. Display "Change to be given is:", Display-change.
Group items • A 01 item can contain subordinate items • An item subordinate to a 01 item • has a higher level number than its owning level • gives the picture (alphanumeric) to the owning level 01 Person-details. What picture? 02 Person-name pic x(20). 02 Person-address. What picture? 03 Address-road pic x(30). 03 Address-area pic x(15). 03 Address-county pic x(20). 03 Address-zip pic x(15).