Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.
-
Upload
rosemary-hood -
Category
Documents
-
view
213 -
download
0
Transcript of Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.
![Page 1: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/1.jpg)
Presentation © Copyright 2002, Bryan Meyers
Defining Data with Definition Specifications
Chapter 3
![Page 2: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/2.jpg)
Programming in RPG IVThird Edition
2
Objectives
• Define work fields, data structures and other data items
• Identify the appropriate data type for data items
• Set the initial value for data items
• Distinguish among program variables, literals and constants
![Page 3: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/3.jpg)
Programming in RPG IVThird Edition
3
Definition Specifications
• Define all fields in your program• Definition specifications define work fields
(standalone variables)– Input specifications define fields from database– S in position 24 indicates standalone variable
• Specify name, length, and decimal positions (if any)
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D TotalDue S 7 2D CtyStZip S 40
![Page 4: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/4.jpg)
Programming in RPG IVThird Edition
4
Numeric Literal
• May include a decimal point and/or sign
• Sign must be the left most character of the literal
• May include digits 0 thru 9
• Should never contain commas, dollar signs, or percent signs
• Must not be enclosed in apostrophes
![Page 5: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/5.jpg)
Programming in RPG IVThird Edition
5
Character Literals
• To indicate that a value is a character literal simply enclose it with apostrophes
![Page 6: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/6.jpg)
Programming in RPG IVThird Edition
6
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
![Page 7: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/7.jpg)
Programming in RPG IVThird Edition
7
Assigning Initial Values to Data
• Specify the value using the INZ keyword in the field definition
• The value is indicated using a literal or a figurative constant
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D MaxLimit S 7 2 INZ(10500.00)D CompName S 40 INZ(‘Kay Elmnop Enterprises’)D HighLimit S 7 2 INZ(*HIVAL)
![Page 8: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/8.jpg)
Programming in RPG IVThird Edition
8
Zoned vs. Packed Decimal
• Zoned decimal requires a full byte of storage– Data type S in position 40
• Packed decimal use a compressed storage format– Data type P in position 40
• Integers and binary numbers require even less memory than the decimal data types do– Data type I (integer)– Data type U (unsigned integer)– Data type B (binary)
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D TotalDue S 7S 2D TotalDue2 S 7P 2D UpDown S 5I 0D RecCount S 10U 0
![Page 9: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/9.jpg)
Programming in RPG IVThird Edition
9
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– Do not specify length or decimal positions
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D EnrollDate S DD StartTime S TD TransTime S Z
![Page 10: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/10.jpg)
Programming in RPG IVThird Edition
10
Indicator Data Type
• Referred to in other languages as Boolean data type
• Code N in column 40
• Must be a single byte
• You can initialize to *ON or *OFF
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D InpError S N INZ(*OFF)
![Page 11: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/11.jpg)
Programming in RPG IVThird Edition
11
Defining Constants
• A named constant differs from a standalone in two respects– Value never changes during processing– Defined with no specified length
• Code the letter C, for constant, in column 24• Enter the value in the Keywords area
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D FICA C .0765D ExVicePres C 'John Adams'D PhoneEdtWd C '( ) - 'D IndDay C D'1776-07-04'
![Page 12: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/12.jpg)
Programming in RPG IVThird Edition
12
Defining Data Structures
• Subdivide fields into subfields• Change field data types• Data structure has two parts
– Data structure header– 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*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D OptName DSD SubfieldA 3 0D SubfieldB 5 2
![Page 13: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/13.jpg)
Programming in RPG IVThird Edition
13
Defining Data Structure Subfields
• Length notation– Leaves From blank and enters the subfield
length in the To positions
• Absolute notation– From and To indicate the beginning and
ending positions of the subfield
• Length notation is preferred
![Page 14: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/14.jpg)
Programming in RPG IVThird Edition
14
Overlapping Subfields
• Locations of subfields can overlap• Length notation uses the keyword OVERLAY
– Absolute notation indicates the overlap with the From and To
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8DName+++++++++++ETDsFrom+++To/Len+IDc.Keywords+++++++++++++++++++++++++++++D DSD Phone 10 0D AreaCode 3 0 OVERLAY(Phone)D Exchange 3 0 OVERLAY(Phone:4)D LocalNbr 4 0 OVERLAY(Phone:7) //Using OVERLAY with *NEXTD DSD Phone 10 0D AreaCode 3 0 OVERLAY(Phone)D Exchange 3 0 OVERLAY(Phone:*NEXT)D LocalNbr 4 0 OVERLAY(Phone:*NEXT)
![Page 15: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/15.jpg)
Programming in RPG IVThird Edition
15
Points to Remember
• RPG IV requires you to define all fields your programs will use
• Input fields (from files) are defined using Input Specifications
• Standalone fields are defined using Definition Specifications
• You can use the keyword INZ to assign a value to a field
![Page 16: Presentation © Copyright 2002, Bryan Meyers Defining Data with Definition Specifications Chapter 3.](https://reader036.fdocuments.in/reader036/viewer/2022081821/56649e225503460f94b0fc0f/html5/thumbnails/16.jpg)
Programming in RPG IVThird Edition
16
Points to Remember
• 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, Boolean, etc.
• Data structures let you subdivide fields into subfields and redefine fields