8/8/2019 Descriere PRE
1/217
0 !+ 1
K MANUAL OF LANGUAGE HBL
0 !+ 2K1. CHAPTER 1: INTRODUCTION TO LANGUAGE
HBL
This manual describes the language for programming in HBL and is
addressed to whom are already familiar with programming and wants
not be a lesson about programming skill.
The language HBL is originated from DIBOL 11 (DEC) and preserves
some peculiar feature of that.
Whos already expert of DIBOL programming can easily utilize HBL
without traumas.
K MANUAL OF LANGUAGE HBL ;
K1. CHAPTER 1: INTRODUCTION TO LANGUAGE HBL ;
Page 1
8/8/2019 Descriere PRE
2/217
0 !+ 3
K1.1. System Philosophy
A computer programmer should have permission to spend his working
time on thinking about creative solutions without have unnatural
constrictions made by programming language.
The elements of structured program of a language permit the
programmer
to show quickly the solutions by a code having a logic structure very
clear.
This reduces working time and the possibility to make mistakes of
programming; many programmers believe in fact that structural
programming improves efficiency and accuracy of a program.
The HBL, instead, generally, doesnt permit structured programming
because misses those instructions ( as BEGIN-END of DIBOL) that
realize this kind of programming. However, some conventions and
criteria of programming, they will be described in details in this text,
will allowed to create codices of programming having a logic structure
similar to that structured, inheriting all the advantages and more easy
to carry through and read again.
The operational features of a programming language should remain
consistent across operating systems.
HBL permit user to develop a program in a system and move his
software to other system without refill it.
The time to be spent by user to change his program is only when the
K System Philosophy;
Page 2
8/8/2019 Descriere PRE
3/217
original application is created expressively for a particular operating
system and he will be helped by facilities available only in that system.
On giving less elements as possible depending on the system, HBL
minimizes the inclination on developing software and realize
programs for particulars operating systems.
Therefore by HBL is possible reach a wide market of sales without
having to keep a different version of program for each operating
system.
8/8/2019 Descriere PRE
4/217
0 !+ 3
K1.2. Components of System
The main components of HBL are:
Compiler
Accepts rising files including instructions of language HBL
and creates the
strings object containing information at system level that
explain the actions
requested by the program. This manual describes instructions
and organization necessary for a program.
The program of HBL link combines the files object to
make the files of executing code.
Runtime
Performs the actions requested by HBL programmer during
the execution.
This code is never linked with HBL program, so that the
user can generally
update the runtime without link again the existent HBL
programs.
Library of Subroutine External (HLIB)
Is a collection of external subroutines given by HBL, its
including functions added standard that really extend the
same language.
KComponents of System;
Page3
8/8/2019 Descriere PRE
5/217
Method of Access Sequential with Index (ISAM)
Although a programmer can designate his own structures of
file, HBL
does permit facilities ISAM that give a powered structure of
file that improves the access to records whether casual or
sequential.
HBL permits a system ISAM multi-keys that reuses the
space of deleted data, giving up to frequently rearrange of
files deleted ISAM.
The user can create a file to store, restore and update the
information basing on one or more key fields of data of the
record.
For example, the information utilized can be stored in
a file ISA by using the number to identify any record done.
8/8/2019 Descriere PRE
6/217
Debug Symbolical
Allows the program to run in special debug mode
.
This mode is used during the development of program or
when a problem arises during the program drawing up.
Unlike some debuggers that require programs to include
special codices of debug program, its not necessary any
preparation to have HBL running debug mode.
8/8/2019 Descriere PRE
7/217
Page 4
8/8/2019 Descriere PRE
8/217
8/8/2019 Descriere PRE
9/217
0 !+ 2
K2. CHAPTER II: BASIC ELEMENTS OF LANGUAGE
This chapter gives general information about HBL language and about
the structure of HBL programs, introduces the instructions used to
construct the programs and describes the basic elements of language.
KBASIC ELEMENTS OF LANGUAGE;
8/8/2019 Descriere PRE
10/217
0 !+ 3
K2.1. Assemblage of Characters
The basic unit of HBL language is the ASCII character.( Appendix A
lists a assemblage of ASCII characters) The characters are combined in
sequences representing the elements
of HBL language and they are called separators. The sub assemblage
of ASCII characters used in this manual are defined as follow:
:
Numerical : 0, 1, 2, 3, 4, 5, 6, 7, 8 e 9.
Alphabetical: are capital characters from A to Z and small
characters from a to z
Alphanumerical: are both numerical and alphabetical.
Alpha: all ASCII characters, except those that control the devices of I/O
(i.e. carriage return, line feed and form feed).
KAssemblage of Characters ;
8/8/2019 Descriere PRE
11/217
0 !+ 3
K2.2. Organization of a Program
A HBL program consists of a Data Division and a Procedure
Division.
The Data Division defines the data structures that will be used,
instead the Procedure Division defines the algorithms.
The compiling instruction of control PROC splits the two divisions.
The compiling instruction of control END in Procedure Division ends
the main lines
of program (i.e. main)
HBL encourages the modular programming that reduces big programs
to programs checking few main lines and very small subroutine
programs.
Subroutines programs are called by main lines and possibly by other
lines of program.
HBL anticipates an instruction SUBROUTINE that identifies
beginning of subroutine
(See chapter 3 for discussion of instruction SUBROUTINE)
KOrganization of a Program;
8/8/2019 Descriere PRE
12/217
8/8/2019 Descriere PRE
13/217
0 !+ 3
K2.3. Types of Instructions
The HBL instructions are classified as follow:
Instructions of Control for Compiling
Instructions to Manipulate Data
Instructions for Control of Program
Instructions of I/O
In this section will be briefly explained the categories and the
instructions.
A more detailed description will be given on next chapters.
2.3.1.Instructions of Control for Compiling
The Instructions of Control for Compiling are to teach the HBL
compiler and are evaluated only when the program is compiled; they
are not included in the resulting executable program.
PROC
Ends the Division Data and starts the Procedure
Division.
END
Marks the end of program.
KTypes of Instructions;
8/8/2019 Descriere PRE
14/217
2.3.2. Instructions of Data Division
The instructions parts of this group appear only in Data Division,
where the instruction RECORD defines the elements and the other
instructions determinate which modules are using these elements.
The instruction SUBROUTINE is included in this group because it
does appear at the head of Data Division and in the subroutines.
COMMON
Is similar to instruction RECORD in a main program, in fact
both define data of type record and the field associated.
Records and defined fields can be used both by main
program and by subroutine programs.
The data is part of main program.
In a subroutine program COMMON defines the references to
areas of data defined in the main program.
Differing from instruction RECORD, however, it will not be
defined a new space of data.
GLOBAL
Specifies that all definitions RECORD following the
instruction
GLOBAL must be spaces of data allocated in regions of
memory particular having a name instead of in the region
that normally the compiler uses.
This allow both main and subroutine programs to declare
some connections with these data regions and that can be
shared.
RECORD
Defines the disposition of a data type record and defines his
data field.
8/8/2019 Descriere PRE
15/217
Data field in record are defined from left to right in
sequence as they show themselves up.
Only the program that is defining it can access to a data of
kind record (and to his associated fields).
VRECORD
Defines a record VIRTUAL, to build in RUN-TIME.
Inside of a VRECORD we can define pointers to other field
already defined, to obtain a different data grouping.
SUBROUTINE
Identifies the program to compile like a subroutine more than
as
a main program
The instruction SUBROUTINE defines also the parameters
by which the information are passed from the calling
program and subroutine program.
8/8/2019 Descriere PRE
16/217
2.3.3. Instructions to Manipulate Data
These instructions are manipulating data directly:
CLEAR
Initializes one or more variables both by blank (for variables
alpha) and zeros (for decimals variables)
DECR
Decreases of one a decimal variable specified.
INCR
Increases of one a decimal variable specified.
LOCASE
Converts all capital characters of a variable alpha into small
characters.
UPCASE
Converts all small characters of a variable alpha into
capital
characters.
8/8/2019 Descriere PRE
17/217
2.3.4. Instructions for Control of Program
The execution of HBL program starts by the instruction following
PROC and proceeds sequentially on all the remaining programs
instructions.
These kinds of commands are used to create cycles and functions
internal to a program.
CALL
Does transfer the control to a label of program. The control
backs when a command of RETURN is done, ending the
function.
GOTO
Does transfer the control of execution to a specified label.
can be used both non conditioned form or calculated form;
the last one selects a label from a ordered labels list.
IF
Performs an instruction if the logic condition in TRUE.
OFFERROR
Disables the errors trapping (management) set by
ONERROR instruction.
ONERROR
Permits program to manage errors trapping.
The program is stopped immediately when detects the
specified error and restarts at the instruction following the
error label.
RETURN
Completes the execution of a function internal to program or
subroutine program.
The execution backs to the instruction following CALL or
8/8/2019 Descriere PRE
18/217
XCALL that invokes the function or the subroutine.
SLEEP
Stand by the execution for a specified number of seconds.
STOP
Finishes the execution of current program.
Are foreseen two forms: one unconditioned, that backs the
control to system control, the other one is a linking form that
backs the control of execution to another program.
XCALL
Transfers the execution control to a subroutine program
external.
The information can be transferred by variables COMMON or
GLOBAL
or through the arguments of subroutine.
8/8/2019 Descriere PRE
19/217
2.3.5. Instructions of Input/Output
This group of instructions controls the data exchange between the
programs in execution and devices of input/output connected to the
computer system.
These are including devices to store data (i.e. disks and floppy),
printers,
terminals and any other way for data transmission connected to
system.
ACCEPT
Obtains next sequential character from a file (generally from
terminal).
CLOSE
Ends I/O activities on a HBL channel.
DELETE
Deletes a record with key from a ISAM file.
DISPLAY
Writes on file a sequence of one or more characters
(generally on terminal)
FIND
Detects the position of a record in file ISAM to be next
record read by instruction of READS.
FORMS
Controls line or page shift on output file (i.e. printer)
GET
Gets a fixed length binary record from a specified point of
file.
This is an operation binary that is not giving importance to
ASCII characters received.
GETS
Is similar to instruction GET except that the access is
sequential
8/8/2019 Descriere PRE
20/217
instead of casual. The record follows immediately last
information exchanged with the files.
OPEN
Connects an I/O device to the internal channel HBL.
Once that this association is done, the instructions of I/O can
work in this channel till done CLOSE or till program ending.
PUT
Writes a binary record of fixed length in a point of file
specified. This is an operation of binary writing and no
record terminator is affixed (unlike of WRITE)
PUTS
Is similar to instruction PUT except that the access is
sequential
instead of casual. The record is placed in file in the current
position.
READ
Obtains a record ASCII of variable length, from a specified
point of file. The information is accepted until encounters a
record terminator.
READS
Is like the instruction of READ not including that the access
is sequential instead of casual. The record follows last
information exchanged with the files.
READB
Is valid only for files ISAM, does permit to read sequentially
backward. It gives back the record previous to last
exchanged
with the files. This instruction is not in DIBOL-11
RECV
Receives a queued message by an instruction SEND
8/8/2019 Descriere PRE
21/217
previously
executed by current program or by some other program in
the same session.
SEND
It does put a message in queue. We can get it later by
instruction: RECV.
STORE
Memorizes a record into a file ISAM based on one or more
keys
that are internally to the record.
UNLOCK
Unlocks blocked records (automatically) from the current
program.
WRITE
Transmits a record ASCII of variable length to a point
specified
of file. The information transmitted is affixed with a record
terminator.
WRITES
Is like WRITE instruction except the access that is
sequential. The record is inserted in file after last record
exchanged with the files.
8/8/2019 Descriere PRE
22/217
0 !+ 3
K2.4. Format of Instruction Lines
HBL instruction is a single logic line of information that can have no
coincidence with a physic line of code.
Because is not practical to work with lines over 120 characters (80
for the majority of CRT terminals), some time is necessary use lines of
continuation to split a logic line of instruction to shorter physic lines.
The compiler manages a physic line and all the succeeding lines as a
logic line.
A physic line cant be longer than 256 characters (excluding line
terminators).
An instruction can be anywhere in his own logic line.
Blanks and precedent or following tabs are ignored.
The programmer can adopt convention reasonable on identifications
to make the program more readable as possible, because a good
reading
simplifies all other appearance of programs develop and
maintenance.
Well discuss widely about the appearance of program reading in
chapter 6.
KFormat of Istruction Lines;
8/8/2019 Descriere PRE
23/217
2.4.1. Label of Istructions
Any instruction of Procedure Division can be referred by a symbolic
name.
To this label are referred many control instructions of program to
transfer the control to a specified instruction.
The label of instruction must be the first sequence of the instruction,
followed by comma.
The label is composed by alphanumerical characters, but the first one
must be alphabetical.
In example the name SUB04 is acceptable, 3ST6 is not. Consider as
follow:
GOTO LBL02 ;(no label, referred to LBL02)
.
.
.
LBL02, IF (FLG)
CALL SF03 ;( label, referred to F03)
GOTO DONE ;(no label, refers to DONE)
8/8/2019 Descriere PRE
24/217
2.4.2. Lines of Continuation
.
An instruction line HBL can be broken in more consecutive parts.
The second part and next are called continuation lines and they start
by
e commercial (&).
On to improve the reading, blank and tab can precede the symbol &.
However no blank line or comment or directions compiling, can be
inserted
between continuation lines associated or between the first physic line
and
his continuation lines.
For example:
LBL02, GOTO(YSC01,YSC02, ; First two choices
&YSC03,YSC04 ; Second two choices
&),K ; Depending on K
Is not compiled correctly because there are comments. Those comments
are breaking the continuity.
Instead:
LBL02, GOTO(YSC01,YSC02,
&YSC03,YSC04
&),K ; Depending on K
Its correct and can also be written as:
8/8/2019 Descriere PRE
25/217
LBL02, GOTO(YSC01,YSC02,
& YSC03,YSC04
& ),K ; Depending on K
Both are functioning in the mode like to:
LBL02, GOTO(YSC01,YSC02,YSC03,YSC04),K
All the characters that are following the symbol &, except the
comments
at end line, are considered part of the instruction.
To avoid ambiguous problems of programming is not possible break a
constant alpha by the continuation symbol.
In necessary case we need support by opportune traced record and
initialize
the constant alpha by fragments.
See the section 2.8.1 for further discussion of alpha constants.
8/8/2019 Descriere PRE
26/217
2.4.3. Comments
The comments to program scattered between instructions can make
more
understandable the function of the program.
The HBL compiler allows all the physical lines to be ended by a
comment.
In HBL a comment starts by (;), followed by a sequence of ASCII
characters.
If a line contains a constant alpha without a closed apostrophe, the
comment will be interpreted as part of the constant alpha.
2.4.4. Lines Blank
The lines wholly made by blank, tab or optional comments, will be
written
in the list of program but theyll be ignored by HBL compiler.
8/8/2019 Descriere PRE
27/217
0 !+ 3
K2.5. Separators
Some ASCII special characters are used to split consecutive elements
of language in HBL instructions.
Space e Tab
Space and horizontal tab are permitted between adjacent
elements of language and they can be used to improve the
program reading, but they cant be placed internally to the
element s of language and inside constants alpha.
For example, key words, labels with name and data names
cant contain space or tab
Virgola
More than internal of alpha constant, comma has to be used
as permission in specific mode in the description of
instruction format
Parenthesis Right and Left
Right and left brackets must be used as balanced pair except
in alpha constants.
That is for any left bracket must correspond in the following
text a right bracket also.
The left bracket is considered open parenthesis and the right
one is a closed parenthesis.
The bracket pair is including indexes and parts of
information,
is altering the evaluation order of mathematics expression
and Boolean and including the associated arguments to some
instructions HBL.
KSeparators;
8/8/2019 Descriere PRE
28/217
Apex single
The alpha constant are delimited by single apex, open and
closed. The constant alpha value is the whole sequence of
characters between the two limiters.
Semicolon
When semicolon (;) is used external to a constant alpha it
does indicate the end of instruction contained in that line and
the beginning of comment.
All the information from (;) to the physical end of line are
showed in the program list but they are ignored by the HBL
compiler.
Dollar Symbol
The dollar symbol ($) cannot be used in alpha constants,
variables and labels.
If an identifier starts by a ($) symbol, is considered a
function intrinsic. Those functions are explained in Chapter 4.
8/8/2019 Descriere PRE
29/217
0 !+ 3
K2.6. Identifiers
The identifiers are sequences of characters alphanumerical that
transmit information to compiler.
In this section will be described the four kinds of identifiers:
key word, variables names, intrinsic functions names and subroutine
names.
The first character of all the identifiers must be alphabetic, with the
exception of names for intrinsic functions that have to initiate by ($)
symbol or (%) symbol.
Examples of identifiers are: NFIRST, NLAST, TRX.
The HBL compiler is sensitive to context where is used an identifier,
in the way that the same identifier can be a key word, a variable name,
a label, all in the same program.
However if we want obtain a good reading of the program its not
recommended to use this last possibility.
KIdentifiersi;
8/8/2019 Descriere PRE
30/217
2.6.1. Key Words
The key words i.e. READ,END, transmit information to HBL
compiler.
They must be used exactly has showed in the instruction description.
2.6.2. Names of Variables
The names of variables are identifiers that refer to data of record
kind and to the associated fields.
They can be used to improve the program reading;
However, only the first 5 characters are recognized by compiler that
ignores the remaining.
Because the HBL compiler does not convert the small characters to
capital, is necessary that the variable names have to be written by
alphabetic characters capital, with the max length of 5 characters.
2.6.3. Names of Intrinsic Functions
The HBL language supplies with numerous internal functions, known
as intrinsic functions.
A function name is like other identifiers but they have to initiate by
a ($) sign to distinguish them from other identifiers.
( See chapter 4 about name and description of those functions).
2.6.4. Subroutine Names
The names of subroutine are identifiers telling compiler to which
subroutine external program we are referring.
As for the variables names, subroutine names can be long as necessary
for reading, but the compiler recognizes only the first 5 characters of
8/8/2019 Descriere PRE
31/217
the name
and ignores the remaining.
8/8/2019 Descriere PRE
32/217
0 !+ 3
K2.7. Data Types
HBL, because is directed to information processes, uses two forms of
common representation of information:
the string of alpha characters and the string of decimal characters.
Optionally, to speed up eventual computation processes, is possible
use the kind of binary data 32 bit; using this kind is not suggested for
normal
management of I/O files.
2.7.1. Data Alpha
A value of alpha data is a sequence consecutive of character s that
can be treated as an information unit.
Here below there are some examples:
a. This is an example, an example of data alpha!
b.Constant entire per units:
c. 1234567
d. 1a2b3c4d#*&*$&^kh
8/8/2019 Descriere PRE
33/217
that means the number is too long.
Data decimal field are not checked when the records are obtained
from data files; they are checked any time they will be used for
calculations or
as sources of instructions to assign from decimal to alpha or vice
versa.
If characters not numerical are present in a instruction for assign
from decimal to decimal, is generated an error of: Wrong digit on
variable [#20]
Because decimal data fields are including entire values, the
programmer
has to be sure that the data are correctly formatted and regulated
during arithmetical calculation.
2.7.3 Data binary
Data binary of 32 bit can be specified, those will occupy 4 byte of
memory, to be used for index of variables, in the way to speed up the
access in language side.
By this kind of data we can cover a range from -2.147.483.648 to
+2.147.483.647.
Is not recommended use this kind for operation of I/O files,
otherwise we can be limited to sole instructions GET and PUT.
8/8/2019 Descriere PRE
34/217
0 !+ 3
K2.8. Constant
A constant is both a sequence of numerical characters inside limiters
(Single apexes) and a sequence of numerical characters optionally is
preceded by a sign plus or minus.
A constant represents a specific value defined in phase of compilation
and cant be replaced in phase of execution.
2.8.1. Costant Alpha
:
A constant alpha is a sequence of characters contained by single
apexes:
the value of constant is the sequence of characters between two
limiters.
Example of alpha constant as below:
a. 'This is' a constant alph
b. 'as those that follow.......'
c. 'but now', there are not more''
Examples a and c show that when a limiter of an alpha constant is
contained as part of constant value, must be used two limiters adjacent
to represent only one.
In example c, the limiter appears at the end of the constant, then occur
specify one more limiter to close the definition of constant.
Sometime is more convenient to split alpha constant in smaller
physical parts.
KCostant;
8/8/2019 Descriere PRE
35/217
2.8.2. Constant Decimal
A decimal constant is a sequence of numerical characters,
optionally is preceded by a sign plus or minus.
The max number of characters permitted in this constant is 18.
If a decimal constant positive or negative will be used in arithmetical
expression, must be enclose by brackets because the arithmetical
expressions cant contain adjacent arithmetical operators.
8/8/2019 Descriere PRE
36/217
0 !+ 3
K2.9. Variables
Variable is an identifier that refers to a location of memory.
Constant values cant be modified during the execution of program
but variables values can be altered during the execution.
Before to use a variable in a instruction of Procedure Division,
it must be defined in Data Division as a record, or a field alpha or a
decimal field.
More than definition of name and type of data in variable,
the instruction of Data Division determinates the characteristic of
memory of that variable ( that is the length, possible initial values
and positions of memory related to other defined variables).
2.9.1. Simple Variable
Simple variable consists only of name and area data.
A variable not defined as array is referred to the entire area data of
variable, while in the array the variable simple is referring to the first
element of array.
Here below are listed some example of simple variables:
a. HELP
b. Amount
c. P72X3
d. Pins
e. Y73
2.9.2. Variables indexed
KVariabili;
8/8/2019 Descriere PRE
37/217
An indexed variable is referring to an element individual inside of a
list of elements. The name of variable is followed by value of index
contained between round brackets.
The index can be an expression decimal bigger than 0 and defines
the element of list to which we want get in.
For example index to 1 represents the first element of the list.
Any variable can be indexed but his memory area must be inside of
the area data accessible to program.
If area data isnt accessible or if the value of index is smaller of 1,
there will be error: wrong index [#7].
To better understand how the indexed variables are functioning and the
difference with dimensioned array, see the following example:
8/8/2019 Descriere PRE
38/217
Considering the following instruction of Data Division:
RECORD DEMO
ALPHA, 3D4 ,3 ,9876 ,4321
BETA, A6 ,'ABCDEF'
GAMMA, D3 ,545
DELTA, 4A2 ,'LM' ,'NP' ,'RS' ,'TV'
Memory data is allocated as follow:
Variables Memory (characters)
ALPHA(1) 0 0 0 3
(2) 9 8 7 6
(3) 4 3 2 1
BETA A B C D E F
GAMMA 5 4 5
DELTA(1) L M
(2) N P
(3) R S
(4) T V
Reference: to variable Data obtained
DEMO 000398764321ABCDEF545LMNPRSTV
ALPHA 0003
ALPHA(1) 0003
ALPHA(3) 4321
ALPHA(4) ABCD
ALPHA(5) EF54
BETA(2) 545LMN
GAMMA(ALPHA(1)) PRS
DELTA(4) TV
8/8/2019 Descriere PRE
39/217
DELTA(-3) Indexing wrong
ALPHA (4) e ALPHA (5) are both valid references because they are
not extended out of total data space allocated by instructions of data
division;
DELTA (-3) is not acceptable because is not expected a reverse
indexing.
Note that BETA and GAMMA can be indexed even they are simple
variable. BETA (2) is referred to the second group of 6 characters after
beginning of area data of BETA (6 is the extent of single data BETA).
8/8/2019 Descriere PRE
40/217
2.9.2. Interval Absolute
This form of intervals of expression specifies the interval of a
sequence of characters found, and indicates explicitly the initial and
final position by two arithmetical expressions separated by a comma.
Considering the following example:
RECORD ABS
DFLD, D8 ,10203405
AFLD, A13 ,'ABCDEFGHIJKLM'
Reference to variable Data obtained
DFLD(2,4) 020
ABS(8,13) 5ABDCDE
AFLD(3,6) CDEF
AFLD(DFLD(2,3),DFLD(7,8)) BCDE
AFLD(DFLD(2,3)+2,5) DE
AFLD(13,14) MA
DFLD(6,3) Indexing wrong
8/8/2019 Descriere PRE
41/217
2.9.3. Variables indexed Differed
This form permits to refer a field defining his ordinal position inside
to a RECORD, respect to a field PIVOT.
We can combine this index by one of the two methods seen
previously.
Considering the following example:
RECORD ABS
DFLD0, D1 ,9
DFLD, D8 ,10203405
AFLD, A13 ,'ABCDEFGHIJKLM'
DFLD1, D5 ,60708
Reference Data obtained
DFLD(1:) (D8) 10203405
DFLD(2:) (A13) ABCDEFGHIJKLM
DFLD(3:) (D5) 60708
DFLD(4:) (A27) 910203405ABCDEFGHIJKLM60708
DFLD(5:) (??) next memory area
not suggested
AFLD(2:) (D5) 60708
DFLD(2:2) (D8) CDEFGHIJ (bad digit)
DFLD0(3:5,6) (A2) EF
8/8/2019 Descriere PRE
42/217
0 !+ 2
K3. CHAPTER III: DATA DIVISION
The Data Division is the first section of HBL program.
It defines the basic elements used in Procedure Division.
The instructions of RECORD, COMMON, GLOBAL e VRECORD are
used to define the elements and their connections.
The instruction SUBROUTINE must be included at the beginning of
Data Division of a sub routine program.
The instructions RECORD and COMMON define units of information
called record; they are constituted by one or more fields.
The instructions of Procedure Division can manipulate whole records
but also single field.
The instruction RECORD defines the records that can be accessed
generally only from program containing that RECORD instruction.
If the instruction RECORD is inside a field of validity of GLOBAL
instruction, the memory area of record is accessible from any module of
program that refers to the same memory area GLOBAL.
The instruction COMMON defines records accessible from main
program and from subroutine programs referred to record COMMON or
some of his field.
The instruction VRECORD defines a VIRTUAL record to build up in
RUN-TIME any time that is referenced.
KDATA DIVISION;
8/8/2019 Descriere PRE
43/217
Under this instruction we can combine the fields that allocate memory,
with fields that define only the address of other field and are defined in
other RECORD.
The instruction VRECORD cant be contained in a GLOBAL.
As was clear, is necessary to limit the use of VRECORD, because of
heavy management at RUN-TIME level
8/8/2019 Descriere PRE
44/217
8/8/2019 Descriere PRE
45/217
This way is used overall in the I/O operations to exchange records in
a data file.
Note that, when we refer to a record in an instruction of Procedure
Division, its treated as a variable alpha.
8/8/2019 Descriere PRE
46/217
3.1.1.1. Local Record
The local records are defined by instruction RECORD given outside
of
validity field of instruction GLOBAL.
The local record and his fields are called local variables.
The program module in which local variables are defined can be
accessed directly.
Other modules instead cant access directly. However we can refer
directly a subroutine which has specified that variable in his arguments
to a local variable.
To do that, the calling program should specify the variable name in
the instruction XCALL that is calling the subroutine.
3.1.1.2. Record Common
The instruction COMMON defines the record common of a main
program.
Both record common and his fields are called variables common.
A subroutine can refer to a variable common directly by the
instruction
COMMON or can refer indirectly through the arguments of subroutine.
The allocated memory is part of local data area of main program.
The compiler recognizes only the first 5 characters of variable
common name.
The other additional characters appearing in program list are ignored.
L' uso dell' istruzione COMMON nelle subroutine stabilisce i
riferimenti alle aree di memoria del programma main.
The use of instruction COMMON in subroutines determinates the
references to the main program areas.
8/8/2019 Descriere PRE
47/217
Because of the physical structure of record common is defined in a
main program, that structure is unknown during a subroutine
compilation;
Then the control of the structure cant be executed during the
compilation of instruction COMMON in a subroutine.
The compilation creates a reference symbolic to the variable common
called.
The link phase,( that is the process that combines main program and
his subroutines in executable program), determinates the addresses of
memory correctly for any symbolic reference.
Then any declared variable in instruction COMMON in a subroutine
is referred to beginning of memory in the respective variable common
of main program.
That is different from DIBOL-11 that during a link phase of
program,
fixes only the initial point of each variable common of subroutine
and the link of HBL, controls the length of any single variable
COMMON and gives error signal when this one is different from the
one declared in main.
Often the subroutines utilize the common to declare variables in
mode not volatile. (volatile may be = erasable ??)
This can happens when a group of subroutines are executing complex
functions that are sophisticated screen input and control output.
The main program linked with subroutines may have or not have
necessity of data in common.
Despite of it the main program must contain the instruction
COMMON
to define the co division of data areas, because the memory is
allocated during the compilation of instruction COMMON of main and
8/8/2019 Descriere PRE
48/217
because COMMON in a subroutine is referring only to the memory
areas declared in main.
The subroutines with instruction COMMON are stated associated with
their main programs.
When an ensemble of subroutines are modified to be more efficient or
powered, the content or the structure of area COMMON may change.
This makes problems in the management of program, because any
main program that has linked subroutines must be modified at any time
the structures of areas data shared changes.
The programmer can avoid those problems using the instruction
GLOBAL
that is not depending from modules.
8/8/2019 Descriere PRE
49/217
3.1.1.3. Record Global
The global records are defined by instruction RECORD that is inside
of
instruction GLOBAL.
Both global record and his fields are named global variables.
Any instruction GLOBAL defines by name one area of memory
accessible to all programs, then local global are allocated in the
memory
internally the global area in order in which they are declared.
Considering the following instructions of Data Division:
GLOBAL SECTION GLB
RECORD ALEX
FLD1A, A6
FLD2A, D3
RECORD MARY
FLD1M, D2
FLD2M, D7
ENDGLOBAL
Those instructions define a reference to a section named GLB.
The program module access to the first 18 characters of global area and
split them in two consecutive global records.
In DIBOL-11 the magnitude of any global area was determinate by
the bigger global section between those defined by the same name.
If the global section GLB of the above example was used also in
another module, but with length of 139 characters, during the execution
GLB program was established a length of 139 characters.
The above definition was referred only to the first 18 characters of
8/8/2019 Descriere PRE
50/217
the area.
On the contrary the linker HBL makes a control on the length of any
GLOBAL SECTION and signals error in case of declarations unlike
between them.
The global variables accomplish an important function when the
programmer develops the subroutines connected to library.
When these subroutines are in use, they can co divide different
assembles
of data without influence the main program to calling.
Because the calling module is not interested to the content and to the
disposition of global areas, the changing of these areas does not
requires
to modify any main that uses them.
8/8/2019 Descriere PRE
51/217
3.1.1.4. Record Overlay
A program often must re-define the format of a record area.
Considering a data file with a record of uniform length but with a
disposition different determinate by a record variable in all record:
a solution can be to request a program that can use the same internal
area of storing repetitively during the memorizing that comes in
execution.
HBL allows programmer to define those alternative dispositions for a
memory area, including an indicator of overlay (of superimposition) in
any
definition of record.
This indicator consists of two characters, and Xthey appear
like:
X immediately after the name of alternative record disposition;
if the alternative disposition has not name, the overlay indicator is
disposed where the name should stay.
This cause the field definition following the indicator of filling to refer
to memory area defined in overlay record more recent.
We cant assign to overlay record an area of memory bigger than the
one allocated in previous record in overlay if this happens we get an
error of compilation syntax.
On record overlay are added the following restrictions:
1.no one global record can be a record global overlay;
8/8/2019 Descriere PRE
52/217
2. global records cannot superimpose not global records;
3. common record cannot superimpose local record and vice-
versa
(that is on contrary of DIBOL-11)
8/8/2019 Descriere PRE
53/217
Simple examples of record in overlay:
RECORD REC1
A, A5
B, A18
RECORD REC2,X
C, A2
D, A3
RECORD REC3,X
E, A23
COMMON CMN1
CA, A4
CB, A5
COMMON,X
CC, A2
The variable C is referred to the first two characters of A.
The variable D is referred to the last 3 characters of A.
8/8/2019 Descriere PRE
54/217
The variable E is referred to the whole area of memory
allocated to REC1.
8/8/2019 Descriere PRE
55/217
3.1.1.5 Record Virtual
The virtual records can be considered an extension of OVERLAY
records.
Also in this case new memory will not be allocated but will be defined
a record trace that use defined fields in other records.
To insert reference to other records fields, after the field definition, we
insert the name of reference field, preceded by symbol @ (see 3.2)
Inside virtual record theres also the possibility to define fields
allocating memory.
Using this technique we simplify considerably the writing of code by
programmer, because we are allowed to define some views of data
that are the combination of other data.
In these views, for example, we can insert values coming from another
trace record, blank selectively fields define a trace of print and edit.
The construction of record is made at execution time, that is
any time the record is referenced, for this, should not abuse using
virtual records and utilize them only for make a group as previously
discussed.
If we reference the single field of virtual record, it does not make
heavy
the execution and the compiler act as per the record in overlay.
To the virtual records, more than the restrictions indicated for record in
overlay, are added the following restrictions:
1. Is not allowed define a record in overlay to a virtual record.
2.Is not possible define a virtual record inside of GLOBAL SECTION.
8/8/2019 Descriere PRE
56/217
Examples:
RECORD
BETA, D5,12345
DELTA, A8,'paperin
UA30, A30
VRECORD VREC
ALFA, A10,'ABCDEFGHIJ'
IND, D5 @BETA
GAMMA, D8,87654321
INDA, A6 @DELTA
Riference Content
VREC ABCDEFGHIJ1234587654321paperi
IND 12345
INDA paperi
ALFA(2:) 12345
8/8/2019 Descriere PRE
57/217
8/8/2019 Descriere PRE
58/217
elements
defined and magnitude of a single element.
Then, if a field of 6 characters is defined of 10 elements, should be
allocated in memory a space of 60 characters.
In HBL an array can be defined only as simple array,
that is to one dimension, with fields of kind alpha or decimal, and no
more than 16.384 characters.
To the elements individual of an array we can refer in simple mode or
indexed.
The simple form refers to first element of array;
The indexed form refers to n. elements, if n is the value of index;
the first element in number 1, the second is 2, and by the way.
The following example shows the modes above decrypted to access
arrays.
8/8/2019 Descriere PRE
59/217
Considering and evaluating the following instructions of Data Division:
RECORD
ARRAY1, 4A6 ,'ABCDEF' ,'GHIJKL'
&,'MNOPQR' ,'STUVWX'
ARRAY2, 3D3 ,123 ,4 ,789
The space of memory will be allocated as follow, from left to right and
from above to below:
Variable characters in memory
ARRAY1(1) A B C D E F
(2) G H I J K L
(3) M N O P Q R
(4) S T U V W X
ARRAY2(1) 1 2 3
(2) 0 0 4
(3) 7 8 9
The references are as follows:
Reference Variable Data obtained
ARRAY1(1) ABCDEF
ARRAY1(3) MNOPQR
ARRAY2 123
ARRAY2(7,7) 7
ARRAY1(ARRAY2(6,6),12) DEFGHIJKL
8/8/2019 Descriere PRE
60/217
3.1.4. Memory of Work
Generally the definition of a record reflects the structure of records
file data.
The content of area record is checked and the information is
transmitted to, or received by a data file.
However, the majority of programs request a work memory to contain
the values that are not directly associated with the activities of I/O in
data file.
Examples of variables of work memory include:
Variables of control of loop
Flag of internal process
Variables to memorize the intermediate results
In a program HBL this kind of variables are generally declared
as part of one or more records of work w/out name.
The definition of record allocates a section of memory to keep
the work variables that are necessary to program.
8/8/2019 Descriere PRE
61/217
0 !+ 3
K3.2. Definition of Fields
Any instruction of definition of record requires one or more instructions of
field definition.
Any definition of field specifies the behavior of a single field, and all the
field definitions are giving the disposition in memory of record.
.
he format to define a simple field is the following:
[name] , [dim] type length [@pos] [,value initial]
where:
name is optional name used to refer to space of field memory.
If no name is specified, we can also refer to content by index of variable
record
whose the field is part.
If the record name isnt specified, the field content cant be accessed directly.
dim is a constant decimal optional, named field dimension, and indicates how
many times the field is repeated (default 1).
The presence of this specification of dimension indicates a simple array
type is A for alpha, D for decimal and I for binary.
length specifies the number of characters in any occurrence of field.
If the dimension was not specified, the length should be a constant decimal
positive.
In case of variables I, do not specify the length because is fixed to 4 byte
(32 bit).
pos (optional), indicates a field that is pointing to another field, specifying
Kfields;
8/8/2019 Descriere PRE
62/217
eventually an offset.
In this case the field will not reserve memory for the current record, but will
define in alternate a field previously declared.
The referenced field must appertain to the same class of memory
(RECORD/GLOBAL/COMMON).
Similarly for Overlay fields, is not possible specify an initial value for this
kind of fields.
value initial
is the assemble of initial values that are assigned to succeeding
occurrences of field.
This specification is optional and is described with further details
here below.
The initialization of binary fields must be executed as decimal
operation.
The following are simple definition of fields:
RECORD
, A3 ,'XYZ'
INVAL, A20 ,'initial Value
FLD1, 2D7 ,123 ,987
DATA, D6 ,10394
MESE, D2 @DATA ; punta a '01'
GIORNO, D2 @DATA+2 ; punta a '03'
ANNO, D2 @DATA+4 ; punta a '94'
INDEX, I
DATA= DATE
8/8/2019 Descriere PRE
63/217
MESE= MONTH
GIORNO=DAY
ANNO=YEAR
punta a = point to
8/8/2019 Descriere PRE
64/217
0 !+ 3
K3.3. Specification of Initial Values
At start of execution of program, the default value in a alpha field is
blank, (code ASCII 32), and default value of decimal field is zero
(code ASCII 48).
The field is set to the given value before the first instruction of
Procedure Division is executed.
If initial values for an array are specified (i.e. a assemble ordinate of
elements), they are assigned in succession to all the elements starting by
the first.
However is not necessary to give initial values to all the elements of
array: to the elements for which is not given initial value will be
assigned
default value.
Initial values for alpha fields have to be constants alpha and are
allocated by justifying to left by the blank, that mean positioning from
left, or
filling by blank to right, if the initial value is shorter of the specified
field.
Decimal fields require constants decimal and are allocated by
justifying from right with zeros.
If initial value is longer of a single field element, will generate a
"syntax error".
By this way, a constant alpha with 6 characters is not permitted as
initial value to any field having attribute of length less than 6.
The initial values can be specified only for fields allocating memory.
Once that the memory is allocated, the succeeding fields referred to
the allocated area cant have initial values specified.
Then the fields in a record overlay cannot have values initial; if that
will happens, the initialization will be ignored.
KValori Iniziali;
8/8/2019 Descriere PRE
65/217
Considering the following instructions of Data Division:
RECORD
F1, A30
F2, A15
RECORD ,X
FO1, A5
FO2, A3
The fields F1 and F2 can have initial values, because are part of
declaration of a record not overlay.
Then these fields prepare the space in memory to be allocated.
The fields FO1 and FO2 cannot have initial values, because are in the
declaration of an overlay record;
They can only specify an alternative mode to see the previous memory
space allocated.
Because the variables common of a subroutine are giving only
references
to variables common of main, all the initial values specified for
variables common in a subroutine are ignored.
The memory areas GLOBAL are not directly associated with any
module.
For that reason, generally, the definition of records GLOBAL doesnt
permit initial values.
However, the instruction GLOBAL permits to a module to specify
some initial values including option INITin GLOBAL instruction.
The programmer has to make sure that the memory area of GLOBAL
is not accessible before that may be initialized by a module in main or
in a subroutine.
8/8/2019 Descriere PRE
66/217
If occurs a premature access, the memory area will assume an
indefinite content.
We must pay attention when we specify initial values in subroutine.
The value is assigned to the first invocation of subroutine,
but after one more invocation the variables may contain the resulting
values of subroutine, instead of the initial values.
8/8/2019 Descriere PRE
67/217
0 !+ 3
K3.4. instruction RECORD
The instruction RECORD defines both a record local and a global
record and describes their component fields.
If the instruction of RECORD is outside of the field of validity of an
instruction GLOBAL, it will be defined a local record, otherwise is
definite a record global.
The structure of instruction RECORD is the following:
RECORD [name] [,X]
definition of field 1
.
.
.
definition of field n
In this definition, name is an identification optional that refers to the
whole area record, and Xis the identification of overlay optional.
Every definition of field defines a single field inside of the record, and
a field at least must be present.
For the record in overlay are not permitted initial values.
KRECORD;
8/8/2019 Descriere PRE
68/217
The following example defines an area local of 35 characters and a
global area named GBL of 11 characters.
Local area consists of one local record named REC1 (21 characters)
and
of a record w/out name (14 characters).
The record REC1 has an alternative disposition named R1 and one
more w/out name.
The record w/out name has an alternative disposition named OVR.
The global area consists of a global record named G1 and a
disposition alternative without name.
RECORD REC1
ALFA, A13 ,'Valore inizial
BETA, A2
GAMMA, D6 ,975126
RECORD ,X
R1FLD1, A3
R1FLD2, A7
RECORD R1,X
R2FLD1, A5
R2FLD2, A1
RECORD
XX1, A7
XX2, D7 ,11765
RECORD OVR,X
XX1OVR, A3
8/8/2019 Descriere PRE
69/217
XX1END, A4
GLOBAL SECTION GBL ,INIT
RECORD G1
G1A, D5 ,164
G1B, 3D2 ,1 ,27 ,3
RECORD ,X
GOVR1, D2
GOVR2, A1
ENDGLOBAL
8/8/2019 Descriere PRE
70/217
8/8/2019 Descriere PRE
71/217
In the example here below are created two areas record called CMN1
(10characters) and DEMO (51 characters).
CMN1 is a record common with an overlay common named OVR1,
there are an overlay common w/out name and an overlay local w/out
name.
DEMO is the area of a local record with two overlays called TYPE1
and TYPE3 and a overlay common called TYPE2.
COMMON CMN1
CMN1A, A5 ,'abcd
CMN1B, D5 ,12345
COMMON OVR1 ,X
COVR1, 5A1
COMMON ,X
, A5
OVR2, 2D2
RECORD ,X (!! ERROR)
, A5
DIGITS, A5
RECORD DEMO
TYPE, D1 ;area I/O
, A50
RECORD TYPE1 ,X (!! ERROR)
, A1 ; first tipe of disposition
FLDA1, A5
FLDA2, A6
FLDA3, 3D7
COMMON TYPE2 ,X
8/8/2019 Descriere PRE
72/217
, A1 ; second type of disposition
FLDB1, A7
FLDB2, A9
RECORD TYPE3 ,X (!! ERROR)
, A1 ; third type of disposition
FLDC1, A1
FLDC2, 5D2
On the contrary of DIBOL-11, the records common cant over impose
definitions of local records. In the above example, are indicated the
declaration illegal, that will have error signals in phase of compilation.
8/8/2019 Descriere PRE
73/217
0 !+ 3
K3.6. Instruction GLOBAL
The instruction GLOBAL is referred to an area of data global labeled.
Differently from instruction COMMON, the instruction GLOBAL works
equally in main program and in subroutine.
The global areas have no needing to be defined in a module of
specified program.
During the link phase of a program, the capacity of area will be
controlled for any subroutine that is using it, and in case of dissonance,
error will be signaled.
The structure of instruction GLOBAL is as follows:
GLOBAL [DATA] [SEZIONE] name [,INIT]
RECORD instruction 1
.
.
.
RECORD instruction n
ENDGLOBAL
In this definition, name identifies the global memory area to which
we refer. The key words DATA and SECTION are both optional,
INIT is also optional. Any instruction RECORD defines a record
global and his component fields. If the instruction does not include
option INIT, the initial values in definition of RECORD global will
be ignored, and the values of data in area GLOBAL will stay indefinite.
When the option is there, the initial values can be declared.
Only one module in a program can specify the option INIT for a data
area of global memory, if more than one module is using that option an
error in phase program link will be displayed.
KGLOBAL;
8/8/2019 Descriere PRE
74/217
The following is a simple section of GLOBAL:
GLOBAL SECTION GLOB1
RECORD ABLE
ABLE1, A23
ABLE2, 7D2
RECORD ,X
FFF, A5
GGG, A6
SSS, A7
RECORD SCRATCH
SCR1, A50
SCR2, A25
SCR3, A5
ENDGLOBAL
8/8/2019 Descriere PRE
75/217
0 !+ 3
K3.7. Instruction VRECORD
The instruction VRECORD defines a local record VIRTUAL and describes
his component fields.
The structure of instruction VRECORD as follows:
VRECORD [nome]
definition of field 1
.
.
.
definition of field n
In this definition, name is an identifier that refers to a whole area record.
The record area is considered virtual because does not occupy static space, but
is to be made in execution phase, to reading or writing in other defined areas
of field that are following.
The importance of instruction VRECORD resides in the possibility to refer a
group of data to specifying only one name.
This avoids annoying assignments, in case that we have to pass traces record
different to subroutines.
The following example defines the row of print RSTAM,long 80 characters,
for a partial table of any element of record ANAG, long 129 characters.
The record RSTAM can be utilized directly on an instruction WRITES or
DISPLAY, after read the record ANAG,w/out make further assignments.
Vice versa, executing the instruction RSTAM=, will blanking the fields
NOME,
CITTA, INDIR
RECORD ANAG RECORD ANAG
NOME, A30 NAME
INDIR, A30 ADDRESS
CAP, A5 POST CODE
CITTA, A20 CITY
KVRECORD;
8/8/2019 Descriere PRE
76/217
PIVA, A11 PIVA ?
DARE, D11 GIVE
AVERE, D11 HAVE
SALDO, D11 BALANCE
;
VRECORD RSTAM
, A1,'!'
PROGR, A5 ; Progressive of print
, A1,'!'
, A30 @NOME
, A1,'!'
, A20 @CITTA
, A1,'!'
, A20 @INDIR
, A1,'!'
Note that the names of field VREC are omitted because are not essential to
the purpose.
8/8/2019 Descriere PRE
77/217
0 !+ 3K3.8. Instruction SUBROUTINE
The instruction SUBROUTINE identifies a module of program same as subroutine
external and defines also the type of arguments that are necessary.
A subroutine is a section of code separated that resides in a file different from main
program file.
In a program module, the instruction SUBROUTINE must be the first instruction of
Data Division.
The subroutines obey to specific duties that many program modules may request.
Consequently, the subroutines can shorter the time to develop program and facilitate
his maintenance.
The format of instruction SUBROUTINE is as follows:
SUBROUTINE subname
definition of argument 1
.
.
.
definition of argument n
In the above definition, subname is the name by which the subroutine should be
called
(to using instruction XCALL).
The compiler will recognise only the first 5 characters of name and will ignore the
remain.
Is not necessary to define the arguments if subroutine and program have no needing
to exchange information between themselves.
How ever, if the arguments are defined, any definition must include the name that
subroutine uses to refer to argument and the type of argument (alpha:[A},decimal:[D]).
The instruction XCALL in calling program cant contain a number of arguments
bigger than those declared in instruction SUBROUTINE, otherwise well get error:
Number argument XCALL wrong [#6].
Its possible that the instruction XCALL in the calling program has less arguments
of those declared: in this last case the subroutine cant utilize in input nor in output
the arguments that are not passed.
The calling program may have as arguments both variables and expressions.
KSUBROUTINE;
8/8/2019 Descriere PRE
78/217
During the execution, for any variable is created a pointer, that will be used to
access variable when the subroutine refers to that argument.
When the subroutine try to modify the value, a control assures that the argument has
not constant nor expression; if this happens, will be given error of Writing on literal
[#8].
Over arguments is not executed a control of type. So that, a subroutine may define an
argument of type alpha, and the call specifies instead a variable decimal for the same
argument in instruction XCALL.
The instruction SUBROUTINE defines the types added by arguments, but does not
control their length; it is the specified argument to determinate the length.
The length can change at any call to subroutine, if the call uses different variables as
argument. If subroutine tries to go out the memory area of arguments, is signaled a
Indexing error [#7].This can happen only by indexed access or interval to argument.Note that this access can refer to information not requested if the length of argument
is not the same of the one expected by the subroutine.
The example here below contains a subroutine that wait for argument long at least 10
characters; Is showed what happens when the call specify an argument shorter than
the one expected by subroutine.
Considering the following subroutine:
SUBROUTINE ROTAT
;
; Rotate to left the first 10 characters of WHAT
;
WHAT, A
RECORD
FIRST, A1
PROC
FIRST = WHAT(1,1)
WHAT(1,9) = WHAT(2,10)
WHAT(10,10) = FIRST
RETURN
END
8/8/2019 Descriere PRE
79/217
If the calling program has only the following instructions of Data
Division:
RECORD
FLD1, A10 ,'abcdefghij'
FLD2, A9 ,'123456789'
RECORD
FLD3, A2 ,'xz'
Analyze the following calls to subroutine:
XCALL ROTAT(FLD1)
Assign the string 'bcdefghij ad FLD1.
XCALL ROTAT(FLD2)
Is making ROTAT accessing to 10 characters that begin with the first
character of FLD2.
By this, are considered 9 characters of FLD2 and the first character of
FLD3.
Backing from subroutine, the value of FLD2 is '23456789x' and the
value of FLD3 is '1z';
Note that the second character from left of FLD3 is not touched.
XCALL ROTAT(FLD3)
Makes ROTAT on try to access to 10 characters, which start from the
first character of FLD3.
Because there are only two characters remaining in the data space, the
trial to access will cause an:Indexing error [#].
8/8/2019 Descriere PRE
80/217
0 !+ 2
K4. CHAPTER IV: PROCEDURE DIVISION
The Procedure Division starts by the compilation instruction of control
PROC and contains HBL program instructions.
This chapter describes various instructions available in Procedure
Division.
KPROCEDURE DIVISION;
8/8/2019 Descriere PRE
81/217
0 !+ 3
K4.1. Expressions
An expression is a combination of elements of data (called operand)
and arithmetical operation that produces an unique value.
The expressions HBL are both arithmetical and conditional, and
depending on interpretation of expression value.
If the value is interpreted as decimal number, the expression is
arithmetical;
If the value is interpreted as TRUE or FALSE, the expression is
conditional.
The simplest form of expression contains a single constant or
arithmetical
variable w/out operators.
The programmer can make expressions complex by using operators to
combine various kind of operands
The operators unary act only on a single operand and must stay
in left side of the expression;
Binary operand act on two operands and are inserted between the
operands.
Two operators cannot stay adjacent.
Simple examples of expressions valid are:
X - Y * 73/T
ALFA - (BETA.GT.GAMMA)
SINGLE
(VARO1.NE.'Abort').AND. (VARO1.NE.'Destruct')
-TIMER + (.NOT. (LAPSE.GT.TARGET))
KEspressions;
8/8/2019 Descriere PRE
82/217
4.1.1. Operands Available
The operand gives data base for the expression value. In one
expression can be used the following kind of operand:
1. Constants alpha and decimals;
2. Variables alpha and decimals in form simple or indexed or at
intervals;
3. Expressions arithmetical and conditional;
4. Assembles balanced of parenthesis used to clear or modify the
order
of evaluation of expressions.
.
The programmer can make expressions complex how much he wants by
using the four kinds of operands.
Generally the brackets are not requested to evaluate correctly an
expression;
However, they are necessary if the evaluation order is going to be
distorting; they can also be used to document the evaluation order that
we want for a complex expression, or to make easier determinate the
sequence of evaluation of an expression in the next reading of program.
Some operations impose restrictions about the type of data of their
operandi;
GT.Requires that both the operands must be of the same type;
So that is not allowed to relate an operand alpha to an operand
decimal.
Where there is restriction, it must be respected.
To be noted, anyway, that the compiler will not give error, when done
relation between operandi of different type, because, is possible evaluate
the string null and this one will be understood as TRUE or FALSE.
In example:
ALFA.GT.5
8/8/2019 Descriere PRE
83/217
Is interpreted as:
(ALFA.NE.).GT.5
That is correct syntax (see 4.1.3).
8/8/2019 Descriere PRE
84/217
4.1.2. Operators Availabe
The operators control the sequence of evaluation of an expression.
In the group of available operators, to each of them is assigned a priority by which
we measure the importance of operator.
In the evaluation of the expression, the operators act in order of their priority.
The following table lists and defines the arithmetical operators and is ordered by
priority,
starting from operators which have the highest priority.
Priority Operator Type Description
7 + Unary Plus unary (ignored)- Negative
6 * Binary Multiplication
/ Division
5 + Binary Addition
- Subtraction
4 .EQ. Binary Equal to
.NE. Not equal to
.GT. Major of
.LT. Minor of
.GE. Major of or equal to
.LE. Minor of or equal to
.IN. Inclusion string
.LIKE. Compare with mask (4.6)
3 .NOT. Unary NOT Boolean
2 .AND. Binary AND Boolean
1 .OR. Binary OR Boolean
When two or more operators with the same priority are adjacent, they are evaluated
from left to right.
So that, A*B/C is evaluated multiplying A by B and dividing the result by C.
Some time the normal priorities associated to operators are modified. In example, if
the programmer wants do the following equation:
A + B
-------C - D
8/8/2019 Descriere PRE
85/217
The expression is written as A+B/C-D, the priorities of operators said that the division
should be executed at first. The value resulting is calculated as the function is written:
B
A + --- - D
C
The only way to give a correct order of evaluation is to using the parenthesis, writing
the equation as (A+B)/(C-D).
A balanced assemble of brackets elevate the expression that is enclosing a higher
level of priority.
For example, if the priorities are numerical values assigned from 1 to 19, an
assembly
balanced of brackets creates a new priorities assy from 11 to 19,(Anyone of these is higher than any normal priority).
Any assemble of parenthesis repeated elevate the priorities (with an increase of 9 in
our example).
So that is in the expression:
A + B * (C - (D + E)/(F * (G - H)) + I)
The factor G-H is evaluated for first because it is closed by the most internal
brackets.
Assuming that the variables have the following values:
A = 10 B = 30 C = 5 D = 2
We observe the result of following expressions:
Expression Result
A + B / C * D 22
A + B / (C * D) 13
(A + B) / (C * D) 4
The variables and constant alpha are permitted as operand only when are used with
the operators relational (that is EQ., .NE., .GT., .LE., .IN.).
The operators of relation request that both the operands are of the same type.
The operands decimals are compared like in the standard arithmetic; the operand
8/8/2019 Descriere PRE
86/217
alpha
are compared by use the order of characters of assemble of code ASCII (NULL is
the character with the lowest order).
Consider the following expressions:
Expression Result
'ABCDEF' .EQ. 'ABC' true
'ABCDEF' .EQ. 'ABD' false
'CDE' .IN. 'ABCDEF' true
4 .IN. 123458 true
If the alpha operands differ in length inside an expression, only the characters of the
shortest operand are compared, and the additional characters of the longest operand
are ignored.
The operator LIKE can be used only in variables alpha and it permits to compare
with a masck, that is a string containing characters jollyas the regulation of shell
of UNIX:
* = Any string of characters, also empty
? = Any character
[xyz]= Any character of the list of characters closed by brackets:
in the case showed, the characters x,y,z.
The characters enclosed by squared brackets can also be jolly(excluded the ]
that in this case, they dont have particular meaning.
[x-z]= Qualsiasi carattere nel range specificato: nel caso mostrato, i caratteri
a,y,z.
\ = Take out the particular meaning from jolly characters.
Of both strings, is analyzed only the significant part excluding the final blank.
Examples:
Expressions Result
'ABCDEF ' .LIKE. 'ABC' false
'ABCDEF ' .LIKE. 'ABC*' true
'ABCDEF ' .LIKE. '*DE*' true'ABCDEF ' .LIKE. 'A?C?EF' true
'ABCDEF ' .LIKE. 'A[B-D]CDEF' true
8/8/2019 Descriere PRE
87/217
'ABCDEF ' .LIKE. 'A[ABC]CDEF' true
'AB*DEF ' .LIKE. 'AB*F' true
'AB*DEF ' .LIKE. 'A*BCDEF' true
'AB*DEF ' .LIKE. 'A\*CDEF' false
'AB*DEF ' .LIKE. 'AB\*DEF' true
'ABCDEF ' .LIKE. 'ABCDEF' true
8/8/2019 Descriere PRE
88/217
4.1.3. Speciali Notes
When in the instruction of Procedure Division appears an expression,
its interpreted like a conditional expression or arithmetical.
On describing expressions as follows, these conventions are used:
aexp to indicate an expression arithmetical
dexp to indicate an expression decimal
avar to indicate a variable alpha
dvar to indicate a variable decimal
fvar to indicate an expression conditional.
When in an instruction appears an expression conditional, his value is
interpreted as TRUE or FALSE.
HBL defines as TRUE a value not null, and like FALSE a value null.
During the evaluation of an expression, the operators relational and
bolean (.LE.,.AND.,etch.) will operate on their operands to give a result
with value 1 if the relation or the condition is TRUE, or 0 if is
FALSE.
That is:
17 + 3 * ('ABCD' .EQ. 'ABC')
The result is 20 because is true that ABCD is equal to ABC.
Because HBL uses the context of an expression to rule how his result
should be interpreted, the variables decimals or alphanumerical can be
also used like expression conditionals.
I.E. the instruction IF can easily test the status null/not null of the
variable, and use the result of this test.
For convention, the variables alphanumerical are considered NULL,
when they contain only blank (code ASCII=32).
Assuming that: the subroutine CHECK is responsible for control of
data fields, and is ensuring that their values are inside of a pre-
8/8/2019 Descriere PRE
89/217
established interval.
Assuming also that CHECK has a variable settled to zero as first
argument, if the interval is not accessed, or is settle to 1 on the
contrary,
the following instruction will call the subroutine, and in base to the
error flag, will address the execution in a side of module that is
controlling the errors:
XCALL CHECK (FLAG, VAR1, VAR2, VAR3)
IF (FLAG) GOTO OOPS
To extending this feature to avar, will be possible evaluate a single
variable to test if his value is blank or not:
AVAR= ; Clear AVAR
IF(AVAR) GOTO OOPS ; Result false
8/8/2019 Descriere PRE
90/217
4.1.4. Operator Division
The operator division in HBL divides in base of the type of data that
are manipulated.
Because of HBL does not allow the type decimal with fix dot,
when we divide two data decimal, the value of variable will be
truncated during every operation.
For example, 17 divided by 2 give as result 8; the fraction part (0.5) is
truncated.
8/8/2019 Descriere PRE
91/217
0 !+ 3
K4.2. Functions Intrinsic
HBL anticipate an assemble of functions defined internally and called
function intrinsic.
These functions can be used any time are permitted decimal constants.
The intrinsic functions must begin by dollar symbol ($).
4.2.1. $ERLIN
Returns the lines number of the instruction that cause the error
trappable most recent.
The number of line of any instruction appears on program list made
by command hbd-1.
4.2.1. $ERNUM
Returns the code number of the most recent error that can be trapped.
If the program provides the trappable errors management (i.e. with
ONERROR), the value that is back by $ERNUM can help the program
to
differentiate various trappable errors, in the way that each error can be
treated appositively.
4.2.3. $LEN
Backs the area length of the memory referred to the argument
specified.
$LEN is used to develop subroutines to treat arguments with variable
length, because often is necessary to know the length of an argument in
subroutine to control the elaboration of his content.
For example, $LEN can help in a subroutine doing the grammatical
KFunctions Intrinsic;$ERLIN;$ERNUM;$LEN;$RDLEN;
8/8/2019 Descriere PRE
92/217
analysis to an argument alpha, to decode a command line.
$LEN of an argument null give back -1.
The format of function $LEN is:
$LEN(variable)
8/8/2019 Descriere PRE
93/217
Considering the following instructions of Data Division:
RECORDAA, A10 ,'abcdefghij'
BB, D6 ,102507
CC, D1 ,4
The following are examples of $LEN:
Function Length
$LEN(AA) 10
$LEN(AA(5,7)) 3
$LEN(AA(5,6)) 2
$LEN(AA(BB(2,3),CC) 3
4.2.4. $RDLEN
Give back the length of the last record read, by using an instruction of
READ, READS, GET or GETS.
This function can be particularly useful with an instruction READS,
because the length of record read can change. Is useful, for example,
to determinate the number of characters read by the terminal to limit
input of a record.
4.2.5. Examples of Intrinsic Functions
The following are examples of some intrinsic function described in the
previous section:
Example #1:
8/8/2019 Descriere PRE
94/217
LOOP,
DISPLAY(15, 'Insert next command: ')
READS(15, INPUT)
IF ($RDLEN) GOTO VRDL
WRITES(15, 'Input null ignored )
GOTO LOOP
VRDL, BUF(1,5) = $RDLEN , "ZZZZX'
DISPLAY(15, "The length is : ", BUF(1,5), 13, 10)
WRITES(15, INPUT)
Example #2:
SUBROUTINE ROTAT
;
; Rotates to left all characters of WHAT.
; Is used the function $LEN because theres no way
; to know the length of WHAT before.
;
WHAT, A
RECORD
FIRST, A1
PROC
FIRST = WHAT(1,1)
WHAT(1, $LEN(WHAT)-1) =
WHAT(2,$LEN(WHAT))
WHAT($LEN(WHAT),$LEN(WHAT)) = FIRST
RETURN
END
8/8/2019 Descriere PRE
95/217
0 !+ 3
K4.3. Instruction of Assignment
The instruction of assignment changes the value of specified variable.
This instruction included many forms. Usually, an instruction of
assignment has the following format:
destination=source
The destination can be a simple variable, indexed or at intervals, the
value of which will be altered.
The source is an expression that will be destined as new value.
Every expression contained in source is evaluated before that the
designed value will be altered; then, there will be no conflict when the
same variable is present both as destination and as source part.
Here the instruction of assignment as example:
ALFA = ALFA * 3
Multiplies the actual value of ALPHA by 3; the result is later assigned
as new value of ALPHA.
KInstruction of Assignement ;
8/8/2019 Descriere PRE
96/217
4.3.1. Assignment from Alpha to Alpha
Quando la destinazione una variabile alfa e la sorgente una
variabile o una costante alfa,
When the destination is a variable alpha and the source is a variable
or a constant alpha, the instruction of assignment copies the information
from an area of memory to another area.
I f the source is shorter than destination, the information of source is
loaded in destination by a justification from left and by characters blank
(That is the source is loaded starting from left and exceeding space
is filled by characters blank).
If the source is longer than destination, only the characters that stay
more in left side of source are copied in destination.
Assuming the following instruction of Data Division:
RECORD XYZ
ABC, A6 ,'ABCDE'
DEF, A2 ,'XY'
RESULT, A4
The following assignment will value:
Instruction New value of RESULT:
RESULT = DEF 'XY '
RESULT = ABC 'ABCD'
RESULT = XYZ(4,9) 'DEXY
RESULT = '1234' '1234'
8/8/2019 Descriere PRE
97/217
4.3.2. Assignment from Alpha to Decimal
When the destination is a decimal variable and the source is a variable
or a constant alpha, the instruction of assignment represents a
conversion to decimal.
The information alpha must be a representation of whole character
with sign.
This representation alpha is converted to decimal form and assigned to
the variable decimal.
If the number of significant digits in the converted value is less than
the
length of destination, the value is allocated by justifying from right
with zeros, (that is to align it to right, and fill the left by zeros).
If the value is bigger than the length of destination, only the value that
stay more to right are allocated.
Se, durante la conversione, viene incontrato un carattere diverso da
blank, segno (+ o -),
If during the conversion, is encountered a character different from
blank,
sign (+ or -), or a numerical digit, is given the error: Wrong digit on
variable [#20].
The characters of sign can be found in any position in form alpha and
they are applied in the same order in which they are.
The blank characters are ignored.
Assuming the following instruction of Data Division:
RECORD
RESULT, D6
AFLD1, A7 ,'-1-2-3'
AFLD2, A10 ,'1234567890'
The following assignments have value:
8/8/2019 Descriere PRE
98/217
Instruction New value of RESULT
RESULT = AFLD1 -000123
RESULT = AFLD1(1,4) 000012
RESULT = '123456789' 456789
RESULT = ' 3 5 8 ' 000358
RESULT = 'ABCDE' "Digit wrong"
8/8/2019 Descriere PRE
99/217
4.3.3. Assignment from Decimal to Decimal
If the destination is a variable decimal and the source is an expression
arithmetical decimal,
the instruction assigns the value of the expression to variable
destination.
If the number of significant digit of value is littler of the destination
length, it is loaded with a justification to right by zeros.
If the number of significant digit is bigger of the destination length,
the digit more to left are deleted.
Considering RESULT with a field of 6 digit:
Instruction New value of RESULT
RESULT = 123 000123
RESULT = 1234567 234567
4.3.4Assignment from Decimal to Alpha
If the destination is a variable alpha and the source is an expression
decimal, the assignment represents an operation of formatting.
The value of the expression decimal is loaded in the memory area of
variable alpha as the regulation of format described.
There are two kind of assignment; the type used depends on the fact
that the format is or not explicitly specified as part of the instruction.
4.3.4.1. Formatting Implicit
8/8/2019 Descriere PRE
100/217
If the source consists only of an expression arithmetical, the value is
transferred to destination by the following rules:
1. The digits of numbers are loaded to justifying from right by
blank;
2. If the value is negative, is inserted a sign (minus) before the
most significant digit at left;
3. If the number of digits of value is bigger than the length of
destination, it will be transferred only the digits more at right;
If the value is negative, the sign minus is not inserted;
4. If the number of digits of value is negative, are transferred all
digits of value, but the sign minus isnt inserted.
8/8/2019 Descriere PRE
101/217
Assuming the following instruction of Data Division:
RECORD
RESULT, A6
DFLD1, D3 ,-23
DFLD2, D6 ,-123456
Observe the following assignment:
Instruction New value of RESULT
RESULT = DFLD1 ' -23'
RESULT = DFLD2 '123456' (w/out sign minus)
RESULT = 123456789 '456789'( only the more at right)
RESUT = DFLD1 * (-4) ' 92'
8/8/2019 Descriere PRE
102/217
4.3.4.2. Formatting Explicit
If the source consists of an expression arithmetical followed by a
comma and a variable or constant alpha, the assignment contains a
specification of format explicit.
The loading of destination is explained by specification of format.
If the format is shorter than destination, the information to be
formatted is loaded by justifying from right by blank.
If the format is longer than destination, is filled only the portion more
at right of the information.
The specification of format is a sequence of characters that describe
how the destination will be seen.
Some characters of sequence have a meaning special:
X represents a single digit. It determinates the form digit of source that
will be inserted in the specified position of destination.
The digits are extracted from source starting from right and continuing
to left.
By the X more at right of format is received the digit more at right of
source.
If there is more X characters respect to the digits of source, the
positions
more at left of X will be loaded by zeros.
Z also represents a position of digits.
However, a Z differs from X if there is more Z than digits significant
to be transferred from source.
The position Z is loaded by a blank if there are not X or comma at the
left of format.
If a comma stay to left and not to right, the position Z is filled by one
zero.
It is also placed one zero, when X is in left side of Z.
(- minus), is inserted in the corresponding position of destination, if
8/8/2019 Descriere PRE
103/217
used like the first or the last character of format. If the source is
positive is placed a blank.
Otherwise if the sign minus is used inside a format, is inserted a small
line in the corresponding position of destination.
(, comma), is inserted a decimal comma in the corresponding position
of destination. More over, any Z appearing at right side of comma is
treated like its a X.
(. dot) inserts a dot in the corresponding position of destination, but
only when one of the following conditions is valid:
1. There are remaining significant digits to be transferred;
2. Theres a X character at left of dot.
. Any other character that appears in the format string is directly
inserted in destination.
If ALPHA is a field alpha of 10 characters, the following example
shows
some ways to use the format characters:
Instruction New value of ALPHA
ALFA = 987 ,'XXXXXX-' ' 000987 '
ALFA = -987 ,'XXXXXX-' ' 000987-'
ALFA = 987 ,'XXX-XXX' ' 000-987'
ALFA = 987 ,'XXXXXX' ' 000987'
ALFA = 987 ,'ZZZZZZ' ' 987'
ALFA = -987 ,'-ZZZZZZ' ' - 987'
ALFA = 98765 ,'Z.ZZZ.ZZZ' ' 98.765'
8/8/2019 Descriere PRE
104/217
ALFA = 9876 ,'VAL: Z,ZZ' ' VAL: 8,76'
ALFA = 95 ,'This puts a X in' 'uts a 5 in'
8/8/2019 Descriere PRE
105/217
By assignment of binary variable to one decimal, is done the
conversion regularly, maintaining the consistence arithmetical.
When we assign:
4.3.5. Assignment from Binary to Decimal or Alphato alpha,
we can consider the double transformation Binary->Decimal and
Decimal->Alpha.
4.3.6. Assignment from Decimal or Alpha to Binary
Similarly to the previous case, the conversion from decimal to binary,is done regularly, maintaining the consistence arithmetical.
The assignment from alpha to Binary, can be seen as double
interchange
Alpha->Decimal and Decimal->Binary.
4.3.7. Control Check of Justifications
For default, the formatted in
Top Related