A way to call a PC .EXE program:
PGM STRPCO PCTA(*YES) STRPCCMD PCCMD('C:WINNTSYSTEM32CALC.EXE') ENDPGM
A different way of having a compile
time array:
D MonthsOfYear DS D 27a Inz('January February March ') D 27a Inz('April May June ') D 27a Inz('July August September') D 27a Inz('October November December ') D Month12Names 9a Overlay(MonthsOfYear) Dim(12)
A data structure array:
D DS
D Address 87a Dim(100) Ascend D Street1 30a Overlay(Address) D Street2 30a Overlay(Address:*Next) D City 20a Overlay(Address:*Next) D State 2a Overlay(Address:*Next) D Zip 5a Overlay(Address:*Next)Copy Spool File to PC Text File:
Open Windows Explorer.
Open AS/400 Operations Navigator and do following:
- Start
- Programs
- IBM AS/400 Client Access Express.
- iSeries Operations NavigatorClick the AS/400 where your spool file is.
Click on Basic Operations.
Click on printer output.
All your spool files will appear in the right screen.
Click on the spool file you wish to copy.
Drag the spool file into a folder in your Windows Explorer and the spool file is copied
into a text file, which can also be opened in Excel.
Window Subfile with messages:
Create a normal window subfile, then create a similar control for the window subfile
as listed below with the WINDOW key word specifying another window. This additional
window will be used as a definition for the window specified in the control for the
window subfile. This additional window will have the size, function keys if needed,
and an error message at the bottom of the window. You have to do a WRITE for this
additional window prior to the EXFMT.
See examples below:
0265.00 A R RICKC2 SFLCTL(IS0P09S2)
0266.00 A*%%TS SD 20050901 153238 RHUCKLEBER REL-V5R1M0 5722-WDS
0267.00 A SFLSIZ(0006)
0268.00 A SFLPAG(0006)
0269.00 A WINDOW(RICKKEYS)
0270.00 A CF03(03 'Exit')
0271.00 A CF11(11 'Different View')
0272.00 A CF12(12 'Previous')
0273.00 A CF13(13 'Inc/Exclude Discharge')
0274.00 A PAGEDOWN(21 'Page Down')
0275.00 A PAGEUP(22 'Page Up')
0276.00 A RTNCSRLOC(&CURREC &CURFLD)
0277.00 A OVERLAY
0278.00 A N50 SFLDSP
0279.00 A N50 SFLDSPCTL
0280.00 A 50 SFLCLR
0281.00 A 99 SFLEND(*MORE)
0282.00 A RRN2 4S 0H SFLRCDNBR
0312.00 A R RICKKEYS
0313.00 A*%%TS SD 20050830 153622 RHUCKLEBER REL-V5R1M0 5722-WDS
0314.00 A WINDOW(8 1 14 76 *NOMSGLIN)
0315.00 A TEXT('Command Keys')
0316.00 A KEEP
0317.00 A OVERLAY
0318.00 A WDWBORDER((*COLOR BLU) –
(*DSPATR RI)-
0319.00 A (*CHAR ' '))
0320.00 A 13 2 'F3=Exit'
0321.00 A COLOR(BLU)
0322.00 A 13 13 'F11=More Info'
0323.00 A COLOR(BLU)
0324.00 A 13 30 'F12=Previous'
0325.00 A COLOR(BLU)
0326.00 A 13 46 'F13=Include Discharged'
0327.00 A COLOR(BLU)
0328.00 A ERRMSG 76A O 14 1 DSPATR(HI) INDICATOR DATA TYPENote: Some free format examples only work with V5R1 and higher.
Note: Some languages refer to this as a Boolean data type. An indicator field is a single-byte field
that can contain only two logical values: ‘1’ or ‘0’. You can also refer to these values using *ON
and *OFF, respectfully. Indicator data is usually used within an RPGIV program to signal a true/false
condition and can be tested on as a true/false condition.
Examples follow:
D Spec:
D IsGood S N INZ(*OFF)
/FREE
EXSR ChkGood EXSR ChkGood;
IF IsGood IF IsGood;
EXSR DoSomething EXSR DoSomthing;
EVAL IsGood = *OFF IsGood = *OFF;
ELSE ELSE;
EXSR GiveErr EXSR GiveErr;
ENDIF ENDIF;
/END-FREE
AID-Generating Keys(For testing if a key has
been pressed)
The AID (attention indicator) code identifies to the host system the function being requested from the keyboard. The AID code is returned by certain input operations when the operator presses an AID-generating key. The following table lists the AID-generating keys and the AID codes associated with each key for INFDS.
Note: If you don’t like testing with indicators, try using the INFDS
Note: Try using the File Information Data Structure (INFDS) below:
Note: Example code that is less cryptic than using indicators is on the next page.
F Spec:
F RickDsply CF E WORKSTN
INFDS(WkdSpa)
***File Information Data Structure
D Specs:
D WKDSPA DS
D Fkey 369 369
***Only use the keys you need below in your code
***Keys Pressed Constants
D F1 C CONST(X’31’)
D F2 C CONST(X’32’)
D F3 C CONST(X’33’)
D F4 C CONST(X’34’)
D F5 C CONST(X’35’)
D F6 C CONST(X’36’)
D F7 C CONST(X’37’)
D F8 C CONST(X’38’)
D F9 C CONST(X’39’)
D F10 C CONST(X’3A’)
D F11 C CONST(X’3B’)
D F12 C CONST(X’3C’)
D F13 C CONST(X’B1’)
D F14 C CONST(X’B2’)
D F15 C CONST(X’B3’)
D F16 C CONST(X’B4’)
D F17 C CONST(X’B5’)
D F18 C CONST(X’B6’)
D F19 C CONST(X’B7’)
D F20 C CONST(X’B8’)
D F21 C CONST(X’B9’)
D F22 C CONST(X’BA’)
D F23 C CONST(X’BB’)
D F24 C CONST(X’BC’)
D CLEAR C CONST(X’BD’)
D ENTER C CONST(X’F1’)
D HELP C CONST(X’F3’)
D PAGEUP C CONST(X’F4’)
D PAGEDN C CONST(X’F5’)
D PRINT C CONST(X’F6’)
Fixed Format Free Format
/FREE
IF Fkey = F1 IF Fkey = F1;
EXSR Func1 EXSR Func1;
ELSEIF Fkey = F2 ELSEIF Fkey = F2;
EXSR Func2 EXSR Func2;
ELSEIF Fkey = Enter ELSEIF Fkey = Enter;
EXSR FuncEnter EXSR FuncEnter;
ELSEIF Fkey = PageUp ELSEIF Fkey = PageUp;
EXSR FuncPgUp EXSR FuncPgUp;
ELSEIF Fkey = PageDn ELSEIF Fkey = PageDn;
EXSR FuncPgDn EXSR FuncPgDn;
ENDIF ENDIF;
/END-FREE
OR
Note: If you don’t like testing with indicators, try using the INDDS keyword which lets you associate a data structure name with the INDARA indicators for a workstation or printer file. This data structure contains the conditioning and response indicators passed to and from data management for the file, and is called an indicator data structure.
Note: Example code that is less cryptic than using indicators is on the next page.
F Spec:
F RickDsply CF E WORKSTN
INDDS(Indicators)
Example code on next page.
* These indicator variables can be tested on as Boolean Logical Variables.
* ‘IF Exit’ means the same thing as ‘IF Exit = *ON’.
In other words you test by coding ‘IF Exit’ and don’t use ‘If Exit = *ON’ and
code ‘IF NOT Exit’ and don’t use ‘IF Exit = *OFF’.
* To use these indicator types you have to declare the keyword INDARA in you display file (DDS).
D Indicators DS
* For PageDown(Rename PageDown to indicator 21 in subfile definition: PAGEDOWN(21 ‘PageDown’)
D PagDwn 21 21N
* Use for F3=Exit(Rename CF03 to indicator 03 in subfile definition: CF03(03 ‘F3=Exit’)
D Exit 3 3N
* Use for F5=Update(Rename CF05 to indicator 05 in subfile definition: CF05(05 ‘F5=Update’)
D Update 5 5N
* Use for F12=Cancel(Rename CF12 to indicator 12 in subfile definition: CF12(12 ‘F12=Cancel’)
D Cancel 12 12N
* Conditioning indicators for format "DispSflCtl"
D SflDSpctl 41 41N
D SflDsp 42 42N
D SflEnd 43 43N
D SflClr 44 44N
* Set indicators to display the subfile:
Fixed Format Free Format
C /FREE
C EVAL SflDsp = *ON SflDsp = *ON;
C EVAL SflEnd = *OFF SflEnd = *OFF;
C EVAL SflClr = *OFF SflClr = *OFF;
C EXFMT DispSflCtl EXFMT DispSflCtl;
*
* Using indicator variables, we can write more readable programs:
C EXFMT Query EXFMT Query;
C IF Exit or Cancel IF Exit or Cancel;
C RETURN RETURN;
C ELSEIF Update ELSEIF Update;
C EXSR Refresh EXSR Refresh;
C ELSEIF PagDwn ELSEIF PagDwn;
C EXSR LoadSF EXSR LoadSF;
C ENDIF ENDIF;
C /END-FREE
BUILT-IN FUNCTIONS
The original release of RPG IV included a set of built-in functions. These built-in functions were:
%ADDR, %PADDR, %SIZE, %ELEM, %SUBST, %TRIM, %TRIML, %TRIMR
In addition, under OS/400 V3R2 and V3R7 the %PARMS built-in function was introduced. Since then, several built-in functions
have been added to RPG IV. The following table provides the OS/400 Version and Release that the specific built-in functions were
introduced and/or enhanced.
Version | Built-in Function | Parameters | Return Value Description |
V3R7 | numeric expression | Absolute value of expression | |
variable name | Address of variable | ||
V5R1 | memory size | Pointer to the allocated storage. | |
V4R2 | graphic, date, time, timestamp, or numeric expression | Value in character data type | |
V5R1 | compare-value : data-to-search { : start-position } | First position in the searched-data that contains a character not in the list of the characters in the compare value. | |
V5R1 | compare-value : data-to-search { : start-position } | Last position in the searched-data that contains a character not in the list of the characters in the compare value. (Search begins with the right-most character and proceeds to the left. | |
V5R1 | { value { : date-format-code } | A date data-type value after converting the "value" to the specified date format. If no value is specified, the current system date is returned. | |
V5R1 | Days | A duration value that can be used in an expression to add a number of days to a date value. | |
V3R7 | numeric expression {:digits : decpos} | Value in packed numeric format. If digits and decpos are specified the result value is formatted to fit in a variable of the number of digits specified. | |
V3R7 | numeric expression : digits : decpos | Half-adjusted value in packed numeric format. The length and decimal positions | |
V3R7 | numeric expression | Number of decimal digits. | |
V5R1 | start-date : end-date : duration-code | Calculates the difference between two date fields. The type of difference returned is specified by the duration-code. | |
V4R4 | Numerator : Denominator | Performs integer division and returns the quotient (result) of that division operation. | |
V3R7 | non-float numeric expression : edit code {:*CURSYM | *ASTFILL | currency symbol} | String representing edited value. | |
V3R7 | numeric expression | Character external display representation of float. | |
V3R7 | non-float numeric expression : edit word | String representing edited value | |
array, table, or multiple occurrence data structure name | Number of elements or occurrences | ||
V4R2 | {file name} | '1' if the most recent file input operation or write to a subfile (for a particular file, if specified) | ended in an end-of-file or | beginning-of-file condition '0' otherwise. | |
V4R2 | {file name} | '1' if the most recent SETLL (for a particular file, if specified) or LOOKUP operation found an exact match '0' otherwise. | |
V4R2 | '1' if the most recent operation code with extender 'E' specified resulted in an error '0' otherwise. | ||
V3R7 | numeric expression | Value in float format. | |
V4R2 |