דילוג לתוכן המרכזי
eLearner.app
מודול 1 · שיעור 2 מתוך 22/10 בקורס~12 min
שיעורי מודול (2/2)

משתנים ותמונה

In COBOL, all variables used must be declared inside the DATA DIVISION. Specifically, temporary variables in memory used for program logic reside inside the WORKING-STORAGE SECTION.

Level Numbers

COBOL variable declaration makes use of level numbers to structure and organize data hierarchically:

  • 01: Defines a main variable or group item (the highest level).
  • 05, 10, 15: Define subordinate fields within a level 01 group item.
  • 77: Historically indicated independent elementary variables that could not be subdivided further.

In modern practice, level 01 is commonly used to declare independent elementary variables.

The PICTURE (or PIC) Clause

The PICTURE (abbreviated PIC) clause specifies the type of data and the character length of the variable. The three fundamental format characters are:

  1. X (Alphanumeric): Can contain letters, numbers, and special characters.
    • PIC X(10) declares a string of exactly 10 characters.
  2. 9 (Numeric): Can only contain numeric digits.
    • PIC 9(3) declares an integer composed of 3 digits (up to 999).
  3. V (Implicit Decimal Point): Used in decimal numbers to represent where the fractional part begins (the decimal point is not stored physically).
    • PIC 9(3)V99 declares a number with 3 integer digits and 2 decimal places.

The VALUE Clause

To assign an initial value to a variable at declaration time, use the VALUE clause.

Code
01 WS-PROJECT-NAME PIC X(15) VALUE "ELEARNER".
01 WS-USER-AGE     PIC 9(3)  VALUE 25.

All variable definitions must end with a period ..


Try it yourself

פעילות גופנית#cobol.m1.l2.e1
ניסיונות: 0טוען...

Declare a level 01 alphanumeric variable named WS-USER-NAME of length 20 characters and set its initial value to 'ALICE'.

טוען עורך...
הצג רמז

Use the format: 01 WS-USER-NAME PIC X(20) VALUE 'ALICE'.

הפתרון זמין לאחר 3 ניסיונות

פעילות גופנית#cobol.m1.l2.e2
ניסיונות: 0טוען...

Declare a level 01 numeric variable named WS-USER-AGE of 3 digits with an initial value of 25.

טוען עורך...
הצג רמז

Use the syntax: 01 WS-USER-AGE PIC 9(3) VALUE 25.

הפתרון זמין לאחר 3 ניסיונות