Sei sulla pagina 1di 10

COBOL

In strongly typed languages like Modula-2, Pascal or ADA

the assignment operation is simple because assignment is


only allowed between data items with compatible types.

The simplicity of assignment in these languages is achieved

at the cost of having a large number of data types.

In COBOL there are basically only three data types,

Alphabetic (PIC A)
Alphanumeric (PIC X)
Numeric (PIC 9)

But this simplicity is achieved only at the cost of having a

very complex assignment statement.

In COBOL assignment is achieved using the MOVE verb.

09/03/16

ER/CORP/CRS/LA01

The MOVE Verb


Identifier

MOVE

Literal

TO Identifier ...

The MOVE copies data from the source identifier or literal


to one or more destination identifiers.

The source and destination identifiers can be group or


elementary data items.

When the destination item is alphanumeric or alphabetic


(PIC X or A) data is copied into the destination area from
left to right with space filling or truncation on the right.

When data is MOVEd into an item the contents of the item


are completely replaced. If the source data is too small to
fill the destination item entirely the remaining area is zero
or space filled.
09/03/16

ER/CORP/CRS/LA01

MOVE Example
MOVE
MOVE JHON
JHON TO
TO SUR-NAME.
SUR-NAME.
MOVE
MOVE PATRICK
PATRICK TO
TO SUR-NAME.
SUR-NAME.

01 SUR-NAME PIC X(008).

09/03/16

ER/CORP/CRS/LA01

MOVE Example
MOVE
MOVE JHON
JHON TO
TO SUR-NAME.
SUR-NAME.
MOVE
MOVE PATRICK
PATRICK TO
TO SUR-NAME.
SUR-NAME.

01 SUR-NAME PIC X(008).

J H O N

09/03/16

ER/CORP/CRS/LA01

MOVE Example
MOVE
MOVE RYAN
RYAN TO
TO SUR-NAME.
SUR-NAME.
MOVE
MOVE PATRICK
PATRICK TO
TO SUR-NAME.
SUR-NAME.

01 SUR-NAME PIC X(008).

P A T R I C K

09/03/16

ER/CORP/CRS/LA01

MOVE to a numeric
item

When the destination item is numeric, or edited


numeric, then data is aligned along the decimal point
with zero filling or truncation as necessary.

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.

09/03/16

ER/CORP/CRS/LA01

MOVE - Example
01 GROSS-PAY

PIC 9(004)V99.
GROSS-PAY

0 0 0 0 0 0

MOVE ZEROS TO GROSS-PAY.

GROSS-PAY

0 0 1 2 4 0

MOVE 12.4 TO GROSS-PAY.

GROSS-PAY

MOVE 123.456 TO GROSS-PAY.

0 1 2 3 4 5 6

MOVE 12345.757 TO GROSSPAY.


09/03/16

GROSS-PAY

1 2 3 4 5 7 5 7

ER/CORP/CRS/LA01

MOVE - Example
01 COUNTRY-POP
01 PRICE-RS

PIC 999.
PIC 999V99.
COUNTRY-POP

MOVE 1234 TO COUNTRY-POP.

1 2 3 4

MOVE 12.4 TO COUNTRY-POP.

COUNTRY-POP

0 1 2 4

MOVE 154 TO PRICE-RS.

PRICE-RS

1 5 4 0 0
MOVE 3552.75 TO PRICE-RS.
09/03/16

ER/CORP/CRS/LA01

PRICE-RS

3 5 5 2 7 5

The DISPLAY Verb


Identifier

DISPLAY
Literal

Identifier
...

Literal

UPON Mnemonic - Name WITH NO ADVANCING

From time to time it may be useful to display messages and


data values on the screen.

A simple DISPLAY statement can be used to achieve this.

A single DISPLAY can be used to display several data items,


literal or any combination of these.

The WITH NO ADVANCING clause suppresses the carriage


return/line feed. For example, DISPLAY ENTER ACCOUNT
NO. WITH NO ADVANCING CLUSE means that the prompt
for acct no will remain on the same line as the message.
09/03/16

ER/CORP/CRS/LA01

The ACCEPT verb


Format 1. ACCEPT Identifier FROM Mnemonic - name
DATE

DAY

Format 2. ACCEPT Identifier FROM


DAY
OF
WEEK

TIME

Examples

01
CURRENT-DATE
01
CURRENT-DATE
* YYMMDD
* YYMMDD

PIC
PIC 9(006).
9(006).

01
DAY-OF-YEAR
PIC
9(005).
01
DAY-OF-YEAR
PIC
9(005).
** YYDDD
(Julian
Date
format)
YYDDD (Julian Date format)
01
DAY-0F-WEEK
01
DAY-0F-WEEK
* D (1=Monday)

PIC
PIC 9(001).
9(001).

01
CURRENT-TIME
01
CURRENT-TIME
* HHMMSSss
s = S/100

PIC
PIC 9(008).
9(008).

* D (1=Monday)
* HHMMSSss

09/03/16

s = S/100

ER/CORP/CRS/LA01

10

Potrebbero piacerti anche