SlideShare a Scribd company logo
1 of 144
Download to read offline
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COBOL
Programming
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COBOL
This is a complete course about this powerful programming
language in use on IBM AS/400 and mainframe yet.
This course cover next points:
- Structure of COBOL program.
- Data types
- Using files
- Word reserved
- programming structured
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COBOL
Structure of COBOL program:
A COBOL Program consists of following 4 divisions:
• IDENTIFICATION DIVISION
• ENVIRONMENT DIVISION
• DATA DIVISION
• PROCEDURE DIVISION
All the divisions must appear in the same order as shown
above.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Identification Division
It names the program and may include the date the
program was written, the date of compilation, and other
such documentary information about the program.
COBOL Identification Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTPGM.
AUTHOR. PROGRAMMER NAME.
INSTALLATION. XYZ.
DATE-WRITTEN. 99/99/99.
DATE-COMPILED. 99/99/99.
COBOL Identification Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Environment Division
• Configuration Section
• Input-Output Section.
The Configuration Section is optional.
When specified, it can describe the computer on which
the source program is compiled and the computer on
which the object program is executed.
COBOL Identification Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COBOL Environment Division
Configuration Section
• SOURCE-COMPUTER
• OBJECT-COMPUTER
• SPECIAL-NAMES
Input-Output Section
• File-Control.
• I-O-Control
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Configuration Section can:
• Relate IBM-defined environment-names to user-defined
mnemonic names
• Specify a substitution for the currency sign
• Interchange the functions of the comma and the period
in PICTURE clauses and numeric literals
COBOL Configuration Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-AS400.
OBJECT-COMPUTER. IBM-AS400.
SPECIAL-NAMES. TOP IS TOP-OF-PAGE.
COBOL Configuration Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COBOL Input-Output Section
The Input-Output Section
•Define each file to be used
•Identify its external storage medium
•Assign the file to one or more input/ output
devices
•Specify information needed for efficient
transmission of data between the external
medium and the COBOL program
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
File-Control Paragraph
•Names and associates the files with the
external media.
A COBOL program can process:
Data Base Files:
• Physical Files
• Logical Files
COBOL Input-Output Section
Device Files:
• Display Files
• Tape Files
• Printer Files
• Diskette Files
• ICF Files
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example1:
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DISPLAY-FILE
ASSIGN TO WORKSTATION-TESTDSPF
ORGANIZATION IS TRANSACTION
ACCESS IS DYNAMIC
RELATIVE KEY IS RRN
FILE STATUS IS FILE-STATUS.
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example2:
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PHY-FILE1
ASSIGN TO DATABASE-PHYSICAL1
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS EXTERNALLY-DESCRIBED-KEY
FILE STATUS IS WS-PHY-FILE1-STATUS.
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SELECT Paragraph
•Makes association between the file and the
external medium
•It consists of 3 parts:
• Device
• File Name
• Attribute
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
DEVICE:
• Specifies the type of Device that the file will use
• It can be changed at run-time
List of Different Devices:
Device File ‘
WORKSTATION Display File
DATABASE Externally described Database File
DISK Program described Database file
FORMATFILE Externally described Printer file
PRINTER Program described Printer file
TAPEFILE Tape File
DISKETTE Diskette File
COBOL Select Paragraph
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
FILE-NAME:
• 1 thru 10 char. system name of the actual external file
• For Database files, a member name can not be specified
in the COBOL program. If a particular member is to be
specified, the OVRDBF command must be used at
execution time to specify the member name
• The file-name can be changed at execution time with
the TOFILE parameter of the OVRxxxF command
COBOL Select Paragraph
ATTRIBUTE:
• This part can be SI
• SI indicates that a separate indicator area has been
specified in the DDS for the FORMATFILE or
WORKSTATION file
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Device File Name Default File-name
WORKSTATION Required - Optional
DATABASE Required - N/A
DISK Required - N/A
FORMATFILE Required - Optional
PRINTER Optional QPRINT N/A
TAPE FILE Optional QTAPE N/A
DISKETTE Optional QDKT N/A
COBOL Select Paragraph
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ORGANIZATION Clause
• For Database files, it indicates the use of the file in the
program (permanent logical structure of the file)
• 4 types of organization:
• Sequential
• Indexed
• Relative
• Transaction
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SEQUENTIAL ORGANIZATION
•The physical order in which the records are
placed in the file determines the sequence of
records
•The relationships among records in the file do
not change, except that the file can be
extended
•There are no keys. Both database files and
device files can have sequential organization
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
INDEXED ORGANIZATION
• Each record in the file has an embedded key called a
key data item that is associated with an index
• An index provides a logical path to the data records,
according to the contents of the associated embedded
record key data items
• Only database files can have indexed organization
COBOL Input-Output Section
RELATIVE ORGANIZATION
• Each record area is identified by a relative record
number; the access method stores and retrieves a
record, based on its relative record number
• Relative files must be assigned to DISK or DATABASE
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
TRANSACTION ORGANIZATION
• Work station and data communication files can have
TRANSACTION organization
ACCESS MODE Clause
• It defines the manner in which the records of the file are
made available for processing
• If the ACCESS MODE clause is not specified, sequential
access is assumed
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ACCESS MODE Clause
• Sequential Access Mode
• Sequential Organization
• Indexed Organization
• Relative Organization
• Random Access Mode
• Indexed Organization
• Relative Organization
• Dynamic Access Mode
• Indexed Organization
• Relative Organization
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ACCESS MODE Clause
• Sequential-Access Mode: Allows reading and writing
records of a file in a serial manner; the order of
reference is implicitly determined by the position of a
record in the file
• Random-Access Mode: Allows reading and writing
records in a programmer-specified manner; the control
of successive references to the file is expressed by
specifically defined keys supplied by the user
• Dynamic-Access Mode: Allows a specific I/O request to
determine the access mode. Therefore, records may be
processed sequentially and/or randomly
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
RECORD KEY Clause
• It must be specified for an indexed file
• Each record in the file must have a unique record key
value
• EXTERNALLY-DESCRIBED-KEY specifies that the key(s)
for this file are same that are externally described in
DDS
• WITH DUPLICATES phrase can be specified for files
assigned to DATABASE
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
RECORD KEY Clause
Note:
An error will be encountered at run-time, if
• ‘DUPLICATES’ is specified in COBOL program and file
was created with ‘UNIQUE” specified in DDS
• ‘DUPLICATES’ is not specified in COBOL program
and file was created allowing non unique keys
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
RELATIVE KEY Clause
• It specifies the relative record number for a specific
logical record within a relative file.
• The POSITION parameter on the OVRDBF command
can be used to set the file position indicator. This
causes processing to begin with a record other than the
first record.
COBOL Input-Output Section
FILE-STATUS Clause
• It monitors the execution of each input-output request
for the file
• In some cases it indicates the I-O errors
• It must be defined in Data Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
I-O-Control Paragraph
• It is specified when checkpoints are to be taken and the
storage areas to be shared by different files
• This paragraph is optional in a COBOL program
COBOL Input-Output Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Division
• The Data Division of a COBOL source program
describes, in a structured manner, all the data to be
processed by the object program
• This section outlines the structure of the Data Division
and explains the types of data and how they are related
in a COBOL program
COBOL Data Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
• File Section
• Describes externally stored data (including sort-
merge files)
• Working-Storage Section
• Describes internal data
• Linkage Section
• Describes data made available by another
program.
COBOL Data Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
DATA DIVISION.
FILE SECTION.
FD DISPLAY-FILE.
01 DISPLAY-REC
COPY DD-ALL-FORMATS OF TESTDSPF.
FD PHY-FILE1.
01 PHY-FILE1-RCD.
COPY DDS-ALL-FORMATS OF PHYSICAL1.
FD PHY-FILE2.
01 PHY-FILE2-REC.
COPY DDSR-ALL-FORMATS OF PHYSICAL2.
COBOL Data Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
DD: to reference alias (alternate) names - 30 Chars
“_” is replaced by “-”
DDR:does everything that the DD option does.
Invalid COBOL char @, #, $, _ is replaced by
Valid COBOL char A, N, D, -
removes “_” from the end of a field name.
DDS:to reference internal DDS format field names
DDSR: does everything that the DDS option does.
Invalid COBOL char @, #, $, _ is replaced by
Valid COBOL char A, N, D, -
removes “_” from the end of a field name.
COBOL Data Division/Copy Options
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
WORKING-STORAGE SECTION.
FD DISPLAY-FILE.
01 PHYSICAL2-PARMS.
05 PHYSICAL2-PRODCD PIC X(04).
05 PHYSICAL2-INV PIC S9(03).
05 PHYSICAL2-STATUS PIC X(01).
88 PHYSICAL2-NONE-FOUND VALUE "0".
88 PHYSICAL2-ALL-VERIFIED VALUE "1".
88 PHYSICAL2-UNVERIFIED VALUE "2".
77 ERR-MESSAGE PIC X(80) VALUE SPACES.
COBOL Data Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
LINKAGE SECTION.
01 FUNCTION-MEMBER.
05 FUNCTION-CODE PIC X.
88 END-OF-PGM VALUE SPACES.
88 ENTRY-OPERATION VALUE "E".
88 VERIFY-OPERATION VALUE "V".
05 MEMBER-CODE PIC X.
88 ENTRY-MEMBER VALUE "E".
88 CLUSTER-MEMBER VALUE "C".
01 USER-ID PIC X(10).
01 JOB-NUMBER PIC X(10).
COBOL Data Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
• For all files except sort/merge, the File Section must
contain an FD (File Description) entry
• For each sort or merge file, the File Section must contain
an SD (Sort Description) entry
COBOL File Section
file-description-entry
• Represent the highest level of organization in the File
Section
• Provide information about the physical structure and
identification of a file, and gives the record-name(s)
associated with that file
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
record-description-entry
• A set of data description entries that describe the
particular record(s) contained within a particular file
• More than one record description entry may be specified;
each is an alternative description of the same record
storage area
• Data areas described in the File Section are not available
for processing unless the file containing the data area is
open
• The initial value of a data item in the File Section is
undefined
COBOL File Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
file-name
• Must follow the level indicator (FD or SD), and must be
the same as that specified in the associated SELECT clause
• The file-name must be unique within this program
• One or more record description entries must follow the
file-name. When more than one record description entry
is specified, each entry implies a redefinition of the same
storage area
• The clauses that follow file-name are optional; they may
appear in any order
COBOL File Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
BLOCK CONTAINS Clause
• Specify the size of the physical records
• If the records in the file are not blocked, the clause may
be omitted
• This clause is always active for tape files, but is syntax-
checked only for diskette files
COBOL File Section
RECORDS
• Specify the number of logical records contained in each
physical record
• Maximum record size is 32766; maximum block size is
32766
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
LABEL RECORDS Clause
• Indicate the presence or absence of labels
• If it is not specified for a file, label records for that file
must conform to the system label specifications
• Generally treated as documentation
STANDARD
• Labels conforming to system specifications exist for this
file
OMITTED
• No labels exist for this file
COBOL File Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
• File Data (External Data)
• File data is contained in files
• Program Data (Internal Data)
• Program data is created by the program itself
COBOL Data Types
Levels of Data
• After a record has been defined, it can be subdivided to
provide more detailed data references
• A system of level-numbers specifies the organization of
elementary and group items into records. Special level-
numbers are also used; they identify data items used for
special purposes
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
Data Relationships
• The relationships among all data to be used in a
program are defined in the Data Division, through a
system of level indicators and level-numbers
• A level indicator, with its descriptive entry, identifies
each file in a program. Level indicators represent the
highest level of any data hierarchy with which they are
associated; FD is the file description level indicator and
SD is the sort-merge file description level indicator
• A level-number, with its descriptive entry, indicates the
properties of specific data
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
• A level-number is a 1- or 2-digit integer between 01 and
49, or one of three special level-numbers: 66, 77, or 88
• The following level-numbers are used to structure records:
• 01 Specify the record itself and is the most inclusive
level-number possible. A level-01 entry may be either a
group item or an elementary item
• 02-49 Specify group and elementary items within a
record
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Special Level-Numbers
• Special level-numbers identify items that do not structure
a record. The special level-numbers are:
• 66 Identifies items that must contain a RENAMES
clause; such items regroup previously defined data
items
• 77 Identifies data item description entries —
independent Working-Storage or Linkage Section
items that are not subdivisions of other items, and are
not sub-divided themselves
• 88 Identifies any condition-name entry that is
associated with a value of a conditional variable
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
BLANK WHEN ZERO Clause
• Specify that an item contains nothing but spaces when
its value is zero
• Specify only for elementary numeric or numeric-edited
items
• These items must be described, either implicitly or
explicitly, as USAGE IS DISPLAY. When this clause is
specified for a numeric item, the item is considered a
numeric-edited item
• Must not be specified for level-66 or level-88 items
• Not allowed for items described with the USAGE IS
INDEX clause or the USAGE IS POINTER clause
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
Coding Example:
01 WS-GROUP-ITEM.
05 WS-VAR1 PIC X(001).
05 WS-VAR2 PIC 9(006) BLANK WHEN ZERO.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
JUSTIFIED Clause
• Override standard positioning rules for a receiving item
of the alphabetic or alphanumeric categories
• May be specified only at elementary level. JUST is an
abbreviation for JUSTIFIED, and has the same meaning.
RIGHT is an optional word and has no effect on the
execution of the program
• Cannot be specified for numeric, numeric-edited, or
alphanumeric-edited items
• Must not be specified with level-66 (RENAMES) and
level-88 (condition-name) entries
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
Coding Example:
01 WS-GROUP-ITEM.
05 WS-VAR1 PIC X(001).
05 WS-VAR2 PIC X(006) JUSTIFIED RIGHT.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
LIKE Clause
• Define the PICTURE, USAGE, and SIGN characteristics of
a data item by copying them from a previously defined
data item
• Make the length of the data item you define different
from the length of the original item
• Cause the new data item to inherit specific
characteristics from the existing data item. These
characteristics are the PICTURE, USAGE, SIGN, and
BLANK WHEN ZERO attributes of the existing item
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
Coding Example:
01 WS-GROUP-ITEM1.
05 WS-VAR1 PIC X(001).
05 WS-VAR2 PIC X(006) JUSTIFIED RIGHT.
01 WS-GROUP-ITEM2 LIKE WS-GROUP-ITEM1.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
PICTURE Clause
• Specify the general characteristics and editing
requirements of an elementary item
• Must be specified for every elementary item except an
index data item or the subject of the RENAMES clause
• The PICTURE character-string may contain a max of 30
chars
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
Coding Example:
01 WS-GROUP-ITEM1.
05 WS-VAR1 PIC X(001).
05 WS-VAR2 PIC 9(006).
01 ITEM-1 PIC X(3) VALUE "ABC".
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
REDEFINES Clause
• To use different data description entries to describe the
same computer storage area
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
01 SYSTEM-DATE PIC 9(6) VALUE ZEROS.
01 SYS-DATE REDEFINES SYSTEM-DATE.
05 SYS-YEAR PIC 9(2).
05 SYS-MONTH PIC 9(2).
05 SYS-DAY PIC 9(2).
01 SYSTEM-DATE PIC 9(6) VALUE ZEROS.
01 SYS-DATE REDEFINES SYSTEM-DATE.
05 SYS-YEAR PIC X(2).
05 SYS-MONTH PIC X(2).
05 SYS-DAY PIC X(2).
01 WS-AGE-FIELD.
05 WS-AGE-ALPHA PIC X(03) VALUE ZEROS.
05 WS-AGE REDEFINES WS-AGE-ALPHA PIC 9(03).
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
RENAMES Clause
• Specify alternative, possibly overlapping, groupings of
elementary data items
• The special level-number 66 must be specified for data
description entries that contain the RENAMES clause
• One or more RENAMES entries can be written for a
logical record
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
Coding Example:
01 SYSTEM-DATE-8.
05 SYS-CENTURY PIC 9(2).
05 SYS-YEAR PIC 9(2).
05 SYS-MONTH PIC 9(2).
05 SYS-DAY PIC 9(2).
66 SYSTEM-DATE-6 RENAMES SYS-YEAR THROUGH SYS-
DAY.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SIGN Clause
• Specify the position and mode of representation of the
operational sign for a numeric entry
• USAGE IS DISPLAY must be specified, explicitly or
implicitly
USAGE Clause
• Specify for an entry at any level. However, if it is
specified at the group level, it applies to each
elementary item in the group
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Computational Items
• Value used in arithmetic operations
• Must be numeric
• The maximum length of a computational item is 18 decimal
digits
The PICTURE of a computational item may contain only:
9 One or more numeric character positions
S One operational sign
V One implied decimal point
COMPUTATIONAL-3 or COMP-3 - equivalent of PACKED-
DECIMAL
COMPUTATIONAL-4 or COMP-4 - equivalent of BINARY
Data Types
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Data Types
VALUE Clause
• Specify the initial contents of a data item or the value(s)
associated with a condition-name
• Use of the VALUE clause differs depending on the Data
Division section in which it is specified; In the File and
Linkage sections, the VALUE clause must be used only in
condition-name entries;
in the Working-Storage Section, the VALUE clause may be
used in condition-name entries, or in specifying the initial
value of any data item
• The data item assumes the specified value at the beginning
of program execution.
• If the initial value is not explicitly specified, it is
unpredictable
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Working-Storage Section
• The Working-Storage Section describes data records that
are not part of external data files but are developed and
processed internally
• The Working-Storage Section contains record description
entries and data description entries for independent data
items, called data item description entries
record-description-entry
• Data entries in the Working-Storage Section that bear a
definite hierarchic relationship to one another must be
grouped into records structured by level number
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
data-item-description-entry
• Independent items in the Working-Storage Section that
bear no hierarchic relationship to one another need not
be grouped into records, provided that they do not need
to be further subdivided. Instead, they are classified and
defined as independent elementary items. Each is defined
in a separate data-item description entry that begins with
either the level number 77 or 01
• The initial value of any data item in the Working-Storage
Section, except an index data item, is specified by
associating a VALUE clause with the item
• The initial value of any index data item, or of any data
item not associated with a VALUE clause, is undefined
Working-Storage Section
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Linkage Section
• Describe data made available from another program
• Record description entries and data item description
entries in the Linkage Section provide names and
descriptions, but storage within the program is not
reserved because the data area exists elsewhere
• Any data description clause may be used to describe items
in the Linkage Section, with one exception: the VALUE
clause may not be specified for items other than level-88
items
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Linkage Section
Coding Example:
LINKAGE SECTION.
01 FROMDATE.
05 FROMMM PIC 99.
05 FROMDD PIC 99.
05 FROMYY PIC 99.
01 TODATE.
05 TOMM PIC 99.
05 TODD PIC 99.
05 TOYY PIC 99.
01 DAYS PIC S9(7) COMP-3.
01 STATUS-CODE PIC 1.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COBOL - Procedure Division
Procedure Division
Consists of optional declaratives, and procedures that
contain sections and/or paragraphs, sentences, and
statements
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Procedure Division
• The USING Phrase
• Required only if the object program is to be invoked by
a CALL statement and that statement includes a USING
phrase
• Makes data items defined in a calling program available
to a called subprogram
• Each USING identifier must be defined as a level-01 or
level-77 item in the Linkage Section of the called
subprogram
• Must not contain a REDEFINES clause
• Maximum number of data-names - 30
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Procedure Division
Procedures
• Within the Procedure Division, a procedure consists of:
• A section or a group of sections
• A paragraph or group of paragraphs
• A procedure-name is a user-defined name that
identifies a section or a paragraph
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Section
A section header optionally followed by one or more
paragraphs
• Section-header
• A section-name followed by:
• the keyword SECTION
• an optional segment-number
• a separator period
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Paragraph
A paragraph-name followed by a separator period,
optionally followed by one or more sentences
Paragraph-name
• A user-defined word that identifies a paragraph
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Sentence
One or more statements terminated by a separator period
Statement
• A syntactically valid combination of identifiers and
symbols beginning with a COBOL verb
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Identifier
• A syntactically correct combination of a data name
• In any Procedure Division reference, the contents of an
identifier must be compatible with the class specified
through its PICTURE clause, or results are
unpredictable
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Declaratives
• Provide one or more special-purpose sections that are
executed when an exceptional condition occurs
• When Declarative Sections are specified, they must be
grouped at the beginning of the Procedure Division,
and the entire Procedure Division must be divided into
sections
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
PROCEDURE DIVISION.
DECLARATIVES.
ERROR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON INPUT-
DATA.
ERROR-ROUTINE.
IF CHECK-STATUS= "30"
ADD 1 TO DECLARATIVE-ERRORS.
END DECLARATIVES.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Common Phrases
There are several phrases common to arithmetic and data
manipulation statements; these phrases are described
below
CORRESPONDING Phrase
• Allows ADD, SUBTRACT, and MOVE operations to be
performed on elementary data items of the same name
if the group items to which they belong are specified
• Both identifiers following the key word
CORRESPONDING must name group items
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
MOVE CORRESPONDING DATE-YYMMDD TO DATE-WITH-
SLASHES.
01 DATE-YYMMDD.
05 YY PIC XX.
05 MM PIC XX.
05 DD PIC XX.
01 DATE-WITH-SLASHES.
05 MM PIC XX.
05 SLASHA PIC X VALUE "/".
05 DD PIC XX.
05 SLASHB PIC X VALUE "/".
05 YY PIC XX.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
GIVING Phrase
• The value of the identifier that follows the word GIVING
is set equal to the calculated result of the arithmetic
operation
• Because this identifier is not involved in the
computation, it may be a numeric edited item
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
SUBTRACT SUB1 FROM SUB2 GIVING RESULT.
DIVIDE NUM1 BY 10 GIVING RESULT.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ROUNDED Phrase
• After decimal point alignment, the number of places in
the fraction of the result of an arithmetic operation is
compared with the number of places provided for the
fraction of the resultant identifier
• When the size of the fractional result exceeds the
number of places provided for its storage, truncation
occurs unless ROUNDED is specified. When ROUNDED
is specified, the least significant digit of the resultant
identifier is increased by 1 when-ever the most
significant digit of the excess is greater than or equal
to 5
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
DIVIDE NUM1 BY 10 GIVING RESULT ROUNDED.
COMPUTE RESULT ROUNDED = NUM1 * NUM2.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SIZE ERROR Phrases
• A size error condition can occur in three different ways:
• When the absolute value of the result of an
arithmetic evaluation, after decimal point alignment,
exceeds the largest value that can be contained in
the result field
• When division by zero occurs
• In an exponential expression, when
• Zero raised to the exponent Zero
• Zero raised to a negative exponent
• A negative number raised to a fractional exponent
• The size error condition applies only to final results, not
to any intermediate results
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
ADD 1 TO NUM1
ON SIZE ERROR MOVE 0 TO NUM1
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Input-Output Statements
• Transfer data to and from files stored on external media
• Control low-volume data that is obtained from or sent
to an input/output device
Common Processing Facilities
Applied to more than one input-output statement:
• Status key
• INVALID KEY condition
• INTO/FROM identifier phrase
• File position indicator
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Status Key
• If the FILE STATUS clause is specified in the FILE-
CONTROL entry, a value is placed in the specified
status key (the 2-character data item named in the FILE
STATUS clause) during execution of any request on that
file, which indicates the status of that request
• The value is placed in the status key before execution
of any EXCEPTION/ERROR declarative or INVALID
KEY/AT END phrase associated with the request
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PROJECT-FILE
ASSIGN TO DATABASE_PROJECT
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EXTERNALLY-DESCRIBED-KEY
FILE STATUS IS WS-PROJECT-FILE-STATUS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PROJECT-FILE-STATUS PIC XX.
88 WS-IO-SUCCESSFUL VALUE "00" THRU "09".
88 WS-END-OF-FILE VALUE "10" THRU "19".
88 WS-INVALID-KEY VALUE "20" THRU "29".
88 WS-IO-ERROR VALUE "30" THRU "99".
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
INVALID KEY Condition
• Can occur during execution of a START, READ, WRITE,
REWRITE, or DELETE statement
• When occurs, the input-output statement that caused
the condition is unsuccessful
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
READ PROJECT RECORD
INVALID KEY
MOVE "N" TO PROJECT-RECORD-FOUND
NOT INVALID KEY
MOVE "Y" TO PROJECT-RECORD-FOUND
END-READ.
IF WS-PROJECT-FILE-STATUS >= "30"
MOVE "N" TO PROJECT-RECORD-FOUND
END-IF.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
INTO/FROM Identifier Phrase
• Valid for READ, RETURN, RELEASE, REWRITE, and
WRITE statements
• The identifier specified must be the name of an entry in
the Working-Storage Section or the Linkage Section, or
of a record description for another previously opened
file
• Record-name/file-name and identifier must not refer to
the same storage area
• The INTO phrase may be specified in a READ or
RETURN statement
• The FROM phrase may be specified in a RELEASE,
REWRITE, or WRITE statement
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
READ PROJECT RECORD
INTO WS-PROJECT
FORMAT IS "PROJECT1"
INDICATORS ARE WS-INDICATOR-TABLE
END-READ.
REWRITE SUBFILE PROJECT-RCD
FROM WS-PROJECT1SFL-O
FORMAT IS “PROJECT11SFL"
INDICATORS ARE WS-INDICATOR-TABLE
INVALID KEY CONTINUE
END-REWRITE.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Procedure Division Statements
ACCEPT Statement
• Transfer data into the specified identifier
• No editing or error checking of the incoming data
Procedure Division
Coding Example:
ACCEPT SYSTEM-DATE FROM DATE.
ACCEPT SYSTEM-TIME FROM TIME.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ACQUIRE Statement
• Acquire a program device for a TRANSACTION file
ADD Statement
• Sum two or more numeric operands and stores the
result
Procedure Division
Coding Example:
ADD 1 TO PROJECT-COUNTER.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
CALL Statement
• Transfer control from one object program to another
within the run unit
• Pass control to the first non-declarative instruction of
the called subprogram
• Called subprograms themselves can contain CALL
statements, but a called subprogram that contains a
CALL statement that directly or indirectly calls the
calling program gives unpredictable results
Procedure Division
Coding Example:
CALL "XXXVALIDDT" USING DATE-CHECK.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
CANCEL Statement
• Ensure that the next time the referenced subprogram is
called it will be entered in its initial state
• Close all open files
• Operate only on the program specified, and not on any
program that may have been called by the canceled
program
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
CANCEL Statement
• No action is taken when a CANCEL statement is
executed, naming a program that has not been called
in the run unit, or that names a program that was
called and subsequently canceled. In either case,
control passes to the next statement
• If names a program that does not exist in the library list,
an error message is issued
Coding Example:
CANCEL "XXXVALIDDT“.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
CLOSE Statement
• Terminate the processing of volumes and files, with
optional rewind and/or lock or removal, where
applicable
• Terminate the processing of volumes and files, with
optional rewind and/or lock or removal, where
applicable
• If the file is in an open status and the execution of a
CLOSE statement is unsuccessful, the
EXCEPTION/ERROR procedure (if specified) for this file
is executed
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Procedure Division
CLOSE Statement
• If a CLOSE statement for an open file is not processed
before a STOP RUN for this run unit, the file is implicitly
closed
Coding Example:
CLOSE PROJECT.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COMMIT Statement
• Provide a way of synchronizing changes to data base
records while preventing other jobs from modifying
those records until the COMMIT is performed
• All record locks held by the job since the last
commitment boundary for files under commitment
control are released and the records become available
to other jobs
• Only affect files under commitment control
• If a COMMIT is executed and there are no files opened
under commitment control, the COMMIT statement
has no effect and no commitment boundary is
established
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
COMPUTE Statement
• Assign the value of an arithmetic expression to one or
more data items
• With the COMPUTE statement, arithmetic operations
can be combined without the restrictions on receiving
data items imposed by the rules for the ADD,
SUBTRACT, MULTIPLY, and DIVIDE statements
Procedure Division
Coding Example:
COMPUTE RESULT = NUM1 - 1.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
CONTINUE Statement
• Allow to specify a no operation statement
• Indicate that no executable instruction is present
• May be used anywhere a conditional statement
• Has no effect on the execution of the program
Procedure Division
Coding Example:
READ PROJECT
INVALID KEY
CONTINUE
END-READ.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
DELETE Statement
• Remove a record from an indexed or relative file
• For indexed files, the key may then be reused for record
addition
• For relative files, the space is then available for a new
record with the same RELATIVE KEY value
• File must be open in I-O mode
• Record is logically removed from the file and can no
longer be accessed
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
DELETE PROJECT-FILE RECORD
INVALID KEY
MOVE "N" TO WS-PROJRCT-RECORD-FOUND
NOT INVALID KEY
MOVE "Y" TO WS-PROJECT-RECORD-FOUND
END-DELETE
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
DISPLAY Statement
• Transfer the contents of each operand to the output
device
• Contents are displayed on the output device in the
order, left to right, in which the operands are listed
Procedure Division
Coding Example:
DISPLAY IO-ERR-MSG UPON CNSL.
DISPLAY USER-MSG.
SPECIAL-NAMES. SYSTEM-CONSOLE IS CNSL.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
DIVIDE Statement
• Divide one numeric data item into or by one or more
others, and sets the values of data items equal to the
quotient and remainder
Coding Example:
DIVIDE WS-HOURS BY 24
GIVING WS-DAYS
REMAINDER WS-REMAINDER-HOURS.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
EVALUATE Statement
• Provide a shorthand notation for a series of nested IF
statements
Procedure Division
EVALUATE MENU-INPUT
WHEN ”0"
PERFORM INIT-PROC
WHEN "1" THRU "9"
PERFORM PROCESS-PROC
WHEN "R"
PERFORM READ-PARMS
WHEN "X"
PERFORM CLEANUP-PROC
WHEN OTHER
PERFORM ERROR-PROC
END-EVALUATE.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
EXIT Statement
• Provide a common end point for a series of paragraphs
Coding Example:
200-PROCESS.
IF PROJECT-FOUND = “Y"
PERFORM 250-PARA1
ELSE
PERFORM 260-PARA2
END-IF.
200-EXIT.
EXIT.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
EXIT PROGRAM Statement
• Specify the end of a called
program and returns control to
the calling program
• When there is no next executable
statement in a called program,
an implicit EXIT PROGRAM
statement is executed
Procedure Division
Coding Example:
END-OF-JOB.
IF NO-PROJ-ERROR THEN
CLOSE PROJECT.
IF NO-DISPLAY-ERROR THEN
CLOSE DISPLAY-FILE.
EOJ-EXIT.
EXIT PROGRAM.
STOP RUN.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
GOBACK Statement
• Function like the EXIT PROGRAM statement when it is
coded as part of a program that is a subprogram in a
COBOL run unit, and like the STOP RUN statement
when coded in a program that is a main program in a
COBOL run unit
• Specify the logical end of a program
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
PROCEDURE DIVISION USING LINK-PARMS.
100-MAIN.
IF PROJECT-FOUND = “Y"
PERFORM 150-PARA1
ELSE
PERFORM 250-PARA2
END-IF.
GOBACK.
100-EXIT.
EXIT.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
GO TO Statement
• Transfer control from one part of the Procedure Division
to another
• Three types of GO TO statements:
1. Unconditional
2. Conditional
3. Altered (Obsolete)
Procedure Division
Coding Example:
IF PROJECT1 NOT = PROJECT2 THEN
GO TO 220-READ-NEXT-PROJECT
END-IF
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
IF Statement
• Evaluate a condition and provides for alternative
actions in the object program, depending on the
evaluation
Coding Example:
IF (MENU-INPUT >= "1") AND (MENU-INPUT <= "9") THEN
PERFORM PROCESS-PROC
ELSE
IF (MENU-INPUT = "R") THEN
PERFORM READ-PARMS
END-IF
END-IF.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
INITIALIZE Statement
• Sets selected categories of data fields to predetermined
values
• Functionally equivalent to one or more MOVE
statements
Procedure Division
Coding Example:
INITIALIZE PROJECT1-FIELD1.
INITIALIZE PROJECT1.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
INSPECT Statement
• Specify that characters in a data item are to be counted
(tallied) or replaced or both
• Count the occurrence of a specific character (alphabetic,
numeric, or special character) in a data item
• Fill all or portions of a data item with spaces or zeros
• Translate characters from one collating sequence to
another
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
INSPECT WS-PAGE-IN-ERROR
REPLACING LEADING ZEROS BY SPACES.
INSPECT PROJECT1-FIELD1
TALLYING WS-SPACE-CNTR FOR ALL “ “.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
MERGE Statement
• Combine two or more identically sequenced files (that
is, files that have already been sorted according to an
identical set of ascending/ descending keys) on one or
more keys and makes records available in merged
order to an output procedure or output file
• May appear anywhere in the Procedure Division except
in a Declarative Section
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
MOVE Statement
• Transfer data from one area of storage to one or more
other areas
Procedure Division
Coding Example:
MOVE NUM1 TO NUM2
MOVE "MISSING OR INVALID VALUE" TO WS-ERROR-
MESSAGE.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
MULTIPLY Statement
• Multiplies numeric items and sets the values of data
items equal to the results
Procedure Division
Coding Example:
MULTIPLY NUM1 BY NUM2 GIVING RESULT.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
OPEN Statement
• Initiate the processing of files
• Vary depending on the type of file:
• Sequential files
• Indexed files
• Relative files
• Transaction files
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Sequential files
• At least one of the phrases, INPUT, OUTPUT, I-O, or
EXTEND, must be specified with the OPEN keyword
• The INPUT, OUTPUT, I-O, and EXTEND phrases may
appear in any order
Indexed and Relative Files
• At least one of the phrases, INPUT, OUTPUT, or I-O,
must be specified with the OPEN keyword. The INPUT,
OUTPUT, and I-O phrases may appear in any order
Transaction Files
• A TRANSACTION file must be opened in the I-O mode
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
OPEN I-O FILE1.
OPEN INPUT FILE2,
FILE3.
OPEN OUTPUT FILE4.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
PERFORM Statement
• Transfer control explicitly to one or more procedures
and implicitly returns control to the next executable
statement after execution of the specified
procedure(s) or imperative statements is completed
• 4 PERFORM statement formats:
1. Basic PERFORM
2. TIMES phrase PERFORM
3. UNTIL phrase PERFORM
4. VARYING phrase PERFORM
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
PERFORM 110-INITIALIZATION.
PERFORM 300-LOAD-PROJECTS
VARYING CNT1 FROM 1 BY 1
UNTIL CNT1 > PROJECT-COUNT
END-PERFORM.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
READ Statement
• Make a record available to the program
• Associated file must be open in INPUT or I-O mode
• For sequential access, the READ statement makes the
next logical record from a file available to the object
program
• For random access, the READ statement makes a
specified record from a direct-access file available to
the object program
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
READ PROJECT-FILE
INVALID KEY SET INVALID-PROJ TO TRUE
END-READ.
READ PROJECT-FILE-L NEXT RECORD
AT END PERFORM 300-END-OF-FILE-PROCESSING
END-READ .
READ PROJECT-FILE
AT END SET END-OF-FILE TO TRUE
END-READ.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
RELEASE Statement
• Transfer records from an input/output area to the initial
phase of a sorting operation
• Can only be used within the range of an input
procedure associated with a SORT statement
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
RETURN Statement
• Transfer records from the final phase of a sort or merge
operation to an OUTPUT PROCEDURE
• Can be used only within the range of an output
procedure associated with a SORT or MERGE statement
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
REWRITE Statement
• Logically replace an existing record in a direct-access
file
• Associated direct-access file must be open in I-O mode
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
REWRITE Statement for Sequential Files
• When the access mode is sequential, the last prior
input/output statement executed for this file must be a
successfully executed READ statement. When the
REWRITE statement is executed, the record retrieved by
that READ statement is logically replaced
• The INVALID KEY phrase must not be specified for a file
with sequential organization
• An EXCEPTION/ERROR procedure may be specified
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
REWRITE Statement for Indexed Files
• When the access mode is sequential, the record to be
replaced is specified by the value contained in the
prime RECORD KEY. When the REWRITE statement is
executed, this value must equal the value of the prime
record key data item in the last record read from this
file
• The INVALID KEY phrase must be specified if an
applicable USE AFTER STANDARD EXCEPTION
procedure is not specified for the associated file-name
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
REWRITE Statement for Relative Files
• For relative files in sequential access mode, the INVALID
KEY phrase must not be specified
• An EXCEPTION/ERROR procedure may be specified
• The INVALID KEY phrase must be specified in the
REWRITE statement for relative files in the random or
dynamic access mode, and for which an appropriate
USE AFTER STANDARD EXCEPTION procedure is not
specified
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
REWRITE Statement for Relative Files
• When the access mode is random or dynamic, the
record to be replaced is specified in the RELATIVE KEY
data item
• If the file does not contain the record specified, an
invalid key condition exists, and, if specified, the
INVALID KEY imperative-statement is executed
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
REWRITE PROJECT-RCD
INVALID KEY
CONTINUE
END-REWRITE.
REWRITE SUBFILE PROJECT-RCD
FROM WS-LIST1SFL-O
FORMAT IS "LIST1SFL"
INDICATORS ARE WS-INDICATOR-TABLE
INVALID KEY CONTINUE
END-REWRITE.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ROLLBACK Statement
• Provide a way to cancel one or more changes to data-
base records when the changes should not remain
permanent
• Any changes made to files under commitment control
since the last commitment boundary are removed from
the database
• A commitment boundary is the previous occurrence of
a ROLLBACK or COMMIT statement
• If no COMMIT or ROLLBACK has been issued, the
commitment boundary is the first OPEN of a file under
commitment control
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
ROLLBACK Statement
• Removal of changes takes place for all files under
commitment control in the job, and not just for files
under commitment control in the COBOL program that
issues the ROLLBACK
• All record locks held by the job for files under
commitment control are released and the records
become available to other jobs
• Has no effect on files not under commitment control
• If a ROLLBACK is executed and there are no files under
commitment control, the ROLLBACK is ignored
• A ROLLBACK, when executed, leaves files in the same
open or closed state as before execution
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SEARCH Statement
• Search a table for an element that satisfies the specified
condition, and adjusts the associated index to indicate
that element
Coding Example:
SEARCH PROJECT-TABLE
AT END
DISPLAY "TABLE OVERFLOW"
SEARCH PROJECT-TABLE VARYING PROJECT-TABLE-INDEX
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SET Statement
• Establish reference points for table handling
operations by doing one of the following:
1. Placing values associated with table elements into indexes
associated with index-names
2. Incrementing or decrementing an occurrence number
3. Setting the status of an external switch to ON or OFF
4. Moving data to condition names to make conditions true
5. Setting addresses of pointer data items
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
SET PARM-ERROR-FOUND TO TRUE.
READ PROJECT-RECORD
AT END SET NO-MORE-RECORDS TO TRUE
END-READ.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SORT Statement
• Accept records from one or more files, sorts them
according to the specified key(s), and makes the sorted
records available either through an OUTPUT
PROCEDURE or in an output file
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
START Statement
• Provide a means of positioning within an indexed or
relative file for subsequent sequential record retrieval
• This positioning is achieved by comparing the key
values of records in the file with the value you place in
the RECORD KEY portion of a file’s record area (for an
indexed file), or in the RELATIVE KEY data item (for a
relative file) prior to execution of the START statement
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
START PROJECT-FILE
KEY IS NOT LESS THAN EXTERNALLY-DESCRIBED-KEY
INVALID KEY
SET NO-MORE-RECORDS TO TRUE
END-START.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
STOP Statement
• Halts execution of the object program either
permanently or temporarily
Procedure Division
STRING Statement
• String together the partial or complete contents of two
or more data items or literals into one single data item
• One STRING statement can be written instead of a
series of MOVE statements
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
STRING LASTNAME DELIMITED BY " "
"," DELIMITED BY SIZE
FIRSTNAME DELIMITED BY SIZE
INTO USERNAME.
STRING MM, "/", DD, "/", YY DELIMITED BY SIZE
INTO CURR-DATE.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
SUBTRACT Statement
• Subtract one numeric item, or the sum of two or more
numeric items, from one or more numeric items, and
stores the result
Procedure Division
Coding Example:
SUBTRACT 1 FROM NUM1
SUBTRACT 1 FROM NUM1 GIVING RESULT.
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
UNSTRING Statement
• Cause contiguous data in a sending field to be
separated and placed into multiple receiving fields
• One UNSTRING statement can be written instead of a
series of MOVE statements
Procedure Division
Coding Example:
UNSTRING NAME
INTO NAME1
NAME2
NAME3.
01 NAME PIC X(60).
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
WRITE Statement
• Release a logical record for an output or input/output
file
• When the WRITE statement is executed
• the associated indexed or relative file must be open
in OUTPUT, I-O, or EXTEND mode
• the associated sequential file must be open in
OUTPUT or EXTEND mode
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Coding Example:
WRITE ERROR-LINE FROM ERROR-REPORT-LINE
AFTER ADVANCING 2 LINES
END-WRITE.
WRITE PROJECT-RECORD
END-WRITE.
WRITE PROJECT-RECORD
FORMAT IS "LIST1CMD"
INDICATORS ARE WS-INDICATOR-TABLE
INVALID KEY CONTINUE
END-WRITE.
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Language Element COBOL/400 Limit
• Data Division
• Length of:
• Working-Storage Section
group item 3 000 000 bytes
• Linkage Section group item 3 000 000 bytes
• Elementary item 3 000 000 bytes
• Procedure Division
• Number of:
• GO TO proc-name 255
• IF nesting levels 30
• CALL parameters 30
• SORT-MERGE input files 31
• SORT-MERGE keys 30
Procedure Division
Ingeniero Giovanny Guillen Bustamante
Especialista Certificado IBM i – PMP – Scrum Master
Language Element COBOL/400 Limit
• General
• Number of Files 99
• Number of characters to identify:
• Library-name 10
• Program-name 10
• Text-name 10
• Environment Division
• Number of:
• SELECT file-names 99
Procedure Division
Ingeniero Giovanny Guillen Bustamante
PMP Certified
IBM i Certified Specialist
E-mail: giovanny_guillen_b@Hotmail.com
Gracias

More Related Content

What's hot

Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programmingTarun Sharma
 
The security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgThe security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgEric Vanderburg
 
A beginner's guide to cobol programming
A beginner's guide to cobol programmingA beginner's guide to cobol programming
A beginner's guide to cobol programmingNirmal Pati
 
Introduction to assembler_programming_boston_2
Introduction to assembler_programming_boston_2Introduction to assembler_programming_boston_2
Introduction to assembler_programming_boston_2satyabrataDash18
 
Programming language
Programming languageProgramming language
Programming languageMakku-Sama
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)guest251d9a
 
Computer programming - turbo c environment
Computer programming - turbo c environmentComputer programming - turbo c environment
Computer programming - turbo c environmentJohn Paul Espino
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Rebaz Najeeb
 
HFM, Workspace, and FDM – Voiding your warranty
HFM, Workspace, and FDM – Voiding your warrantyHFM, Workspace, and FDM – Voiding your warranty
HFM, Workspace, and FDM – Voiding your warrantyCharles Beyer
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it worksMark John Lado, MIT
 
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2Bro Shola Ajayi
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to ProgrammingChaffey College
 
COBOL FOR FRESHER
COBOL FOR FRESHERCOBOL FOR FRESHER
COBOL FOR FRESHERNirmal Pati
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 

What's hot (19)

Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
 
The security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgThe security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric Vanderburg
 
All around cobol
All around cobolAll around cobol
All around cobol
 
A beginner's guide to cobol programming
A beginner's guide to cobol programmingA beginner's guide to cobol programming
A beginner's guide to cobol programming
 
Advanced C - Part 1
Advanced C - Part 1 Advanced C - Part 1
Advanced C - Part 1
 
Introduction to assembler_programming_boston_2
Introduction to assembler_programming_boston_2Introduction to assembler_programming_boston_2
Introduction to assembler_programming_boston_2
 
Programming language
Programming languageProgramming language
Programming language
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
Computer programming - turbo c environment
Computer programming - turbo c environmentComputer programming - turbo c environment
Computer programming - turbo c environment
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation
 
HFM, Workspace, and FDM – Voiding your warranty
HFM, Workspace, and FDM – Voiding your warrantyHFM, Workspace, and FDM – Voiding your warranty
HFM, Workspace, and FDM – Voiding your warranty
 
Group 19 CD project
Group 19 CD projectGroup 19 CD project
Group 19 CD project
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it works
 
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
 
COBOL FOR FRESHER
COBOL FOR FRESHERCOBOL FOR FRESHER
COBOL FOR FRESHER
 
Embedded _c_
Embedded  _c_Embedded  _c_
Embedded _c_
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 

Similar to Cobol training

License compliance in embedded linux with the yocto project
License compliance in embedded linux with the yocto projectLicense compliance in embedded linux with the yocto project
License compliance in embedded linux with the yocto projectPaul Barker
 
[FINANCE] Software Development - Project Management
[FINANCE] Software Development - Project Management [FINANCE] Software Development - Project Management
[FINANCE] Software Development - Project Management SafetyCulture1
 
IT Project Management : Software Development Life Cycle
IT Project Management : Software Development Life CycleIT Project Management : Software Development Life Cycle
IT Project Management : Software Development Life CycleSafetyCulture1
 
Oracle XML Publisher / BI Publisher
Oracle XML Publisher / BI PublisherOracle XML Publisher / BI Publisher
Oracle XML Publisher / BI PublisherEdi Yanto
 
Managing OSS license obligations
Managing OSS license obligationsManaging OSS license obligations
Managing OSS license obligationsnexB Inc.
 
Log Analysis for WAS Liberty and WAS Traditional
Log Analysis for WAS Liberty and WAS TraditionalLog Analysis for WAS Liberty and WAS Traditional
Log Analysis for WAS Liberty and WAS TraditionalDon Bourne
 
Virtual Puppet Ecosystem Workshop - March 18,2020
Virtual Puppet Ecosystem Workshop - March 18,2020Virtual Puppet Ecosystem Workshop - March 18,2020
Virtual Puppet Ecosystem Workshop - March 18,2020Puppet
 
What's New in File-AID 16.03
What's New in File-AID 16.03What's New in File-AID 16.03
What's New in File-AID 16.03Compuware
 
LAB - Component Based Development
LAB - Component Based DevelopmentLAB - Component Based Development
LAB - Component Based DevelopmentPerforce
 
How to display country code in the apache
How to display country code in the apacheHow to display country code in the apache
How to display country code in the apacheBenHamminton
 
Bareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan Duehr
Bareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan DuehrBareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan Duehr
Bareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan DuehrNETWAYS
 
Converting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right toolsConverting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right toolsDevOps for Enterprise Systems
 
IC-314 for the AccurioPress C2070/C2070P/C2060
IC-314 for the AccurioPress C2070/C2070P/C2060IC-314 for the AccurioPress C2070/C2070P/C2060
IC-314 for the AccurioPress C2070/C2070P/C2060Eyal Benedek
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1Anil Polsani
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1Anil Polsani
 
2015.12.06 - digi test evaluation B&G & FFW (1)
2015.12.06 - digi test evaluation B&G & FFW (1)2015.12.06 - digi test evaluation B&G & FFW (1)
2015.12.06 - digi test evaluation B&G & FFW (1)Gráinne D'alton
 
AD101: IBM Domino Application Development Futures
AD101: IBM Domino Application Development FuturesAD101: IBM Domino Application Development Futures
AD101: IBM Domino Application Development FuturesEamon Muldoon
 
[CCP Games] Versioning Everything with Perforce
[CCP Games] Versioning Everything with Perforce[CCP Games] Versioning Everything with Perforce
[CCP Games] Versioning Everything with PerforcePerforce
 

Similar to Cobol training (20)

License compliance in embedded linux with the yocto project
License compliance in embedded linux with the yocto projectLicense compliance in embedded linux with the yocto project
License compliance in embedded linux with the yocto project
 
[FINANCE] Software Development - Project Management
[FINANCE] Software Development - Project Management [FINANCE] Software Development - Project Management
[FINANCE] Software Development - Project Management
 
IT Project Management : Software Development Life Cycle
IT Project Management : Software Development Life CycleIT Project Management : Software Development Life Cycle
IT Project Management : Software Development Life Cycle
 
Oracle XML Publisher / BI Publisher
Oracle XML Publisher / BI PublisherOracle XML Publisher / BI Publisher
Oracle XML Publisher / BI Publisher
 
Managing OSS license obligations
Managing OSS license obligationsManaging OSS license obligations
Managing OSS license obligations
 
Log Analysis for WAS Liberty and WAS Traditional
Log Analysis for WAS Liberty and WAS TraditionalLog Analysis for WAS Liberty and WAS Traditional
Log Analysis for WAS Liberty and WAS Traditional
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Virtual Puppet Ecosystem Workshop - March 18,2020
Virtual Puppet Ecosystem Workshop - March 18,2020Virtual Puppet Ecosystem Workshop - March 18,2020
Virtual Puppet Ecosystem Workshop - March 18,2020
 
What's New in File-AID 16.03
What's New in File-AID 16.03What's New in File-AID 16.03
What's New in File-AID 16.03
 
LAB - Component Based Development
LAB - Component Based DevelopmentLAB - Component Based Development
LAB - Component Based Development
 
How to display country code in the apache
How to display country code in the apacheHow to display country code in the apache
How to display country code in the apache
 
Bareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan Duehr
Bareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan DuehrBareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan Duehr
Bareos Python Plugins Hacking Workshop by Maik Aussendorf & Stephan Duehr
 
Converting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right toolsConverting to the latest COBOL Compiler made simple with the right tools
Converting to the latest COBOL Compiler made simple with the right tools
 
IC-314 for the AccurioPress C2070/C2070P/C2060
IC-314 for the AccurioPress C2070/C2070P/C2060IC-314 for the AccurioPress C2070/C2070P/C2060
IC-314 for the AccurioPress C2070/C2070P/C2060
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1
 
2015.12.06 - digi test evaluation B&G & FFW (1)
2015.12.06 - digi test evaluation B&G & FFW (1)2015.12.06 - digi test evaluation B&G & FFW (1)
2015.12.06 - digi test evaluation B&G & FFW (1)
 
Task recorder control
Task recorder controlTask recorder control
Task recorder control
 
AD101: IBM Domino Application Development Futures
AD101: IBM Domino Application Development FuturesAD101: IBM Domino Application Development Futures
AD101: IBM Domino Application Development Futures
 
[CCP Games] Versioning Everything with Perforce
[CCP Games] Versioning Everything with Perforce[CCP Games] Versioning Everything with Perforce
[CCP Games] Versioning Everything with Perforce
 

More from Giovanny Guillen

Curso java desde cero nivel i - modulo v
Curso java desde cero   nivel i - modulo vCurso java desde cero   nivel i - modulo v
Curso java desde cero nivel i - modulo vGiovanny Guillen
 
Curso java desde cero nivel i - modulo iv
Curso java desde cero   nivel i - modulo ivCurso java desde cero   nivel i - modulo iv
Curso java desde cero nivel i - modulo ivGiovanny Guillen
 
Curso java desde cero nivel i - modulo iii
Curso java desde cero   nivel i - modulo iiiCurso java desde cero   nivel i - modulo iii
Curso java desde cero nivel i - modulo iiiGiovanny Guillen
 
Curso java desde cero nivel i - modulo ii
Curso java desde cero   nivel i - modulo iiCurso java desde cero   nivel i - modulo ii
Curso java desde cero nivel i - modulo iiGiovanny Guillen
 
Curso java desde cero nivel i - modulo i
Curso java desde cero   nivel i - modulo iCurso java desde cero   nivel i - modulo i
Curso java desde cero nivel i - modulo iGiovanny Guillen
 
Libro Ingeniería del Software
Libro Ingeniería del SoftwareLibro Ingeniería del Software
Libro Ingeniería del SoftwareGiovanny Guillen
 
Programacion RPG - Gestión de Errores y Excepciones
Programacion RPG - Gestión de Errores y ExcepcionesProgramacion RPG - Gestión de Errores y Excepciones
Programacion RPG - Gestión de Errores y ExcepcionesGiovanny Guillen
 
Programacion RPG: Conceptos ILE
Programacion RPG: Conceptos ILEProgramacion RPG: Conceptos ILE
Programacion RPG: Conceptos ILEGiovanny Guillen
 
Programacion RPG Operaciones
Programacion RPG OperacionesProgramacion RPG Operaciones
Programacion RPG OperacionesGiovanny Guillen
 
Programacion RPG Especificaciones de Entrada y Salida
Programacion RPG Especificaciones de Entrada y SalidaProgramacion RPG Especificaciones de Entrada y Salida
Programacion RPG Especificaciones de Entrada y SalidaGiovanny Guillen
 
Programación RPG - Conceptos
Programación RPG - ConceptosProgramación RPG - Conceptos
Programación RPG - ConceptosGiovanny Guillen
 
IBM i - Manejo de archivos y datos
IBM i - Manejo de archivos y datosIBM i - Manejo de archivos y datos
IBM i - Manejo de archivos y datosGiovanny Guillen
 
Gestión de la Capacidad en Fábricas de Software
Gestión de la Capacidad en Fábricas de SoftwareGestión de la Capacidad en Fábricas de Software
Gestión de la Capacidad en Fábricas de SoftwareGiovanny Guillen
 

More from Giovanny Guillen (20)

Curso java desde cero nivel i - modulo v
Curso java desde cero   nivel i - modulo vCurso java desde cero   nivel i - modulo v
Curso java desde cero nivel i - modulo v
 
Curso java desde cero nivel i - modulo iv
Curso java desde cero   nivel i - modulo ivCurso java desde cero   nivel i - modulo iv
Curso java desde cero nivel i - modulo iv
 
Curso java desde cero nivel i - modulo iii
Curso java desde cero   nivel i - modulo iiiCurso java desde cero   nivel i - modulo iii
Curso java desde cero nivel i - modulo iii
 
Curso java desde cero nivel i - modulo ii
Curso java desde cero   nivel i - modulo iiCurso java desde cero   nivel i - modulo ii
Curso java desde cero nivel i - modulo ii
 
Curso java desde cero nivel i - modulo i
Curso java desde cero   nivel i - modulo iCurso java desde cero   nivel i - modulo i
Curso java desde cero nivel i - modulo i
 
Libro Ingeniería del Software
Libro Ingeniería del SoftwareLibro Ingeniería del Software
Libro Ingeniería del Software
 
Portafolio de proyectos
Portafolio de proyectosPortafolio de proyectos
Portafolio de proyectos
 
Seguridad del ibm i as400
Seguridad del ibm i as400Seguridad del ibm i as400
Seguridad del ibm i as400
 
Programacion RPG - Gestión de Errores y Excepciones
Programacion RPG - Gestión de Errores y ExcepcionesProgramacion RPG - Gestión de Errores y Excepciones
Programacion RPG - Gestión de Errores y Excepciones
 
Programacion RPG: Conceptos ILE
Programacion RPG: Conceptos ILEProgramacion RPG: Conceptos ILE
Programacion RPG: Conceptos ILE
 
Programacion RPG Operaciones
Programacion RPG OperacionesProgramacion RPG Operaciones
Programacion RPG Operaciones
 
Programacion RPG Especificaciones de Entrada y Salida
Programacion RPG Especificaciones de Entrada y SalidaProgramacion RPG Especificaciones de Entrada y Salida
Programacion RPG Especificaciones de Entrada y Salida
 
Programación RPG - Conceptos
Programación RPG - ConceptosProgramación RPG - Conceptos
Programación RPG - Conceptos
 
Organizational values
Organizational valuesOrganizational values
Organizational values
 
IBM i - AS/400 - SDA
IBM i - AS/400 - SDAIBM i - AS/400 - SDA
IBM i - AS/400 - SDA
 
IBM i - Manejo de archivos y datos
IBM i - Manejo de archivos y datosIBM i - Manejo de archivos y datos
IBM i - Manejo de archivos y datos
 
Ingenieria requerimientos
Ingenieria requerimientosIngenieria requerimientos
Ingenieria requerimientos
 
Earn value
Earn valueEarn value
Earn value
 
Gestión de la Capacidad en Fábricas de Software
Gestión de la Capacidad en Fábricas de SoftwareGestión de la Capacidad en Fábricas de Software
Gestión de la Capacidad en Fábricas de Software
 
Fabricas de software
Fabricas de softwareFabricas de software
Fabricas de software
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Cobol training

  • 1. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COBOL Programming
  • 2. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COBOL This is a complete course about this powerful programming language in use on IBM AS/400 and mainframe yet. This course cover next points: - Structure of COBOL program. - Data types - Using files - Word reserved - programming structured
  • 3. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COBOL Structure of COBOL program: A COBOL Program consists of following 4 divisions: • IDENTIFICATION DIVISION • ENVIRONMENT DIVISION • DATA DIVISION • PROCEDURE DIVISION All the divisions must appear in the same order as shown above.
  • 4. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Identification Division It names the program and may include the date the program was written, the date of compilation, and other such documentary information about the program. COBOL Identification Division
  • 5. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: IDENTIFICATION DIVISION. PROGRAM-ID. TESTPGM. AUTHOR. PROGRAMMER NAME. INSTALLATION. XYZ. DATE-WRITTEN. 99/99/99. DATE-COMPILED. 99/99/99. COBOL Identification Division
  • 6. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Environment Division • Configuration Section • Input-Output Section. The Configuration Section is optional. When specified, it can describe the computer on which the source program is compiled and the computer on which the object program is executed. COBOL Identification Division
  • 7. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COBOL Environment Division Configuration Section • SOURCE-COMPUTER • OBJECT-COMPUTER • SPECIAL-NAMES Input-Output Section • File-Control. • I-O-Control
  • 8. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Configuration Section can: • Relate IBM-defined environment-names to user-defined mnemonic names • Specify a substitution for the currency sign • Interchange the functions of the comma and the period in PICTURE clauses and numeric literals COBOL Configuration Section
  • 9. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-AS400. OBJECT-COMPUTER. IBM-AS400. SPECIAL-NAMES. TOP IS TOP-OF-PAGE. COBOL Configuration Section
  • 10. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COBOL Input-Output Section The Input-Output Section •Define each file to be used •Identify its external storage medium •Assign the file to one or more input/ output devices •Specify information needed for efficient transmission of data between the external medium and the COBOL program
  • 11. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master File-Control Paragraph •Names and associates the files with the external media. A COBOL program can process: Data Base Files: • Physical Files • Logical Files COBOL Input-Output Section Device Files: • Display Files • Tape Files • Printer Files • Diskette Files • ICF Files
  • 12. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example1: INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT DISPLAY-FILE ASSIGN TO WORKSTATION-TESTDSPF ORGANIZATION IS TRANSACTION ACCESS IS DYNAMIC RELATIVE KEY IS RRN FILE STATUS IS FILE-STATUS. COBOL Input-Output Section
  • 13. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example2: INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PHY-FILE1 ASSIGN TO DATABASE-PHYSICAL1 ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY IS EXTERNALLY-DESCRIBED-KEY FILE STATUS IS WS-PHY-FILE1-STATUS. COBOL Input-Output Section
  • 14. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SELECT Paragraph •Makes association between the file and the external medium •It consists of 3 parts: • Device • File Name • Attribute COBOL Input-Output Section
  • 15. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master DEVICE: • Specifies the type of Device that the file will use • It can be changed at run-time List of Different Devices: Device File ‘ WORKSTATION Display File DATABASE Externally described Database File DISK Program described Database file FORMATFILE Externally described Printer file PRINTER Program described Printer file TAPEFILE Tape File DISKETTE Diskette File COBOL Select Paragraph
  • 16. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master FILE-NAME: • 1 thru 10 char. system name of the actual external file • For Database files, a member name can not be specified in the COBOL program. If a particular member is to be specified, the OVRDBF command must be used at execution time to specify the member name • The file-name can be changed at execution time with the TOFILE parameter of the OVRxxxF command COBOL Select Paragraph ATTRIBUTE: • This part can be SI • SI indicates that a separate indicator area has been specified in the DDS for the FORMATFILE or WORKSTATION file
  • 17. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Device File Name Default File-name WORKSTATION Required - Optional DATABASE Required - N/A DISK Required - N/A FORMATFILE Required - Optional PRINTER Optional QPRINT N/A TAPE FILE Optional QTAPE N/A DISKETTE Optional QDKT N/A COBOL Select Paragraph
  • 18. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ORGANIZATION Clause • For Database files, it indicates the use of the file in the program (permanent logical structure of the file) • 4 types of organization: • Sequential • Indexed • Relative • Transaction COBOL Input-Output Section
  • 19. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SEQUENTIAL ORGANIZATION •The physical order in which the records are placed in the file determines the sequence of records •The relationships among records in the file do not change, except that the file can be extended •There are no keys. Both database files and device files can have sequential organization COBOL Input-Output Section
  • 20. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master INDEXED ORGANIZATION • Each record in the file has an embedded key called a key data item that is associated with an index • An index provides a logical path to the data records, according to the contents of the associated embedded record key data items • Only database files can have indexed organization COBOL Input-Output Section RELATIVE ORGANIZATION • Each record area is identified by a relative record number; the access method stores and retrieves a record, based on its relative record number • Relative files must be assigned to DISK or DATABASE
  • 21. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master TRANSACTION ORGANIZATION • Work station and data communication files can have TRANSACTION organization ACCESS MODE Clause • It defines the manner in which the records of the file are made available for processing • If the ACCESS MODE clause is not specified, sequential access is assumed COBOL Input-Output Section
  • 22. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ACCESS MODE Clause • Sequential Access Mode • Sequential Organization • Indexed Organization • Relative Organization • Random Access Mode • Indexed Organization • Relative Organization • Dynamic Access Mode • Indexed Organization • Relative Organization COBOL Input-Output Section
  • 23. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ACCESS MODE Clause • Sequential-Access Mode: Allows reading and writing records of a file in a serial manner; the order of reference is implicitly determined by the position of a record in the file • Random-Access Mode: Allows reading and writing records in a programmer-specified manner; the control of successive references to the file is expressed by specifically defined keys supplied by the user • Dynamic-Access Mode: Allows a specific I/O request to determine the access mode. Therefore, records may be processed sequentially and/or randomly COBOL Input-Output Section
  • 24. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master RECORD KEY Clause • It must be specified for an indexed file • Each record in the file must have a unique record key value • EXTERNALLY-DESCRIBED-KEY specifies that the key(s) for this file are same that are externally described in DDS • WITH DUPLICATES phrase can be specified for files assigned to DATABASE COBOL Input-Output Section
  • 25. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master RECORD KEY Clause Note: An error will be encountered at run-time, if • ‘DUPLICATES’ is specified in COBOL program and file was created with ‘UNIQUE” specified in DDS • ‘DUPLICATES’ is not specified in COBOL program and file was created allowing non unique keys COBOL Input-Output Section
  • 26. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master RELATIVE KEY Clause • It specifies the relative record number for a specific logical record within a relative file. • The POSITION parameter on the OVRDBF command can be used to set the file position indicator. This causes processing to begin with a record other than the first record. COBOL Input-Output Section FILE-STATUS Clause • It monitors the execution of each input-output request for the file • In some cases it indicates the I-O errors • It must be defined in Data Division
  • 27. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master I-O-Control Paragraph • It is specified when checkpoints are to be taken and the storage areas to be shared by different files • This paragraph is optional in a COBOL program COBOL Input-Output Section
  • 28. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Division • The Data Division of a COBOL source program describes, in a structured manner, all the data to be processed by the object program • This section outlines the structure of the Data Division and explains the types of data and how they are related in a COBOL program COBOL Data Division
  • 29. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master • File Section • Describes externally stored data (including sort- merge files) • Working-Storage Section • Describes internal data • Linkage Section • Describes data made available by another program. COBOL Data Division
  • 30. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: DATA DIVISION. FILE SECTION. FD DISPLAY-FILE. 01 DISPLAY-REC COPY DD-ALL-FORMATS OF TESTDSPF. FD PHY-FILE1. 01 PHY-FILE1-RCD. COPY DDS-ALL-FORMATS OF PHYSICAL1. FD PHY-FILE2. 01 PHY-FILE2-REC. COPY DDSR-ALL-FORMATS OF PHYSICAL2. COBOL Data Division
  • 31. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master DD: to reference alias (alternate) names - 30 Chars “_” is replaced by “-” DDR:does everything that the DD option does. Invalid COBOL char @, #, $, _ is replaced by Valid COBOL char A, N, D, - removes “_” from the end of a field name. DDS:to reference internal DDS format field names DDSR: does everything that the DDS option does. Invalid COBOL char @, #, $, _ is replaced by Valid COBOL char A, N, D, - removes “_” from the end of a field name. COBOL Data Division/Copy Options
  • 32. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master WORKING-STORAGE SECTION. FD DISPLAY-FILE. 01 PHYSICAL2-PARMS. 05 PHYSICAL2-PRODCD PIC X(04). 05 PHYSICAL2-INV PIC S9(03). 05 PHYSICAL2-STATUS PIC X(01). 88 PHYSICAL2-NONE-FOUND VALUE "0". 88 PHYSICAL2-ALL-VERIFIED VALUE "1". 88 PHYSICAL2-UNVERIFIED VALUE "2". 77 ERR-MESSAGE PIC X(80) VALUE SPACES. COBOL Data Division
  • 33. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master LINKAGE SECTION. 01 FUNCTION-MEMBER. 05 FUNCTION-CODE PIC X. 88 END-OF-PGM VALUE SPACES. 88 ENTRY-OPERATION VALUE "E". 88 VERIFY-OPERATION VALUE "V". 05 MEMBER-CODE PIC X. 88 ENTRY-MEMBER VALUE "E". 88 CLUSTER-MEMBER VALUE "C". 01 USER-ID PIC X(10). 01 JOB-NUMBER PIC X(10). COBOL Data Division
  • 34. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master • For all files except sort/merge, the File Section must contain an FD (File Description) entry • For each sort or merge file, the File Section must contain an SD (Sort Description) entry COBOL File Section file-description-entry • Represent the highest level of organization in the File Section • Provide information about the physical structure and identification of a file, and gives the record-name(s) associated with that file
  • 35. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master record-description-entry • A set of data description entries that describe the particular record(s) contained within a particular file • More than one record description entry may be specified; each is an alternative description of the same record storage area • Data areas described in the File Section are not available for processing unless the file containing the data area is open • The initial value of a data item in the File Section is undefined COBOL File Section
  • 36. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master file-name • Must follow the level indicator (FD or SD), and must be the same as that specified in the associated SELECT clause • The file-name must be unique within this program • One or more record description entries must follow the file-name. When more than one record description entry is specified, each entry implies a redefinition of the same storage area • The clauses that follow file-name are optional; they may appear in any order COBOL File Section
  • 37. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master BLOCK CONTAINS Clause • Specify the size of the physical records • If the records in the file are not blocked, the clause may be omitted • This clause is always active for tape files, but is syntax- checked only for diskette files COBOL File Section RECORDS • Specify the number of logical records contained in each physical record • Maximum record size is 32766; maximum block size is 32766
  • 38. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master LABEL RECORDS Clause • Indicate the presence or absence of labels • If it is not specified for a file, label records for that file must conform to the system label specifications • Generally treated as documentation STANDARD • Labels conforming to system specifications exist for this file OMITTED • No labels exist for this file COBOL File Section
  • 39. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master • File Data (External Data) • File data is contained in files • Program Data (Internal Data) • Program data is created by the program itself COBOL Data Types Levels of Data • After a record has been defined, it can be subdivided to provide more detailed data references • A system of level-numbers specifies the organization of elementary and group items into records. Special level- numbers are also used; they identify data items used for special purposes
  • 40. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types Data Relationships • The relationships among all data to be used in a program are defined in the Data Division, through a system of level indicators and level-numbers • A level indicator, with its descriptive entry, identifies each file in a program. Level indicators represent the highest level of any data hierarchy with which they are associated; FD is the file description level indicator and SD is the sort-merge file description level indicator • A level-number, with its descriptive entry, indicates the properties of specific data
  • 41. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master • A level-number is a 1- or 2-digit integer between 01 and 49, or one of three special level-numbers: 66, 77, or 88 • The following level-numbers are used to structure records: • 01 Specify the record itself and is the most inclusive level-number possible. A level-01 entry may be either a group item or an elementary item • 02-49 Specify group and elementary items within a record Data Types
  • 42. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Special Level-Numbers • Special level-numbers identify items that do not structure a record. The special level-numbers are: • 66 Identifies items that must contain a RENAMES clause; such items regroup previously defined data items • 77 Identifies data item description entries — independent Working-Storage or Linkage Section items that are not subdivisions of other items, and are not sub-divided themselves • 88 Identifies any condition-name entry that is associated with a value of a conditional variable Data Types
  • 43. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types BLANK WHEN ZERO Clause • Specify that an item contains nothing but spaces when its value is zero • Specify only for elementary numeric or numeric-edited items • These items must be described, either implicitly or explicitly, as USAGE IS DISPLAY. When this clause is specified for a numeric item, the item is considered a numeric-edited item • Must not be specified for level-66 or level-88 items • Not allowed for items described with the USAGE IS INDEX clause or the USAGE IS POINTER clause
  • 44. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types Coding Example: 01 WS-GROUP-ITEM. 05 WS-VAR1 PIC X(001). 05 WS-VAR2 PIC 9(006) BLANK WHEN ZERO.
  • 45. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types JUSTIFIED Clause • Override standard positioning rules for a receiving item of the alphabetic or alphanumeric categories • May be specified only at elementary level. JUST is an abbreviation for JUSTIFIED, and has the same meaning. RIGHT is an optional word and has no effect on the execution of the program • Cannot be specified for numeric, numeric-edited, or alphanumeric-edited items • Must not be specified with level-66 (RENAMES) and level-88 (condition-name) entries
  • 46. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types Coding Example: 01 WS-GROUP-ITEM. 05 WS-VAR1 PIC X(001). 05 WS-VAR2 PIC X(006) JUSTIFIED RIGHT.
  • 47. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types LIKE Clause • Define the PICTURE, USAGE, and SIGN characteristics of a data item by copying them from a previously defined data item • Make the length of the data item you define different from the length of the original item • Cause the new data item to inherit specific characteristics from the existing data item. These characteristics are the PICTURE, USAGE, SIGN, and BLANK WHEN ZERO attributes of the existing item
  • 48. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types Coding Example: 01 WS-GROUP-ITEM1. 05 WS-VAR1 PIC X(001). 05 WS-VAR2 PIC X(006) JUSTIFIED RIGHT. 01 WS-GROUP-ITEM2 LIKE WS-GROUP-ITEM1.
  • 49. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types PICTURE Clause • Specify the general characteristics and editing requirements of an elementary item • Must be specified for every elementary item except an index data item or the subject of the RENAMES clause • The PICTURE character-string may contain a max of 30 chars
  • 50. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types Coding Example: 01 WS-GROUP-ITEM1. 05 WS-VAR1 PIC X(001). 05 WS-VAR2 PIC 9(006). 01 ITEM-1 PIC X(3) VALUE "ABC".
  • 51. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master REDEFINES Clause • To use different data description entries to describe the same computer storage area Data Types
  • 52. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: 01 SYSTEM-DATE PIC 9(6) VALUE ZEROS. 01 SYS-DATE REDEFINES SYSTEM-DATE. 05 SYS-YEAR PIC 9(2). 05 SYS-MONTH PIC 9(2). 05 SYS-DAY PIC 9(2). 01 SYSTEM-DATE PIC 9(6) VALUE ZEROS. 01 SYS-DATE REDEFINES SYSTEM-DATE. 05 SYS-YEAR PIC X(2). 05 SYS-MONTH PIC X(2). 05 SYS-DAY PIC X(2). 01 WS-AGE-FIELD. 05 WS-AGE-ALPHA PIC X(03) VALUE ZEROS. 05 WS-AGE REDEFINES WS-AGE-ALPHA PIC 9(03). Data Types
  • 53. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master RENAMES Clause • Specify alternative, possibly overlapping, groupings of elementary data items • The special level-number 66 must be specified for data description entries that contain the RENAMES clause • One or more RENAMES entries can be written for a logical record Data Types
  • 54. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types Coding Example: 01 SYSTEM-DATE-8. 05 SYS-CENTURY PIC 9(2). 05 SYS-YEAR PIC 9(2). 05 SYS-MONTH PIC 9(2). 05 SYS-DAY PIC 9(2). 66 SYSTEM-DATE-6 RENAMES SYS-YEAR THROUGH SYS- DAY.
  • 55. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SIGN Clause • Specify the position and mode of representation of the operational sign for a numeric entry • USAGE IS DISPLAY must be specified, explicitly or implicitly USAGE Clause • Specify for an entry at any level. However, if it is specified at the group level, it applies to each elementary item in the group Data Types
  • 56. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Computational Items • Value used in arithmetic operations • Must be numeric • The maximum length of a computational item is 18 decimal digits The PICTURE of a computational item may contain only: 9 One or more numeric character positions S One operational sign V One implied decimal point COMPUTATIONAL-3 or COMP-3 - equivalent of PACKED- DECIMAL COMPUTATIONAL-4 or COMP-4 - equivalent of BINARY Data Types
  • 57. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Data Types VALUE Clause • Specify the initial contents of a data item or the value(s) associated with a condition-name • Use of the VALUE clause differs depending on the Data Division section in which it is specified; In the File and Linkage sections, the VALUE clause must be used only in condition-name entries; in the Working-Storage Section, the VALUE clause may be used in condition-name entries, or in specifying the initial value of any data item • The data item assumes the specified value at the beginning of program execution. • If the initial value is not explicitly specified, it is unpredictable
  • 58. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Working-Storage Section • The Working-Storage Section describes data records that are not part of external data files but are developed and processed internally • The Working-Storage Section contains record description entries and data description entries for independent data items, called data item description entries record-description-entry • Data entries in the Working-Storage Section that bear a definite hierarchic relationship to one another must be grouped into records structured by level number
  • 59. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master data-item-description-entry • Independent items in the Working-Storage Section that bear no hierarchic relationship to one another need not be grouped into records, provided that they do not need to be further subdivided. Instead, they are classified and defined as independent elementary items. Each is defined in a separate data-item description entry that begins with either the level number 77 or 01 • The initial value of any data item in the Working-Storage Section, except an index data item, is specified by associating a VALUE clause with the item • The initial value of any index data item, or of any data item not associated with a VALUE clause, is undefined Working-Storage Section
  • 60. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Linkage Section • Describe data made available from another program • Record description entries and data item description entries in the Linkage Section provide names and descriptions, but storage within the program is not reserved because the data area exists elsewhere • Any data description clause may be used to describe items in the Linkage Section, with one exception: the VALUE clause may not be specified for items other than level-88 items
  • 61. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Linkage Section Coding Example: LINKAGE SECTION. 01 FROMDATE. 05 FROMMM PIC 99. 05 FROMDD PIC 99. 05 FROMYY PIC 99. 01 TODATE. 05 TOMM PIC 99. 05 TODD PIC 99. 05 TOYY PIC 99. 01 DAYS PIC S9(7) COMP-3. 01 STATUS-CODE PIC 1.
  • 62. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COBOL - Procedure Division Procedure Division Consists of optional declaratives, and procedures that contain sections and/or paragraphs, sentences, and statements
  • 63. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Procedure Division • The USING Phrase • Required only if the object program is to be invoked by a CALL statement and that statement includes a USING phrase • Makes data items defined in a calling program available to a called subprogram • Each USING identifier must be defined as a level-01 or level-77 item in the Linkage Section of the called subprogram • Must not contain a REDEFINES clause • Maximum number of data-names - 30
  • 64. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Procedure Division Procedures • Within the Procedure Division, a procedure consists of: • A section or a group of sections • A paragraph or group of paragraphs • A procedure-name is a user-defined name that identifies a section or a paragraph
  • 65. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Section A section header optionally followed by one or more paragraphs • Section-header • A section-name followed by: • the keyword SECTION • an optional segment-number • a separator period Procedure Division
  • 66. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Paragraph A paragraph-name followed by a separator period, optionally followed by one or more sentences Paragraph-name • A user-defined word that identifies a paragraph Procedure Division
  • 67. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Sentence One or more statements terminated by a separator period Statement • A syntactically valid combination of identifiers and symbols beginning with a COBOL verb Procedure Division
  • 68. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Identifier • A syntactically correct combination of a data name • In any Procedure Division reference, the contents of an identifier must be compatible with the class specified through its PICTURE clause, or results are unpredictable Procedure Division
  • 69. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Declaratives • Provide one or more special-purpose sections that are executed when an exceptional condition occurs • When Declarative Sections are specified, they must be grouped at the beginning of the Procedure Division, and the entire Procedure Division must be divided into sections Procedure Division
  • 70. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: PROCEDURE DIVISION. DECLARATIVES. ERROR SECTION. USE AFTER STANDARD ERROR PROCEDURE ON INPUT- DATA. ERROR-ROUTINE. IF CHECK-STATUS= "30" ADD 1 TO DECLARATIVE-ERRORS. END DECLARATIVES. Procedure Division
  • 71. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Common Phrases There are several phrases common to arithmetic and data manipulation statements; these phrases are described below CORRESPONDING Phrase • Allows ADD, SUBTRACT, and MOVE operations to be performed on elementary data items of the same name if the group items to which they belong are specified • Both identifiers following the key word CORRESPONDING must name group items Procedure Division
  • 72. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: MOVE CORRESPONDING DATE-YYMMDD TO DATE-WITH- SLASHES. 01 DATE-YYMMDD. 05 YY PIC XX. 05 MM PIC XX. 05 DD PIC XX. 01 DATE-WITH-SLASHES. 05 MM PIC XX. 05 SLASHA PIC X VALUE "/". 05 DD PIC XX. 05 SLASHB PIC X VALUE "/". 05 YY PIC XX. Procedure Division
  • 73. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master GIVING Phrase • The value of the identifier that follows the word GIVING is set equal to the calculated result of the arithmetic operation • Because this identifier is not involved in the computation, it may be a numeric edited item Procedure Division
  • 74. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: SUBTRACT SUB1 FROM SUB2 GIVING RESULT. DIVIDE NUM1 BY 10 GIVING RESULT. Procedure Division
  • 75. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ROUNDED Phrase • After decimal point alignment, the number of places in the fraction of the result of an arithmetic operation is compared with the number of places provided for the fraction of the resultant identifier • When the size of the fractional result exceeds the number of places provided for its storage, truncation occurs unless ROUNDED is specified. When ROUNDED is specified, the least significant digit of the resultant identifier is increased by 1 when-ever the most significant digit of the excess is greater than or equal to 5 Procedure Division
  • 76. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: DIVIDE NUM1 BY 10 GIVING RESULT ROUNDED. COMPUTE RESULT ROUNDED = NUM1 * NUM2. Procedure Division
  • 77. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SIZE ERROR Phrases • A size error condition can occur in three different ways: • When the absolute value of the result of an arithmetic evaluation, after decimal point alignment, exceeds the largest value that can be contained in the result field • When division by zero occurs • In an exponential expression, when • Zero raised to the exponent Zero • Zero raised to a negative exponent • A negative number raised to a fractional exponent • The size error condition applies only to final results, not to any intermediate results Procedure Division
  • 78. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: ADD 1 TO NUM1 ON SIZE ERROR MOVE 0 TO NUM1 Procedure Division
  • 79. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Input-Output Statements • Transfer data to and from files stored on external media • Control low-volume data that is obtained from or sent to an input/output device Common Processing Facilities Applied to more than one input-output statement: • Status key • INVALID KEY condition • INTO/FROM identifier phrase • File position indicator Procedure Division
  • 80. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Status Key • If the FILE STATUS clause is specified in the FILE- CONTROL entry, a value is placed in the specified status key (the 2-character data item named in the FILE STATUS clause) during execution of any request on that file, which indicates the status of that request • The value is placed in the status key before execution of any EXCEPTION/ERROR declarative or INVALID KEY/AT END phrase associated with the request Procedure Division
  • 81. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PROJECT-FILE ASSIGN TO DATABASE_PROJECT ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS EXTERNALLY-DESCRIBED-KEY FILE STATUS IS WS-PROJECT-FILE-STATUS. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-PROJECT-FILE-STATUS PIC XX. 88 WS-IO-SUCCESSFUL VALUE "00" THRU "09". 88 WS-END-OF-FILE VALUE "10" THRU "19". 88 WS-INVALID-KEY VALUE "20" THRU "29". 88 WS-IO-ERROR VALUE "30" THRU "99". Procedure Division
  • 82. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master INVALID KEY Condition • Can occur during execution of a START, READ, WRITE, REWRITE, or DELETE statement • When occurs, the input-output statement that caused the condition is unsuccessful Procedure Division
  • 83. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: READ PROJECT RECORD INVALID KEY MOVE "N" TO PROJECT-RECORD-FOUND NOT INVALID KEY MOVE "Y" TO PROJECT-RECORD-FOUND END-READ. IF WS-PROJECT-FILE-STATUS >= "30" MOVE "N" TO PROJECT-RECORD-FOUND END-IF. Procedure Division
  • 84. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master INTO/FROM Identifier Phrase • Valid for READ, RETURN, RELEASE, REWRITE, and WRITE statements • The identifier specified must be the name of an entry in the Working-Storage Section or the Linkage Section, or of a record description for another previously opened file • Record-name/file-name and identifier must not refer to the same storage area • The INTO phrase may be specified in a READ or RETURN statement • The FROM phrase may be specified in a RELEASE, REWRITE, or WRITE statement Procedure Division
  • 85. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: READ PROJECT RECORD INTO WS-PROJECT FORMAT IS "PROJECT1" INDICATORS ARE WS-INDICATOR-TABLE END-READ. REWRITE SUBFILE PROJECT-RCD FROM WS-PROJECT1SFL-O FORMAT IS “PROJECT11SFL" INDICATORS ARE WS-INDICATOR-TABLE INVALID KEY CONTINUE END-REWRITE. Procedure Division
  • 86. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Procedure Division Statements ACCEPT Statement • Transfer data into the specified identifier • No editing or error checking of the incoming data Procedure Division Coding Example: ACCEPT SYSTEM-DATE FROM DATE. ACCEPT SYSTEM-TIME FROM TIME.
  • 87. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ACQUIRE Statement • Acquire a program device for a TRANSACTION file ADD Statement • Sum two or more numeric operands and stores the result Procedure Division Coding Example: ADD 1 TO PROJECT-COUNTER.
  • 88. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master CALL Statement • Transfer control from one object program to another within the run unit • Pass control to the first non-declarative instruction of the called subprogram • Called subprograms themselves can contain CALL statements, but a called subprogram that contains a CALL statement that directly or indirectly calls the calling program gives unpredictable results Procedure Division Coding Example: CALL "XXXVALIDDT" USING DATE-CHECK.
  • 89. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master CANCEL Statement • Ensure that the next time the referenced subprogram is called it will be entered in its initial state • Close all open files • Operate only on the program specified, and not on any program that may have been called by the canceled program Procedure Division
  • 90. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master CANCEL Statement • No action is taken when a CANCEL statement is executed, naming a program that has not been called in the run unit, or that names a program that was called and subsequently canceled. In either case, control passes to the next statement • If names a program that does not exist in the library list, an error message is issued Coding Example: CANCEL "XXXVALIDDT“. Procedure Division
  • 91. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master CLOSE Statement • Terminate the processing of volumes and files, with optional rewind and/or lock or removal, where applicable • Terminate the processing of volumes and files, with optional rewind and/or lock or removal, where applicable • If the file is in an open status and the execution of a CLOSE statement is unsuccessful, the EXCEPTION/ERROR procedure (if specified) for this file is executed Procedure Division
  • 92. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Procedure Division CLOSE Statement • If a CLOSE statement for an open file is not processed before a STOP RUN for this run unit, the file is implicitly closed Coding Example: CLOSE PROJECT. Procedure Division
  • 93. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COMMIT Statement • Provide a way of synchronizing changes to data base records while preventing other jobs from modifying those records until the COMMIT is performed • All record locks held by the job since the last commitment boundary for files under commitment control are released and the records become available to other jobs • Only affect files under commitment control • If a COMMIT is executed and there are no files opened under commitment control, the COMMIT statement has no effect and no commitment boundary is established Procedure Division
  • 94. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master COMPUTE Statement • Assign the value of an arithmetic expression to one or more data items • With the COMPUTE statement, arithmetic operations can be combined without the restrictions on receiving data items imposed by the rules for the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements Procedure Division Coding Example: COMPUTE RESULT = NUM1 - 1.
  • 95. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master CONTINUE Statement • Allow to specify a no operation statement • Indicate that no executable instruction is present • May be used anywhere a conditional statement • Has no effect on the execution of the program Procedure Division Coding Example: READ PROJECT INVALID KEY CONTINUE END-READ.
  • 96. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master DELETE Statement • Remove a record from an indexed or relative file • For indexed files, the key may then be reused for record addition • For relative files, the space is then available for a new record with the same RELATIVE KEY value • File must be open in I-O mode • Record is logically removed from the file and can no longer be accessed Procedure Division
  • 97. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: DELETE PROJECT-FILE RECORD INVALID KEY MOVE "N" TO WS-PROJRCT-RECORD-FOUND NOT INVALID KEY MOVE "Y" TO WS-PROJECT-RECORD-FOUND END-DELETE Procedure Division
  • 98. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master DISPLAY Statement • Transfer the contents of each operand to the output device • Contents are displayed on the output device in the order, left to right, in which the operands are listed Procedure Division Coding Example: DISPLAY IO-ERR-MSG UPON CNSL. DISPLAY USER-MSG. SPECIAL-NAMES. SYSTEM-CONSOLE IS CNSL.
  • 99. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master DIVIDE Statement • Divide one numeric data item into or by one or more others, and sets the values of data items equal to the quotient and remainder Coding Example: DIVIDE WS-HOURS BY 24 GIVING WS-DAYS REMAINDER WS-REMAINDER-HOURS. Procedure Division
  • 100. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master EVALUATE Statement • Provide a shorthand notation for a series of nested IF statements Procedure Division EVALUATE MENU-INPUT WHEN ”0" PERFORM INIT-PROC WHEN "1" THRU "9" PERFORM PROCESS-PROC WHEN "R" PERFORM READ-PARMS WHEN "X" PERFORM CLEANUP-PROC WHEN OTHER PERFORM ERROR-PROC END-EVALUATE.
  • 101. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master EXIT Statement • Provide a common end point for a series of paragraphs Coding Example: 200-PROCESS. IF PROJECT-FOUND = “Y" PERFORM 250-PARA1 ELSE PERFORM 260-PARA2 END-IF. 200-EXIT. EXIT. Procedure Division
  • 102. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master EXIT PROGRAM Statement • Specify the end of a called program and returns control to the calling program • When there is no next executable statement in a called program, an implicit EXIT PROGRAM statement is executed Procedure Division Coding Example: END-OF-JOB. IF NO-PROJ-ERROR THEN CLOSE PROJECT. IF NO-DISPLAY-ERROR THEN CLOSE DISPLAY-FILE. EOJ-EXIT. EXIT PROGRAM. STOP RUN.
  • 103. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master GOBACK Statement • Function like the EXIT PROGRAM statement when it is coded as part of a program that is a subprogram in a COBOL run unit, and like the STOP RUN statement when coded in a program that is a main program in a COBOL run unit • Specify the logical end of a program Procedure Division
  • 104. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: PROCEDURE DIVISION USING LINK-PARMS. 100-MAIN. IF PROJECT-FOUND = “Y" PERFORM 150-PARA1 ELSE PERFORM 250-PARA2 END-IF. GOBACK. 100-EXIT. EXIT. Procedure Division
  • 105. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master GO TO Statement • Transfer control from one part of the Procedure Division to another • Three types of GO TO statements: 1. Unconditional 2. Conditional 3. Altered (Obsolete) Procedure Division Coding Example: IF PROJECT1 NOT = PROJECT2 THEN GO TO 220-READ-NEXT-PROJECT END-IF
  • 106. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master IF Statement • Evaluate a condition and provides for alternative actions in the object program, depending on the evaluation Coding Example: IF (MENU-INPUT >= "1") AND (MENU-INPUT <= "9") THEN PERFORM PROCESS-PROC ELSE IF (MENU-INPUT = "R") THEN PERFORM READ-PARMS END-IF END-IF. Procedure Division
  • 107. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master INITIALIZE Statement • Sets selected categories of data fields to predetermined values • Functionally equivalent to one or more MOVE statements Procedure Division Coding Example: INITIALIZE PROJECT1-FIELD1. INITIALIZE PROJECT1.
  • 108. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master INSPECT Statement • Specify that characters in a data item are to be counted (tallied) or replaced or both • Count the occurrence of a specific character (alphabetic, numeric, or special character) in a data item • Fill all or portions of a data item with spaces or zeros • Translate characters from one collating sequence to another Procedure Division
  • 109. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: INSPECT WS-PAGE-IN-ERROR REPLACING LEADING ZEROS BY SPACES. INSPECT PROJECT1-FIELD1 TALLYING WS-SPACE-CNTR FOR ALL “ “. Procedure Division
  • 110. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master MERGE Statement • Combine two or more identically sequenced files (that is, files that have already been sorted according to an identical set of ascending/ descending keys) on one or more keys and makes records available in merged order to an output procedure or output file • May appear anywhere in the Procedure Division except in a Declarative Section Procedure Division
  • 111. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master MOVE Statement • Transfer data from one area of storage to one or more other areas Procedure Division Coding Example: MOVE NUM1 TO NUM2 MOVE "MISSING OR INVALID VALUE" TO WS-ERROR- MESSAGE.
  • 112. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master MULTIPLY Statement • Multiplies numeric items and sets the values of data items equal to the results Procedure Division Coding Example: MULTIPLY NUM1 BY NUM2 GIVING RESULT.
  • 113. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master OPEN Statement • Initiate the processing of files • Vary depending on the type of file: • Sequential files • Indexed files • Relative files • Transaction files Procedure Division
  • 114. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Sequential files • At least one of the phrases, INPUT, OUTPUT, I-O, or EXTEND, must be specified with the OPEN keyword • The INPUT, OUTPUT, I-O, and EXTEND phrases may appear in any order Indexed and Relative Files • At least one of the phrases, INPUT, OUTPUT, or I-O, must be specified with the OPEN keyword. The INPUT, OUTPUT, and I-O phrases may appear in any order Transaction Files • A TRANSACTION file must be opened in the I-O mode Procedure Division
  • 115. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: OPEN I-O FILE1. OPEN INPUT FILE2, FILE3. OPEN OUTPUT FILE4. Procedure Division
  • 116. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master PERFORM Statement • Transfer control explicitly to one or more procedures and implicitly returns control to the next executable statement after execution of the specified procedure(s) or imperative statements is completed • 4 PERFORM statement formats: 1. Basic PERFORM 2. TIMES phrase PERFORM 3. UNTIL phrase PERFORM 4. VARYING phrase PERFORM Procedure Division
  • 117. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: PERFORM 110-INITIALIZATION. PERFORM 300-LOAD-PROJECTS VARYING CNT1 FROM 1 BY 1 UNTIL CNT1 > PROJECT-COUNT END-PERFORM. Procedure Division
  • 118. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master READ Statement • Make a record available to the program • Associated file must be open in INPUT or I-O mode • For sequential access, the READ statement makes the next logical record from a file available to the object program • For random access, the READ statement makes a specified record from a direct-access file available to the object program Procedure Division
  • 119. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: READ PROJECT-FILE INVALID KEY SET INVALID-PROJ TO TRUE END-READ. READ PROJECT-FILE-L NEXT RECORD AT END PERFORM 300-END-OF-FILE-PROCESSING END-READ . READ PROJECT-FILE AT END SET END-OF-FILE TO TRUE END-READ. Procedure Division
  • 120. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master RELEASE Statement • Transfer records from an input/output area to the initial phase of a sorting operation • Can only be used within the range of an input procedure associated with a SORT statement
  • 121. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master RETURN Statement • Transfer records from the final phase of a sort or merge operation to an OUTPUT PROCEDURE • Can be used only within the range of an output procedure associated with a SORT or MERGE statement Procedure Division
  • 122. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master REWRITE Statement • Logically replace an existing record in a direct-access file • Associated direct-access file must be open in I-O mode Procedure Division
  • 123. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master REWRITE Statement for Sequential Files • When the access mode is sequential, the last prior input/output statement executed for this file must be a successfully executed READ statement. When the REWRITE statement is executed, the record retrieved by that READ statement is logically replaced • The INVALID KEY phrase must not be specified for a file with sequential organization • An EXCEPTION/ERROR procedure may be specified Procedure Division
  • 124. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master REWRITE Statement for Indexed Files • When the access mode is sequential, the record to be replaced is specified by the value contained in the prime RECORD KEY. When the REWRITE statement is executed, this value must equal the value of the prime record key data item in the last record read from this file • The INVALID KEY phrase must be specified if an applicable USE AFTER STANDARD EXCEPTION procedure is not specified for the associated file-name Procedure Division
  • 125. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master REWRITE Statement for Relative Files • For relative files in sequential access mode, the INVALID KEY phrase must not be specified • An EXCEPTION/ERROR procedure may be specified • The INVALID KEY phrase must be specified in the REWRITE statement for relative files in the random or dynamic access mode, and for which an appropriate USE AFTER STANDARD EXCEPTION procedure is not specified Procedure Division
  • 126. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master REWRITE Statement for Relative Files • When the access mode is random or dynamic, the record to be replaced is specified in the RELATIVE KEY data item • If the file does not contain the record specified, an invalid key condition exists, and, if specified, the INVALID KEY imperative-statement is executed Procedure Division
  • 127. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: REWRITE PROJECT-RCD INVALID KEY CONTINUE END-REWRITE. REWRITE SUBFILE PROJECT-RCD FROM WS-LIST1SFL-O FORMAT IS "LIST1SFL" INDICATORS ARE WS-INDICATOR-TABLE INVALID KEY CONTINUE END-REWRITE. Procedure Division
  • 128. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ROLLBACK Statement • Provide a way to cancel one or more changes to data- base records when the changes should not remain permanent • Any changes made to files under commitment control since the last commitment boundary are removed from the database • A commitment boundary is the previous occurrence of a ROLLBACK or COMMIT statement • If no COMMIT or ROLLBACK has been issued, the commitment boundary is the first OPEN of a file under commitment control Procedure Division
  • 129. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master ROLLBACK Statement • Removal of changes takes place for all files under commitment control in the job, and not just for files under commitment control in the COBOL program that issues the ROLLBACK • All record locks held by the job for files under commitment control are released and the records become available to other jobs • Has no effect on files not under commitment control • If a ROLLBACK is executed and there are no files under commitment control, the ROLLBACK is ignored • A ROLLBACK, when executed, leaves files in the same open or closed state as before execution Procedure Division
  • 130. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SEARCH Statement • Search a table for an element that satisfies the specified condition, and adjusts the associated index to indicate that element Coding Example: SEARCH PROJECT-TABLE AT END DISPLAY "TABLE OVERFLOW" SEARCH PROJECT-TABLE VARYING PROJECT-TABLE-INDEX Procedure Division
  • 131. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SET Statement • Establish reference points for table handling operations by doing one of the following: 1. Placing values associated with table elements into indexes associated with index-names 2. Incrementing or decrementing an occurrence number 3. Setting the status of an external switch to ON or OFF 4. Moving data to condition names to make conditions true 5. Setting addresses of pointer data items Procedure Division
  • 132. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: SET PARM-ERROR-FOUND TO TRUE. READ PROJECT-RECORD AT END SET NO-MORE-RECORDS TO TRUE END-READ. Procedure Division
  • 133. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SORT Statement • Accept records from one or more files, sorts them according to the specified key(s), and makes the sorted records available either through an OUTPUT PROCEDURE or in an output file Procedure Division
  • 134. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master START Statement • Provide a means of positioning within an indexed or relative file for subsequent sequential record retrieval • This positioning is achieved by comparing the key values of records in the file with the value you place in the RECORD KEY portion of a file’s record area (for an indexed file), or in the RELATIVE KEY data item (for a relative file) prior to execution of the START statement Procedure Division
  • 135. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: START PROJECT-FILE KEY IS NOT LESS THAN EXTERNALLY-DESCRIBED-KEY INVALID KEY SET NO-MORE-RECORDS TO TRUE END-START. Procedure Division
  • 136. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master STOP Statement • Halts execution of the object program either permanently or temporarily Procedure Division STRING Statement • String together the partial or complete contents of two or more data items or literals into one single data item • One STRING statement can be written instead of a series of MOVE statements
  • 137. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: STRING LASTNAME DELIMITED BY " " "," DELIMITED BY SIZE FIRSTNAME DELIMITED BY SIZE INTO USERNAME. STRING MM, "/", DD, "/", YY DELIMITED BY SIZE INTO CURR-DATE. Procedure Division
  • 138. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master SUBTRACT Statement • Subtract one numeric item, or the sum of two or more numeric items, from one or more numeric items, and stores the result Procedure Division Coding Example: SUBTRACT 1 FROM NUM1 SUBTRACT 1 FROM NUM1 GIVING RESULT.
  • 139. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master UNSTRING Statement • Cause contiguous data in a sending field to be separated and placed into multiple receiving fields • One UNSTRING statement can be written instead of a series of MOVE statements Procedure Division Coding Example: UNSTRING NAME INTO NAME1 NAME2 NAME3. 01 NAME PIC X(60).
  • 140. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master WRITE Statement • Release a logical record for an output or input/output file • When the WRITE statement is executed • the associated indexed or relative file must be open in OUTPUT, I-O, or EXTEND mode • the associated sequential file must be open in OUTPUT or EXTEND mode Procedure Division
  • 141. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Coding Example: WRITE ERROR-LINE FROM ERROR-REPORT-LINE AFTER ADVANCING 2 LINES END-WRITE. WRITE PROJECT-RECORD END-WRITE. WRITE PROJECT-RECORD FORMAT IS "LIST1CMD" INDICATORS ARE WS-INDICATOR-TABLE INVALID KEY CONTINUE END-WRITE. Procedure Division
  • 142. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Language Element COBOL/400 Limit • Data Division • Length of: • Working-Storage Section group item 3 000 000 bytes • Linkage Section group item 3 000 000 bytes • Elementary item 3 000 000 bytes • Procedure Division • Number of: • GO TO proc-name 255 • IF nesting levels 30 • CALL parameters 30 • SORT-MERGE input files 31 • SORT-MERGE keys 30 Procedure Division
  • 143. Ingeniero Giovanny Guillen Bustamante Especialista Certificado IBM i – PMP – Scrum Master Language Element COBOL/400 Limit • General • Number of Files 99 • Number of characters to identify: • Library-name 10 • Program-name 10 • Text-name 10 • Environment Division • Number of: • SELECT file-names 99 Procedure Division
  • 144. Ingeniero Giovanny Guillen Bustamante PMP Certified IBM i Certified Specialist E-mail: giovanny_guillen_b@Hotmail.com Gracias