***************************************************************************
** The Program Development Menu and the Lattice RPGII Development System **
** by Richard W. Evans Spring 1999 **
***************************************************************************

Lattice has created a complete program development system using the RPGII language. The coding format has been designed to be the same as that used on the IBM System 36 midrange computer system. In fact, programs developed on the 36 can be downloaded to the PC and complied with the Lattice compiler for use on the PC. Likewise, development can occur on the PC in Lattice. The source from the PC can be uploaded to the System 36 and compiled for use on that system. What follows is an explanation of how to use the Lattice Development System for the CIS258 class.

All RPGII programing must be done on the PC's in the labs. RPG is loaded on the hard disk on the file server and is an option on the workstation menu. You must have two 1.44mb 3.5" floppy diskettes, a WORK diskette for your programs and data and a BACKUP diskette for a backup.

The PDM Menu screen:



1. Entering/changing a program:

Have your WORK diskette in drive A: and take option 1 off of the main menu. Enter the name of the source program. You are now in the Source Entry Utility program. Follow the instructions on the screen. F1 will pop up help screens. Be sure to SAVE your program before you QUIT or what you did will be lost!

2. Compiling and Linking a program:

Have your WORK diskette in drive A: and take option 2 off of the main menu. Enter the name of the source program. A list of the program as it is compiling will appear on the screen along with error messages. See the end of this file for a list of thee rror codes and reasons. The compiled program will be generated on your WORK diskette. To look at the compiled listing on the screen, take option D off of the main menu and enter the following command:

VIEW REPORT.PRR (Print File for RPG Source)

A complete list of all compile time error messages can
be found in the Lattice manuals located in the Lab. Refer to
those books regularly.

3. Entering/changing a screen:

Have your WORK diskette in drive A: and take option 3 off of
the main menu. Enter the name of the screen. You are now in the
Source Entry Utility program. Follow the instructions on the
screen. F1 will pop up help screens. Be sure to SAVE your
screen before you QUIT or what you did will be lost!

4. Compiling a screen:

Have your WORK diskette in drive A: and take option 4 off of the main menu. Enter the name of the screen. A list of the screen as it is compiling will appear on the screen along with error messages. The compiled screen will be generated on your WORK diskette. To look at the compiled listing on the screen,take option D off of the main menu and enter the following command:

VIEW REPORT.PRS (Print File for SCREEN Source)

5. Creating test files:

This diskette contains a complete set of data for runningthe homework that is assigned from the book.

To create your own data, take option 5 off of the main menu and enter the name of the data file. The .DAT extension will automatically be added. If the data file already exists, you will be allowed to change the data in it or add to it.

6. Screen Desgin Aid

This is an interactive delveopment program that allows you todesign RPG screens without having to write the screen format
code.

D. Running your program:

To run a test of your compiled program, take option D off of the main menu and enter the following command line:

{Program Name} {Program File Name}={Disk File Name}

Let's say you are testing the first assignment. You should have called the program RPG011. The name of the data file in the F-spec of your source program should have been NAFILE. The name of the test data set on disk is PE1.DAT. Therefore, the correct command line to test your program out would look like this:

RPG011 NAFILE=PE1.DAT

If you would like to test without printing, set the printer to
variable length in the F spec and change your command line to read:

RPG011 NAFILE=PE1.DAT,PRINT=PRINT.PRT

The printing will occur to disk instead of to the printer.

To look at your printed output on the screen, enter the DOS command:

VIEW PRINT.PRT (Print file for PRINTED output)

To print it on the printer use the DOS command:

TYPE PRINT.PRT > PRN.

D. Making Backups

To backup your WORK diskette, place it in drive A: and place your BACKUP diskette in drive B:. Take option D off of the main menu and enter the following DOS command: DISKCOPY A: B:. When completed, you will have a duplicate set of information on both your WORK and BACKUP diskettes. Make backups frequently.

=================
Evans Conventions
=================

The following is an example of what your first four lines of each program should look like.

H* description of your program PROGNAME
H*
H* Your Name mm/dd/yy
H*

The F-spec for your printed output should look like this:

FPRINT O V 80 OF PRINTER

Always use the file name of PRINT so all programs are alike. This makes following the logic of the program much easier later. The OF stands for overflow and tells RPG that you want to control the page skipping so that you don't print over the edge of a
page.

Here is an example of how to set up your printer O-specs for the automatic printing of page headings at the beginning of the program and at each overflow to a new page.



When you are setting up your fields for the printed report,
please use the following rules.

. Do NOT center your titles over the fields.
. Start all printing at the left margin (position 1).
. Left justify the first heading word.
. Left justify all headings for CHARACTER fields.
. Right justify all headings for NUMERIC fields on the right most digit.
. Right justify all date headings.
. Leave 2 blanks between fields, if possible.

Run Time Halt Messages:

Run time halt messages occur during program execution to let you know that an error has been detected. The following is an example of a halt message:

EXIT HALT #: 29 SPEC: I LINE: 00070

0 - CONTINUE 1 - SKIP 2 - CONTROLLED ABORT 3 - ABORT

In the example above, halt 29 refers to a numeric input error. The line number in the RPG source code that the field is defined is 00070. When a halt occurs, you have to take one of the available options in response to it. You may not have all four of the above options.

0 - Continue -- Control is returned to the program and processing continues
1 - Bypass -- The remainder of the program cycle is bypassed and the next record is read
2 - Controlled Abort -- LR operations are processed and the open  files are closed
3 - Abort -- The job is canceled

Run Time Error codes:

A copy of the Lattice manuals are available in the Lab for your use during the lab sessions. The following are a few of the error codes you might encounter when running your programs. The complete list of compile and run time errors will be found in the manuals.

Code Description

13 Divide by zero
14 Array index error
17 Too many entries for a table
18 Demand file at EOF or never opened
22 Duplicate add to an index file
27 Edit code error
28 Relative record number =< 0 during CHAIN
29 Input numeric field error
30 No record found for direct or indexed random file
31 File open error
32 File creation error
33 File read error
34 File write error
File close error
37 Format file not found
38 Format name not found; Could also indicate memory overflow in screen work area. Recompile screen using SFGR /O
41 File open error due to network violation
42 File creation error due to network violation
43 File read error due to network violation
44 File write error due to network violation
45 File close error due to network violation
50 Unidentified record
60 Record out of sequence
70 File out of matching record sequence
71 File not positioned for update
72 File not positioned for delete
73 Index file not opened
81 Short record error
82 Record length error
87 .DBF and .NDX mismatch
88 .DBF record length longer than F spec

ISAM File I/O Errors are distinguished by the letters DBC in parentheses. The error number references the user to the Lattice RPGII manual for more information. The following is a sample error message followed by a list of the frequently found error messages:

HALT (DBC) #:0203 FILE NAME: CUSTOMER.DBF
2-CONTROLLED ABORT 3-ABORT

In the above example, the program has not been able to locate the customer file on disk. The only options are to terminate with (2) or without (3) LR processing and normal file closings. This error might occur if the name of the file as specified in the F spec is not the same as it is on disk and the command line did not relate the two.

EG: the file name in the program is CUSTOMER and the name on disk is CUST. If the command to run the program was entered as LISTCUST, the program would be looking for a file called CUSTOMER.DBF. The proper command would be LISTCUST CUSTOMER=CUST. This tells the program that the file called CUSTOMER in the program will be found on disk with the name CUST.DBF.

2 - Controlled LR operations are processed and the open Abort files are closed
3 - Abort The job is canceled

File Error Messages:

202 Maximum number of .DBF files already opened
203 .DBF file open failure at the physical level
204 Failed to read the .DBF header. Rebuild the index.
401 Record number too big or zero
403 .DBF read failure at the physical level
702 Key in .NDX points to non-existent record or zero
1303 Failed to allocated dynamic memory
1305 Failed to create .NDX at physical level
1402 Maximum number of .NDX files already opened
1403 .NDX file open failure at the physical level
1404 Failed to read .NDX
1405 File cannot be recognized as .NDX
1406 Failed to allocate dynamic memory opening .DBF
1590 .NDX file is not open
1701 Requested key not found in .NDX
3301 Memory allocation problem
8203 Network error: record locked for update

H. Help Screens

The H option off of the main menu brings up a series of help screens. You may print these help screens by taking option D off of the main menu and entering the following command at the DOS
prompt:

TYPE J:\EVANS\RPGHELP.TXT > PRN

To print this help text:

TYPE A:RPGHELP.TXT > PRN

X. Ending a Session

When you are finished, take option X off of the main menu. DO NOT turn the workstation off. Be sure to take your diskettes out of the machine, clean up your work area, and take any printed reports from the printer.

XI. RPG Compile Time Errors Codes:

W = Warning error
T = Terminal error
I = Informative message

W 005 Invalid debug code in column 15, assume blank.
W 006 Control specification was previously defined. Current specification is ignored.
W 010 Invalid entry in column 18, assume blank.
W 011 Must be blank(S), assume blank(S).
W 014 Invalid alternate collating sequence entry in column 26, assume S.
W 016 Invalid 1P entry in column 41, assume 1.
W 018 Invalid file translation entry in column 43, assume F.
W 020 Invalid dismount entry in column 46, assume M.
T 022 Invalid entry in column 6 or specification type out of sequence.
T 023 Invalid or blank filename in columns 7-14.
T 024 Filename previously defined in columns 7-14.
W 025 Invalid device name in columns 40-46, assume disk.
W 026 Invalid or blank file type entry in column 15, assume default for device.
W 027 Position 19 in control specification not blank, M, D, or Y, assume M.
W 028 File designation in column 16 is invalid for either file type or device, assume secondary.
W 030 File designation entry in column 16 invalid for output file, assume blank.
I 032 No primary file specified in column 16, assume first secondary as primary.
W 034 Multiple primary files defined in column 16, assume secondary.
W 036 Invalid end of file entry in column 17, assume blank.
W 037 Invalid file format entry in column 19.
W 038 End of file entry in column 17 invalid for file type.
W 039 Invalid sequence entry in column 18, assume blank.
W 040 Sequence entry in column 18 invalid for type of file or mode of processing. Assume blank.
W 041 Invalid record length entry in columns 24-27, assume default for device.
W 042 Invalid block length entries in columns 20-23, assume record length.
T 044 Invalid entry in column 32.
W 045 Overflow indicator in columns 33-34 previously defined, assume blank.
W 046 Invalid overflow indicator in columns 33-34, assume blank.
W 047 Overflow indicator in columns 33-34 invalid for type of file, assume blank.
W 048 Invalid or blank extension code entry in column 39 for table file or record address file, assume E.
W 049 Invalid extension code entry in column 39, assume L.
W 051 Extension code entry in column 39 invalid with P, S, C, or D in column 16, assume blank.
W 055 File conditioning entries in columns 71-72 invalid for table files or keybord, assume blank.
W 057 Invalid file conditioning entries in columns 71-72.
T 064 Invalid or undefined to filename in columns 19-26.
T 067 Invalid table or array name in columns 27-32.
T 068 Invalid or missing number of entries per record entry in columns 33-35.
T 070 Invalid or missing number of entries per table or array in columns 36-39.
T 071 Number of entries per record in columns 33-35 exceeds number of entries per Table/Array in columns 36-39.
T 072 Invalid or missing length of entry in columns 40-42 or 52-54.
T 073 Length specified for each Table/Array record, in columns 33-35 and 40-42 or 52-54, exceeds record length.
W 074 Invalid packed or binary entry, assume blank.
W 075 Packed or binary valid only for pre-execution time tables or arrays.
W 076 Invalid decimal position entry assume 0.
W 077 Invalid sequence entry in column 45 or 57, assume blank.
T 079 Invalid alternate Table/Array name in columns 46-51.
W 080 Alternate Table/Array name in columns 46-51 and/or 27-32 missing for entries in columns 33-45 or 52-57, assume blank.
T 082 Length of Table/Array in columns 40-42 or 52-54 exceeds maximum.
T 085 Invalid, missing or undefined filename or data structure.
W 087 Form length entry in columns 15-17 invalid or greater than 112.
W 088 Invalid or missing form length entry in columns 18-19, assume FL.
W 089 Overflow line entry in columns 20-22 invalid or greater than form length.
W 090 Invalid or missing overflow line entry in columns 23-24, assume OL.
W 093 File and record type entries and field type entries are in the same line.
T 094 File and record type description must precede this specification.
T 095 AND or OR line out of order.
T 096 AND line follows line with no record identification codes.
I 097 No field described for previous record or data structure.
W 098 Invalid sequence entry in columns 15-16, assume alphabetic sequence entry.
W 101 Numeric sequence entry in columns 15-16 not in ascending order or the first is not 01.
W 102 Invalid number entry in column 17 for numeric sequence, assume N.
W 103 Invalid option entry in column 18 for numeric sequence, assume O.
W 104 Number/Option entries invalid with alphameric sequence entries. Entries not specified correctly for data structure.
W 105 Position for record identification code is missing.
T 106 Invalid position entry for record identification codes in columns 21-24, 28-31, 35-38, or to position in columns 48-51.
W 107 Invalid NOT entry in column 25, 32, or 39, assume N.
W 108 Invalid C/Z/D entry in column 26, 33 or 40, assume C.
W 111 Invalid P, B entry, assume blank.
T 112 Invalid or blank FROM and/or TO entry in columns 44-51.
T 113 FROM entry in columns 44-47 exceeds TO entry in columns 48-51.
W 115 Field specified as packed or binary illegally, assume blank.
W 117 Decimal position in column 52 invalid for array, assume blank.
T 118 Field name in columns 53-58 missing or invalid.
W 119 Invalid control level indicator in columns 59-60, assume blank.
W 120 Invalid matching field entry in columns 61-62, assume blank.
T 121 From file cannot have an E in column 17 of file description specification when to file is a demand file.
W 122 Field was previously defined with different length or decimal positions, or field was already defined in a data structure
W 123 Invalid control level entry in columns 7-8.
T 125 Invalid field name or constant.
T 126 Illgal syntax for table, array, lable, subroutine, or file name.
W 127 Field length entry in columns 49-51 invalid with no result field, assume 49-51 blank.
T 128 Invalid operation code in columns 28-32.
T 132 Factor 2 must be a filename.
W 133 Numeric field length exceeds 15, assume 15.
W 134 Alphameric field length exceeds 256, assume 256.
W 137 Invalid result field length in columns 49-51, assume 15 for numeric or 256 for alphameric field.
W 138 Decimal position entry in column 52 invalid with no field length entry
in columns 49-51, assume blank.
W 140 Invalid half adjust entry in column 53, assume H.
W 141 DEBUG calculation operation used but debug option not specified in the control specification.
T 143 Invalid line type in column 15.
T 144 AND or OR line not preceded by record identification.
W 145 Invalid Skip/Space entries in columns 17-22 for AND line, assume blank.
T 146 Invalid Filename in Columns 7-15 on the output specification
W 148 Invalid field name in columns 32-37.
W 149 Invalid or missing constant.
W 150 Invalid blank after entry in column 39, assume blank.
W 153 Blank or illegal end position was specified. End position was calculated.
W 154 Entries in columns 7-22 invalid for a field description specification, assume blank.
T 158 Table name invalid for field name entry in columns 53-58.
W 159 Missing record identifying indicator in columns 19-20.
T 161 AND or OR line invalid with data structures, or RLABL.
W 162 Record identifying indicator in columns 19-20 invalid for an AND line.
W 163 Entries in column 17-18, 21-42 or 55-74 invalid for look ahead record/field or for field in a data structure.
W 165 Indicators in columns 65-70 invalid for whole array or field defined as data structure. Blank is assumed.
W 166 Plus or minus indicator in columns 65-68 invalid for alphameric field.
W 169 Control or matching fields invalid for an array or data structure.
W 170 Matching or control fields invalid with demand or chain files.
W 171 Look ahead records invalid with file type, or with this device.
W 173 No fields specified for look ahead record.
W 174 Limits file not processed by record address file or SETLL operation.
T 175 Invalid file type for SETLL operation.
W 178 Binary invalid with control or matching fields.
T 179 Array length specified in data structure not large enough to contain array as specified in extension specs.
W 181 Inconsistent field length for control or matching fields of one level.
T 182 Invalid split control field specification.
W 183 Control or matching fields of a level specified as both alphameric and numeric. Assume numeric.
W 184 All of the valid match levels were not referenced in the last record group.
T 186 Match/control fields without field record relation must precede match/control fields with field record relation.
T 187 Match/control fields with field record relation must be grouped according to the field record relation indicator.
W 188 Field record relation indicator used improperly with match or control field.
T 189 Invalid sequence for calculation specifications.
T 190 Invalid sequence for BEGSR and ENDSR operation codes.
T 191 A subroutine must not call itself.
T 193 Branching between detail, total, LR and subroutine calculations invalid.
W 194 SETOF operation invalid for LR indicator.
W 195 Length of search word not equal to length of element in table or array.
T 196 Factor 2 or result field invalid for LOKUP operation code.
W 197 Search table has more entries than its related table.
W 198 Indicator entered in columns 54-57 invalid with LOKUP on an unsequenced table or array.
W 199 Test for both high and low invalid for LOKUP operation.
Low indicator is ignored.
W 200 Resulting indicators in columns 54-59 required or not allowed for
operation specified.
W 201 Half adjust entry in column 53 for division operation followed by an MVR operation, assume no half adjust.
T 202 MVR operation code does not follow DIV operation.
T 203 SUBST operation code has no second line.
W 204 Half adjust entry in column 53 invalid for operation or number of decimal positions specified, assume blank.
T 205 COMP, TESTZ, or MVR invalid for an array.
T 206 Invalid comparison of factor 1 and factor 2
T 207 Field type, alphameric or numeric, invalid for operation specified.
T 208 FORCE operation invalid at total time.
T 209 File type invalid for use with this operation code.
W 212 EXCPT operation code specified but no exception output records specified.
T 213 Program contains unassociated or missing EXSR/BEGSR label.
T 214 GOTO branches to a BEGSR name.
T 215 Factor 1, factor 2, or result field entry missing.
T 216 Factor 1, factor 2, or result field entry invalid for this operation.
T 219 Result field entry in columns 43-48 missing.
T 220 Result field entry in columns 43-48 invalid for this operation.
W 221 Result field length may not be large enough.
W 222 Constant has no ending quote.
T 223 Subroutine specifications are the only calculation specifications
specified.T 224 Zero constant is invalid as a divisor in columns 33-42.
W 225 Conditioning indicators in columns 9-17 invalid with TAG, BEGSR, ENDSR or RLABL operation. Blank is assumed.
T 226 A reserved word other than PAGE invalid.
T 227 Result field in columns 43-48 is a look ahead field or constant.
T 228 Invalid index.
T 229 Indexing invalid for tables or fields.
T 231 GOTO does not branch to a TAG.
T 232 This name was previously used on a TAG, BEGSR or ENDSR.
W 256 1P indicator invalid with total or except records.
W 258 Space and/or skip entries in columns 17-22 invalid for device, assume blank.
W 259 Skip entries in columns 19-22 invalid or greater than form
length specified, assume blank.
W 260 Invalid space entries in columns 17-18, assume blank.
W 261 Fetch overflow entry in column 16 invalid for device, assume blank.
W 262 Overflow indicator invalid for an except record or with LR. assume blank.
W 263 Fetch overflow invalid with overflow indicator entered in columns 23-31, assume no fetch.
W 264 Overflow indicator used is not assigned to this file.
W 266 Fetch overflow invalid with 1P indicator, assume no fetch overflow.
W 267 1P indicator invalid for combined files. assume blank.
W 269 Invalid indicators used in an AND relationship with 1P.
T 270 End position entry in columns 40-43 for constant, data structure, edit word, field, or table/array exceeds record length.
I 272 End position entry in columns 40-43 for constant, edit word, field, data structure, or array too low.
W 273 Output indicators in columns 23-31 missing or all negative.
T 274 Indicators missing for an AND or OR line.
W 275 Conditioning indicators columns 23-31, may not be specified on the output line containing the WORKSTN format name.
W 276 Invalid edit code in column 38. Blank is assumed.
T 277 Invalid edit word size.
W 278 Edit codes invalid with fields other than unpacked numeric fields, constants other than '*' currency symbol.
T 279 Constants in columns 45-70 invalid for X, Y and Z edit codes.
W 280 Field length for Y edit code less than 3 or greater than 6. If greater than 6, only low order 6 digits are edited.
W 281 Decimal positions invalid for field edited by Y code.
W 282 Name of field to be edited, by code specified in column 38, missing.
T 283 Invalid file type for output record.
T 287 Columns 32-37 not blank when 40-43 is K1-K8.
T 290 *PLACE precedes all field names and constants.
W 291 Invalid entries in columns 38, 39, or 44-74 for output operation, assume blanks.
W 293 Blank after specified for a constant.
W 295 Invalid entry in column 16, assume blank.
T 296 Format name for WORKSTN file output required but missing, or multiple format names specified for one output record.
T 300 Value of array index exceeds number of array elements.
W 304 Invalid indicator or improper use of a valid indicator. Blank is assumed.
W 305 Indicator assigned but not used to condition operations.
T 306 Indicator used to condition operations but not assigned.
W 307 Filename defined but never used. Specification is dropped.
W 308 Sequencing invalid for file with no match field, assume column 18 on file description specification blank.
W 309 Sequence entry invalid or blank for file with match field specified, assume first valid sequence or A.
W 310 Extension code specified in column 39 on file description specification for this file but E specification missing.
W 311 A line counter spec. was provided for this file but an extension code was not entered in column 39 of the file spec.
W 314 Field, table or array name defined but never used.
T 315 Field name used but never defined, or table name or array element used as an array index.
T 316 Invalid definition for reserved word.
T 317 Number of decimal positions specified exceeds field length.
W 318 Missing a record conditioned by 1P and forms positioning specified on control specification.
W 319 No data for alternate collating sequence or file translation.
W 320 Invalid alternate collating sequence data record.
T 321 Invalid, undefined or a table filename on file translation data record.
W 322 Alternate collating sequence or file translation data invalid.
T 323 Table, array name specified more than once on extension spec. Data structure specified more than once on input spec.
W 325 All primary and secondary files are conditioned by external indications.
W 326 Compile time tables specified but no data found.
T 327 Split control fields may not have parts that are packed.
I 331 No input specifications found.
T 332 Sequence error found in compile time Table/Array.
W 333 Table/Array full or no Tables/Arrays for following data.
W 334 Short table.
W 335 Edit word specified with other than unpacked numeric fields.
W 336 Filename defined but never used. specification dropped.
T 337 Invalid sequence for EXIT and RLABL operation codes.
W 339 An output reference is required for each update file, or if add is specified.
W 374 Entry in column 16 invalid.
W 392 Last entry in one or more compile time Table/Arrays was blank.
W 394 ADD or DEL in columns 16-18 not allowed on AND/OR lines, assume blank.
T 400 Invalid mode of processing entry in column 28.
T 402 Combination of processing mode is illegal.
T 403 Invalid length of key field in columns 29-30.
T 404 Invalid record address type entry in column 31.
T 405 Invalid key start location entry in columns 35-38.
W 407 Invalid file addition entry in column 66, assume A.
W 408 Number of data blocks in columns 68-69 is invalid or not allowed with this device.
T 451 Continuation, K in column 53, invalid for device or file type
W 452 Entry in columns 54-59 is invalid or missing
W 453 Continuation entry in columns 54-59 is repeated for a file. Second entry is ignored.
W 454 Entry in columns 60-65 is invalid, assumed 1 or blank.
T 502 From filename is a record address file that is used more than once.
T 503 To file for a RA file is either 1) not a primary, secondary, or demand file, or 2) missing, or a non-disk file.
W 510 Length given for binary field is not 1 to 4. Assume 4.
W 511 Packed length greater than 8 for a field, table or array. Assume 8.
T 519 Columns 18-59 are invalid with AN/OR lines, or operation code is missing with indicators present. Assume blank.
T 520 This line is not an AN/OR line and previous line has no op. code or this line has no indicators and no op. code.
W 521 Minus indicator not allowed for test bit operation of only one bit.
W 522 All three resulting indicators are the same.
T 523 A negative factor for the square root operation is not allowed.
T 524 Whole arrays are no allowed as factor 1 with CHAIN or LOKUP operation code.
T 525 Operation code is invalid for device type or mode of processing.
T 527 Whole arrays or tables cannot be specified in factor 2.
T 528 Factor 2 of SUBST operation has non-zero decimal position. assume zero.
T 528 Factor 2 must be a 6 position alphanumeric field or array element with the EXDSR operation code.
W 541 File designation is invalid for addrout file, assume R.
T 543 Length of key, columns 29-30, or length of key and key start location greater than record length.
T 544 Length of record address field or key field, columns 29-30, blank or invalid.
W 548 File Addition/Deletion invalid for file type, device, or mode or processing, assume blank.
T 551 Record length missing or invalid for disk file.
W 554 Add specified on the file description specifications but add not referenced on output.
W 555 No add specified on file description.
T 557 Mask for bit operation is not 0-7.
W 558 Invalid use of, or missing, resulting indicators with this operation code. Assume invalid resulting indicators blank.
T 559 Factor 2 or the result field is invalid for specified operation code.
T 561 Key field start location columns 35-38 given but not allowed, assume blank.
T 562 File type for from filename and/or to filename invalid with Table/Array.
T 565 Column 31 invalid for device type.
T 566 Invalid use of device as from filename.
W 568 Length of key field or record address length, columns 29-30, given but not allowed, assume blank.
T 570 Look ahead with numeric sequence or look ahead follows a numeric record.
T 571 More than one look ahead record in a file, or look ahead not valid in a data structure.
T 572 Look ahead cannot be the only record in a file.
T 573 Multiple record address files defined.
T 574 External indicator, columns 71-72, not the same as record address file.
W 576 Compile time table data found. Compile time table or array not specified in extension specifications.
T 577 Only one file associated with record address file is allowed in a program.
T 578 A record address file or a file associated with a record address file is required but not defined.
T 580 Referenced a match level which is not valid, or defined a level more than once.
W 582 The relative record number for the CHAIN operation must be numeric with zero decimal.
W 585 Chain or demand file specified, but appropriate operation code not found in the calculation specifications.
T 587 If factor 1 or factor 2 is a whole array, the result field must be a whole array.
T 591 Length of field in factor 1 not equal to key length of file specified in factor 2.
T 592 For sequentially processed update file, T entry in column 15 is invalid.
T 594 To filename may not be used with execution time array.
T 595 Columns 27-32 and 46-51 must be both table or both array names.
W 597 End position specified for *PLACE less than twice that of highest end position previously specified.
W 598 Alphanumeric Table/Array specified as packed. Assume numeric.
T 603 Input specifications invalid for KEYBORD file.
T 604 Invalid or missing message indicator specified on SET or KEY operation.
W 609 KEYBORD specified as primary file, but function never used.
W 610 Only command key indicators valid as resulting indicators on SET operation.
T 614 Operation requires KEYBORD specification on file description.
W 616 KEYBORD and WORKSTN must have primary, secondary, or demand designation. Assume demand.
T 632 SET or KEY operation specified with no function.
T 646 Whole array invalid for specified operation code.
W 647 Unequal key lengths specified for keys of identical format.
T 650 Compile time arrays overlap arrays in the same data structure.
W 656 Record information or data structure specified on same
specification as field type entries for a data structure.
W 657 Sequence entry in columns 15-16 must be blank for a data structure.
W 658 Columns 21-74 must be blank for a data structure.
T 660 Data structure name invalid in calculations except with RLABL.
W 707 Result field must be either a 6 or 12 position numeric
field when using TIME operation code.
W 720 Column 15 is not C for WORKSTN file, assume C.
T 721 More than 1 WORKSTN file is invalid.
T 722 CONSOLE/KEYBORD/CRT files are not allowed with WORKSTN file.
T 725 Columns 60-65 do not contain a valid field name for a continuation record
T 728 Block length must be blank for WORKSTN, assume blank.
T 801 AND line is invalid for this device.
W 802 Record identification codes in columns 35-41 are not allowed with this device.
T 803 Invalid or blank entries in columns 21-34 for this device.
T 804 Inconsistent record identification code usage on OR line.
T 806 Invalid or no record identification indicator defined.
T 807 Field length defined for record identification is not length of identification.
T 808 Invalid start position for first field to be prompted.
T 809 Invalid FROM or TO entry in columns 44-51 for field prompt description.
W 810 Field record relation indicators, columns 63-64, are invalid with a prompt field.
T 811 Length of prompt field in columns 44-51 exceeds limit. Maximum field lengths - alphanumeric 66, numeric 15.
T 813 Record identification indicators must be unique.
T 815 A CONSOLE file must have at least 1 prompt field.
T 816 Factor 2 must be a console file for a valid result field entry.
T 817 Factor 2 given on SET operation without result field entry 'ERASE'.
W 818 Invalid entry in columns 49-51.
T 821 Multiple CONSOLE files defined but only one is allowed.
W 822 CONSOLE can only be an input file. Assume input.
T 828 Whole array name invalid for field name entry in columns 53-58 for CONSOLE file.
W 901 Nested copy file is invalid.
W 903 Copy file not found.
T 950 This opcode 'END' must follow a DO, DOWxx, DOUxx, or IFxx.
T 952 The opcode 'END' is required for CASxx operation group.
T 954 The structured opcode specified in Detail/Total/LR/subroutine must be specified by an END within each Calculation time.
T 956 The operation code 'ELSE' must follow and match with the operation code IFxx.
T 958 Factor 1 must contain the entry '*LIKE' for DEFN op code.
T 959 Factor 2 must contain the name of the field that provides the attributes for the field being previously defined.
T 970 EXCPT name is defined in the output spec., but never specified in the calculation spec.
T 972 EXCPT name is specified in the calculation spec., but never defined in the output spec.
T 988 Invalid standard collating sequence. It must be one of A, E, or blank.
T 989 E is invalid with PRINTER, CRT, CONSOLE, KEYBORD, WORKSTN, ISAM, ADDROUT, or variable record type file
T 999 Internal error.


XII. OPERATION CODES

Add (ADD)

The ADD operation code performs simple addition involving the values in factor 1, factor 2, and the result field. The result field contains the sum of the operation, while factor 1 and factor 2 remain the same after the operation. Factor1 may be blank. When factor 1 is missing, factor 2 and the result field are added together and the sum replaces the old result field value.

Zero and Add (Z-ADD)

The Z-ADD operation code is a special addition operation, which adds zeros to the result field before adding the value in factor 2 to make the sum. This will reset the result field to equal factor 2. Factor 1 should be blank.

Subtract (SUB)

The SUB operation code performs simple subtraction involving the values in factor 1, factor 2, and the result field. The value in factor 2 is subtracted from the value in factor 1. The result field contains the value of the operation, while Factor 1 and factor 2 remain the same after the operation. Factor 1 may be blank. When factor 1 is missing, factor 2 is subtracted from the result field and the result replaces the old result field value.

Zero and Subtract (Z-SUB)

The Z-SUB operation code is a special subtraction operation,
which causes the value in the result field to be set to zeros
before subtracting factor 2. The result of the operation sets the
result field value to a value opposite factor 2, or simply
changes the sign of factor 2. Factor 1 should be blank.

Multiply (MULT)

The MULT operation code performs simple multiplication involving
factor 1, factor 2, and the result field. The result field
contains the product of the operation, while factor 1 and factor
2 remain the same after the operation. Factor 1 may be blank.
When factor 1 is missing, factor 2 and the result field are
multiplied together and the product replaces the old result field
value.

Make sure the result field is large enough to contain the product
or digits may be truncated if the result overflows the field.

Divide (DIV)

The DIV operation code performs simple division involving factor
1, factor 2, and the result field. Factor 2 is considered the
divisor and factor 1 the dividend (i.e., factor 1 is divided by
factor 2). The result field contains the value of the operation,
while factor 1 and factor 2 remain the same after the operation.
Factor 1 may be blank. When factor 1 is missing, factor 2 is
divided into the result field and the result replaces the old
result field value.

A zero value is not valid for factor 2. If factor 2 is zero, the
program will issue a run-time halt message to the operator.
Factor 1 or the result field may be zero, but the result of the
operation will also be zero.

The result of the DIV operation is an integer value, and any
remainder is lost unless the following operation is a MVR
operation. You may use half adjust to round values to the next
integer. However, half adjust cannot be used in conjunction with
a following MVR operation.

Move Remainder (MVR)

The MVR operation code is a special operation for use with DIV
operations. The MVR operation must follow a DIV operation. It
takes the remainder of the DIV operation and moves the value to
the result field. Factor 1 and factor 2 should be blank.

The result field or MVR value is limited to 15 places including
decimal positions, but will be dependent on the field definitions
for the previous DIV operation. The total number of possible
integer positions is equal to or less than the value in factor 2
of the DIV operation. The number of decimal positions can be
equal to the field in factor 1 or the sum of the decimal
positions in factor 2 and the result field,

Cross Foot (XFOOT)

The XFOOT (CROSS FOOT) operation code is a special operation for
numeric arrays. The XFOOT operation causes each item in the
array to be totaled together and the sum placed in the result
field. Factor 1 should be blank.

The result field may be an element in the factor 2 array. In
this case, the value in the element before the start of the XFOOT
operation is used in the total.

Move (MOVE)

The MOVE operation code causes the contents of factor 2 to be
moved to rightmost positions of the field in the result field.
Factor 1 should be blank.

Characters are transferred from the field in factor 2 to the
result field starting from the right. Thus, if the field in
factor 2 is longer than the result field, only the right-hand
portion of the field in factor 2 is transferred.

If the field in factor 2 is shorter than the result field, the
characters from factor 2 will be moved to the rightmost portion
of the result field. The excess characters on the left in the
result field will not be changed. For example:

Move Left (MOVEL)

The MOVEL operation code moves data in the opposite direction of
MOVE. The contents of the field or the literal present in factor
2 are moved to the leftmost positions in field in the result
field. Factor 1 should be blank.

This operation differs from MOVE in that MOVEL starts moving the
characters in factor 2 from the left and places them
left-justified in the result field.

Compare (COMP)

The COMP operation code performs a simple comparison test on
factor 1 and factor 2. The result of the test determines the
status of the indicators in columns 54-59. One resulting
indicator position must be used in the operation, and the result
field should be blank.

Before the comparison test starts, all indicators in columns
54-59 are turned off. Then, the indicator representing the
condition matching the test results is turned on.

The values used in testing must be the same type, either both
alphanumeric or both numeric. Any valid field, table or array
element, or literal may be used. Alternate collating sequences
will be applied to alphanumeric fields before the comparison.

The comparison begins with the leftmost character of each value.
When using alphanumeric fields, a shorter value is filled with
blanks to the length of the longer before comparing data. When
using numeric fields, the values are aligned at the decimal
position and filled with zeros for missing digits.

Compare and Branch (CABxx)

The CABxx operation code is an extension of the COMP operation
and tests fields for certain conditions. The outcome of the test
is a transfer of program control to a specified point within the
program.

The operation is based upon a comparison of two factors, the
result is then tested against the suffix of the operator CABxx
where xx represents the suffix. Factor 1 and factor 2 can
contain:

A character literal
A numeric literal
An array element
A table element
A data structure subfield
A field name

When the comparison result agrees with the test specified by the
operator suffix, a branch will be made to the TAG operation
associated with the label specified in the result field.

The CABxx operator suffixes are specified as follows:

GT Factor 1 is GREATER THAN factor 2
LT Factor 1 is LESS THAN factor 2
EQ Factor 1 is EQUAL TO factor 2

Set On (SETON)

The SETON operation code causes any indicators in columns 54-59
to be turned on.

Set Off (SETOF)

The SETOF operation code causes the indicators in columns 54-59
to be turned off.

GOTO

The GOTO operation code performs a branch operation to the label
specified in factor 2. Factor 1, the result field, and resulting
indicators should all be blank. The name in factor 2 may be up
to 10 characters long.

TAG

The TAG operation code works in conjunction with a GOTO or CABXX
operation, and performs no operation itself, but merely specifies
reference points for these other operations. The name in factor
1 of the TAG statement becomes a label that must have at least
one corresponding GOTO or CABxx operation. Conditioning
indicators, factor 2, the result field, and resulting indicators
should all be blank. Only control level indicators may be used
to specify total calculation branch labels.

The label name in factor 1 may be up to 10 characters, and must
follow standard RPG naming conventions.

CASxx

The CASxx operation code operates like a COMP and EXSR operation
together. The CASxx operation compares factor 1 and factor 2
according to the relationship given in the xx portion. If factor
1 and factor 2 satisfy the xx relationship, the subroutine
specified in the result field is executed. When no relationship
is given an unconditional execution of the subroutine occurs.

You may build a CAS group of CAS operations. However, this
nested group of CAS operations must contain only CAS operations,
and only one END statement should follow the last CAS operation
in the group to delineate the end of the CAS group. Control is
passed from one CAS operations to the next until a subroutine is
chosen out of the CAS group for execution or an END statement is
encountered. When the subroutine finishes control returns to the
next operation after the END statement of the CAS group. Unlike
DO groups the END statement may not be condition by indicators.

Resulting indicators may also be used, which will be set
according to the comparison results.

DO

The DO operation code performs a loop task a specified number of
times. The loop starts with the DO operation and ends with the
END statement.

All the calculations in the DO loop are repeated until the limit
value in factor 2 is met. Factor 1 contains a numeric literal or
field to specify the starting value. If factor 1 or factor 2 has
no value, the starting or limit value for the loop defaults to 1.

The result field holds the index value. Each time the DO loop is
performed the value in the index field increments until the limit
value is reached. If the result field is blank, the compiler
will generate a default index field. A numeric literal cannot be
used as an index field. The index value is always set to the
starting value in Factor 1 when the DO loop begins. The index
value increments according to the value in factor 2 of the END
statement. The default increment value is 1.

Both the DO operation and the END statement may be conditioned by
indicators. Conditioning indicators for the DO operation are
checked only at the start of the operation. If the indicators
are in the correct status, the DO loop is executed. Conditioning
indicators for the END statement are checked each time at the end
of the DO loop. If the indicators are in the correct status, the
DO loop continues; if not, processing continues with the next
calculation following the END statement.

Note the following when using DO loops:

If the limit value is not equal to or greater than the starting
value, the loop will never be executed.

If the increment value in the END statement is set to a negative
or zero value, the DO loop will never end, and you will have to
reboot your PC to abort the program.

A DO loop can be terminated by changing the index value,
increment value, limit value, or conditioning indicators on the
END statement.

The default index field has a length of 15, and by specifying a
shorter index field you can save memory.

The following are valid entries for factor 1, factor 2 on both
the DO and END operation codes, and the result field excluding
one:

A numeric literal (not valid in the result field)
A numeric field name
A table name
A data structure subfield with zero decimal positions
An array element

DOUxx

The DOU operation code specifies a do-until operation loop. The
loop is performed at least once unless conditioned by indicators,
and continues as long as the condition given in xx is
unsatisfied. The comparison between factor 1 and factor 2 takes
place when the END statement is encountered. If the relationship
between factor 1 and factor 2 is met, processing moves on to the
next operation following the END statement. If the relationship
is not true, processing repeats the operations in the DOU group.

Both factor 1 and factor 2 must be of the same data type, but may
contain character or numeric literals, a field name, an array or
table element, or a data structure subfield. They cannot be
blank.

The DOUxx and END operations may be conditioned by indicators.
If there are conditioning indicators on the DOU operation, they
are checked only at the start of the DOU loop. If conditioning
indicators are used with an END statement, the END operation is
performed only if the correct indicators are true. Control
passes to the next operation following an END statement when
conditioning indicators are not true.

An ELSE statement cannot be conditioned by indicators unless it
is a part of an lfxx operation in total calculations. You may
use LO, Ll-L9 or LR for documentation purposes only.

Every IFxx/ELSE operation must be closed with an END statement.

DOWxx

A variation on the DOUxx operation, this operation tests
the relationship between the two factors before further
processing of subsequent instructions. Subject to the
specified condition being met, processing will continue
within the DOW group until an END instruction is encountered.
When the END operation is performed, processing returns
to the DOW statement for another comparison of the factors.

Both factor 1 and factor 2 must be of the same data type,
but may contain either:

A character literal.
A numeric literal.
A field name.
An array or table element.
A data structure subfield.
Neither factor 1 or factor 2 can be blank.

The DOWxx and END operations may be conditioned by indicators.
If there are conditioning indicators on the DOW operation,
they are checked only at the start of the DOW loop. If
conditioning indicators are used with an END statement, the
END operation is performed only if the correct indicators
are true. Control passes to the next operation following
an END statement when conditioning indicators are not true,
and the DOW operations are performed only once.

END

The END instruction signifies the finish of a CASxx, DO, DOUxx,
DOWxx or IFxx group. There are differences in the format and
function depending on the operation code.

For DO, DOUxx and DOWxx operations, the END statement may be
conditioned by indicators. If conditioning indicators are used
with the END instruction, then the END operation is performed
only when the indicators are true. If they are not true,
processing continues with the next operation following the END
statement.

In the case of the DOUxx operation the END operation compares the
two factors before returning control to the DOUxx statement.
With the DOWxx operation, an END instruction merely returns
processing to DOWXX statement for a comparison of the two
factors.

When using the IFxx operation or a CASxx group, the END statement
may not be conditioned by indicators, except control level
indicators in total calculations for documentation purposes only.

The END statement functions as the closing point in an IFxx
operation or CASxx group. The END statement informs the program
where to pass control after the testing of IFxx instruction or
completion of a subroutine in a CASxx group.

IFxx (If/Then)

The IFxx operation code serves as the pivot of two program
control sequences using either IFxx/END or lFxx/ELSE/END
structures and is largely self-explanatory:

1. When the relationship between factor 1 and factor 2 does not
exist according to the specified xx together with no attached
ELSE, then program control is passed to the first executable
operation following the associated END operation.

2. When the relationship between factor 1 and factor 2 does not
exist according to the specified xx and an ELSE operation is
specified, when program control passes to the first operation
following the ELSE operation.

When using this operation code the following requirements are
necessary: Both factors must contain either numeric or character
data.

1. The conditioning indicator entries on the END operation which
are attached to the IFxx operation must be blank.

2. The closing of an IFxx group must be done with an END operation.

In situations where an IFxx operation is followed by an ELSE
operation, an END operation is required after the ELSE operation,
but not after the IFxx operation.

Begin Subroutine (BEGSR)

The BEGSR operation code defines the start of a subroutine, and
it must be the first statement in the subroutine. Factor 1
specifies the name of the subroutine. All conditioning
indicators, factor 2, the result field, and resulting indicators
should be blank.

End Subroutine (ENDSR)

ENDSR instruction serves as the last statement of a subroutine to
define the end of the subroutine. Factor 1 may contain a label
for a GOTO operation within the subroutine, thus providing an
exit from the subroutine. The ENDSR operation ending the
subroutine automatically causes a branch back to the next
statement following the EXSR operation code.

Execute Subroutine (EXSR)

The EXSR operation code causes the execution of an internal
subroutine. Factor 2 must contain the name of the subroutine to
execute, and the same name must appear on a BEGSR instruction.
EXSR may appear anywhere in the program to indicate that the
subroutine is being called. Whenever EXSR appears, the
subroutine is automatically executed.

Conditioning indicators may be used with an EXSR operation. If
the indicators have the correct status, the subroutine is
executed. If there are no conditioning indicators, the
subroutine is always performed.

Entire subroutines can be conditioned by control level indicators
when the control level indicator is used with the EXSR operation.

After all operations in the subroutine are done, processing
returns to the line following the EXSR specification.

Lookup Operation (LOKUP)

The LOKUP operation code works in connection with tables and
arrays. The LOKUP operation does a search for a given element in
a table or array. The search word for the operation is found in
factor 1 and the table or array is specified in factor 2. The
result field may contain the name of a related table or array,
and the resulting indicators are used to indicate the type and
results of the search.

Exception Output (EXCPT)

The EXCPT operation code causes exception output lines to be
written during detail or total calculations. All output lines
specified as exception output (E in column 15) must be written
using an EXCPT operation; they will not be written during the
output cycle. Factor 2 may contain an exception reference name
to condition the output of specific exception lines. Factor 1,
the result field, and resulting indicators should be blank.

If exception names are not used, indicators can be used to
condition output lines. When an EXCPT operation specifies no
exception name, only exception output lines without exception
names in columns 32-37 will be written.

Read Next Record (READ)

The READ operation code causes an input record to be read from
a demand or full-procedural file during calculations. Factor 2
should name the file, and indicators may be specified in
columns 56-59 to check operation results. Factor 1, the
result field, and columns 54-55 should be blank.

The indicator in columns 58-59 will turn on whenever the file
in factor 2 has reached end-of-file. If no indicator is
specified for the end-of-file condition, a run-time halt
error will occur at end- of-file.

Read Equal Key (READE)

The READE operation code is a special read operation for
indexed full-procedural DISK files. Factor 1 contains the
key to be found, and factor 2 should be the name of an
index file. An indicator must be specified in columns 58-59
to error conditions. The result field and columns 54-55
should be blank.

When a READE operation is performed, the operation takes
the current position in the index file and reads the next
sequential record. If this record matches the key in
factor 1, the data record is returned as input. If the
key does not match or the file is at end-of-file, the
indicator in column 58-59 is turned on and no record is
returned as input.

Factor I can be a field name, an array, a table element,
or a literal and must have the same field type and length
as the key field being read.

An indicator may also be specified in columns 56-57 to
trap network record lock errors. When a file is opened
for update processing, a read operation for a record
locked by another program will generate a display message
for the user to wait until the record is free. If you
would like to bypass the default RPG message, you can
provide your own program logic for record lock
situations by specifying an indicator in columns 56-57.
If the record is locked when the program attempts to
read it, the indicator turns on.

If a READE operation does not find the correct record,
the file record pointer may need to be repositioned
with a SETLL or C14AIN operation to avoid subsequent
failure of READ, READE and READP operations.

The READE operation is useful when processing duplicate
key files. You can simply CHAIN to the first key, and
read all the following records with the same key by
using a READE operation.

Read Prior Record (READP)

The READP operation code operates like a READ operation
in reverse. Factor 2 must contain the name of the full-
procedural file to be read. A resulting indicator must
be specified in positions 58-59 to check for beginning-of-file
condition. Factor 1, the result field, and columns 54-55
should be blank.

When a READP operation is used, the record before the
current data record is read as input. The resulting
indicator is switched on when the sequential record
immediately before the current record does not, in fact,
exist; in other words, a beginning-of-file condition.
The indicator is switched off before each READP operation.

An indicator may also be specified in columns 56-57
to trap network record lock errors. When a file is
opened for update processing, a read operation for a
record locked by another program will generate a
display message for the user to wait until the record
is free. If you would like to bypass the default RPG
message, you can provide your own program logic for
record lock situations by specifying an indicator in
columns 56-57. If the record is locked when the
program attempts to read it, the indicator turns on.

Chain to a Specific Record (CHAIN)

The CHAIN operation code provides the ability to
directly read a specific record by key or relative
record number. Factor 1 contains the key or relative
record number of the desired record. Factor 2 should
be the name of an index or direct file specified as
chained or full-procedural. An indicator should be
used in columns 54-55 to check for invalid records.
The result field and columns 58-59 should be blank.

Concatenate String (CATST)

The CATST operation code is a unique Lattice feature
which joins two strings together to form a longer
string. Factor 1 and factor 2 may be an alphanumeric
literal or a data field name which would be
concatenated and placed in the result field.

If the concatenated string has a shorter length
than the result field, it is placed left-justified
with blank-fill; if longer it is truncated from the right.

For example, if factor 1 containing the word 'London',
and factor 2 containing the word 'Bridge' are concatenated,
the result field would contain 'London Bridge'.

Factor 1 Operation Factor 2 Result Field
London CATST Bridge London Bridge

Substring (SUBST)

The SUBST operation code is another unique Lattice feature
that extracts a substring of user-defined length from a
given character-string and places it in the result field.
SUBST must be specified in two specification lines:

1. In the first line, factor 1 represents the string from which
a substring will be extracted. Factor 2 specifies the starting
point (from 1) in the string.

2. In the second line, factor 2 specifies the length of the
substring to be extracted and the result field specifies
the field containing the substring.

Factor 1 may be an alphanumeric literal or a field name and
factor 2 may be a numeric literal or numeric field name. If
the starting point is greater than the length, a run-time
error message is displayed.

The following example demonstrates the SUBST function
where factor 1 contains the string 'Cheviot Hills'.
After execution of SUBST the result field would contain
the string 'Cheviot'.

Factor 1 Operation Factor 2 Result Field
Line 1: Cheviot Hills SUBST 1
Line 2: 7 Cheviot

Time of Day (TIME)

The TIME operation code references the system clock
and date for input into the program. The result field
should contain a numeric field either 6 or 12 bytes
in length and zero decimal positions. Factor 1, factor 2,
and the resulting indicators should be blank.

With the TIME operation both the time and date may be
accessed or just the time. If the field is specified
with a length of 6, only the time will be entered into
the field. To get both, a 12-byte field must be used.
The first 6 bytes represent the time, and the last
6 bytes represent the date.

The time of day is written in the format of HHMMSS
(hours, minutes, seconds). The date will follow the
system date format selected on the Control Specification,
and may be MMDDYY, DDMMYY or YYMMDD.

*LIKE DEFN

The DEFN operation code is an instruction for copying
the field attributes of one field to a new field. The
keyword' LIKE' must be in factor 1. Factor 2 contains a
previously defined field, and the result field contains
the name of a new field. Field attributes in columns 49-52
may contain a plus or minus sign with a 2 digit number
to lengthen or shorten the field in relationship to the
field length of the field in factor 2. The resulting
indicators should be blank.

The *LIKE DEFN operation simple instructs the compiler
to create the field named in the result field according
the field attributes for the field in factor 2. These
attributes include the length, decimal position, and
type (either alphanumeric or numeric). If column 49
contains a plus or minus sign, a number in columns 50-51
will increase or shorten the length of the new field.
Otherwise, the exact length is used for the new field.

Factor 2 cannot contain a literal or data structure name.
However, an array or table name may be used because
the new field can be defined according to element attributes.

The *LIKE DEFN operation can only be used to define
alphanumeric or numeric fields. Arrays, tables, and
data structures must be defined with the proper RPG
specifications.

DATA STRUCTURES

A data structure can be used to:

Define the same internal area multiple times using
different data formats, as in the following:



Figure 9.1 Using a Data Structure to Redefine the Same Internal Area
Multiple Times

Subdivide a field so that either the entire field or its subfields
can be referenced, as in the following:



Figure 9.2 Using a Data Structure to Define Subfields within a Field

Group fields for easier reference, as in the following:



Figure 9.3 Using a Data Structure to Group Field

Defining a Data Structure

To specify a data structure, make the following entries
(the columns that are not mentioned must be blank):

COLUMN 6 I

COLUMNS 7-14 Optionally, the name of the data structure.
When specified, the name must meet the
requirement of a field name. The data
structure name can be referenced in one
of two ways:
1. As a field only on the Input or Output Specifications.
2. As an RLABL.


COLUMN 18 If the data structure is to be associated
to a local data area, a 'U' should be entered.
COLUMNS 19-20 DS, which identifies this as a data structure.

Defining Subfields

To specify the subfields of a data structure, make the
following entries. These entries must be made on the
line below the DS specification. The columns not mentioned must be blank.

COLUMN 6 I
COLUMNS 44-47 The number of the record position in which
the subfield begins relative to the beginning
of the data structure.
COLUMNS 48-51 The number of the record position in which
the subfield ends relative to the beginning
of the data structure.
COLUMNS 53-58 The subfield name, which can be the same
as an input field name or a result field name,
and it can appear as an RLABL. Subfields can
be used in factor 1, factor 2, or as an output
field. However the same subfield name cannot be
specified as part of another data structure.
RPG field name rules apply to subfield names.

Rules for Data Structures

When using a data structure, consider the following:

A data structure is considered an alphanumeric byte string.
The data structure is initialized to blanks except for
that part of the data structure that is initialized
with an array. You must ensure that numeric subfields
are initialized with numeric data prior to their use
in CHAIN, LOKUP, COMP, or editing operations.

If the element is a compile-time array, the array data
is placed in the data structure after the data structure
has been initialized to blanks.

You can redefine a subfield in the data structure by
specifying the same or part of the same 'from'/'to'
position for another subfield.

The name of an input field or a result field that is
being redefined in a data structure must be specified
in the data structure or be the data structure name.
However, it does not have to immediately precede the
subfields redefining it.

If a field appears as a data structure name or
as a data structure subfield name, the physical space
reserved for that field is in the data structure,
regardless of where the field was defined.

The 'from' and 'to' positions specified in a data
structure for an input field that is being redefined
are relative to the beginning of the data structure,
not relative to the positions that the field occupies
in the input record.

A subfield can have the same length attributes as
other fields or subfields.

The maximum length of an alphanumeric subfield is
256 characters while the maximum length of a numeric
subfield is 15 characters.

If arrays are specified as subfields, the length
specified must equal the amount of storage required
to store the entire array.

The following restrictions apply to the use of a
data structure:

A packed or binary numeric field cannot be specified
as a subfield within the data structure. The field
can be defined as packed or binary in a file. RPG
converts the field to zoned decimal format when
it is placed in the data structure.

The field is carried in zoned decimal format within
the data structure.

The length of a data structure is defined in one of two ways:

1. If the data structure name is specified as a field
in an input record, the length of the data structure
is the same as the length of the input field. If the
'to' position specified for a subfield exceeds the
length defined for the input field, the input field
specification is invalid.

2. If the data structure name is not specified as a
field in an input record, the length is defined by
the highest 'to' position specified for a subfield.

A subfield may not be an RPG reserved word, array
element, or a table name.


XIII. Changing Printer Fonts



The square brackets within a literal in the Lattice RPGII
source cause the compiler to print the data within the brackets
in double sized characters on a dot matrix printer.

Whatever follows the characters X' in the Lattice RPGII
source causes the compiler to treat whatever follows the X' as
hex control characters. X'0F is the same as the \015 (print in
compressed mode) printer control code for Lotus 1-2-3. X'1B40 is
the same as the \027@ (reset the printer to normal printing)
control code in Lotus.

Once the control code is used, the printing stays in that
mode until another code changes it. Let's say you want to print
a report in compressed mode. I would use the following in my
printer output:




XIV. SORTING

A SORT program is used to rearrange the records in one or more
data files according to the KEY specifications, and write the
records to an output file.

Think about sorting your checks when they come back from the bank.
How do you do it? Check number sequence.

The DOS sort. Comes with DOS. Allows you to sort any data file
into sequence by one key field. The sort is done in memory. All
records in your input file must be able to fit in available memory
at the same time. You can sort in A or D sequence. The starting
position of the sort can be specified on the command line:

SORT /R /+n < infile > outfile

If you specify /R, the sort is descending. Leave /R off and you
get an ascending sort.

Use +n to indicate the starting position of the key field. SORT
assumes that the KEY starts in that position and continues to the
end of the record. Leave +n off and the KEY is the entire record.
File redirection is used to indicate the input and output files.
Leave either or both off and SORT assumes the console device
(keyboard input and screen output).

The Lattice SORT uses disk as a work area to sort any size file.
You create a file with the parameters in it or type the parameters
at the command line when asked. You may specify multiple input
files. You may specify more than one key field. Each statement
is called a DIRECTIVE STATEMENT. Here are the ones you will need:


Example:

CUSTOMER FILE: CUST.DAT



To sort the file into NAME within ZIP code sequence, we would use
the following sort file. To build it, we will use the following
DOS command:

COPY CON CUST.SRT

At the blinking cursor, we enter the following lines:

INFILE = CUST.DAT
OUTFILE = CUSTS.DAT
RECORD = V
FIELD = NAME(6,30,A),ZIP(58,5,A)
KEY = ZIP(A),NAME(A)
END
^Z

To sort the CUSTomer file we would enter the following DOS com-

mand:

SORT < CUST.SRT


DOS SORT EXERCISE:

The SORT.EXE program that comes with DOS is fast and easy to
use. However, it can only sort a file that will fit in memory. It
is a memory sort. To try it out run the following from the DOS
prompt. <E> means to press the enter key.

SORT <E>

You should be at a blank line with a blinking cursor. Type
the following.

GEORGE <E>
ANN <E>
TOM <E>
DICK <E>
SAM <E>
<F6> <E>

The list will be sorted and a sorted version displayed. You
can direct the output to disk by starting it with this line.

SORT > JUNK.DAT <E>

You will still get to enter the data on the keyboard. When
entry is completed, the sorted output will go to the file you
redirected it to. In this case I called it JUNK.DAT. If you want
to sort a file that is on disk, you must redirect both the input
and output.

SORT < INPUT.DAT > OUTPUT.DAT <E>

The file called INPUT.DAT will be read into memory and
sorted. The sorted output will be placed into a new file called
OUTPUT.DAT. You would enter the actual names of your input and
output files.

There are options in the sort that allow you to select the
positions to sort on and whether you want to sort into ascending
or descending sequence. The DOS manual explains this in detail.
However, SORT.EXE from DOS only sorts a file that will fit in
memory.


XV. LATTICE SORT EXERCISE

The LATTICE SORT.EXE uses disk to sort any size file. It
will do every thing the DOS sort can do and a lot more. You may
select records based on certain criteria. You may even select
certain fields. Your output can contain complete records or it
can be a record address file for use in RPGII.

Let's try it out by using one of the data sets from the book.
DS03.DAT is a good one to play with. It contains names and codes.



To use the Lattice sort, we must give it information about
the file to be sorted, how we want it sorted, and where the sorted
data should end up. To do that we need to answer the following
questions:


We can enter this information one line at a time after we run
the program (SORT.EXE) or we can place this data in a file to used
as input to the sort program. Let's do it that way. Enter the
following from the DOS prompt:



The field line tells the Lattice sort that the name will be
found starting in position 1 for a length of 25 characters and
that it is alphameric. The code starts in 26 and is 5 long and
alphameric. The key line tells the sort that we want the file
sorted on the name field in ascending sequence.

To run the sort, enter the following command:

SORT < DS03.SRT

You should see a progress report on the screen while the sort
is running. When it finishes, look at the sorted file using the
following command and check the sequence.

VIEW DS03S.DAT

The SORT from Lattice uses the hard disk drive as a work
area. Therefore, your file can be larger than the amount of
memory that you have available. The only limitation is the amount
of space on your hard disk. If you needed to sort a file that had
5mb of data, you would need at least 10mb of free space on your
disk; 5mb for the work area and 5mb for the final output file.

The Lattice program will also let you use a .DBF file as
input creating a .DAT file as the output. You would do this by
saying RECORD=D,3 to indicate a dBaseIII format input file in
stead of the RECORD=V that indicates a variable length .DAT file.
There are ways to select/exclude records based on the contents of
fields within your record. You can also create a different record
layout for your output. Any good system needs a versatile SORT
program. The Lattice SORT does everything you need and it does it
quickly.


To get on screen HELP, type SORT and press ENTER. At the
first > type ? and press ENTER. The following will appear on the
screen:



XVI. Additional File Errors:

101 nofields value is 0.
102 nofields value is > 128 bytes.
103 Field name greater than 10 bytes.
104 Invalid field type specified.
105 Field length = 0 or > 254 bytes.
106 Record length > 4000 bytes.
107 Failed to create the DBF file at physical level.
108 Failed to write to the DBF file at physical level.
201 Unrecognized mode parameter.
202 Failed to allocate dynamic memory.
203 DBF file open failure at physical level (e.g., non-existent file).
204 Failed to read the DBF file at physical level.
205 Failed to allocate dynamic memory.
206 Failed to read the DBF file at physical level.
207 File not recognized as a DBF file.
208 Failed to allocate dynamic memory.
209 The file cannot be recognized as a DBF file.
210 Failed to allocate dynamic memory.
211 Failed to allocate dynamic memory.
212 Semaphore time out on DBFFILE list.
301 Semaphore time out on DBFFILE list.
302 Failed to seek the the DBF file at physical level.
303 Failed to lock the DBF file header.
304 Failed to write the DBF file at the physical level.
305 Failed to close the DBF file at the physical level.
306 Internal error, DBFFILE list possibly corrupt.
401 Record number too big or zero.
402 Failed to seek the DBF file at physical level.
403 Failed to read the DBF file at physical level.
451 Field name not found.
461 Non-existant field number.
501 Record number too big or zero.
502 Improper request, no insertions allowed in SHARED mode.
601 Improper request. (Can't use in SHARED mode, use dbdelete.)
602 Record number too large or zero.
701 Update attempt on a record that was not locked by dbgetupd.
702 Record number too large or zero.
703 Failed to seek or read the DBF file at physical level.
704 Failed to seek or read the DBF file at physical level.
705 Internal error. (DBF file structure corrupt.)
801 Invalid width or decimal value.
802 Unbalanced combination of width and decimal values.
803 Corrupt input.
804 Empty or all blank input.
805 Input string is too long.
806 Invalid character, expected a digit.
807 Decimal point found more than once.
808 Invalid representation of a negative number.
809 Null input string.
810 Negative sign (-) found more than once.
811 Positive sign (+) found more than once.
812 Improper input character found.
851 width less than or equal to zero.
852 Field empty or all blank.
901 Invalid call when using AUTO locking.
902 Buffer requested too small.
911 Invalid call in AUTO lock mode.
912 User supplied buffer not large enough.
913 Failed to seek the NDX file at the physical level.
914 Failed to read the NDX file at the physical level.
1001 Failed to seek the DBF file at the physical level.
1002 Failed to read the DBF file at the physical level.
1003 Internal error. (DBF file structure corrupted.)
1201 Failed to seek the DBF file at physical level.
1202 Failed to seek the DBF file at physical level.
1203 Failed to seek the DBF file at physical level.
1204 Failed to seek the DBF file at physical level.
1205 Static data corrupted possibly by application overwrite.
1206 Failed to write onto the DBF file at physical level.
1207 Failed to seek the DBF file at physical level.
1208 Failed to write onto the DBF file at physical level.
1210 Failed to allocate dynamic memory for DBF shift-down operation.
1211 Failed to seek the DBF file at physical level for DBF shift-down operation.
1212 Failed to read the DBF file at physical level during DBF shift-down operation.
1213 Failed to seek the DBF file at physical level during DBF shift-down operation.
1214 Failed to write onto the DBF file at physical level during DBF shift-down operation.
1215 Failed to seek the DBF file at physical level during DBF shift-down operation.
1216 Failed to seek the DBF file at physical level immediately after OF shift-down operation.
1220 Failed to allocate dynamic memory for DBF shift-up operation.
1221 Failed to seek the DBF file at physical level for DBF shift-up operation.
1222 Failed to read the DBF file at physical level during DBF shift-up operation.
1223 Failed to seek the DBF file at physical level during DBF shift-up operation.
1224 Failed to write onto the DBF file at physical level during DBF shift-up operation.
1225 Failed to seek the DBF file at physical level during DBF shift-up operation.
1226 Failed to seek the DBF file at physical level immediately after ]OF shift-up operation.
1301 Undefined "keytype" specified.
1302 Key length too long or zero.
1303 Failed to allocate dynamic memory.
1304 Key expression too long or zero.
1305 Failed to create the NDX file at physical level.
1306 Failed to write onto the NDX file at physical level.
1401 Unrecognized mode parameter.
1402 Failed to allocate dynamic memory.
1403 Failed to open NDX file at physical level.
1404 Failed to read the NDX file at physical level.
1405 The file cannot be recognized as a NDX file.
1406 Failed to allocate dynamic memory.
1407 Semaphore time out on NDXFILE linked list.
1408 Failed to allocate dynamic memory.
1501 Semaphore time out on NDXFILE linked list.
1502 Failed to close the NDX file at physical level.
1503 Internal error, NDXFILE list possibly corrupt.
1601 recno is zero or negative.
1602 NDX exceeded private buffer size.
1603 Memory allocation failure.
1604 Failed to seek NDX file.
1605 Failed to write to NDX file.
1606 Failed to seek NDX file.
1607 Failed to write to NDX file.
1608 Failed to allocate dynamic memory.
1631 Failed to seek NDX file.
1632 Failed to read NDX file.
1633 Failed to allocate dynamic memory.
1701 NDX file has no keys. (Probably newly created NDX file.)
1702 Requested key not found in the NDX file.
1810 Top of the NDX file reached.
1820 No keys found in the NDX file.
1901 No current key positioned (top of index).
1902 No current key positioned (bottom of index).
2010 End of the NDX file reached.
2020 No keys found in the NDX file.
2101 The DBF file is not open.
2102 The NDX file is not open.
2202 The NDX file is not open.
2603 End of he NDX file reached. (The requested key is larger than any other existing key.)
2301 The DBF file is not open.
2302 The NDX file is not open.
2501 Failed to allocate dynamic memory.
2502 Failed to seek the NDX file at physical level.
2503 Failed to read the NDX file at physical level.
2504 The key expression in the NDX file is too long. (The file is probably corrupted or not a .NDX)
2601 No key exists in the NDX file.
2602 Synonymous to d-MAYBE.
2701 Failed to seek the NDX file at physical level.
2702 Failed to write the NDX file at physical level.
2703 Failed to allocate dynamic memory.
2704 Failed to seek the NDX file at physical level.
2705 Failed to read the NDX file at physical level.
2801 Failed to seek the NDX file at physical level.
2802 Failed to write onto the NDX file at the physical level.
2803 Failed to seek the NDX file at physical level.
2804 Failed to write onto the NDX file at the physical level.
2805 Failed to seek the NDX file at physical level.
2806 Failed to write onto the NDX file at the physical level.
2901 Invalid date.
2911 Invalid date.
3301 Failed to allocate dynamic memory.
3401 Failed to allocate dynamic memory.
8001 Unrecognized mode argument.
8002 DBF file not open in SHARED mode.
8003 NDX file not open in SHARED mode.
8005 Improper filetype argument.
8026 DBF file not open in SHARED mode.
8027 Automatic locking not specified.
8028 Another record is already locked for update.
8051 DBF file not open in SHARED mode.
8052 DBF file is in AUTO lock mode, only d_TEST requests allowed.
8053 Size bytes already locked by caller.
8054 Some records already locked by caller.
8055 DBF file is already locked by caller.
8056 DBF file is not locked, unlock request.
8057 Failed to seek the DBF file at the physical level.
8076 NDX file not open in SHARED mode.
8077 NDX file in AUTO lock mode.
8078 NDX file not locked by caller.
8079 NDX already locked by caller.
8080 Failed to seek NDX file at physical level.
8091 Failed to seek NDX file at physical level.
8092 Failed to read NDX file at physical level.
8093 Failed to read and unlock NDX file.
8094 Failed to read NDX file.
8126 DBF file not open in SHARED mode.
8127 DBF file is in AUTO lock mode.
8128 Failed to seek the DBF file at the physical level.
8129 Invalid lock mode.
8151 DBF file not open in SHARED mode.
8152 DBF file is in AUTO lock mode.
8161 Size bytes not locked by this process.
8162 Entire DBF file already locked by caller.
8163 Size bytes are already locked by caller.
8164 Failed to seek the DBF file at the physical level.
8175 Entire file is already locked.
8176 A range of records are already locked.
8177 Failed to seek the DBF file at the physical level.
8185 The entire file is locked, can't unlock only records.
8186 No records are locked.
8187 Failed to seek the DBF file at the physical level.
8201 Invalid lock mode specified.
8202 File region already unlocked on unlock request.
8203 File region already locked on lock request.
8301 Failed to seek the DBF file at the physical level.
8302 Failed to write the DBF file at the physical level.
8303 Can't pack DBF file if using user supplied buffer.
8304 Couldn't update DBF size information in header.
8305 Failed to truncate file after packing.
8306 Can't pack in SHARED mode.
8321 Invalid request. (Can't use dbgetupd and dbrtupd on same file.)
8322 Failed to allocate dynamic memory.
8323 Record has been changed by a different station since initially read for update. (old is different than listing record.)
8361 File structure pointer is NULL.
8362 Unrecognized flletype parameter (not d_DBF, d_NDX or d-DBT).
8363 Semaphore time out on file structure list.
8364 File structure invalid. (Not found in list.)
8365 File structure invalid. (ID tag is not valid.)
8366 Semaphore time out on file structure.