COP 2121 Some Basic Cobol Verbs

From In The Wings
Revision as of 12:42, 23 February 2007 by Jka (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The DISPLAY Verb

  • Used to display several data items or literals or any combination of these
  • The WITH NO ADVANCING clause suppresses the carriage return/line feed
IDENTIFICATION DIVISION.
PROGRAM-ID. DisplayOption.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 	Int-1		PIC 999 		VALUE 100.
01 	Alph-1  	PIC XXX 	VALUE “ABC”

PROCEDURE DIVISION.
MAIN-ROUTINE.
	DISPLAY Int-1
	DISPLAY Alpha-1
	DISPLAY “Demonstrating NO ADVANCING  Option”
	DISPLAY Int-1 WITH NO ADVANCING
	DISPLAY Alpha-1
	DISPLAY Alpha-1
        STOP RUN.

The ACCEPT Verb

  • Gets the user response and stores the data in the memory allocated for the Identifier in the WS section
IDENTIFICATION DIVISION.
PROGRAM-ID.  AcceptAndDisplay.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 StudentDetails.
   02  StudentName.
       03 Surname      		PIC X(8).
       03 Initials    	 	PIC XX.
   02  StudentId       		PIC 9(7).
   02  CourseCode      		PIC X(4).
   02  Section           		PIC 9(4).
   02  Gender          		PIC X.

01 CurrentDate.
   02  CurrentYear     		PIC 99.
   02  CurrentMonth    		PIC 99.
   02  CurrentDay      		PIC 99.

01 DayOfYear.
   02  FILLER          		PIC 99.
   02  YearDay         		PIC 9(3).

01 CurrentTime.
   02  CurrentHour     		PIC 99.
   02  CurrentMinute   		PIC 99.
   02  FILLER         		PIC 9(4).
PROCEDURE DIVISION.
Begin.
    DISPLAY "Enter student details using template below".
    DISPLAY "NNNNNNNNNNSSSSSSSCCCCGGGGS                ".
    ACCEPT  StudentDetails.
    ACCEPT  CurrentDate FROM DATE.
    ACCEPT  DayOfYear FROM DAY.
    ACCEPT  CurrentTime FROM TIME.
    DISPLAY "Name is ", Initials SPACE Surname.
    DISPLAY "Date is " CurrentDay SPACE CurrentMonth SPACE CurrentYear.
    DISPLAY "Today is day " YearDay " of the year".
    DISPLAY "The time is " CurrentHour ":" CurrentMinute.
    STOP RUN.

The MOVE Verb

  • Copies data from the Identifier-1 or literal to one or more destination identifiers
  • The source and destination identifiers can be group or elementary data items

MOVEing Data to Alphanumeric Item

  • When the destination item is alphanumeric or alphabetic (PIC X or A) data is copied into the destination area from left to right
    • If receiving field is longer, low-order (right-most) positions are replaced with spaces
    • If receiving field is shorter, low-order characters in sending field are truncated

MOVEing Data to Numeric Item

  • Data is aligned along the decimal point
    • When the decimal point is not explicitly specified in either the source or destination items, the item is treated as if it had an assumed decimal point immediately after its rightmost character
  • Digits in integer part moved right to left starting at decimal point
    • Unfilled high-order (leftmost) integer positions filled with zeros if receiving field has more integer positions than sending field
    • High-order digits truncated if receiving field has fewer integer digits than sending field
  • Digits in decimal part moved left to right starting at decimal point
    • Unfilled low-order decimal positions filled with zeros if receiving field has more decimal positions than sending field
    • Low-order digits are truncated if receiving field has fewer decimal positions than sending field

Group Move

  • When receiving field is a group item, alphanumeric MOVE rules are followed
  • If subfields are numeric, invalid data may be stored in subfields

Recommendations

  • Avoid using sending field with different data type than receiving field
  • Move numeric fields, numeric literals, or ZEROS to numeric fields
  • Move alphanumeric fields, nonnumeric literals, ZEROS or SPACES to alphanumeric fields

Arithmetic Verbs

  • ADD, SUBTRACT, MULTIPLY, DIVIDE
  • All require fields operated on to
    • Have numeric PICTURE clause
    • Contain numeric data when statements are executed