RPG IV - Chapter 3

Download Report

Transcript RPG IV - Chapter 3

RPG IV
Defining Data with Definition
Specifications - Chapter 3
Objectives:
Define work fields, data structures and
other data items
Set the initial value for data items
Distinguish among program variables,
literals and constants
Definition Specifcations
Define all fields in your program
Specify name, length, and type
Input Specifications define fields from
database
Definition Specifications define work
fields or stand-alone fields
Numeric Literal
The literal may include a decimal point
and/or sign.
The sign must be the left most character
of the literal.
The literal may include digits 0 thru 9.
The literal should never contain commas,
dollar signs, or percent signs.
The literal must not be enclosed in
apostrophes.
Character Literals
To indicate that a value is a character
literal simply enclose it with
apostrophes.
Figurative Constants
*BLANK(S) - fills a character field with blanks
*HIVAL - fills a character with X’FFFF… (all bits
on), fills a numeric field with all 9s and + sign
*LOVAL - fills a character with x’000…(all bits
off), fills a numeric field with all 9s and - sign
*ZERO(S) - fills a numeric field with zeros
*ALL - causes a string to be repeated in a field
*OFF - character value of ‘0’
*ON - character value of ‘1’
*NULL- used with pointers
Assigning Initial Values to Data
Specify the value using the INZ
keyword in the fields definition
The value is indicated using a numeric
or character literal or a figurative
constant
Zoned Decimal and Packed
Decimal
Zoned decimal requires a full byte of
storage
Packed-decimal use a compressed
storage format
Integers and binary numbers require
even less memory than the decimal
data types do
Date, Time and Timestamp
Timestamp is a combination of date
and time
Define a standalone field, put a D (for
dates), T (for times) and Z (for
timestamp) in column 40
Indicator Data Type
Refered to in other languages as
Boolean data type
Code N in column 40
You can initialize to *ON or *OFF
Defining Constants
A named constant differs from a
standalone in two respects:
Its value never changes during
processing
It is defined with no specified length
Code the letter C, for constant, in
column 24
Enter the value in the Keywords area
Defining Data Structures
Subdivide fields into subfields
Change field data types
Data structure has two parts, the data
structure header and the definition for
the subfields
DS coded in 24-25 on D spec signals
the beginning of a data structure
Enter name of data structure in 7-21
Defining Data-Structure
Subfields
Absolute notation, uses From and To to
indicate the beginning and ending
postions of the subfield
Length notation, leaves From blank
and enters the subfield length in the To
positions
Length notation is prefered
Overlapping Subfields
Locations of subfields can overlap
Absolute notation clearly indicates the
overlap with the From and To
Length notation uses the keyword
OVERLAY
Points to Remember
RPG IV requires you to define all fields
your programs will use
Input fields are defined using Input
Specifications and standalone fields
are defined using Definition
Specifications
You can use the keyword INZ to assign
a value to a field
Points to Remember (cont)
Figurative constants are built-in literals
with specified values.
Definition Specifications are used to
define named constants as well as
standalone fields
RPG IV supports many data types;
character, numeric, date, and boolean
Data structures let you subdivide fields
into subfields and redefine fields