Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 F-spec – Defines the use of a file zWhat sorts of files can RPG read? yDatabase yLocal PC-based – stream files yCommunications devices yWorkstations.

Similar presentations


Presentation on theme: "1 F-spec – Defines the use of a file zWhat sorts of files can RPG read? yDatabase yLocal PC-based – stream files yCommunications devices yWorkstations."— Presentation transcript:

1 1 F-spec – Defines the use of a file zWhat sorts of files can RPG read? yDatabase yLocal PC-based – stream files yCommunications devices yWorkstations (aka 5250 screens) yPrinter

2 2 The file definition statement zF-Spec yFile name yType (input, output, update) yKeyed file or not yDevice associated to file (disk, printer, workstn) yVarious keywords xRecord names xSystem or User-controlled Open

3 3 The file definition statement zF-Spec yFile name yType yKeyed or not yDevice associated yVarious keywords xRecord names xSystem or User-controlled Open File specifications tell only the file name – how do you think the system figures out where the file is located?

4 4 The file definition statement zF-Spec yFile name yType yKeyed or not yDevice associated yVarious keywords xRecord names xSystem or xUser-controlled Open File specifications tell only the file name – how do you think the system figures out where the file is located? ANSWER = LIBRARY LIST is searched. File will NOT be found if containing library is not in LIBL. Same searching applies to ALL objects.

5 5 The file definition statement zF-Spec yFile name yType yKeyed or not yDevice associated yVarious keywords xRecord names xSystem or User-controlled Open Type controls: - whether Input, Output, Update - Full procedural or not - External/internal described

6 6 The file definition statement zF-Spec yFile name yType yKeyed or not yDevice associated yVarious keywords xRecord names xSystem or User-controlled Open Keyed: - For Keyed database files only - Arrival sequence for others

7 7 The file definition statement zF-Spec yFile name yType yKeyed or not yDevice associated yVarious keywords xRecord names xSystem or User-controlled Open Device: - DISK – for database - PRINTER – for reports - WORKSTN – for display - other user-defined types

8 8 F-specs layout Input,Output Externally described Record Length Keyed Device Spec type File name Line number Full Procedural QPRINT and QSYSPRT are system-supplied PRINTER Files – no specific format – use for internal definition (O-specs)

9 9 F-specs layout Input,Output Externally described Record Length Keyed Device Spec type File name Line number Full Procedural As previously discussed, advantage is: the program brings in the field definitions, frees programmer from coding and reduces risk of errors. External files are typically created with DDS or SQL (two forms of Data Definition languages).

10 10 F-Spec for Display FHWDSPF05 CF E Workstn F INDDS(Indicators) F sfile(detail:CurrRRN) File – externally defined display file (DSPF) File type C=combined (input/output) F=full procedural E= externally defined Continuation lines Workstn = display screen INDDS = Indicator array SFILE = optional subfile name : record number

11 11 F-specs for DB update more…. This file definition is more sophisticated because of Update, Adding records. Note: use of rename of record format name – particularly helpful when using SQL-defined files because SQL defaults record name = filename.

12 12 Resolving runtime errors – FILE NOT FOUND When you try to run a program and objects required (FILES, programs) are not located, you get the error above. What to do to remedy? 1)Position cursor on error, press F1=Help 2)Find out what is missing 3)Use ADDLIBLE to add YOURLIB 4)Use EDTLIBL to review library list and make changes. 5)Make sure OBJECTNAME is correct, not misspelled

13 13 Resolving runtime errors F1=Help – shows more detail

14 14 Resolving runtime errors F10=Joblog – shows more detail Tells what and where So, remember to setup your library list to provide all resources you need!

15 15 F-spec prompted – easier to fill in the blanks? You can press F1=HELP on each field of the specification

16 16 File Operations for Database zFull Procedural operations y Open – Open a file y Close – close a file y Read – input the next available record y Write – insert or output a record y Delete – remove a record y Update – Output the current record y Chain – retrieve a specific record from the cursor position y SetLL – set the cursor position Before a key y SetGT – set the cursor position after a key Full Procedural means the programmer controls the flow with the Operation codes

17 17 File Operations for Display zFull Procedural operations y Open – Open the display file (automatic by default) y Close – close the display file (automatic by default) y EXFMT – write then read record data to screen y Read – read a record from screen y Write – insert record into subfile or write record to screen y Readc – input the next changed record from subfile y Chain – retrieve a specific record from the subfile y Delete – remove a record from subfile y Update – update the current record in subfile Full Procedural means the programmer controls the flow with Operation codes

18 18 More commonly used file I/O operations zEXCEPT – Output to internally described printer file zREADE – Read the next record with equal key value zREADP – read previous record zREADPE – read previous equal record zCOMMIT – Complete a Transaction when Journaling zROLBK – Rollback (uncomplete) a Transaction while Journaling

19 19 Looping while reading files Loop while FILE1 has records in it (not end-of-file) /FREE // Read a record from file and do something with it READ REC1; DOW NOT %EOF; // File was NOT at EOF because you came here EXSR Somelogic; // with record just read ENDDO; //... /END-FREE Note the test happens once? What happens if NO records in FILE1? %EOF{(filename)} is a Built-in-function to test file status. Filename is optional but makes everything clearer when used.

20 20 Looping while reading files Loop until either FILE1 or FILE2 has reached end-of-file, process all records /FREE DOU %EOF(FILE1) AND %EOF(FILE2); // Read a record from each file and compare the records READ REC1; READ REC2; IF %EOF(FILE1) AND %EOF(FILE2); // Both files have reached end-of-file EXSR EndCompare; ELSEIF %EOF(FILE1); // FILE1 is shorter than FILE2 – process remainder of FILE2 EXSR ProcessRemainderF2; ELSEIF %EOF(FILE2); // FILE2 is shorter than FILE1 – process remainder of FILE1 EXSR ProcessRemainderF1; ELSE; // Both files still have records to be processed EXSR CompareRecs; ENDIF; ENDDO; //... /END-FREE Here, where two files are being read, the %EOF(Filename) is much clearer. %EOF(FILE1) returns a Boolean variable (1/0) where 1=EOF and 0=not-EOF. Note: Optional Filename makes for improved clarity, especially when more than one file is used.

21 21 Do While typically requires that you repeat the READ before the end of the loop. Why? Looping while reading files // Outside Loop – process all customers // Inside Loop – process all orders for specific customer /FREE READ CUSTOMER; DOW NOT %EOF(CUSTOMER); // Read all records from Orders with matching customer ID from Customer READE ORDERS CUSTID; DOW NOT %EOF(ORDERS); // Found a record for Order within Customer – process it EXSR ProcessOrder; READE ORDERS CUSTID; ENDDO; READ CUSTOMER; ENDDO; //... /END-FREE READE = Read Equal

22 22 Do Until typically requires that you repeat the EOF check inside the loop. Why? Looping until reading files // Outside Loop – process all customers // Inside Loop – process all orders for specific customer /FREE DOU %EOF(CUSTOMER); READ CUSTOMER; IF NOT %EOF(CUSTOMER); // Read all records from Orders with matching customer ID from Customer DOU %EOF(ORDERS); READE ORDERS CUSTID; IF NOT %EOF(ORDERS); // Found a record for Order within Customer – process it EXSR ProcessOrder; ENDDO; //... /END-FREE

23 23 Another way to code the same DOU loop using LEAVE. Which is best? Which is more readable? Looping until reading files // Outside Loop – process all customers // Inside Loop – process all orders for specific customer /FREE DOU %EOF(CUSTOMER); READ CUSTOMER; IF %EOF(CUSTOMER); LEAVE; ELSE; // Read all records from Orders with matching customer ID from Customer DOU %EOF(ORDERS); READE ORDERS CUSTID; IF %EOF(ORDERS); LEAVE; ELSE; // Found a record for Order within Customer – process it EXSR ProcessOrder; ENDDO; //... /END-FREE

24 24 Other useful file-related Built-In-Functions z%EOF – file at end status z%FOUND – did the system find the record you wanted z%ERROR – was there a file i/o error encountered such as might happen if the file was not open when a read was issued yNote: here you might employee the Monitor or File information data (INFDS) or program status data (PSDS) capabilities to see what the error was. z%STATUS – returns most recently set file status First three return Boolean 1=yes, 0=no

25 25 Monitor Blocks C MONITOR C READ FILE1 C IF NOT %EOF C EVAL Line = %SUBST(Line(i) : %SCAN(***: Line(i)) + 1) C ENDIF C ON-ERROR 1211 C... handle file-not-open C ON-ERROR *FILE C... handle other file errors C ON-ERROR : C... handle string error and array-index error C ON-ERROR C... handle all other errors C ENDMON …… continue processing Why is this approach interesting? Similar to anything in Java or C? Monitor Block * The MONITOR block consists of the READ statement and the IF group. * - The first ON-ERROR block (status 1211) handles condition file is not open. * - The second ON-ERROR block handles all other file errors possible. * - The third ON-ERROR block handles the string-operation status * code and array index status code * - The fourth ON-ERROR block (which could have had a factor 2 * of *ALL) handles errors not handled by the specific ON-ERROR * operations. * If no error occurs in the MONITOR block, control passes from the * ENDIF to the line following ENDMON.

26 26 Monitor Blocks C MONITOR C READ FILE1 C IF NOT %EOF C EVAL Line = %SUBST(Line(i) : %SCAN(***: Line(i)) + 1) C ENDIF C ON-ERROR 1211 C... handle file-not-open C ON-ERROR *FILE C... handle other file errors C ON-ERROR : C... handle string error and array-index error C ON-ERROR C... handle all other errors C ENDMON …… continue processing Why is this approach interesting? Similar to anything in Java or C? Monitor Block * The MONITOR block consists of the READ statement and the IF group. * - The first ON-ERROR block (status 1211) handles condition file is not open. * - The second ON-ERROR block handles all other file errors possible. * - The third ON-ERROR block handles the string-operation status * code and array index status code * - The fourth ON-ERROR block (which could have had a factor 2 * of *ALL) handles errors not handled by the specific ON-ERROR * operations. * If no error occurs in the MONITOR block, control passes from the * ENDIF to the line following ENDMON. Softly handles ALL possible errors which programmer can anticipate in the code segment.

27 27 Normal Codes Code Condition No exception/error occurred Called program returned with the LR indicator on Conversion resulted in substitution. Exception/Error Codes Code Condition Value out of range for string operation Negative square root Divide by zero An intermediate result is not large enough to contain the result Float underflow. An intermediate value is too small to be contained in the intermediate result field Invalid characters in character to numeric conversion functions Invalid Date, Time or Timestamp value Date overflow or underflow. (For example, when the result of a Date calculation results in a number greater than *HIVAL or less than *LOVAL.) Date mapping errors, where a Date is mapped from a 4-character year to a 2-character year, and the date range is not Variable-length field has a current length that is not valid Table or array out of sequence Array index not valid OCCUR outside of range Reset attempted during initialization step of program Called program or procedure failed; halt indicator (H1 through H9) not on Error calling program or procedure Pointer or parameter error Status Codes

28 28 Exception/Error Codes Code Condition Called program or procedure returned with halt indicator on Halt indicator on in this program Halt indicator on when RETURN operation run RPG IV formatted dump failed Class or method not found for a method call, or error in method call Error while converting a Java array to an RPG parameter on entry to a Java native method Error converting RPG parameter to Java array on exit from an RPG native method Error converting RPG parameter to Java array in preparation for a Java method call Error converting Java array to RPG parameter or return value after a Java method Error converting RPG return value to Java array Error on DSPLY operation Data area specified on IN/OUT not found *PDA not valid for non-prestart job Data area type or length does not match Data area not locked for output Error on IN/OUT operation User not authorized to use data area User not authorized to change data area Error on UNLOCK operation Length requested for storage allocation is out of range Error encountered during storage management operation Data area previously locked by another program Data area locked by program in the same process Character field not entirely enclosed by shift-out and shift-in characters Conversion between two CCSIDs is not supported Failure to retrieve sort sequence Failure to convert sort sequence Commitment control not active Rollback operation failed Error occurred on COMMIT operation Error occurred on ROLBK operation Decimal data error (digit or sign not valid) The level number of the compiler used does not agree with RPG IV run-time subroutines Internal failure in ILE RPG compiler or in run-time subroutines Program exception in system routine. Status Code Examples Contd

29 29 More information and examples zFor more on Monitor blocks, File and Program Error Handling errors in main programs, subroutines or procedures ySee File and program Exception errors – RPG Reference manual ySee Error Handling - RPG Reference manual ySee Begin Monitor Group – RPG Reference manual yOr Use HELP in RDi to search for terms


Download ppt "1 F-spec – Defines the use of a file zWhat sorts of files can RPG read? yDatabase yLocal PC-based – stream files yCommunications devices yWorkstations."

Similar presentations


Ads by Google