Footers to subfiles Arrays Tables and Builtin Functions
Footers to subfiles, Arrays, Tables and Built-in Functions
For Loop! For startpos by increment to end; Endfor; Ctr is previously defined as a whole number For ctr = 1 by 1 to 5; Endfor; Repeats the loop 5 times
Arrays vs Tables • Essentially do the same thing • Except: – Data in Tables are loaded when the program first runs and is never changed – Data in Arrays can be loaded anytime and can be changed
Defining an Array DINVARRAY 1 15 0 DIM(5) In this case, INVARRAY is made up of 15 numbers. The array has 5 elements, so each element is made up of 3 numbers.
Array Functions • %elem(arrayname) – Returns the number of elements in the array • %xfoot(arrayname) – Adds up the values of the array
INVRPG
Tables • Loaded at run time • Data in the RPG program • Data in a file
Tables – Data in RPG D Month S 9 DIM(12)CTDATA PERRCD(2) (CTDATA means compile time data) At the very end of the program: O ** January February March April May June July August September. October November December In. Valid 1 35
Tables – Data in RPG • To find a month name: • UMONTH is a keyword that returns the month number, so: month(UMONTH) Will return the correct month name
%TLOOKUP – finds data in the array • Returns true if what your looking for is found, false if it isn’t If %TLookup(PNo: Tab. Part. No: Tab. Rest); Where PNo is the part number that we’re looking for If the %Tlookup is successful, Tab. Part. No will contain the part that we found and Tab. Rest will contain the data from the same table row in Tab. Rest
MARKSTABZ
Tables – Data in File FPart. Tab 2 IT F 18 D Tab. Part. No S 3 D D Tab. Rest S 15 Part. Tab 2 has the following data 100 Screwdriver 0999 200 Hammer 1488 300 Saw 2999 400 Wrench 0700 500 Workbench 9599 600 Drill 5999 DISK DIM(6) FROMFILE(Part. Tab 2) PERRCD(1) DIM(6) ALT(Tab. Part. No)
%len • Returns the length of a variable • Particularly useful if the variable is defined as *VARCHAR Length = %len(string);
%subst • Substring Num = %subst(string: start: len); starts at position start and return len number of characters Num = %subst(string: start); starts at position start and returns the number of remaining characters
%scan • Scans a string for a set of characters and returns where the set starts position = %scan(scan: string); If string = ‘This is text’ and scan is ‘is’, then position would be 3 position = %scan(scan: string: start); If start is 5, then position would be 6
%XLATE • Translates a character string Dup Dlo c c 'ABCDEFGHIJKLMNOPQRSTUVWXYZ‘ 'abcdefghijklmnopqrstuvwxyz‘ If String = ‘This is RPG’ uppercase = %xlate(lo: up: string); Then uppercase is ‘THIS IS RPG’ lowercase = %xlate(up: lo: string: convpos); Then lowercase = ‘this is rpg’
- Slides: 16