You are currently on IBM Systems Media’s archival website. Click here to view our new website.

IBM i > DEVELOPER > RPG

A Traditional Approach to a Modern Technology

V5R4 simplifies the use of XML with RPG programs

V5R4 simplifies the use of XML with RPG programs

One of RPG's traditional strengths has been that it provides a simple interface to complex technologies. For example, those who've programmed interactive applications using CICS* or CCP have to appreciate the relative simplicity of the interface provided by EXFMT. More recently, RPG has perhaps lost a little of this complex-made-simple focus. Rather, the power of the language has been increased through features such as expressions and subprocedures. The most recent enhancements have moved RPG IV into the realm of free-form languages (V5R1), added powerful facilities for interfacing with Java* (V5R1) and strengthened its data-definition capabilities (V5R2). Certainly the Java interface was welcomed by many of us and has opened the door to some exciting technologies such as the capability to create spreadsheets using the Jakarta POI classes. However, the word "simple" wouldn't come to mind when describing this interface.

With V5R4, RPG IV returns to its roots and steps up to the challenge of providing a simple interface to a modern technology-XML. Generating XML is rarely a problem, or at least not to the degree that it requires direct language support. XML can be generated within an RPG program by stringing the various delimiters and text values together, or using the template approach offered by products such as CGIDEV2, which was originally designed for the production of Web pages. And this is to name but two of the available options. Parsing and processing XML documents is a different matter, however. It can be a complex process and one to which RPG isn't ideally suited. It's this latter area that the new features address.

Those who have yet to be hit by the requirement to process XML documents will really appreciate these new features when your time comes-and come it will as XML usage becomes more widespread. Those who have already had to deal with XML documents have adopted many approaches from writing their own XML parsers to using Java or other parsers such as the C-based ExPat. There's no need to throw this work away, but you may still find the new RPG IV features easier to use for new tasks.

While assistance with XML processing is undoubtedly the major feature of the V5R4 release, there are also many other interesting features, which we'll also cover here. Since XML is the hot topic of the day, we'll start there.

XML Support

XML support is provided by two new opcodes, XML-SAX and XML-INTO, which work in conjunction with two new built-in functions (BIFs), %XML and %HANDLER. Although these new opcodes, like the traditional EVAL, are available for use in both Extended Factor-2 and /Free syntax, the full functionality of XML-INTO is only available in /Free because of those pesky column limits again. The problem arises because XML-INTO is eight characters in length, so within the 10-position opcode area, there's no room for an operation extender, and as you'll see later XML-INTO supports both the E(rror) and H(alf-adjust) extenders.

XML-INTO-In its simplest form, XML-INTO parses an XML document extracting a single element directly into a variable. It can be a single variable or an array. Most often, however, it's used to extract several elements and use the values extracted to populate a data structure (DS) or DS array. This is the approach to use when the number of items to be retrieved is known. Later we'll examine a variant of XML-INTO that can be used to process XML documents of indeterminate length.

With V5R4, RPG IV returns to its roots and steps up to the challenge of providing a simple interface to a modern technology-XML. Generating XML is rarely a problem, or at least not to the degree that it requires direct language support.

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.



Advertisement

Advertisement

2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters