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

%HANDLER-All of our examples so far assume that the number of elements in the XML stream is known. Or that at least it will be within the maximum number of elements that an RPG IV array can define (32K). What if that number isn't big enough? That's where the %HANDLER BIF comes into play.

When handling an undefined number of elements with XML-INTO, we must specify the %HANDLER BIF in place of the receiver variable. The BIF identifies a user-defined procedure that will be called every time the receiver variable is full. The syntax for %HANDLER is:

%HANDLER (handlingProcedure : communicationArea )

The first parameter identifies your handling procedure by specifying the name of its prototype. The second parameter identifies a communications area, which is provided so you can indirectly pass a parameter to your procedure. This communications area can be of any data type and size. It will be passed on to your handler procedure as the first parameter.

The actual receiver variable type is specified by the second parameter of your handling procedure's prototype. The receiver variable must be an array and must be a read-only parameter (i.e., it must be specified with the DIM and CONST keywords in the prototype). A third parameter is also passed to the handler in the form of a 4-byte integer (10I)-this represents a count of the number of elements passed in the second (i.e., the receiver) parameter.

Because the receiver variable must be an array, there's one other notable difference to using %HANDLER compared with specifying a receiver variable. The 'path=...' option must be specified to direct the parser to the correct starting point within the XML document.

Now that we know the basics of using %HANDLER, let's apply it to our example in Code Sample 2. As you see at (H), the customer array contains 99 elements. Let's suppose that we need to code for the possibility that there are more than 99 customer elements in the XML document. We would do this by modifying example (E) as shown in Code Sample 3.

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.

comments powered by Disqus



2018 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
not mf or hp