Contents. ILE RPG Reference. About ILE RPG Reference Who Should Use This Reference Prerequisite and Related Information. RPG is a high-level programming language (HLL) for business applications. RPG is an IBM proprietary programming language and its later versions are. RPG II is a very early and popular version of the IBM RPG programming language. It was developed in the late s and designed to work on the smallest IBM.
|Published (Last):||8 July 2015|
|PDF File Size:||13.29 Mb|
|ePub File Size:||8.99 Mb|
|Price:||Free* [*Free Regsitration Required]|
March by Jon ParisSusan Gantner. View the PTFs and Op-code here. This time we want to rgle on a couple of the additional items that we mentioned in that article, and to introduce a more generic version of our CSV parser.
We will also describe the trace support that IBM have built in to facilitate the development of parsers.
We’ll begin by discussing the changes we made to the CSV parser. To keep our original example simple, that parser was hard-coded to expect exactly two specific fields of data in the CSV file being parsed.
IBM RPG II – Wikipedia
Making the code more generic also requires that we look into how to deal with error conditions detected in the CSV data uncovered during parsing and how to determine when specific data was missing. We won’t be showing a lot of the code, since so much of it is unchanged from the previous articlebut if you would like to examine it in full detail we will post a link to the source code bundle soon.
We decided to take the route of using the file’s header row to supply the field names since such CSV files are common.
It simply contains a count of the number of active elements, and the values of those elements. The element size and the number of elements were arbitrary choices that should be big enough for most purposes.
By using a template, we ensured that should we ever need to change these sizes in the future that this can be easily achieved. We then create two instances of this template B. The process of loading the column headings begins at C by obtaining a record.
The resulting value is tested D to ensure that data was obtained. Note that once the error has been reported control will not return to your parser but rather RPG will issue an error message including the error code that you supplied as the second parameter on the call. The number you use is entirely up to you, but we suggest that you establish some shop standards to document which code means what.
In this situation, the message in the job log looks like this:. At E we load the column heading data structure by calling our getFields procedure and passing it the record.
IBM RPG II
This routine handles the field separators as well as any special characters such as double quotes around strings. We’ll discuss the mechanics of the routine in a future article. By the time that control returns to the main line again, the record headings are all in place within the value array of the DS columnData and the count field has been set with the number of active entries. The significance of this count will become apparent later. Once the column names have been obtained we process each of the records in the file calling the getFields routine to populate the fieldData data structure.
We then proceed to loop through all of the fields that we found F. Notice that at G we test to see if the current index exceeds the count of the number of column names that we found. This would indicate that there are more fields in the record than we were told to expect. For each field for which we have a column heading i. This continues until all the fields in the record have been processed.
One quick point on column names: However, we found out the hard way that it does not do this for names. Trailing spaces are not a problem, but leading spaces must be removed from the names or you will get a field name mismatch.
At this time, you might be wondering what would happen if we have less data that we have column headings. In other words, field s have been missed off the end of the record. We’ll see how that works when we look at the sample program that utilizes this parser. Before we move on to look at the sample program, one quick comment on alternative options for handling the column names where there are none in the file.
The first and most obvious would be to simply generate names for each column found in the record, e. While this is an easy solution, the major disadvantage is that it results in some pretty meaningless field names in the user program.
Note that the field names must match those in the column headings of the first record in the file. But, as we have pointed out when wiring about XML-INTO, this is a very blunt instrument since it ignores all missing fields, kbm just the ones that you might consider optional.
For example, in our test scenario, perhaps we have records for non-U. In those cases, no state value would be expected, but we still want the rest of the data to be present. This condition is tested for at N and a message issued to note the omission.
Will no longer cause an error due to a missing field.
ILE RPG Reference
So while the line with the state column omitted is OK, if we modified the line to look like this:. Any spaces encountered would be turned to underscores if this option is used. Developing a parser can be tricky until you get the hang of it and, unlike Open Access, each parser will be different and therefore will not lend itself to the program template approach that we use with Open Access.
In particular, should the parser “blow up” not that our code ever did that of course! For rplge reason, IBM supplied a very nice debugging option that when enabled will give you lots of information about what has happened.
Scott Klement’s web page
In the future, IBM intend to offer other options, such as to allow the rpglw data to be written to a file. Just to show you the kind of information supplied, here’s an extract from a trace generated when processing a file that had too many fields in the record.
Notice that the information is indented to show the hierarchical level i. Kbm can also see the results of each and every call that the parser made to start and end structures, report names and values, etc.
You can also see that our error code 2 too many fields shows up, along with the position in the file at which the error was detected. But wait, there’s more! You can also add your own debugging information to the trace by calling the QrnDiTrace procedure and supplying a message and nesting level information. We really like this feature. Perhaps more importantly, we look forward to seeing what third parties and open-source groups can do with it.
If you have any questions or thoughts on this new support please let us know. Like what you just read? To receive technical tips and articles directly in your inbox twice im month, sign up for the EXTRA e-newsletter here. Namespace support makes rpgke opcode a viable option.