AS-400 All in One
AS-400 All in One
AS-400 All in One
Operating System/400
The Integrated Operating System: OS/400
Javas Integration into the AS/400 System
Object Orientation
The AS/400 database, named DB2/400, is a relational database. It is one of the few
systems that provides an integrated database that is part of the operating system. There is no
need to purchase, install, and maintain a separate database. Some advantages of an integrated
database are standardization of data definitions and structures, lower initial and maintenance
costs, automatic data management and processing, and improved productivity.
The database model of DB2/400 is relational. However, unlike other relational database
management systems, which owe their structure to a collection of tables and views, DB2/400
masks the terms commonly used in other relational databases (i.e., tables and views) and, instead,
uses the terms of physical files and logical files to accommodate the programming requirements of
the system. Despite the difference in the terminology, DB2/400 is fully relational. It embodies the
structure and functions of a relational database management system.
On most traditional systems, programs are tied very closely to the way the data are defined and
stored on the system. Record layouts of the files (i.e., record and field specifications) are defined
in the programs that process the files. When file layouts are changed, such as by adding new
fields to the file, all the programs that use the file must be changed and recompiled.
The AS/400 database management system, on the other hand, separates data definitions from
programs by offering externally described files in addition to the traditional program described files.
An externally described file is defined by a data definition that exists outside the programs. Data
Description Specifications (DDS) are used for describing files externally. There are several
AS/400 storage management implements a virtual storage scheme through an advanced structure
called single-level storage. The term virtual storage refers to a technique for managing a limited
amount of main memory and a much larger amount of lower-speed disk storage in such a way that
the distinction is largely transparent to users.
On the AS/400, all disk storage is regarded by the operating system as virtual memory.
No distinction is made between disk storage and main memory. All storage appears to be one
homogeneous sea of main memory. Unlike most traditional systems that utilize virtual storage, the
AS/400 creates and maintains only one address space for its objects. Other virtual storage
implementations must create and maintain separate address spaces and often treat programs
different than they treat data. The simplicity of single-level storage results in a consistent and more
complete virtual storage system than most other systems.
On the AS/400, main memory is called main storage. Disk storage is called auxiliary storage. You may
also hear disk storage referred to as DASD (direct access storage device).
Many other computer systems require you to take responsibility for how information is stored on disks.
When you create a new file, you must tell the system where to put the file and how big to make it. You
must balance files across different disk units to provide good system performance. If you discover later
that a file needs to be larger, you need to copy it to a location on disk that has enough space for the
new, larger file. You may need to move other files to maintain system performance.
The AS/400 system takes responsibility for managing the information in auxiliary storage. When you
create a file, you estimate how many records it should have. The system places the file in the best
location for good performance. In fact, it may spread the data in the file across multiple disk units.
When you add more records to the file, the system assigns additional space on one or more disk units.
The system uses a function that is called virtual storage to create a logical picture of how the data
looks. This logical picture is similar to the way we think of the data. In virtual storage, all of the
records that are in a file are together (contiguous), even though they may be physically spread across
multiple disk units in auxiliary storage. The virtual storage function also keeps track of where the most
current copy of any piece of information is-in main storage or in auxiliary storage.
Single-level storage is the unique architecture of the AS/400 that allows main storage, auxiliary storage,
and virtual storage to work together accurately and efficiently. With single-level storage, programs and
system users ask for data by name, not by where the data is located. Now lets move one more step up
the technical ladder for a little more information! Kenneth
Common Communications Support (CCS): a set of standards for connecting and communicating
computer systems.
Common Programming Interface (CPI): describes the languages to be used by developers to build
SAA compliance applications.
Common User Access (CUA): a set of screen standards used for interacting between applications
and users.
The following table shows the three major systems covered by SAA:
System Operating System
Mainframe MVS/ESA and VM/ESA
AS/400 OS/400
PC OS/2
The AS/400 fully supports SAA. It ensures horizontal and vertical growth and enhances the
customers investment in application software.
Client/Server Technology
Client/server technology is the single most irresistible movement in the computer industry in recent
years. It represents a new concept and technology that links computers from different platforms. In
a client/server environment, one or more computer systems function as servers that provide
services to their client systems. The services offered by server systems include administration of
data retrieval and update, data processing and computing, and distributed data management.
Client/server computing links the intuitive graphical user interface of client computers with the
processing power and sophisticated database of a server computer. It allows end users from client
systems such as PCs to access data and request services from a server such as the AS/400. With
its many advanced client/server hardware and software features, the AS/400 is very well
positioned in the client/server market segment. See Part 4 for more details about client/server
technology on AS/400.
Groupware is a software that allows an user to work together with a group of other people.
The groupware enables you to:Create database to be used by a group of people working on a
common project. Send e-mail to individuals and groups in an organization. Collect data from
individuals in a group or in an organization. Combine data, spreadsheets, graphics, text, and tables
from different systems and sources. Lotus Notes/Lotus Domino, or simply called Notes and
Domino, arguably, is the most widely used groupware in the industry. Lotus and Domino go hand in
hand, and use computers all connected together in a Client/Server and network environment. The
clients are individual computers (i.e., PCs or workstations) that are connected together by a server
acting as a central nerve center for the Notes network. The Notes server is named Lotus Domino
or simply called Domino. In other words, Lotus Notes is the client product that runs on a variety of
workstations, and Lotus Domino is the server product that runs on a variety of server platform.
Server Domino integrates multiple Notes clients.
Internet is the world-wide network of networks that are connected to each other sharing
information. Intranet is an organizations internet network that uses internet tools within the
organization. World Wide Web, or simply called WWW or Web, is a mesh of interconnected
servers and clients that use the same standard format for creating documents (HTML) and
accessing documents (HTTP).
Internet technology is fundamentally changing the way organizations do business. AS/400
provides internet, intranet, and Web support such as:
TCP/IP (Transmission Control Protocol/Internet Protocol) and LAN (Local Area Network)
networking capabilities.
Internet Connect for AS/400 enables you to put together internet and intranet solutions in an
organization. AS/400 is enabled to be used as a Web server. DB/2 WWW can deliver data to users
over the internet or intranet. The AnyMail server provides an integrated e-mail service between an
AS/400 internet server and Lotus Notes on various client workstations. The IBM Internet Connect
Secure Server (ICSS) for AS/400 supports the Secure Sockets layer (SSL) protocol for securing
World Wide Web communications between an AS/400 server and Web browsers.
In the system area, AS/400e series and advanced series with Internet Connect for AS/400 delivers
the simplicity and ease of use in an internet and/or intranet environment. Firewall for AS/400
provides security and data integrity in the internet environment where AS/400 is the internet server.
It controls the access and flow of information between a secure network and an unsecured
network.
SAP Enabling
SAP AG, is the third largest software company worldwide. It is the worlds leading
provider of client/server business applications. Its suite of client/server data processing products,
called SAP R/3, is based on the concept of combining all the business activities and technical
processes that are used within an organization into a single, integrated software. SAP R/3 has
been installed in most of the Fortune 500 companies, and has become a software standard in
many industries.
SAP AG and IBM AS/400 Division have been working together to provide business reengineering
and the ultimate business management solution for organizations. Both companies
are worldwide leaders in their respective fields. AS/400 is the leading commercial business system
with over 275,000 systems installed in over 140 countries. SAP AG is the leading provider of
integrated business applications in more than 4300 companies and is represented in 41 countries.
The strengths of both AS/400 and SAP R/3 system complement each other to provide a complete
business solution. The SAP R/3 System on AS/400 provides user interface (presentation clients),
application logic (application server), and data management (database server). It allows SAP R/3
to port on AS/400, incorporating AS/400 existing function into R/3.
All AS/400 system models running on AS/400 operating system, OS/400, are Year 2000 ready.
From its cutting-edgy applications to its advanced technology, AS/400 provides year 2000
interfaces that are fully integrated and tested.
For any organization that uses application software, such as Accounts Payable, Inventory Control,
and Cost Accounting, chances are that these software rely on accurate date calculation. The
organization must ensure that its hardware, operating system, and applications are Year 2000
ready. If that organization currently runs on AS/400, it is ready for Year 2000 on all counts.
AS/400 operating system incorporates flexible ways to handle dates and use dates in calculation.
In addition, AS/400 and IBM business partners provides a number of tools and application
software designed to assist organizations with their Year 2000 transformations. These products
provide AS/400 users and developers with a standard set of system calls for date retrieval, date
arithmetic, date format conversions and other routines. An impact analysis tool and a conversion
tool, SEARCH2000 and BYPASS2000, developed by an IBM business partner, assist in finding
dates, identifying their formats, and converting old date formats to new formats.
Operating System/400
An operating system is a set of software routines that directs the operation of the computer. It
manages the hardware resources and executes tasks under the control of software or interactive
commands. All AS/400 models are supported by a single, integrated operating system called
Operating System/400 (OS/400).
OS/400 is a preloaded, integrated operating system for all models of the AS/400. The
single, integrated system approach makes it easy for AS/400 users to upgrade their models within
the system unit and to standardize their software development. For users who have a System/36
or System/38, OS/400 provides migration capabilities to the AS/400.
In addition, OS/400 uses the blueprints and principles of Systems Application Architecture (SAA).
OS/400 enables integrated network computing, object-oriented portability, and Web technology to
open gateway for Java functionality. The latest release of AS/400 operating system provides an
integrated Java compliant implementation that includes Virtual Machine (JVM). JVM is
implemented under the machine interface (MI), the AS/400 Developer Kit for Java, and the AS/400
Toolbox for Java.
Java has become predominant programming language for Web development and network
The AS/400 Advanced Server Models are the core of IBMs new client/server hardware solution.
These models are specifically designed and built for client/server computing. They use different
processors and microcode designed to meet the special requirements of the client/server
environment.
The AS/400 system units have many unique traits. Some of the more important traits include All
AS/400 models use the same operating system, OS/400. All AS/400 models use the same
database, DB2/400.
All AS/400 models use the same basic utilities, including PDM, SEU, DFU, and SDA.
With the programming development manager (PDM), you can perform the following functions:
PDM also gives you access to other objects on the AS/400* system so that you can use the
following utilities in the Application Development ToolSet/400 licensed
program:
library
is a special type of object (object of type *LIB) that is used to group related objects. A library,
therefore, is a directory to a group of objects. There are only two types of libraries: *PROD
(Production) and *TEST (Test). Every AS/400 system has a system library named QSYS that is
provided in the
OS/400* operating system to contain system-oriented objects. QSYS is a large library that points
to all the system-oriented objects.
File
is an object of type *FILE that has an attribute that describes the type of the file. For example, a
source physical file has an attribute of PF-SRC, a data file has an attribute of PF-DTA, and a
printer file has an attribute of PRTF. Physical files and logical files both contain members.
Member
is a subset of records in a physical file (PF-SRC or PF-DTA). Each member conforms to the
characteristics of the file. You can define the type of a member, or select a type used with PDM
commands.
You can start the programming development manager (PDM) from the AS/400 Main Menu or by
typing the STRPDM command on the command line. You can also start PDM by typing any of the
following commands on the command line:
. WRKLIBPDM
. WRKOBJPDM
. WRKMBRPDM
2. Select option 2 (Programming Development Manager (PDM)), and press Enter. The AS/400
Programming Development Manager (PDM) menu appears. You can select one of the options
from this menu to work with libraries, objects, members, or user-defined options.
To start PDM by using the STRPDM command, type STRPDM on any command line and press
Enter. The AS/400 Programming Development Manager (PDM) menu is displayed.
To start PDM and work with the list of libraries from your previous PDM session, type
WRKLIBPDM on the command line without specifying any parameters, and press Enter. The
Work with Libraries Using PDM display appears. To display a specific list of libraries, specify
parameters after the WRKLIBPDM command. For example, to display a list of all libraries starting
with BA, type the following command on any command line, and
press Enter:WRKLIBPDM LIB(BA\) The Work with Libraries Using PDM display appears.
To start PDM and work with all the objects in a library from your previous PDM session, type
WRKOBJPDM on the command line without specifying any parameters, and press Enter. The
Work with Objects Using PDM display appears. To display a specific object in a library, specify
parameters after the WRKOBJPDM command. For example, for a list of all the CLP programs in
the ATEST library that start with CHG, type the following command on any command line, and
press Enter:
WRKOBJPDM LIB(ATEST) OBJ(CHG\) OBJTYPE(\PGM) OBJATR(CLP)
The Work with Objects Using PDM display appears.
To start PDM and work with all the members in the file and library from your previous PDM
session, type WRKMBRPDM on the command line without specifying any parameters, and press
Enter. The Work with Members Using PDM display appears. To work with a specific list of
members, specify parameters after the WRKMBRPDM command. For example, for a list of all
members in the CMDSRC
file in the ATEST library with a type of CMD that start with C, type the following command on any
command line, and press Enter:
WRKMBRPDM FILE(ATEST/CMDSRC) MBR(C\) MBRTYPE(CMD)
The Work with Members Using PDM display appears.
You can perform the following tasks when working with libraries:
View a library list
View a list of libraries
Work with an alphabetical list of libraries
Create a library
A library list is an ordered list of library names. It identifies the libraries that are searched and the
order of the search. A list of libraries, however, is an alphabetic list of all the libraries, or a subset
list of all the libraries, on the system.
1. Select option 1 (Work with libraries) from the AS/400 Programming Development Manager
(PDM) menu, and press Enter. The Specify Libraries to Work With display appears.
2. Type one of the following values in the Library prompt, and press Enter:*LIBLDisplays a list of
all libraries in your library list
*USRLIBL Displays a list of all libraries in the user portion of your library list
Note: You can also specify these values for the LIB parameter of the WRKLIBPDM command.
3. Press F3 (Exit) to return to the AS/400 Programming Development Manager (PDM) menu. You
can add libraries to, or remove them from, the library list. When you remove a library from the
library list, you are only taking the library off the library list temporarily. The library is not deleted
from the system. You can also change the search order by changing the position of libraries in
your library list.
1. Select option 1 (Work with libraries) from the AS/400 Programming Development Manager
(PDM) menu, and press Enter. The Specify Libraries to Work With display appears.
2. Type one of the following values in the Library prompt, and press Enter.
*ALL
Displays a list of all libraries in the system.
*ALLUSR
Displays a list of all nonsystem libraries, including a list of all user-defined
libraries.
ABC*
Displays a list of all items that begin with the characters ABC for example, ABC, ABCD, or
ABCTEST.
*ABC
Displays a list of all items ending with the characters ABC, for example, ABC, DABC, or
TESTABC.
*B*
Displays a list of all items that have the character B anywhere in the name, for example, B,
BALL, or ABCD.
A*C
Displays a list of all items that begin with the character A and end with the character C, for
example, AC, ABC, or AZZZC.
a*
Displays a list of all items within quotation marks that start with the character a, for example, a,
aB, or aD.
**ALL
Displays a list of all items ending with ALL, for example, ALL, BALL, or TESTALL. The double
asterisk is needed in this case because ALL is defined as the value to display a list of all libraries.
Note: You can also specify these values for the LIB parameter of the WRKLIBPDM command.
3. Press F3 (Exit) to return to the AS/400 Programming Development Manager
(PDM) menu.
Creating a Library
You can create a library if you are working with a list of libraries (list type *ALL or*ALLUSR). To
create a library called ANEXAMP:
CRTLIB press F4
Type ANEXAMP in the Library prompt, \PROD or \TEST in the Library type prompt,and a
description of the library in the Text text description prompt, and press Enter. This example
creates library ANEXAMP.
A message at the bottom of the display indicates that the library was created.
Deleting a Library
Using PDM, you can delete libraries you no longer need by selecting the Delete option.
To delete library ANEXAMP and library AOLD:
Type DLTLIB and enter the lib name to delete
Renaming a Library
When using PDM, you can display the following information about a library:
. Library size
. Time and date the library was created
. Time and date the library was changed
. Time and date the library was last saved
. Time and date the library was last restored
QSYS (*LIB)
[special library]
|
| contains
|
Library (*LIB)
|
| contains
|
.------------------+----^-----------------.--------.
| | | |
Programs (*PGM) Out queues (*OUTQ) Files (*FILE) Other
[Executable] | | objects
| contains |
Spooled Files |
[Output intended for Printer] |
|
.----------------^--.
| |
DB2/400 Chapter 3
Database files
A database file is one of several types of the system object type *FILE kept in the system that
contains descriptions of how input data is to be presented to a program from internal storage and
how output data is to be presented to internal storage from a program. There are several types of
database files:
Source file
Physical file
Logical file
Source file
A source file contains uncompilable programming code and input data needed to create some
types of objects. A source file can contain source statements for such items as high-level
language programs and data description specifications. A source file can be a source physical
file, diskette file, tape file, or inline data file.
A physical file is a database file that stores application data. It contains a description of how data
is to be presented to or received from a program and how data is actually stored in the database.
A physical file consists of fixed-length records that can have variable-length fields. Physical files
contain one record format and one or more members. From the perspective of the SQL interface,
physical files are identical to tables.
Logical file
A logical file is a database file that logically represents one or more physical files. It contains a
description of how data is to be presented to or received from a program. This type of database
file contains no data, but it defines record formats for one or more physical files. Logical files let
users access data in a sequence and format that is different from the physical files they
represent. From the perspective of the SQL interface, logical files are identical to views and
indexes.
For a physical file, use this position to specify the data type of the field within the database.
Specify data type in a logical file only to override or change the data type of the corresponding
field in the physical file on which this logical file is based. If you leave this position blank, the field
you are defining has the same data type as the corresponding field in the physical file(s) on
which the logical file(s) is based.
Entry Meaning
P Packed decimal
S Zoned decimal
B Binary
F Floating-point
A Character
H Hexadecimal
L Date
T Time
Z Time stamp
Floating-point
(single precision) 1 through 9 digits
Floating-point
(double precision) 1 through 17 digits
Date 6, 8, or 10 characters
Time 8 characters
The length for fields with data type L (date), T (time), or Z (timestamp) is determined by the
system. You should not enter a field length in positions 30 through 34. The field length for date
and time includes the separator. A timestamp has a fixed format that has the following form:
YYYY-MM-DD-hh.mm.ss.uuuuuu
Type in a maximum of 9 digits for single precision and 17 digits for double precision. The OS/400
program supports a floating-point accuracy of 7 digits for single precision and 15 digits for double
precision. The total number of bytes occupied by all the fields in a record must not exceed 32 766
(in storage). The system determines the number of bytes actually occupied in storage as follows:
Data Type Bytes Occupied in Storage
Binary
1 through 4 digits 2 bytes
5 through 9 digits 4 bytes
10 through 18 digits 8 bytes
Floating-point 4 bytes
(single precision)
The following keywords are valid for both physical and logical files (except where noted):
ABSVAL FLTPCN
ALIAS FORMAT
ALL (logical files only) LIFO
ALWNULL (physical files only) NOALTSEQ
CHECK RANGE
CHKMSGID REF (physical files only)
CMP REFFLD (physical files only)
COLHDG REFSHIFT
COMP RENAME (logical files only)
CONCAT (logical files only) SIGNED
DATFMT SST (logical files only)
DATSEP TEXT
DESCEND TIMFMT
DFT (physical files only) TIMSEP
DIGIT TRNTBL (logical files only)
DYNSLT (logical files only) UNIQUE
EDTCDE UNSIGNED
EDTWRD VALUES
FCFO VARLEN
FIFO ZONE
The following keywords are valid only for simple and multiple format logical files:
PFILE
REFACCPTH
The following keywords are valid only for join logical files:
JDFTVAL JOIN
JDUPSEQ JREF
JFILE
JFLD
When you use DDS to describe a source file (usually created without DDS, using the
CRTSRCPF command or when a logical file is based on a physical file to be used as a source
file, you cannot use the following keywords:
ABSVAL NOALTSEQ
ALTSEQ SIGNED
DESCEND UNIQUE
FCFO VARLEN
FIFO ZONE
LIFO
A UNIQUE
A R ST@REC
A ST@SID 5A
A ST@NAM 20A
A ST@GEN 1A
A ST@DOB 8P 0
A ST@AD1 15A
A ST@AD2 15A
A ST@AD3 15A
A ST@PHO 12P 0
A ST@COU 15A
A K ST@SID
Use this field-level keyword to specify column headings used as a label for this field by text
management, the query utility, the data file utility (DFU), and the screen design aid (SDA).
The format of the keyword is:
COLHDG(line-1 [line-2 [line-3]])
A maximum of three lines of 20 characters each is allowed. Each line of the column heading
must be enclosed in apostrophes. Use double apostrophes ( ) to specify apostrophes within
column headings. Use one or more blanks to separate the first column heading line from the
second and the second from the third. For a physical file, if you do not specify COLHDG and it is
not retrieved from a referenced field, the field name is used. If you do not specify COLHDG for a
logical file, the column heading from the physical file is used, except when the field is a
concatenation of fields; in this case, the default is the field name. If you specify COLHDG but do
not specify TEXT, 50 positions of column heading information are used as text. For example,
COLHDG(Order Date) is equivalent to TEXT(Order Date).
Example:
The following example shows how to specify the COLHDG keyword for a physical file.
Decimal positions or data type must be specified for ORDDAT since Order Date is a numeric
field (denoted by NNNNN below). The following display illustrates how the column headings can
appear when running text management,query, DFU, or SDA.
Customer
Order City
Date Customers Name Field
NNNNN XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
Use this field-level keyword to specify the format of a date field. This keyword is valid only for
date fields (data type L) or for logical file zoned fields (data type S), packed fields (data type P),
or character fields (data type A) whose corresponding physical file fields are date fields (data
type L).
Example:
The following example shows how to specify the DATFMT keyword.
00010 A
00020 A R RECORD
00030 A DATFLD1 L DATFMT(*JUL)
00040 A DATFLD2 L DATFMT(*EUR)
The DATSEP keyword overrides the job attribute. It does not change the system default.
Example:
The following example shows how to specify the DATSEP keyword.
00010 A
00020 A R RECORD1
00030 A DATFLD2 L DATFMT(*DMY) DATSEP(-)
00040 A DATFLD4 L DATSEP( )
Use this key field-level keyword to specify that the values of this character, hexadecimal, or
numeric key field are retrieved in descending sequence. The default is ascending sequence.
See SIGNED (Signed) keyword for physical and logical files on page 69 for an example of
data sorted using the DESCEND keyword.
This keyword has no parameters.
Example:
The following example shows how to specify the DESCEND keyword for a logical file.
00010 A K ITEM
00020 A K BALDUE DESCEND
When you use the Initialize Physical File Member (INZPFM) command for a member in
this file.
When you use the Copy File (CPYF) command with FMTOPT(*MAP) specified and a
field in the to-file is not in the from-file.
This keyword does not affect the physical file on input operations.
Example:
The following example shows how to specify the DFT keyword.
00010 A R RECORD1
00020 A CHARFLD1 20A DFT(Sample field)
00030 A CHARFLD2 5A DFT(XD985955185)
00040 A HEXFLD1 3H DFT(ABC)
00050 A HEXFLD2 3H DFT(XC1C2C3)
00060 A NUMFLD1 5S 0 DFT(99999)
00070 A NUMFLD2 5S 2 DFT(999.99)
00080 A NUMFLD3 5S 2 DFT(999)
00090 A NUMFLD4 5S 2 DFT(*NULL)
00100 A ALWNULL
00110 A NUMFLD5 5S 2 DFT(999.99)
00120 A ALWNULL
00130 A DATFLD1 L DATFMT(*MDY) DATSEP(-)
00140 A DFT(12-31-91)
00150 A TIMFLD1 T DFT(11.15.00)
Use this field-level keyword to specify an alternative name for a field. When the program is
compiled, the alternative name is brought into the program instead of the DDS field name.
Use this select/omit field-level keyword to specify the action to be taken after all other select/omit
specifications have been processed for this logical file. Specify ALL with S in position 17 to direct
the OS/400 program to select any records that do not meet any of the other select/omit rules.
Specify O in position 17 to direct the OS/400 program to omit any records that do not meet any
of the other select/omit rules. If specified, ALL must follow the other select/omit keywords. You
cannot specify a field name with the ALL keyword.
If you do not specify the ALL keyword, the default action taken is the opposite of the last
select/omit
specification you made for the file. If the last specification was a select, the default is to omit all.
If the last
specification was an omit, the default is to select all.
Example:
Use this field-level keyword to define this field to allow the null value.
When you specify the ALWNULL keyword, the maximum length you can specify in positions 30
to 34 is 32765 bytes (32 739 if the field is also variable length). For physical files, when you
specify the DATFMT keyword with values of *JOB, *MDY, *DMY, *YMD, or *JUL and the field
allows null value, you must specify a valid date on the DFT keyword for this field.
Example:
00010 A R RECORD1
00020A FIELD1 75A ALWNULL
00030A FIELD2 100A
00040A FIELD3 L ALWNULL
00050A DATFMT(*MDY)
00060A DFT(12/25/93)
A
FIELD1 is defined to allow the null value. The default value of FIELD1 is the null value. FIELD2
is defined to not allow the null value. The default value of FIELD2 is blanks.
CHECK does not affect the physical or logical file being defined. When you define an input-
capable field in a display file, refer to the field you are now defining by specifying R in position 29
and using the REF or REFFLD keyword. At display file creation, the OS/400 program copies the
CHECK keyword and other field attributes from the field in the physical or logical file into the field
in the display file. You can override the CHECK keyword (as well as all other validity-checking
keywords and the CHKMSGID keyword) by specifying any validity checking keyword for the field
in the display file. See the Reference for display files topic for details.
The rules for specifying this keyword in a physical or logical file are similar to those for a display
file.
However, only the following codes are allowed in physical or logical files:
Code Meaning
AB Allow blank
ME Mandatory enter
MF Mandatory fill
M10 IBM* Modulus 10 self-check algorithm
M10F IBM Modulus 10 self-check algorithm
M11 IBM Modulus 11 self-check algorithm
M11F IBM Modulus 11 self-check algorithm
VN Validate name
VNE Validate name extended
At the select/omit-field level, the format of the keyword is: COMP(relational-operator field-name)
Specify the value parameter at either the field level or the select/omit field level. Specify the field
name parameter only at the select/omit field level.
Example 1:
The following example shows how to specify the COMP keyword for character and numeric
strings.
1 COMP is specified for FIELDA and FIELDB as a validity checking keyword for display files that
refer to FIELDA and FIELDB.
2 COMP is specified as a select/omit keyword for FIELDC, FIELDA, FIELDB, and FIELDE.
Records
from the physical file PF1 are retrieved through this logical file record format depending on the
following comparisons:
FIELDC: Records are selected when FIELDC equals FIELDD.
FIELDA: Records not meeting FIELDC test are selected only when FIELDA is not equal
to zero.
Use this record-level keyword to identify the physical file(s) containing the data to be accessed
through the record format you are now defining.
Example 1:
00010 A R LOGRCD1 PFILE(PF1)
Example 2:
00010 A R LOGRCD2 PFILE(PF1 PF2)
A:
In this example, LOGRCD2 must use fields common to PF1, and PF2, and LOGRCD3 must
use fields common to PF1, PF2, and PF3.
Example 3:
00010 A R LOGRCD4 PFILE(PF1)
A:
Specify this keyword at the field level, the select- or omit-field level, or both.
The format of the keyword is:
RANGE(low-value high-value)
Example 1:
The following example shows how to specify character and numeric strings for the RANGE
keyword.
Use this field-level keyword when you want to combine two or more fields from the physical file
record format into one field in the logical file record format you are defining. The name of this
concatenated field must appear in positions 19 through 28.
Examples:
The following examples show how to specify the CONCAT keyword.
Example 1:
MTH, DAY, and YEAR are fields in the physical file that are concatenated into one field DATE in
the logical file, as shown in the following example.
Example 2:
In the following example, if the program changes DATE from 01 03 81 to 02 05 81, the value
placed in the physical record does not change because the fields specified last are MTH (value
01), DAY (value 03), and YEAR (value 81). However, if MTH, DAY, and YEAR are changed to
new values, the value of DATE in the physical record also changes.
Physical and Logical Files, CONCAT 40 OS/400 DDS Reference: Physical and Logical Files
Example 4:
In the following example, if the fields from PF1 are:
FIXED1 is a fixed length field.
FIXED2 is a fixed length field.
VARLEN1 is a variable length field.
Use this join-level keyword to identify which pair of files are joined by the join specification in
which you specify this keyword.
On each JFILE keyword, the from file must occur before the to file.
If you specify numbers, they correspond to the files specified on the JFILE keyword. The
following are the valid values:
Use this record-level keyword to identify the physical files containing the data to be accessed
through the join logical file you are defining.
This keyword is similar to the PFILE keyword except it identifies this file as a join logical file.
The JFILE keyword is not allowed with the PFILE keyword. The JFILE keyword is required at
the record level in a join logical file. The JFILE keyword requires a minimum of two physical file
names. You can specify the same file name more than once. The first file is called the primary
file, which is the file from which the join will begin. All other files are called secondary files. Up
to 31 secondary files can be specified (32 total files on the JFILE keyword).
Note: If the names in the physical file are not unique, you must specify relative file numbers.
Use this join-level keyword to identify the from and to fields whose values are used to join
physical files in a join logical file. These fields are both referred to as join fields.
The join fields must correspond to fields in the physical files identified on the JOIN keyword for
this join specification. The name you specify on the JFLD keyword must be the same as the
name specified in the physical file unless it was renamed in the join logical file. If you do not
specify a JOIN keyword, then the JFILE keyword is used. This keyword is valid only for join
logical files. At least one JFLD keyword is required for each join specification. A join
specification is identified by J in position 17. Since at least one join specification is required in a
join logical file, you must have at least one JFLD keyword specified in a join logical file.
Examples:
The following examples show how to specify the JFILE keyword.
Example 1:
00010 A R JREC JFILE(PF1 PF2)
00020 A J JOIN(PF1 PF2)
00030 A JFLD(NAME1 NAME2)
Example 2:
In the join logical file, PF1 is the primary file and PF2 is the secondary file.
Example 3:
00010 A R JREC JFILE(PF1 PF2)
00020 A J JOIN(PF1 PF2)
00030 A JFLD(NAME1 NAME2)
In the join logical file, the JFLD keywords specify that NAME1 in physical file PF1 is used to join
to NAME2 in physical file PF2.
Example 4:
00010 A R JREC JFILE(PF1 PF2)
00020 A J JOIN(PF1 PF2)
00030 A JFLD(NAME1 NAME2)
00040 A JFLD(ADDR1 ADDR2)
Example 5:
00010 A R RECORD1 JFILE(PFA PFB PFC)
00020 A J JOIN(PFA PFB)
00030 A JFLD(NAME1 NAME2)
00040 A J JOIN(PFA PFC)
00050 A JFLD(NAME1 NAME3)
00060 A NAME1
A
In this example, PFA is joined to PFB and also to PFC.
Example 6:
The following example shows how to specify JOIN using relative file numbers.
Example 7:
The join logical file in this example is based on four physical files. The VENDORS file, which is
specified first on the JFILE keyword, is the primary file and has relative file number 1. The
PARTS, PARTWARE, and WAREHOUSE files, which are secondary files, have relative file
numbers 2, 3, and 4, respectively. Notice the pattern of numbers specified on the JOIN
keywords:
1 The first parameter value on the first JOIN keyword (the first from file) must be the primary
file.
2 The second parameter values specified on the JOIN keywords (to files) must reflect the same
order as the secondary files on the JFILE keyword. If file names were specified instead of
relative
file numbers, they would have to be specified in the following order:
Use this field-level keyword in join logical files for fields whose names are specified in more
than one
physical file. This keyword identifies which physical file contains the field.
Join logical files are based on two or more physical files (up to 32). Field names specified in the
record
format in a join logical file must uniquely identify only one field from the physical files on which
the join logical file is based. For example, if the join logical file is based on two physical files,
and each physical file has the field named NAME, you must specify the JREF keyword to
identify which physical file the field comes from.
Examples:
The following examples show how to specify the JREF keyword.
Example 1:
Use this file-level keyword to indicate that the selection and omission tests specified in the file
(using
select/omit specifications) are done at processing time. This keyword specifies dynamic
select/omit rather than access path select/omit.
You must use the DYNSLT keyword when you want to select or omit fields and any of the
following are true:
The logical file has arrival sequence (no key fields are specified). See example 1 below.
The logical file is a join logical file with the JDFTVAL keyword specified.
The logical file is a join logical file, select/omit fields come from more than one of the
physical files the
The select/omit fields are on the same select or omit statement. See example 3 below.
The select/omit fields are on a mixture of select and omit statements. See example 4 below.
The select/omit fields are on select statements that are ORed together.
The select/omit fields are on omit statements that are ANDed together.
You cannot specify the DYNSLT keyword with the REFACCPTH keyword.
Examples:
The following examples show how to specify the DYNSLT keyword.
Example 1:
The following example shows how to specify dynamic select with arrival sequence.
00010 A DYNSLT
00020 A R RECORD1 PFILE(PF1)
00030 A FLD1
00040 A FLD2
00050 A S FLD1 COMP(GT 2)
FLD1 FLD2
1 aaaa
2 dddd
3 jjjj
4 bbbb
As your program does input operations, the system tests the first two records according to the
select/omit values, but does not supply them to your program. Your program only sees the last
two records:
FLD1 FLD2
3 jjjj
4 bbbb
Example 2:
The following example shows how to specify dynamic select with keyed sequence access path.
00010 A DYNSLT
00020 A R RECORD1 PFILE(PF1)
00030 A FLD1
00040 A FLD2
00050 A K FLD1
00060 A S FLD2 COMP(GT bbbb)
A
In this example, the DYNSLT keyword is not required. The logical file supplies records to your
program in keyed sequence. Assume that physical file PF1 has the following records:
FLD1 FLD2
1 aaaa
2 dddd
3 jjjj
4 bbbb
When your program requests a record, the system tests the value of FLD2 for that record
according to the select/omit values. Your program only sees the following records:
FLD1 FLD2
2 dddd
3 jjjj
Example 3:
The following example shows how to specify a join logical file with select/omit comparing fields
from two physical files.
00010 A DYNSLT
00020 A R RECORD1 JFILE(PF1 PF2)
00030 A J JFLD(FLD1 FLD3)
00040 A FLD1 JREF(PF1)
00050 A FLD2 JREF(PF1)
00060 A FLD3 JREF(PF2)
00070 A FLD4 JREF(PF2)
00080 A S FLD1 COMP(GT FLD4)
A
FLD1 and FLD2 come from the primary file (PF1), and FLD3 and FLD4 come from the
secondary file
(PF2). The select specification compares FLD1 from the primary file with FLD4 from the
secondary file. Therefore, the DYNSLT keyword is required.
Example 4:
The following example shows how to specify a join logical file with select and omit using fields
from more than one physical file.
00010 A DYNSLT
00020 A R JREC JFILE(PF1 PF2)
00030 A J JOIN(PF1 PF2)
00040 A JFLD(FLD1 FLD2)
00050 A FLD1 JREF(PF1)
00060 A FLD2 JREF(PF1)
00070 A FLD3 JREF(PF2)
00080 A K FLD1
00090 A S FLD1 COMP(GT 0)
00100 A O FLD3 COMP(GT 4)
FLD1 and FLD3 come from different physical files and are specified in a mixture of select and
omit statements. Therefore, the DYNSLT keyword is required.
Use this join-level keyword to specify the order in which records with duplicate join fields are
presented when your program reads a join logical file.
This keyword has no effect on the ordering of unique records. If you do not specify the
keyword, the system does not guarantee the order in which records with duplicate join fields
are presented If more than one JDUPSEQ keyword is specified in one join specification, the
order in which you specify the JDUPSEQ keywords determines the order of presentation of
duplicate records. This is similar to specifying an additional key field, in that it determines the
order in which records with duplicate keys are presented.
Example 1:
The following example shows how to specify the JDUPSEQ keyword.
Example 2:
This example assumes the logical file is based on the same physical files as example 1. There
are three records for Anne in PF2, showing three telephone numbers.
When you specify JDUPSEQ with *DESCEND, the records are returned as follows:
Capabilities of CL:
Limitations
Database manipulations are limited to reading files and only a single file can be opened for I/O
operation
VERB
MODIFIER
OBJECT
PARAMETER
Examples:
1.WRKJOB :Work with job
2.WRKACTJOB :Work with active job
3.WRKUSRJOB :Work with user job
4.CRTRPGPGM :Create RPG Program
5.CRTCBLPGM :Create COBOL program
6.CRTCLPGM :Create Control Language Program
7.CRTLF :Create Logical File
8.CRTPRTF :Create Printer File
9.CRTDSPF :Create Display File
But at the same time you wanted to send messages to users in the Inventory department first
informing them that you will be backing up their library, and the letting them know when ht backup
is completed? You could do this from a command line by typing in a series of CL commands similar
like
But if this were a backup routine performed regularly, typing the required series of CL commands
each time the backup was to run would be tedious and error-prone. A better solution would be to
write a cl program that incorporates all the commands. Then instead of typing the CL commands
like that shown above you would type one command to call your program
To write the CL programs we need Data Types, Operators, Control Structure to control the flow of
the program and functions..
Data Type Means which type of data will be stored in the memory. Here we have 3 types Data
Types
Variable Means it varies the value during the execution of the program, in this environment the length
of the variable is 11
Operator Means it is used to operate two operands in CL we have Arithmetic, Relational and Logical
Operators
Operators
|
----------------------------------------------------------------------
| | | |
Arithmetic Relational Logical String
Control Structures are used to control the flow of the execution of the program
Control Structures
|
----------------------------------------------------------
| | |
Conditional Structure Iterative/Repetitive Structure Unconditional Branching
CL is hampered by its lack of support for standard control structures such as DOWHILE,
DOUNTIL, And CASE. To help compensate for this lack of control structures, the GOTO command
frequently used. The GOTO command causes the program to branch to a statement identified by a
label. This is called unconditional branching statement .
IF COND(User Condition)THEN(Statement)
IF COND(User Condition)THEN(Statement)
ELSE(Statement)
IF (User Condition) +
IF (User Condition) +
IF (User Condition) +
Statement
Nested IF else statement:
IF cond(User Condition) THEN(CL COMMAND) +
ELSE IF(User Condition)CL COMMAND +
ELSE CL COMMAND
DO..ENDDO With IF
LOOP:
Command
IF COND(User Condition) THEN(DO)
CALL PGM(PGM1)
GOTO CMDLBL(LOOP)
ENDDO
What is an Expression?
An expression is a group of symbols used to represent a single value. The group of symbols in the
expression 10+2, for example, can be used to represent the value 12
In CL four types of expressions can be used to represent CL command parameter values.
Arithmetic expressions
Character String Expressions
Logical Expressions
Relational Expression.
Using Arithmetic Expressions In CL, you can use an arithmetic expression in three situations
Within the VALUE parameter of the CHGVAR command
Within the COND parameter of the IF command
Within the MAPFLD parameter of the OPNQRYF command
When more than one operator appears within an arithmetic expression you must be awareof the
order in which the operators will be evaluated. CL follows the algebraic standard order of
operations
Order Operator
Signed decimal values(such as 3 or +&num1)
Multiplication(*) and division(/)
Addition(+) and subtraction(-)
CL does not directly support a binary number data type. The only numeric data type CL supports is
*DEC. But CL does provide a way to extract a number stored in binary format and convert it to a
decimal variable by using %BIN (binary) built-in function as an operand in an arithmetic
expression.
The %BIN function operates on a *CHAR variable, extracting a binary numeric value that can be
used in an arithmetic expression. %BIN can extract either 2 or 4 bytes
Example : (%BIN(&number 1 2) + 16)
CL would evaluate the above expression as follows (1) extract the binary number form the
character variable &number starting at position 1 for a length of 2, then (2) add the extracted value
to the number 16 to produce the derived value of the expression.
If you want to extract the binary equivalent of an entire variable, you don`t need to specify a
starting position or length for the %BIN function.
Example: (%BIN(&NUMBER) + 16)
A relational expression contains two operands that are compared. The derived value of the
expression will be either True(1) or False(0) depending on the result of the comparison.
The operands in a relational expression can be any of the following.
Decimal constants
Decimal variables
Arithmetic expressions
Character constants
Character variables
Character string expressions
Logical constants
Logical variables
Logical expression
Relational Operators
Using Logical Expressions which evaluate the logical relationship between two operands, are very
similar to relational expression. The value of logical expression is evaluated as either True(1) or False
(0).
*AND & The expression is true if both operand 1 & 2 are true
There are few hard and fast rules for structuring entries within a CL source member. CL source
members, when properly structured, contain the following four sections.
The program information section this section is not compulsory, good programming style
dictates that It should be present in every CL source member. This section entirely of comments, to
provide information and documentation about the source member and the program.
The program linkage section marks the beginning of the CL program. It is required, and always
contains only CL command: the PGM(program) command.
The declaration section which defines any variables or files that will be used in a CL program,
follows the program linkage section. All received parameters, as well as any other variables that
will be used in the CL program must be declared in the declarations section.
The procedure section this specifies what procedures and processes the program will perform.
This section contains CL commands that specify what the program will do at execution time
Example:1 Example On Simple CL
PGM
SNDPGMMSG MSG('HELLO THIS IS MY FIRSCT CL PROGRAM')
ENDPGM
PGM
DCL VAR(&NAME) TYPE(*CHAR) LEN(10)
SNDUSRMSG MSG('ENTER U R NAME') MSGRPY(&NAME)
SNDUSRMSG MSG('U R NAME IS :' *CAT &NAME)
ENDPGM
Unlike many high level languages, CL uses the same command (CHGVAR) to move values to any
variables, regardless of their data type you can use the chgvar command in any of these with
equal case
To move a character value to a character type variable
To move a decimal value to a decimal type variable
To move a logical value to logical type variable
In addition you can use the CHGVAR command for data conversion the CHGVAR command can:
Convert numeric value to a character value and store it in a character variable
Convert a character value to a decimal valu and store it in a decimal variable
Using CHGVAR with Decimal variable
The value specified can contain only digits, the decimal point ,and leading sign(+ or -) The value
moved into the receiver variable will be properly aligned at the decimal point, as declared in the
DCL command for the receiver variable. If a decimal point isnot included in the VALUE, the VALUE
is auumed to be an integer with no decimal position. The VALUE contains more decimal position
than the receiver the extra digits will be truncated Specifying a VALUE with more integer digits
than the variable can hold will result in an error at the time of the program is executed.
If the character variable contains a decimal point, the decimal point will be placed in the proper
position in the receiver variable.
Excess characters to the right of the decimal point are truncated without error.
PGM
DCL VAR(&NUM1) TYPE(*CHAR) LEN(3)
DCL VAR(&NUM2) TYPE(*CHAR) LEN(3)
DCL VAR(&NUM3) TYPE(*DEC) LEN(3)
DCL VAR(&VAL1) TYPE(*DEC) LEN(3)
DCL VAR(&VAL2) TYPE(*DEC) LEN(3)
DCL VAR(&VAL3) TYPE(*CHAR) LEN(3)
SNDUSRMSG MSG('ENTER FIRST NUMBER:') MSGRPY(&NUM1)
SNDUSRMSG MSG('ENTER SECOND NUMBER:') MSGRPY(&NUM2)
CHGVAR &VAL1 &NUM1
CHGVAR &VAL2 &NUM2
CHGVAR &NUM3 (&VAL1 + &VAL2)
CHGVAR &VAL3 &NUM3
SNDUSRMSG MSG('THE SUM OF TWO NUMBERS ::' *CAT &VAL3)
ENDPGM
PGM
DCL VAR(&NUM) TYPE(*CHAR) LEN(3)
DCL VAR(&VAL) TYPE(*DEC) LEN(3)
SNDUSRMSG MSG('ENTER ANY NUMBER:') MSGRPY(&NUM)
CHGVAR &VAL &NUM
IF COND(&VAL < 0) THEN(SNDUSRMSG MSG('IT IS -VE NUMBER'))
ENDPGM
PGM
DCL VAR(&NUM) TYPE(*CHAR) LEN(3)
DCL VAR(&VAL) TYPE(*DEC) LEN(3)
SNDUSRMSG MSG('ENTER ANY NUMBER:') MSGRPY(&NUM)
CHGVAR &VAL &NUM
IF COND(&VAL < 0) THEN(SNDUSRMSG MSG('IT IS -VE NUMBER'))
ELSE (SNDUSRMSG MSG('IT IS +VE NUMBER'))
ENDPGM
PGM
DCL VAR(&A) TYPE(*CHAR) LEN(3)
DCL VAR(&B) TYPE(*CHAR) LEN(3)
DCL VAR(&C) TYPE(*CHAR) LEN(3)
DCL VAR(&X) TYPE(*DEC) LEN(3)
DCL VAR(&Y) TYPE(*DEC) LEN(3)
DCL VAR(&Z) TYPE(*DEC) LEN(3)
SNDUSRMSG MSG('ENTER FIRST NUMBER:') MSGRPY(&A)
SNDUSRMSG MSG('ENTER SECOND NUMBER:') MSGRPY(&B)
SNDUSRMSG MSG('ENTER THIRD NUMBER:') MSGRPY(&C)
CHGVAR &X &A
CHGVAR &Y &B
CHGVAR &Z &C
IF COND(&X > &Y & &X>&Z) THEN(SNDUSRMSG MSG('A IS BIG'))
ELSE IF (&Y>&Z) SNDUSRMSG MSG('B IS BIG')
ELSE SNDUSRMSG MSG('C IS BIG')
ENDPGM
PGM
/*CONCATINATE WITHOUT EDITING*/
DCL VAR(&STR1) TYPE(*CHAR) LEN(10)
DCL VAR(&STR2) TYPE(*CHAR) LEN(10)
DCL VAR(&STR3) TYPE(*CHAR) LEN(20)
SNDUSRMSG MSG('ENTER FIRST STRING1:') MSGRPY(&STR1)
SNDUSRMSG MSG('ENTER SECOND STRING2:') MSGRPY(&STR2)
CHGVAR &STR3 (&STR1 *CAT &STR2)
SNDUSRMSG MSG('THE RESULTANT STRING IS ::' *CAT &STR3)
ENDPGM
PGM
/*TRAILING BLANKS IN 1 STRING ARE TRUNCATED*/
DCL VAR(&STR1) TYPE(*CHAR) LEN(10)
DCL VAR(&STR2) TYPE(*CHAR) LEN(10)
DCL VAR(&STR3) TYPE(*CHAR) LEN(20)
SNDUSRMSG MSG('ENTER FIRST STRING1:') MSGRPY(&STR1)
SNDUSRMSG MSG('ENTER SECOND STRING2:') MSGRPY(&STR2)
CHGVAR &STR3 (&STR1 *BCAT &STR2)
SNDUSRMSG MSG('THE RESULTANT STRING IS ::' *CAT &STR3)
ENDPGM
PGM
/*IT WILL NOT GIVE ANY BLANKS BETWEEN THE TWO STRINGS*/
DCL VAR(&STR1) TYPE(*CHAR) LEN(10)
DCL VAR(&STR2) TYPE(*CHAR) LEN(10)
DCL VAR(&STR3) TYPE(*CHAR) LEN(20)
SNDUSRMSG MSG('ENTER FIRST STRING1:') MSGRPY(&STR1)
SNDUSRMSG MSG('ENTER SECOND STRING2:') MSGRPY(&STR2)
CHGVAR &STR3 (&STR1 *TCAT &STR2)
SNDUSRMSG MSG('THE RESULTANT STRING IS ::' *CAT &STR3)
ENDPGM
Work management overview how the AS/400 organizes and process work is called work
management. Work management is the complex topic linking together many facets of the OS/400
operating system.
What is a Job?
A job is a unit of work, including all the programs,files instructions and other objects necessary to
perform that work. A Job can be a simple task, such as running a report, or it can be a very
complex series of tasks, such as the entire paryroll operation for a day.
Job Types
|
|
^
-----------------------------
| |
Interactive Job Batch Job
When sign on to the AS/400 you start an interactive job. When you sign off, you end the job. A
batch job, on the other hand requires little or no interaction with the user. Usually you will submit a
batch job from an Interactive job. Once you submit job it will run without any rurther input from
you. In fact wile the batch job runs, you can continue to do work in your interactive job. Batch jobs
usually involve printing reportsor processing complex transactions.
AS/400 assigns a unique name to every AS/400 job. The job name has three parts
What is a Job Description every active job on the AS/400 is associated with a job description.
Usually your system admin will assign a job description to you when he creates your user profile.
A job descrption is an AS/400 object type *JOBD. It defines how a job is to be processed. It
contains such attributes as the hobs execution priority.
What is a Job Queue When you submit a job for processing, it is not processed immediately,
instead it is placed on a job queue to wait for available processor resources. The Object is *JOBQ
that act as a waiting room. Usually, batch job excutes sequentially in the order they were placed
on the job queue.
What is a Library List A jobs library list defines the path of libraries that it will follow when trying
to find programs, files, or other AS/400 Objects
A library list is not an AS/400 object. It is instead, an attribute of a job. The library list is determined
primarily by the job description. You can use the following CL commands to display and/or alter
the contents of a library list:
Executing commands in Batch Using SBMJOB This command allows you to submit a job to
job Queue. You can hold a submitted job on the job queue and release it later. You can also
schedule a job to run at a specific date and time. The SBMJOB has many parameters but in its
simples form it is expressed as follows. SBMJOB CMD(CL-command)
A batch job is entirely separate from the job that submitted it with its won program stack and its
won main storage requirements. The main advantage with this SBMJOB is we can do other work
on your workstation without waiting for the batch job to finish.
The parameters of SBMJOB it offers many parameters tohelp you specify the environment in
which you want a batch job to execute as well as the jobs attributes.
Paramters:JOB,JOBQ,JOBD,SYSLIBL,CURLIB,INLLIBL,PRTDEV,OUTQ,HOLD,SCDDATE,SCDT
IME
This will fired on the date & time mentioned in the SBMJOB
This chapter will introduce ways to handle expected and unexpected errors that occur when a CL
program is executed. We will discuss the CL MONMSG(Monitor message)
There may be occasions when a CL program cannot successfully execute some or all of
the commands contained within the program. The result is a program error
Another type of error that could occur is a program logic error. A logic error can occur if you
make a mistake when writing the program.
Error Messages if an error condition occurs during execution of a CL program, a special kind of
message, called an escape message(*ESCAPE), is automatically sent to the program. The
escape message will identify the error that occurred. If the system detects an escape message
the system sends an inquiry(*INQ) message to the end user to the system operator(for a batch
job), and does not continue until the end user or the system operator responds.
Error Messages
|
|
^
------------------------------------
| |
Command Level Program Level
Command Level message monitor checks only for escape messages generated by a single
command
Program Level message monitor checks for escape messages issued by all commands within
the program
Message Files the description of error messages that can be generated by a CL program are
stored I message files. Message files(AS/400 object type *MSGF) are similar to database files
(object type *FILE). Most messages that can be generated within a CL program are stored in an
IBM-supplied message file named QCPFMSG in lib QSYS. You can display contents of message
file by using DSPMSGD(display message description) or WRKMSGD(work with message
description)
Some Messages
WRKMSGD
Work with Message Descriptions
System: HBUASSOC
Message file: QCPFMSG Library: QSYS
Position to . . . . . . . Message ID
Type options, press Enter.
2=Change 4=Delete 5=Display details 6=Print
ENDPGM
PGM
DCL VAR(&JOBTYPE) TYPE(*CHAR) LEN(1)
RTVJOBA TYPE(&JOBTYPE)
IF COND(&JOBTYPE='1') THEN(SNDUSRMSG MSG('INTERACTIVE'))
ELSE (SNDUSRMSG MSG('BATCH MODE'))
ENDPGM
PGM
DCL VAR(&RUNPTY1) TYPE(*DEC) LEN(2 0)
DCL VAR(&TEMP) TYPE(*CHAR) LEN(10)
RTVJOBA RUNPTY(&RUNPTY1)
IF COND(&RUNPTY1 *LT 50) THEN(CHGJOB RUNPTY(50))
ELSE (CHGJOB RUNPTY(&RUNPTY1))
CHGVAR &TEMP &RUNPTY1
SNDUSRMSG MSG('RUN PRIORITY IS :' *CAT &TEMP)
ENDPGM
The following program will convert the Julian date to MDY vice versa
The following is a sample of CL programming. The program interactively converts dates from Julian to
mdy and vice versa. Results are displayed on line 24 of the terminal. It accepts two parameters. The
&IN parameter which is the date string to be converted. If a Julian string it should be in the format
yynnn where yy is the year number and nnn is the day number of the year. If a MDY string it must be
in the format mmddyy. The second parameter is &TYP which is the type of date to be converted to. It
must be 'J' (Julian) or 'M' (mdy). For example: the command CALL PGM(ICVTDATC) PARM('04180'
'M') will convert the Julian date 04180 to 062804 (June 28, 2004).
IF COND(&TYP = J) THEN(DO)
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*MDY) +
TOFMT(*JUL) TOSEP(*NONE)
ENDDO
IF COND(&TYP = M) THEN(DO)
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*JUL) +
TOFMT(*MDY) TOSEP(*NONE)
ENDDO
Data Areas: A data area is an object used to hold data for access by any job running on the
system data area can be used whenever you need to store information of limited size, independent
of the existence of procedures or files. Typical uses of data areas are:
To provide an area (perhaps within each job's QTEMP library) to pass information within a
job.
To provide a field that is easily and frequently changed to control references within a job,
such as:
Supplying the next order number to be assigned
Supplying the next check number
Supplying the next save/restore media volume to be used
To provide a constant field for use in several jobs, such as a tax rate or distribution list.
To provide limited access to a larger process that requires the data area. A data area can be
locked to a single user, thus preventing other users from processing at the same time.
To create a data area other than a local or group data area, use the Create Data Area
(CRTDTAARA) command. By doing this, you create a separate object in a specific library, and you
can initialize it to a value. To use the value in a CL procedure or program, use a Retrieve Data Area
(RTVDTAARA) command to bring the current value into a variable in your procedure or program. If
you change this value in your CL procedure or program and want to return the new value to the
data area, use the Change Data Area (CHGDTAARA) command.
To display the current value, use the Display Data Area (DSODTAARA) command. You can delete
a data area using the Delete Data Area (DLTDTAARA) command.
You can journal your data areas. This allows you to recover the object to a consistent state, even if
the object was in the middle of some change action when the abnormal IPL or crash occurred.
Journaling also provides for replication of the data area journal to a remote system (using remote
journal for instance). This lets the system reproduce the actions in a similar environment to
replicate the application work.
Local Data Area:A local data area is created for each job in the system, including autostart jobs,
jobs started on the system by a reader, and subsystem monitor jobs.
Group Data Area:The system creates a group data area when an interactive job becomes a group
job (using the Change Group Attributes (CHGGRPA) command).
Create Data Area:Unlike variables, data areas are objects and must be created before they can be
used.
Display Data Area:You can display the attributes (name, library, type, length, data area text
description) and the value of a data area.
VALUE(New Value)
Retrieve Data Area:You can retrieve a data area and copy it to a variable.
Data Queues:
Data queues are a type of system object that you can create, to which one HLL procedure or
program can send data, and from which another HLL procedure or program can receive data.
The receiving program can be already waiting for the data, or can receive the data later.
Using data queues frees a job from performing some work. If the job is an interactive job,
this can provide better response time and decrease the size of the interactive program and
its process access group (PAG). This, in turn, can help overall system performance. For
example, if several workstation users enter a transaction that involves updating and adding
to several files, the system can perform better if the interactive jobs submit the request for
the transaction to a single batch processing job.
Data queues are the fastest means of asynchronous communication between two jobs.
Using a data queue to send and receive data requires less overhead than using database
files, message queues, or data areas to send and receive data.
You can send to, receive from, and retrieve a description of a data queue in any HLL
procedure or program by calling the QSNDDTAQ, QRCVDTAQ, QMHRDQM, QCLRDTAQ,
and QMHQRDQD programs without exiting the HLL procedure or program or calling a CL
procedure or program to send, receive, clear, or retrieve the description.
When receiving data from a data queue, you can set a time out such that the job waits until
an entry arrives on the data queue. This differs from using the EOFDLY parameter on the
OVRDBF command, which causes the job to be activated whenever the delay time ends.
More than one job can receive data from the same data queue. This has an advantage in
certain applications where the number of entries to be processed is greater than one job
can handle within the desired performance restraints. For example, if several printers are
available to print orders, several interactive jobs could send requests to a single data
queue. A separate job for each printer could receive from the data queue, either in first-in-
first-out (FIFO), last-in-first-out (LIFO), or in keyed-queue order.
Data queues have the ability to attach a sender ID to each message being placed on the
queue. The sender ID, an attribute of the data queue which is established when the queue
is created, contains the qualified job name and current user profile.
In addition to these advantages, you can journal your data queues. This allows you to recover the
object to a consistent state, even if the object was in the middle of some change action when the
abnormal initial program load (IPL) or crash occurred. Journaling also provides for replication of
the data queue journal to a remote system (using remote journal for instance). This lets the system
reproduce the actions in a similar environment to replicate the application work.
The following example shows how data queues work. Several jobs place entries on a data queue.
The entries are handled by a server job. This might be used to have jobs send processed orders to
a single job that would do the printing. Any number of jobs can send to the same queue.
Another example using data queues follows. A primary job gets the work requests and sends the
entries to a data queue (by calling the QSNDDTAQ program). The server jobs receive the entries
from the data queue (by calling the QRCVDTAQ program) and process the data. The server jobs
can report status back to the primary job using another data queue.
Data queues allow the primary job to route the work to the server jobs. This frees the primary job to
receive the next work request. Any number of server jobs can receive from the same data queue.
When no entries are on a data queue, server jobs have the following options:
Data queues can also be used when a program needs to wait for input from display files, ICF files,
and data queues at the same time. When you specify the DTAQ parameter for the following
commands:
you can indicate a data queue that will have entries placed on it when any of the following
happens:
An enabled command key or Enter key is pressed from an invited display device
Data becomes available from an invited ICF session
Support is available to optionally associate a data queue to an output queue by using the Create
Output Queue (CRTOUTQ) or Change Output Queue (CHGOUTQ) command. The system logs
entries in the data queue when spooled files are in ready (RDY) status on the output queue. A user
program can determine when a spooled file is available on an output queue by using the Receive
Data Queue (QRCVDTAQ) API to receive information from a data queue.
Jobs running on the system can also place entries on the same data queue as the one specified in
the DTAQ parameter by using the QSNDDTAQ program.
An application calls the QRCVDTAQ program to receive each entry placed on the data queue and
then processes the entry based on whether it was placed there by a display file, an ICF file, or the
QSNDDTAQ program.
MAXLEN(Length) +
KEYLEN(Key length) +
Text( 'Text')
Clearing a Data Q:
Example: Data Q
PGM
ENDPGM
Subtopics:
The operating system that controls all of your interactions with the
AS/400 system is called the Operating System/400 (OS/400) system. From
your work station, the OS/400 system allows you to:
Subtopics:
You use the SEU to enter your code into the system. SEU also provides extensive syntax checking.
For more information about SEU, refer to the SEU User's Guide and Reference.
The SDA utility makes it easier for you to create the displays your program requires. For more
information about SDA, refer to the SDA User's Guide and Reference.
The AS/400 system allows you to insert SQL/400 statements into RPG/400 programs. You enter
SQL/400 statements on a calculation specification. The syntax is shown in Figure 2. You must
observe the following rules:
The starting delimiter /EXEC SQL must be entered into columns 7-15,
with the slash in column 7.
SQL/400 statements can be started on the same line as the starting
delimiter.
C |
C/EXEC SQL (the starting delimiter)
C+
C+ (continuation lines containing SQL statements)
C+
.
C/END-EXEC (the ending delimiter)
C |
C |
Figure 2. Syntax for Entering SQL/400 Statements into an RPG/400 Program
Refer to the SQL/400* Programmer's Guide and the SQL/400* Reference for
the descriptions of how to code SQL/400 statements.
Subtopics:
Restrictions
Restrictions
In the RPG/400 programming language, SQL/400 statements cannot be specified in the referred
source member of a /COPY statement. You should not use SQL/400 statements in an RPG
automatic report program. Instead, you should use the CRTRPTPGM command to process your
RPG automatic report programs and to save the generated RPG/400 source. Automatic report
will generate RPG/400 source, to which you can add SQL/400 statements. To process your
SQL/400 statements and generate an RPG object program, you should use the SQL/400
preprocessor. If SQL/400
statements are processed by the RPG/400 automatic report preprocessor, unpredictable results
may occur. Refer to the SEU User's Guide and Reference for information on how the SEU
handles SQL/400 statement syntax checking, and to the SQL/400* Programmer's Guide and the
SQL/400* Reference for more information on the SQL/400 preprocessor.
This sequence may seem backwards because it starts at the results (the output) and ends at the
beginning (the input). Designing the output first is like knowing where you are going before you
set out on a trip: it helps you decide the best way to get there.
Subtopics:
Your program produces output records. You must decide what to do with those records. In
general, you have three choices (or any combination of the three choices):
If you want to display the output records at your display station, you have to decide what
information you want displayed and how you want it laid out. To define how you want your
displays laid out, you use the display layout sheet. You can then use the SDA utility to create
your own displays. For more information about SDA, refer to the SDA User's Guide and
Reference.
If you want to print the output records, you have to decide what information you want printed
(which fields from which records) and how you want that information laid out on the printed report.
To indicate how you want the printed report laid out, use the printer layout sheet. If you want to
keep the output records in storage, you have to decide what information you want to keep and
how you want to organize the fields in the output records.
After you design all your output records, you code those records on the RPG/400 file description
specifications and output specifications.
Designing the processing means planning the calculations that produce the necessary output.
When you design the processing, you must be aware of how the RPG/400 program cycle works.
The RPG/400 program cycle controls certain read and write operations done on each record. As
a result, the program cycle partly determines how you can process your data.
Type Description
A Character
E Fixed Binary
D Date Field
F Floating Point
G Graphics character set
I Signed integer
P Packed Decimal
S Zoned Field
T Time Field
U Unsigned Integer Field
Z Time stamp Field
* Pointer Field
The following discuss how the three structures can be accomplished in the
RPG/400 programming language.
Subtopics:
Sequential Operation
Conditional Branching
Repeating an Operation
Summary of Structured Programming Operation Codes
Sequential Operation
Sequential operation means any series of instructions that is processed one instruction after
another, without transferring control to another part of the program.
Conditional Branching
Subtopics:
If Else Structure
SELEC Structure
Other Conditional Branching Structures
If Else Structure
SELEC
WHEN the weather is warm
I will wear my sunhat
I will go to the beach
WHEN the weather is cool
I will wear my jacket
OTHERwise, I will not go outside
There are three other ways you can create conditional branches:
You can also create a branch to a subroutine with the EXSR operation and
conditioning indicators.
Repeating an Operation
Subtopics:
Do Operation
Do While Operation
Do Until Operation
Do Operation
Figure is a flowchart of a Do operation, and Figure 8 illustrates the
coding.
Figure Flowchart of a Do Operation
1. Set the index field (result field) to the starting value (factor 1).
2. Test if the index field value is greater than the ending value (factor
2).
If the index field value is greater than the ending value, control
passes to the statement following the END statement.
3. If the index field value is not greater than the ending value, the
operations between the DO statement and the END statement are
processed.
Do While Operation
If you test the condition first and then process the operations, the
structure is called a Do While. An example of a Do While operation is:
C *IN32 DOWEQ'0'
C MOVE *BLANKS STATUS
C MOVE *BLANKS PRCDEX
C MOVE *BLANKS RSCDEX
C Z-ADD0 EHWRKX
C Z-ADD0 ACDATX
C Z-ADD0 TFRRN
C ADD 1 RECNO
C WRITEEMPFIL 32
C END
C* The preceding END denotes the end of the Do While operation.
Figure Design for a Do While Operation Using the DOWxx Operation Code Notice in Figure 10 (the Do
While) that the program first tests if the condition is true. If it is true, the code between the DOW and
the END operations is processed. The program then goes back to test again if the condition is still
true, and the entire cycle is repeated. If the condition is no longer true, control passes to the
instruction immediately following the END operation.
Do Until Operation
If you process the operations first and then test the condition, the structure is called a Do Until
operation. An example of a Do Until operation is:
1. Add 1 to a sum.
C EMPSR BEGSR
C*
C *IN50 DOUEQ'1'
C READ RCEMP 50
C* The following lines of code add current month hours to the year-
C* to-date hours for the employee master file. Since factor 1 is
C* not specified in the statements, factor 2 is added to the result
C* field and the result is placed in the result field. If *INU4
C* is on, this session is being run for year end, and the current
C* year hours are moved to the prior year hours.
C ADD EPHRC EPHRY
C ADD EPNRC EPNRY
C U4 MOVE EPHRY EPHRP
C U4 MOVE EPNRY EPNRP
C* The following code clears the current month hours fields by
C* zeroing them and adding 0 to them. If *INU4 is on, this session
C* is being run for year end, and the current year hours must be
C* zeroed as well.
C Z-ADD0 EPHRC
C Z-ADD0 EPNRC
C U4 Z-ADD0 EPHRY
C U4 Z-ADD0 EPNRY
C* The following code updates the employee master file using the
C* RCEMP format.
C UPDATRCEMP
C END
C* The preceding END statement is associated with the DOUEQ
C* statement.
IFxx (If/Then)
ELSE (Else Do)
ENDyy (End)
DO (Do)
DOWxx (Do While)
DOUxx (Do Until)
ANDxx (And)
ORxx (Or)
CASxx (Conditional Invoke Subroutine)
SELEC (Select a module)
WHxx (When)
OTHER (Otherwise).
Designing Applications
Application design involves determining whether to create one program to do all of the required
functions, or to create multiple programs to make up an application.
Subtopics:
In a single program design, all functions are done within one program.Single program design
applies to both batch and interactive programs. It is best used when there are few, relatively
simple functions.For example, an interactive inquiry program that accepts a customer number
from an operator, finds the corresponding record in a customer master file, and displays the
record as a simple program that could have a single program design.
A slightly more complex program that might also have a single program design is a file
maintenance program that allows an operator to:
An example of a batch program that has a single program design is a program that prints a list of
orders that each operator entered during the day.
Modular program design includes using multiple programs to do multiple functions, one function
per program. Modular program design can be applied to both batch and interactive programs.
For example, the order entry application shown in Figure 13 is designed to have four programs:
Mainline Program
________________ Program
| | Call ________________
____| |________| _____________ |_____ Prompt for
| | | | _____________ | Customer
| | | | _____________ | Number
| | |________| _____________ |
| | | |________________|
| | |
| | | Program
| | | Call ________________
| | |________| _____________ |_____ Line Item
| | | | _____________ | Input
| | | | _____________ |
| | |________| _____________ |
| | | |________________|
| | |
| | | Program
| | | Call ________________
| | |________| _____________ |_____ Totals
| | | | _____________ |
| | | | _____________ |
|_____| |________| _____________ |
|________________| |________________|
Designing, coding, testing, and maintaining several small programs can be easier than
designing, coding, testing, and maintaining one large, complex program. This choice is a
matter of personal preference, but it is often beneficial to keep your programs small and as
simple as possible.
CL functions can be requested from RPG/400 programs because the AS/400 system allows
RPG/400 programs and CL programs to call one another.
A single, long-running program might have sections of code that run infrequently. A modular
design could arrange to have the seldom-used code called only when needed. A potential
disadvantage of modular program design is the additional calling of programs that is required.
These calls take time to code and might require additional system overhead for program
processing.
This chapter describes the kinds of specifications you can enter when creating an RPG/400
source program. This chapter also describes how to use a text editor, such as SEU, to enter this
information directly into the system and thus begin creating your source program online.
Subtopics:
There are seven kinds of RPG/400 specifications. When your source program is compiled, these
specifications must be in the following sequence:
RPG/400
1. Control specifications
2. File description specifications
3. Extension specifications
4. Line counter specifications
5. Input specifications
6. Calculation specifications
7. Output specifications.
RPGILE
1. Header specifications
2. File description specifications
3. Declaration specifications
4. Input specifications
5. Calculation specifications
6. Output specifications.
7. Procedure specifications.
Each of these specifications is described briefly in this chapter. The RPG/400 Reference provides
detailed descriptions for these specifications. RPG/400 programs do not have to use all
specifications. A typical program may use file description, input, calculation, and output
specifications.
Subtopics:
The control specification provides the RPG/400 compiler with information about your program and
your system. This includes:
File description specifications describe all the files that your program uses. The information for
each file includes:
Extension Specifications
Extension specifications describe all record address files, table files, and array files used in the
program. The information includes:
Line counter specifications describe the page or form on which output is printed. The information
includes:
Number of lines per page
Line of the page where overflow occurs.
Input Specifications
Input specifications describe the records, fields, data structures and named constants used by the
program. The information in the input specifications includes:
Calculation specifications describe the calculations to be done on the data and the order of the
calculations. Calculation specifications can also be used to control certain input and output
operations. The information includes:
Output Specifications
Output specifications describe the records and fields in the output files and the conditions under
which output operations are processed. The information includes:
There are two environments that you can compile source programs from: the AS/400 system
environment, and the System/38 Environment. Consequently, there are two ways of compiling
source programs. This chapter describes:
This chapter also contains information on interpreting a compiler listing. To compile a program,
you must ensure that the library QTEMP is in the library list. The CL command CRTRPGPGM
calls the compiler to create an RPG/400 program object and a listing. (If externally described files
are used in the program, the OS/400 system provides information about the files to the program
during compilation.) The following figure shows an overview of the compilation process:
Figure. Overview of the Compilation Process
The compiler checks the syntax of the RPG/400 source program line by line and the
interrelationships between the lines. For example, it checks that all field names are defined and, if
a field is multiply defined, that each definition has the same attributes. The RPG/400 compiler
supports a source file record length of 102. In addition to the usual fields of sequence number (6
characters), last-changed date (6 characters), and the data (80 characters), a field of 10
characters that can contain additional information is placed at the end of the record (positions 93-
102). This information is not used by the RPG/400 compiler but is placed on the extreme right of
the compiler listing. You, the programmer, place information into this field. If you want to use the
additional field, create a source file with a record length of 102. The AS/400 system has an IBM-
supplied RPG/400 source file called QRPGSRC, which has a record length of 92.
Indicators
An indicator is a special type of one byte flag, which is always denoted '0' when off and '1' when
on. Indicators are of two types General and Special indicators.
General Indicators may treated as an array of 99 elements.01 through 99.
Special Indicators are
Level Indicators
Halt Indicators
(Page) Overflow indicators
Command key Indicators
Match indicators
First Page Indicators
Return indicators
Level Indicators: A control level indicator is defined by an entry in positions 63 and 64 of the input
specifications, designating an input field as a control field. It can then be used to condition
calculation and output operations. The valid control level indicator entries are L1 through L9.
Halt Indicators:H1 H9 This indicator can be set on you feel that a severe error has occurred. You
should not use the same halt indicator for more than one error condition.
Page Overflow Indicators:An overflow indicator is defined by the OFLIND keyword on the file
description specifications. It is set on when the last line on a page has been printed or passed.
Valid indicators are *INOA through *INOG, *INOV, and *IN01 through *IN99. A defined overflow
indicator can then be used to condition calculation and output operations. A description of the
overflow indicator and fetch overflow logic is given in Overflow Routine.
Command Key Indicators: These indicators are set on when the corresponding command key is
pressed. [CF1] sets on KA, [CF2] sets on KB and so on.
Match Indicators: Match indicator MR is set on when a record i the primary file matches a record
in a secondary file and does not work in fully procedural programs i.e it does not work outside the
cycle.
First Page Indicators: 1P The first page indicators is meaningful only with internally defined output
files used within the cycle. It provides a way of ensuring that the first pages heading print before
the firs detail line.
Prompt Type D:
Name - Type the name of the data structure, data-structure subfield, named constant, table,
standalone field, or array definition. You can leave this field blank within data-structures.
Blank Leave the field blank for a character field, or a packed decimal
standalone field, or a zoned decimal field data structure subfield.
For zoned or packed data types, the decimal positions field must be
nonblank.
ALIGN
Type this keyword if alignment is required for signed and unsigned
integer subfields.
ALT(array_name)
Indicates that the compile-time or pre-runtime array or table is in
alternating format.
ALTSEQ(*NONE)
Specifies that the normal collating sequence is to be used for
character comparison even when an alternate collating sequence is
specified. This keyword is valid for character definitions.
ASCEND or DESCEND
ASCEND indicates that the array or table is in ascending sequence.
DESCEND indicates that the array or table is in descending sequence.
BASED(ptr)
Indicates that the data structure, run-time array or table, or field
definitions are based on the pointer.
CONST(literal)
Specifies the value of a named constant.
CTDATA
Specifies that the array is a compile-time array.
DATFMT(format{separator})
Specifies the date format for a date type field.
The separator is optional. If you specify an ampersand (&) as the eparator, a blank is used as the
separator character.
DIM(numeric_constant) Specifies the number of elements of an array or table.
DTAARA{(data_area_name)}
Specifies the name of the external data area that is associated with a field, data structure, data
structure subfield, or data area data structure.
EXPORT{(external-name)}
Indicates that the storage for the field is allocated in this module, and optionally specifies the
external name of the exported variable.
EXTFLD(ext_field_name)
Specifies which field in the externally described data structure is renamed.
EXTFMT(data_type)
Choose one of the following external data type values:
B Binary
F Floating-point
I Integer
L Numeric sign Left
P Packed Decimal
R Numeric sign Right
S Zoned numeric
U Unsigned
Programs ILERPG
Example 1: To Add Two Number
DCON1 C CONST('Asif.shaik M.Tech')
DNUM1 S 3I 0 INZ(10)
DNUM2 S 3I 0 INZ(20)
DRES S 5I 0
C CON1 DSPLY
C EVAL RES = NUM1 + NUM2
C RES DSPLY
C EVAL RES = NUM1 - NUM2
C RES DSPLY
C EVAL RES = NUM1 * NUM2
C RES DSPLY
C EVAL RES = NUM1 / NUM2
C RES DSPLY
C Seton LR
DNUM1 S 5S 3 INZ(1.124)
DNUM2 S 5S 3 INZ(0.001)
DRES S 5S 2 INZ(0)
C EVAL RES = NUM1 + NUM2
C RES DSPLY
C EVAL (H) RES = NUM1 + NUM2
C RES DSPLY
C Seton LR
OUTPUT:1.13(ROUNDED) 1.12 (NOT ROUNDED)
DNUM1 S 5S 0 INZ(10)
DNUM2 S 5S 0 INZ(20)
C IF NUM1 > NUM2
C NUM1 DSPLY
C ELSE
C NUM2 DSPLY
C ENDIF
C Seton LR
OUTPUT:20
DNUM1 S 5S 0 INZ(10)
DNUM2 S 5S 0 INZ(20)
DNUM3 S 5S 0 INZ(30)
C IF ((NUM1 > NUM2) AND (NUM1 > NUM3))
C NUM1 DSPLY
C ELSE
C IF (NUM2 > NUM3)
C NUM2 DSPLY
C ELSE
C NUM3 DSPLY
C ENDIF
C ENDIF
C Seton LR
OUTPUT:30
DNUM1 S 5S 0 INZ(1)
DNUM2 S 5S 0 INZ(20)
DRES S 5S 0 INZ(0)
C DOW NUM1 <= NUM2
C EVAL RES = RES + NUM1
C EVAL NUM1 = NUM1 +1
C ENDDO
C RES DSPLY
C Seton LR
OUTPUT:210
DNUM1 S 5S 0 INZ(1)
DNUM2 S 5S 0 INZ(5)
DRES S 5S 0 INZ(0)
C DOU NUM1 >= NUM2
C EVAL RES = RES + NUM1
C EVAL NUM1 = NUM1 +1
C ENDDO
C RES DSPLY
C Seton LR
OUTPUT:10
DNUM1 S 5S 0 INZ(0)
DRES S 5S 0 INZ(0)
C FOR NUM1=10 DOWNTO 1 BY 2
C EVAL RES = RES + NUM1
C ENDFOR
C RES DSPLY
C Seton LR
OUTPUT:30
DNUM1 S 5S 0 INZ(1)
DNUM2 S 5S 0 INZ(10)
C DOW NUM1 <= NUM2
C EVAL NUM1 = NUM1 + 2
C IF NUM1 = 5
C EVAL NUM1 = NUM1 + 2
C ITER
C ENDIF
C ENDDO
C NUM1 DSPLY
C Seton LR
OUTPUT:11
DNUM1 S 5S 0 INZ(1)
DNUM2 S 5S 0 INZ(10)
C DOW NUM1 <= NUM2
C EVAL NUM1 = NUM1 + 2
C IF NUM1 = 5
C EVAL NUM1 = NUM1 + 2
C LEAVE
C ENDIF
C ENDDO
C NUM1 DSPLY
C Seton LR
OUTPUT:7
DMARKS1 S 5S 0 INZ(70)
DMARKS2 S 5S 0 INZ(20)
DMARKS3 S 5S 0 INZ(68)
C SELECT
C MARKS1 WHENLT 35
C MARKS2 ORLT 35
C MARKS3 ORLT 35
C 'FAIL' DSPLY
C OTHER
C 'PASS' DSPLY
C ENDSL
C Seton LR
OUTPUT:FAIL
Example 11:
* Syntax
* %ABS(numeric expression)
*
* %ABS returns the absolute value of the numeric expression specified
* as the parameter. If the value of the numeric expression is
* non-negative, the value is returned unchanged. If the value is
* negative, the value returned is the value of the expression but with
* the negative sign removed.
*
DPi C const(3.1432)
DRadious S 7P 2 Inz(-5.2)
DArea S 7P 2 Inz(0.0)
C Eval Area = Pi * %ABS(Radious)**2
C Area Dsply
C SETON LR
* OUTPUT Area = 8499
Example 12:
* SYNTAX
* %CHAR(expression{:format})
*
* %CHAR converts the value of the expression from graphic, UCS-2,
* numeric, date, time or timestamp data to type character. The
* converted value remains unchanged, but is returned in a format that
* is compatible with character data.
*
* If the parameter is a constant, the conversion will be done at compi
* time
DNum1 S 5i 0 Inz(504)
DStr1 C Const('Asif.Shaik ID:')
DRes S 20A
C Eval Res = Str1 + %CHAR(Num1)
C Res Dsply
C SETON LR
Example 13:
* SYNTAX : %CHECK(comparator : base {: start})
*
DStr1 C Const('Asif.Shaik ID:')
DRes S 3I 0 Inz(0)
C Eval Res = %CHECK('i':Str1:9)
C Res Dsply
C SETON LR
Example 14:
DDIGITS C '0123456789'
C Z-ADD 0 N 1 0
C MOVE '$1200' SALARY 6
C DIGITS CHECK SALARY:2 N
C IF %FOUND
C N DSPLY
C ENDIF
C SETON LR
Example 15:
Example 16:
* %LEN(expression)
* %LEN can be used to get the length of a variable expression or to se
* the current length of a variable-length field.
DNum1 S 7P 2
DNum2 S 5S 1
DNum3 S 5I 0 Inz(10)
DRes S 5I 0 Inz(0)
C Eval Res = %Len(Num1)
C Res Dsply
C Eval Res = %DecPos(Num2)
C Res Dsply
C Eval Res = %Len(Num1*Num2)
C Res Dsply
C SETON LR
Example 17:
* SYNTAX
* %REPLACE(replacement string: source string{:start position {:source
* length to replace}})
*
* %REPLACE returns the character string produced by inserting a
* replacement string into the source string, starting at the start
* position and replacing the specified number of characters.
*
DStr1 S 20A Inz('Asif.Shaik') Varying
DStr2 S 20A Varying
C Eval Str1 = Str1 + ',' + '4Soft'
C Str1 Dsply
C Eval Str2 = %Replace('M.Tech' : Str1 : 12)
C Str2 Dsply
C SETON LR
Example 18:
* SYNTAX
* %SUBST(string:start{:length})
*
* %SUBST returns a portion of argument string. It may also be used as
* result of an assignment with the EVAL operation code.
Example 19:
* SYNTAX
* %TRIM(string)
*
* %TRIM returns the given string less any leading and trailing blanks.
*
DStr1 S 20A Inz(' Asif')
DStr2 S 20A Inz(' Shaik')
C Eval Str2 = Str1 + '.' + Str2
C Str2 Dsply
C Eval Str2 = %Trim(Str1) + '.' + %Trim(Str2)
C Str2 Dsply
C Eval Str2 = %TrimR(Str1)
C Str2 Dsply
C Eval Str2 = %Trim(Str1)
C Str2 Dsply
C SETON LR
Example 20:
* SYNTAX
* %SCAN(search argument : source string {: start})
*
* %SCAN returns the first position of the search argument in the
* source string, or 0 if it was not found. If the start position is
* specified, the search begins at the starting position. The result is
* always the position in the source string even if the starting
* position is specified. The starting position defaults to 1.
*
DName S 15A Inz('Asif.Shaik')
DPos S 5U 0
C Eval Pos = %Scan('S':Name)
C Pos Dsply
C SETON LR
* OUTPUT : Pos = 6
Example 21:
* SYNTAX
* %SQRT(numeric expression)
* %SQRT returns the square root of the specified numeric expression.
* If the operand is of type float, the result is of type float;
* otherwise, |the result is packed decimal numeric. If the parameter
* has a value less |than zero, exception 00101 is issued.
*
DNum1 S 10i 0
DNum2 S 9p 2
DNum3 S 4f
C Eval Num1 = %Sqrt(239874)
C Num1 Dsply
C Eval Num2 = %Sqrt(239874)
C Num2 Dsply
C Eval Num3 = %Sqrt(239874)
C Num3 Dsply
C SETON LR
* OUTPUT : Num1 = 489
* OUTPUT : Num2 = 489.76
* OUTPUT : Num3 = +4.8976936E+02
Example 22:
* SYNTAX
*
* %DATE{(expression{:date-format})}
* %DATE converts the value of the expression from character, numeric,
* or timestamp data to type date. The converted value remains
* unchanged, but is returned as a date.
*
DStr C Const('121406')
DDate S D
C Eval Date = %Date(Str:*MDY0)
C Date Dsply
C SETON LR
Example 23:
* SYNTAX
*
* %TIME{(expression{:time-format})}
* %TIME converts the value of the expression from character, numeric,
* ortimestamp data to type time. The converted value remains
* unchanged, but is returned as a time.
*
DStr C Const('12:14 PM')
DTime S T
C Eval Time = %Time(Str:*USA)
C Time Dsply
C SETON LR
*OUTPUT Time : 12.14.00
Example 24:
* SYNTAX
* %DAYS(number) + %MONTHS(number)
* %DAYS converts a number into a duration that can be added to a date
* or timestamp value.
* %DAYS can only be the right-hand value in an addition or
* subtraction operation. The left-hand value must be a date or
* timestamp. The result is a date or timestamp value with the
* appropriate number of days added or subtracted. For a date, the
* resulting value is in *ISO format.
*
DStr C Const('121406')
DDate S D
C Eval Date = %Date(Str:*MDY0)
C Date Dsply
C Eval Date = Date + %Days(10)
C Date Dsply
C SETON LR
*
* OUTPUT :2006-12-14
* 2006-12-24
Example 25:
* SYNTAX
* %DAYS(number) + %MONTHS(number)
* %DAYS converts a number into a duration that can be added to a date
* or timestamp value.
* %DAYS can only be the right-hand value in an addition or
* subtraction operation. The left-hand value must be a date or
* timestamp. The result is a date or timestamp value with the
* appropriate number of days added or subtracted. For a date, the
* resulting value is in *ISO format.
*
DStr C Const('121406')
DDate S D
C Eval Date = %Date(Str:*MDY0)
C Date Dsply
C Eval Date = Date + %Months(02)
C Date Dsply
C Date Dsply
C SETON LR
*
* OUTPUT :2006-12-14
* 2007-02-14
Example 26:
* SYNTAX
* %REM(n:m)
* %REM returns the remainder that results from dividing operands n by
* m. The two operands must be numeric values with zero decimal
* positions. If either operand is a packed, zoned, or binary numeric
* value, the result is packed numeric. If either operand is an integer
* numeric value, the result is integer. Otherwise, the result is
* unsigned numeric. Float numeric operands are not allowed. The result
* has the same sign as the dividend. (See also %DIV (Return Integer
* Portion of Quotient).)
*
* %REM and %DIV have the following relationship:
*
* %REM(A:B) = A - (%DIV(A:B) * B)
*
DNum1 S 3i 0 Inz(10)
DNum2 S 3i 0 Inz(20)
DRes S 3i 0 Inz(0)
C Eval Res = %Div(Num2:Num1)
C Res Dsply
C Eval Res = %Rem(Num2:Num1)
C Res Dsply
C SETON LR
*
* OUTPUT :2
* 0
Example 27:
*Reserved Words
C *Date Dsply
C *Month Dsply
C *Year Dsply
C *Day Dsply
C SETON LR
*OUTPUT:12142006
* 12
* 2006
* 14
Example 28:
* SYNTAX
HDATFMT(*MDY)
DStr C Const('121406')
DDate S D
C Eval Date = %Date(Str:*MDY0)
C Date Dsply
C SETON LR
* OUTPUT:
* DATFMT(*YMD) = 06/12/14 DATFMT(*YMD-) = 06-12-14
* DATFMT(*DMY) = 14/12/06 VALID SEPERATORS ARE - . /
* DATFMT(*MDY) = 12/14/06
* DATFMT(*ISO) = 2006-12-14
* DATFMT(*USA) = 12/14/2006
* DATFMT(*EUR) = 14.12.2006
* DATFMT(*JIS) = 2006-12-14
Example 29:
Step2 : Use STRDBG and press F4. Specify Display Module Source parameter as *YES. Press
enter.
Step3 : The source code will be displayed. Take the cursor to the line that needs break point and
press F6.
H Specification
Example 30: Example On H Specification.
*Valid Date Formats : *ISO *MDY *YMD *JUL *USA *JIS *EUR
*Valid Date Formats : *HMS *USA *EUR *JIS
*For Date Separators : DATFMT(DMY-)
Output:06/08/19
HTIMFMT (*HMS)
DSTRTIM S T INZ(T'07:00:00')
DENDTIM S T INZ(T'10:50:00')
DH1 S 3S 0
DM1 S 3S 0
C STRTIM DSPLY
C ENDTIM DSPLY
C ENDTIM SUBDUR STRTIM H1:*H
C ENDTIM SUBDUR STRTIM M1:*MN
C H1 DSPLY
C M1 DSPLY
C Seton LR
Output:07:00:00
10:50:00
3
230
HDATFMT (*DMY)
DDATE1 S D INZ(D'19/08/06')
DDATE2 S D INZ(D'18/07/05')
C DATE1 SUBDUR 3:*DAYS DATE2
C DATE2 DSPLY
C Seton LR
Output:16/08/06
HDATFMT (*DMY)
DDATE1 S 8D INZ(D'19/08/06')
DDATE2 S 8D
DNUM S 2S 0 INZ(31)
C DATE1 ADDDUR NUM:*DAYS DATE2
C DATE2 DSPLY
C Seton LR
Output:19/09/06
H DATFMT(*ISO)
DDATE1 S D INZ(D'2006-03-10')
DYY S 4S 0 INZ(0)
DMM S 2S 0 INZ(0)
DDD S 2S 0 INZ(0)
C EXTRCT DATE1:*Y YY
C EXTRCT DATE1:*M MM
C EXTRCT DATE1:*D DD
C YY DSPLY
C MM DSPLY
C DD DSPLY
C Seton LR
Output:2006
3
Types Of Arrays
There are three types of arrays:
The run-time array is loaded by your program while it is running.
The compile-time array is loaded when your program is created. The initial data becomes
a permanent part of your program.
The prerun-time array is loaded from an array file when your program begins running,
before any input, calculation, or output operations are processed.
The essentials of defining and loading an array are described for a run-time array. For defining
and loading compile-time and prerun-time arrays you use these essentials and some additional
specifications.
Note:
Date and time runtime data must be in the same format and use the same separators as the date
or time array being loaded.
Loading a Run-Time Array in One Source Record
If the array information is contained in one record, the information can occupy consecutive
positions in the record or it can be scattered throughout the record.
If the array elements are consecutive on the input record, the array can be loaded with a single
input specification. Figure shows the specifications for loading an array, INPARR, of six elements
(12 characters each) from a single record from the file ARRFILE.
If the array elements are scattered throughout the record, they can be defined and loaded one at
a time, with one element described on a specification line. Figure shows the specifications for
loading an array, ARRX, of six elements with 12 characters each, from a single record from file
ARRFILE; a blank separates each of the elements from the others.
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++
DARC S 3A DIM(12) PERRCD(5) CTDATA
**CTDATA ARC
48K16343J64044HComments can be placed here
12648A47349K346Comments can be placed here
50B125 Comments can be placed here
Each record, except the last, must contain the number of entries specified with the
PERRCD keyword on the definition specifications. In the last record, unused entries must
be blank and comments can be included after the unused entries.
Each entry must be contained entirely on one record. An entry cannot be split between two
records; therefore, the length of a single entry is limited to the maximum length of 100
characters (size of source record). If arrays are used and are described in alternating
format, corresponding elements must be on the same record; together they cannot exceed
100 characters.
For date and time compile-time arrays the data must be in the same format and use the
same separators as the date or time array being loaded.
Array data may be specified in one of two ways:
**CTDATA arrayname: The data for the array may be specified anywhere in the compile-
time data section.
**b: (b=blank) The data for the arrays must be specified in the same order in which they
are specified in the Definition specifications.
Only one of these techniques may be used in one program.
Arrays can be in ascending(ASCEND keyword), descending (DESCEND keyword), or no
sequence (no keyword specified).
For ascending or descending character arrays when ALTSEQ(*EXT) is specified on the
control specification, the alternate collating sequence is used for the sequence checking. If
the actual collating sequence is not known at compile time (for example, if
SRTSEQ(*JOBRUN) is specified on a control specification or as a command parameter)
the alternate collating sequence table will be retrieved at runtime and the checking will
occur during initialization at *INIT. Otherwise, the checking will be done at compile time.
Graphic and UCS-2 arrays will be sorted by hexadecimal values, regardless of the
alternate collating sequence.
If L or R is specified on the EXTFMT keyword on the definition specification, each element
must include the sign (+ or -). An array with an element size of 2 with L specified would
require 3 positions in the source data as shown in the following example.
*....+....1....+....2....+....3....+....4....+....5....+....6....+....*
*....+....1....+....2....+....3....+....4....+....5....+....6....+....*
HKeywords+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
H DATFMT(*USA) TIMFMT(*HMS)
D*ame+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++
* Run-time array. ARI has 10 elements of type date. They are
* initialized to September 15, 1994. This is in month, day,
* year format using a slash as a separator as defined on the
* control specification.
DARI S D DIM(10) INZ(D'09/15/1994')
*
* Compile-time arrays in alternating format. Both arrays have
* eight elements (three elements per record). ARC is a character
* array of length 15, and ARD is a time array with a predefined
* length of 8.
DARC S 15 DIM(8) PERRCD(3)
D CTDATA
DARD S T DIM(8) ALT(ARC)
*
* Prerun-time array. ARE, which is to be read from file DISKIN,
* has 250 character elements (12 elements per record). Each
* element is five positions long. The size of each record
* is 60 (5*12). The elements are arranged in ascending sequence.
DARE S 5A DIM(250) PERRCD(12) ASCEND
D FROMFILE(DISKIN)
*
* Prerun-time array specified as a combined file. ARH is written
* back to the same file from which it is read when the program
* ends normally with LR on. ARH has 250 character elements
* (12 elements per record). Each elements is five positions long.
* The elements are arranged in ascending sequence.
DARH S 5A DIM(250) PERRCD(12) ASCEND
D FROMFILE(DISKOUT)
D TOFILE(DISKOUT)
**CTDATA ARC
Toronto 12:15:00Winnipeg 13:23:00Calgary 15:44:00
Sydney 17:24:30Edmonton 21:33:00Saskatoon 08:40:00
Regina 12:33:00Vancouver 13:20:00
Searching Arrays
|The following can be used to search arrays: |
|The LOOKUP operation code
|The %LOOKUP built-in function
|The %LOOKUPLT built-in function
|The %LOOKUPLE built-in function
|The %LOOKUPGT built-in function
|The %LOOKUPGE built-in function |
|For more information about the LOOKUP operation code, see: |
|Searching an Array with an Index
|Searching an Array Without an Index
|LOOKUP (Look Up a Table or Array Element) |
|For more information about the %LOOKUPxx built-in functions, see %LOOKUPxx (Look Up an
Array Element).
Searching an Array Without an Index
When searching an array without an index, use the status (on or off) of the resulting indicators to
determine whether a particular element is present in the array. Searching an array without an
index can be used for validity checking of input data to determine if a field is in a list of array
elements. Generally, an equal LOOKUP is requested.
In factor 1 in the calculation specifications, specify the search argument (data for which you want
to find a match in the array named) and place the array name factor 2.
In factor 2 specify the name of the array to be searched. At least one resulting indicator must be
specified. Entries must not be made in both high and low for the same LOOKUP operation. The
resulting indicators must not be specified in high or low if the array is not in sequence (ASCEND
or DESCEND keywords). Control level and conditioning indicators (specified in positions 7
through 11) can also be used. The result field cannot be used.
The search starts at the beginning of the array and ends at the end of the array or when the
conditions of the lookup are satisfied. Whenever an array element is found that satisfies the type
of search being made (equal, high, low), the resulting indicator is set on.
Figure 73 shows an example of a LOOKUP on an array without an index.
Figure 73. LOOKUP Operation for an Array without an Index
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords++++++++++++++++++++++++++++
FARRFILE IT F 5 DISK
F*
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++
DDPTNOS S 5S 0 DIM(50) FROMFILE(ARRFILE)
D*
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq..
C* The LOOKUP operation is processed and, if an element of DPTNOS equal
C* to the search argument (DPTNUM) is found, indicator 20 is set on.
C DPTNUM LOOKUP DPTNOS 20
ARRFILE, which contains department numbers, is defined in the file description specifications as
an input file (I in position 17) with an array file designation (T in position 18). The file is program
described (F in position 22), and each record is 5 positions in length (5 in position 27).
In the definition specifications, ARRFILE is defined as containing the array DPTNOS. The array
contains 50 entries (DIM(50)). Each entry is 5 positions in length (positions 33-39) with zero
decimal positions (positions 41-42). One department number can be contained in each record
(PERRCD defaults to 1).
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords++++++++++++++++++++++++++++
FARRFILE IT F 25 DISK
F*
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++
DDPTNOS S 5S 0 DIM(50) FROMFILE(ARRFILE)
DDPTDSC S 20A DIM(50) ALT(DPTNOS)
D*
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq..
C* The Z-ADD operation begins the LOOKUP at the first element in DPTNOS.
C Z-ADD 1 X 3 0
C* At the end of a successful LOOKUP, when an element has been found
C* that contains an entry equal to the search argument DPTNUM,
C* indicator 20 is set on and the MOVE operation places the department
C* description, corresponding to the department number, into DPTNAM.
C DPTNUM LOOKUP DPTNOS(X) 20
C* If an element is not found that is equal to the search argument,
C* element X of DPTDSC is moved to DPTNAM.
C IF NOT *IN20
C MOVE DPTDSC(X) DPTNAM 20
C ENDIF
This example shows the same array of department numbers, DPTNOS, as Figure 73. However,
an alternating array of department descriptions, DPTDSC, is also defined. Each element in
DPTDSC is 20 positions in length. If there is insufficient data in the file to initialize the entire array,
the remaining elements in DPTNOS are filled with zeros and the remaining elements in DPTDSC
are filled with blanks.
Example1 :
DArray1 S 4S 0 Dim(5)
DNum S 4S 0 Inz(1)
C Num DowLt 5
C Eval Array1(Num) = Num
C Array1(Num) Dsply
C Eval Num = Num + 1
C Enddo
C SETON LR
* OUTPUT :1 2 3 4
DArray1 S 4S 0 Dim(5)
DNum S 4S 0 Inz(1)
DRes S 4S 0 Inz(0)
C Num DowLt 5
C Eval Array1(Num) = Num
C Array1(Num) Dsply
C Eval Num = Num + 1
C Enddo
C Eval Res = %XFOOT(Array1)
C Res DSPLY
C
C SETON LR
UUUUUUUUUU TT:TT:TT
Simple Interest Calculation
DD/DD/DD
F3=Exit
UUUUUUUUUU TT:TT:TT
Handling Subroutines
DD/DD/DD
Action Level: B
A. Addtion
S. Subtraction
D. Division
M.Multiplication
R e s u l t I s : 6666
F3=Exit
DD/DD/DD
F3 = Exit
FSTMAST IF E DISK
FILE020FM CF E WORKSTN
C
C READ STMAST
C DOW NOT %EOF(STMAST)
C Z-ADD STNO XSTNO
C MOVEL STNAME XSTNAME
C MOVEL STADR XSTADR
C MOVEL STCRSE XSTCRSE
C Z-ADD STFEES XSTFEE
* ============
C EXFMT REC
* ============
C 03 LEAVE
C READ STMAST
C ENDDO
C SETON LR
FSTMAST IF E DISK
FILE020FM CF E WORKSTN
C
C
C *HIVAL SETGT STMAST
C READP STMAST
C DOW NOT %EOF(STMAST)
C Z-ADD STNO XSTNO
C MOVEL STNAME XSTNAME
C MOVEL STADR XSTADR
C MOVEL STCRSE XSTCRSE
C Z-ADD STFEES XSTFEE
* ============
C EXFMT REC
* ============
C 03 LEAVE
C READP STMAST
C ENDDO
C SETON LR
F3 = Exit
Data structures
The ILE RPG compiler allows you to define an area in storage and the layout of the fields, called
subfields, within the area. This area in storage is called a data structure. You define a data
structure by specifying DS in positions 24 through 25 on a definition specification.
You can use a data structure to:
Define the same internal area multiple times using different data formats
Define a data structure and its subfields in the same way a record is defined.
Define multiple occurrences of a set of data.
Group non-contiguous data into contiguous internal storage locations.
Operate on all the subfields as a group using the name of the data structure.
Operate on an individual subfield using its name.
In addition, there are four special data structures, each with a specific purpose:
A data area data structure (identified by a U in position 23 of the definition specification)
A file information data structure (identified by the keyword INFDS on a file description
specification)
A program-status data structure (identified by an S in position 23 of the definition
specification)
An indicator data structure (identified by the keyword INDDS on a file description
specification).
Data structures can be either program-described or externally described, except for indicator data
structures, which are program-described only. |One data structure can be defined like another
using the LIKEDS |keyword.
A program-described data structure is identified by a blank in position 22 of the definition
specification. The subfield definitions for a program-described data structure must immediately
follow the data structure definition.
An externally described data structure, identified by an E in position 22 of the definition
specification, has subfield descriptions contained in an externally described file. At compile time,
the ILE RPG compiler uses the external name to locate and extract the external description of the
data structure subfields. You specify the name of the external file either in positions 7 through 21,
or as a parameter for the keyword EXTNAME.
Note:
The data formats specified for the subfields in the external description are used as the internal
formats of the subfields by the compiler. This differs from the way in which externally described
files are treated.
An external subfield name can be renamed in the program using the keyword EXTFLD. The
keyword PREFIX can be used to add a prefix to the external subfield names that have not been
renamed with EXTFLD. Note that the data structure subfields are not affected by the PREFIX
keyword specified on a file-description specification even if the file name is the same as the
parameter specified in the EXTNAME keyword when defining the data structure using an external
file name. Additional subfields can be added to an externally described data structure by
specifying program-described subfields immediately after the list of external subfields.
A data area data structure, identified by a U in position 23 of the definition specification, indicates
to the compiler that it should read in and lock the data area of the same name at program
initialization and should write out and unlock the same data area at the end of the program.
Locking does not apply to the local data area (see Local Data Area (*LDA)). Data area data
structures, as in all other data structures, have the type character. A data area read into a data
area data structure must also be character. The data area and data area data structure must have
the same name unless you rename the data area within the ILE RPG program by using the
*DTAARA DEFINE operation code or the DTAARA keyword.
You can specify the data area operations (IN, OUT, and UNLOCK) for a data area that is implicitly
read in and written out. Before you use a data area data structure with these operations, you must
specify that data area data structure name in the result field of the *DTAARA DEFINE operation or
with the DTAARA keyword.
A data area data structure cannot be specified in the result field of a PARM operation in the
*ENTRY PLIST.
If you specify blanks for the data area data structure (positions 7 through 21 of the definition
specification that contains a U in position 23), the compiler uses the local data area. To provide a
name for the local data area, use the *DTAARA DEFINE operation, with *LDA in factor 2 and the
name in the result field or DTAARA(*LDA) on the definition specification.
You can specify a file information data structure (defined by the keyword INFDS on a file
description specifications) for each file in the program. This provides you with status information
on the file exception/error that occurred. The file information data structure name must be unique
for each file. A file information data structure contains predefined subfields that provide
information on the file exception/error that occurred. For a discussion of file information data
structures and their subfields, see File Information Data Structure.
An indicator data structure is identified by the keyword INDDS on the file description
specifications. It is used to store conditioning and response indicators passed to and from data
management for a file. By default, the indicator data structure is initialized to all zeros ('0's).
The rules for defining the data structure are:
It must not be externally described.
It can only have fields of indicator format.
It can be defined as a multiple occurrence data structure.
%SIZE for the data structure will return 99. For a multiple occurrence data structure,
%SIZE(ds:*ALL) will return a multiple of 99. If a length is specified, it must be 99.
Subfields may contain arrays of indicators as long as the total length does not exceed 99.
Error # 43 46 @@ERR#
Mi/odt # 47 50 @@ODT
From To
(Pos. (Pos.
26- 33-
32) 39) Format Length Keyword Information
*INIT
Program initialization
*DETL
Detail lines
*GETIN
Get input record
*TOTC
Total calculations
*TOTL
Total lines
*DETC
Detail calculations
*OFL
Overflow lines
*TERM
Program ending
*ROUTINE
Name of program or procedure
called (first 8 characters).
Note:
*ROUTINE is not valid unless
you use the normal RPG IV
cycle. Logic that takes the
program out of the normal RPG
IV cycle may cause *ROUTINE to
reflect an incorrect value.
Note:
This century field does not
apply to the dates in
positions 276 to 281, or
positions 288 to 293.
201 208 Character 8 Name of file on which the last
file operation occurred (updated
only when an error occurs). This
file name will be truncated if a
long file name is used. See
positions 175-184 for long file
name information.
209 243 Character 35 Status information on the last
file used. This information
includes the status code, the RPG
IV opcode, the RPG IV routine
name, the source listing line
number or statement number, and
record name. It is updated only
when an error occurs.
Note:
The opcode name is in the same
form as *OPCODE in the INFDS
DBranch DS 6 Occurs(10)
DCode 1 2
DName 3 6
C 1 Occur Branch
C Movel '01' Code
C Movel 'Asif' Name
C 2 Occur Branch
C Movel '02' Code
C Movel 'Basha' Name
C 1 Occur Branch
C Code Dsply
C Name Dsply
C 2 Occur Branch
C Code Dsply
C Name Dsply
C Branch Dsply
C SETON LR
DBranch UDS
DCode 1 2
DName 3 6
C Code Dsply
C Name Dsply
C SETON LR
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
D.....................................Keywords+++++++++++++++++++++++++++++
*
* Use length notation to define the data structure subfields.
* You can refer to the entire data structure by using Partno, or by
* using the individual subfields Manufactr, Drug, Strength or Count.
*
D Partno DS
D Manufactr 4
D Drug 6
D Strength 3
D Count 3 0
D
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC..................................
I........................Fmt+SPFrom+To+++DcField+++++++++L1M1FrPlMnZr......
*
* Records in program described file FILEIN contain a field, Partno,
* which needs to be subdivided for processing in this program.
* To achieve this, the field Partno is described as a data structure
* using the above Definition specification
*
IFILEIN NS 01 1 CA 2 CB
I 3 18 Partno
I 19 29 Name
I 30 40 Patno
A DSPSIZ(24 80 *DS3)
A R SFLREC SFL
A XNO 3S 0B 7 4
A XNAME 15A O 7 14
A XCRSE 10A O 7 34
A XFEES 5S 2B 7 52
A R CTLREC SFLCTL(SFLREC)
A CA03(03 'Exit')
A OVERLAY
A 30 SFLDSP
A SFLDSPCTL
A SFLSIZ(0006)
A SFLPAG(0005)
A 1 2DATE
A EDTCDE(Y)
A 1 72TIME
A 1 27'Students Information system'
A COLOR(WHT)
A 5 2'Student No'
A 5 15'Student Name'
A 5 32'Student Course'
A 5 50'Student Fee'
A R FOOTER
A 23 3'F3->EXIT'
A DSPATR(HI)
Rpg Program for the above sub file
All the bellow subfiles are in RPGIII
Declaration in RPGILE:
FSUB1 CF E WORKSTN SFILE(SFLREC:@rrn)
FSUB1 CF E WORKSTN
F @RRN KSFILE SFLREC
FPF1 IF E DISK
C WRITEFOOTER
C EXFMTCTLREC
C EXSR @CMD
C @CMD BEGSR
C *IN03 IFEQ *ON
C SETON LR
C RETRN
C ENDIF
C ENDSR
C @LOAD BEGSR
C READ STREC 50
C *IN50 DOWEQ*OFF
C MOVE STNO XNO
C MOVELSTNAME XNAME
C MOVELSTCRSE XCRSE
C MOVELSTFEES XFEES
C ADD 1 @RRN
C @RRN IFGT 9999
C LEAVE
C ENDIF
C WRITESFLREC
C READ STREC 50
C ENDDO
C @RRN IFGE 1
C SETON 30
C ENDIF
C ENDSR
C *INZSR BEGSR
C Z-ADD0 @RRN 40
C EXSR @LOAD
C ENDSR
Example :2 Expanding
A DSPSIZ(24 80 *DS3)
A R SFLREC SFL
A XNO 3S 0B 7 4
A XNAME 15A O 7 14
A XCRSE 10A O 7 34
A XFEES 5S 2B 7 52
A R CTLREC SFLCTL(SFLREC)
A CF03(03 'Exit')
A N99 ROLLUP(25)
A OVERLAY
A 30 SFLDSP
A SFLDSPCTL
A SFLSIZ(0006)
A SFLPAG(0005)
A 1 2DATE
A EDTCDE(Y)
A 1 72TIME
A 1 27'Students Information system'
A COLOR(WHT)
A 5 2'Student No'
A 5 15'Student Name'
A 5 32'Student Course'
A 5 50'Student Fee'
A R FOOTER
A 23 3'F3->EXIT'
A DSPATR(HI)
Rpg Program for the above sub file
FSUB2 CF E WORKSTN
F @RRN KSFILE SFLREC
FPF1 IF E DISK
C WRITEFOOTER
C EXFMTCTLREC
C EXSR @CMD
C @CMD BEGSR
C *IN03 IFEQ *ON
C SETON LR
C RETRN
C ENDIF
C *IN25 IFEQ *ON PAGE DOWN
C SETOF 25
C EXSR @LOAD
C ENDIF
C ENDSR
C @LOAD BEGSR
C DO 5
C READ STREC 99
C *IN99 IFEQ *ON
C LEAVE
C ENDIF
C MOVE STNO XNO
C MOVELSTNAME XNAME
C MOVELSTCRSE XCRSE
C MOVELSTFEES XFEES
C ADD 1 @RRN
C @RRN IFGT 9999
C LEAVE
C ENDIF
C WRITESFLREC
C ENDDO
C @RRN IFGT 0
C SETON 30
C ENDIF
C ENDSR
C *INZSR BEGSR
C Z-ADD0 @RRN 40
C EXSR @LOAD
C ENDSR
Example :3 Single Page Sub file
A DSPSIZ(24 80 *DS3)
A R SFLREC SFL
A XSTNO 3 0B 6 13
A XNAME 15 B 6 24
A XCRSE 15 B 6 42
A XFEE 5 0B 6 64
A R CTLREC SFLCTL(SFLREC)
A 50 SFLDSP
A 51 SFLDSPCTL
A 52 SFLCLR
A SFLSIZ(0004)
A SFLPAG(0004)
A PAGEUP(25 'UP')
A PAGEDOWN(26 'DN')
A 1 31'Single Page Subfile'
A COLOR(WHT)
A 4 10'Student No Student Name St-
A udent Course Course Fee'
A COLOR(WHT)
A R FOOTER
A CA03(03 'Exit')
A OVERLAY
A 23 3'F3 -> Exit'
A COLOR(WHT)
ileRpg Program for the above sub file
A DSPSIZ(24 80 *DS3)
A R SFLREC SFL
A XNO 3S 0B 7 4
A XNAME 15A O 7 14
A XCRSE 10A O 7 34
A XFEES 5S 2B 7 52
A R CTLREC SFLCTL(SFLREC)
A CF03(03 'Exit')
A N99 ROLLUP(25)
A N98 ROLLDOWN(26)
A 31 SFLCLR
A OVERLAY
A 30 SFLDSP
A SFLDSPCTL
A SFLSIZ(0005)
A SFLPAG(0005)
A 1 2DATE
A EDTCDE(Y)
A 1 72TIME
A 1 27'Students Information system'
A COLOR(WHT)
A 5 2'Student No'
A 5 15'Student Name'
A 5 32'Student Course'
A 5 50'Student Fee'
A R FOOTER
A 23 3'F3->EXIT'
A DSPATR(HI)
Rpg Program for the above sub file
FSUB3 CF E WORKSTN
F @RRN KSFILE SFLREC
FPF1 IF E K DISK
C WRITEFOOTER
C EXFMTCTLREC
C EXSR @CMD
C @CMD BEGSR
C *IN03 IFEQ *ON
C SETON LR
C RETRN
C ENDIF
C *IN25 IFEQ *ON PAGE DOWN
C SETON 31
C WRITECTLREC
C SETOF 31
C Z-ADD0 @RRN
C SETOF 25
C SETOF 98
C EXSR @LOAD
C ENDIF
*
C *IN26 IFEQ *ON PAGE DOWN
C SETON 31
C WRITECTLREC
C SETOF 31
C SETOF 26
C Z-ADD6 @DO 30
C ADD @RRN @DO
C *IN99 IFEQ '1'
C *HIVAL SETGTSTREC
C ENDIF
C DO @DO
C READPSTREC 26
C *IN26 IFEQ '1'
C SETON 98
C *LOVAL SETLLSTREC
C LEAVE
C ENDIF
C ENDDO
C Z-ADD0 @RRN
C EXSR @LOAD
C ENDIF
C ENDSR
C @LOAD BEGSR
C DO 5
C READ STREC 99
C *IN99 IFEQ *ON
C LEAVE
C ENDIF
C MOVE STNO XNO
C MOVELSTNAME XNAME
C MOVELSTCRSE XCRSE
C MOVELSTFEES XFEES
C ADD 1 @RRN
C @RRN IFGT 9999
C LEAVE
C ENDIF
C WRITESFLREC
C ENDDO
C @RRN IFGT 0
C SETON 30
C ENDIF
C ENDSR
C *INZSR BEGSR
C Z-ADD0 @RRN 40
C EXSR @LOAD
C ENDSR
Example : Update The file Which are modified in the subfile
UUUUUUUUUU Students Details - Update TT:TT:TT
DD/DD/DD
F2->Update F3->Exit
Example : Update The file Which are modified and Option field must be 'Y'in the subfile
UUUUUUUUUU Students Details - Update TT:TT:TT
DD/DD/DD
F2->Update F3->Exit
F2->Update F3->Exit
FASIFPF UF E K DISK
FSUB008FM CF E WORKSTN SFILE(SFLREC:@RRN)
D@RRN S 4P 0
C WRITE FOOTER
C DOW *IN03 = *OFF
C EXFMT CTLREC
C 03 LEAVE
C SETOFF 51
C READC SFLREC 51
C DOW *IN51 = *OFF
C XSTNO CHAIN ASIFPF 50
C EXSR $$EDIT
C UPDATE SFLREC
C IF *IN50 = *OFF
C AND *IN02 = *ON
C AND *IN99 = *OFF
C AND XOPT = 'Y'
C Z-ADD XSTNO STNO
C MOVEL XSTNME STNME
C MOVEL XSTADR STADR
C MOVEL XSTCRS STCRS
C Z-ADD XSTNO STNO
C UPDATE STREC
C ENDIF
C READC SFLREC 51
C ENDDO
*
C ENDDO
C SETON LR
C
C *INZSR BEGSR
C EXSR $$LOAD
C ENDSR
*
C $$LOAD BEGSR
C READ ASIFPF 50
C DOW *IN50 = *OFF
C Z-ADD STNO XSTNO
C MOVEL STNME XSTNME
C MOVEL STADR XSTADR
C MOVEL STCRS XSTCRS
C MOVEL STFEE XSTFEE
C ADD 1 @RRN
C IF @RRN>9999
C LEAVE
C ENDIF
C WRITE SFLREC
C READ ASIFPF 50
C ENDDO
C IF @RRN>=1
C SETON 30
C ENDIF
C ENDSR
*
C $$EDIT BEGSR
C IF XSTNME = *BLANKS
C SETON 9799
C ELSE
C SETOFF 97
C ENDIF
C ENDSR