Assuming we are talking about the same thing, a callback is a
procedure called from a procedure as a means of invoking some function
in the caller.

For example, in Scott Klements, HTTPAPI he uses callbacks to for each
time that start of a XML element and one for the end of an XML

You call Scott's HTTPAPI functions and you request that the XML that
gets returned be parsed. To do that you create a procedure in your RPG
that receives a given set of parameters. One for the start <ELEMENT>
and one for the end </ELEMENT>. Each time that the XML parser sees a
start element it calls the procedure you told it to use for start
element and when it sees an end element it calls the procedure you
defined for end element.

Thus the term callback. It calls back to your program to do the
processing. Very powerful tool.

Over the years I have used them for various purposes. One was a state
transition parser. The parser would parse a FedEx string returned from
a FedEx server. Every time it found a action it needed to process
(PutChar, SaveString, etc) it would callback to the calling program to
perform the action requested.

In this example, I am invoking only the end element procedure. Note
the line %pAddr(EndTagProcessing). This tells Scott's program call
procedure EndTagProcessing each time it sees the end of an element.

// Call Scott's API to get xml.
ReturnCode = HTTP_Url_Get_XML(URL :
*Null :
%pAddr(EndTagProcessing) :
%Addr(Data) :

The procedure that is calledback looks like this.

p EndTagProcessing...
p b
d pi
d InOutData...
d LikeDs(TD_Data)
d InDepth...
d Like(StdInt)
d Value
d InTagName...
d 1024a Varying
d Const
d InPath...
d 24567a Varying
d Const
d InTagValue...
d 65535a Varying
d Const
d InAttributeArray...
d Like(StdPtr)
d Dim(32767)

d AttributeValue...
d s 64a Varying

If InPath = '/WeatherBank/Body/Current' And
InTagName = 'Temperature';
If %Trim(InTagValue) = 'Missing';
InOutData.TemperatureMissing = cTrue;
AttributeValue = %Str(InAttributeArray(2));
If AttributeValue = InOutData.TemperatureType;
InOutData.Temperature = %Dec(%Trim(InTagValue):5:1);
InOutData.TemperatureSeen = cTrue;

On Mon, Oct 15, 2012 at 2:50 PM, Richard Reeve <richreeve@xxxxxxxxx> wrote:

Has anyone ever heard of a callback as it is related to the IBM i? I was asked to explain a callback during an interview and I'd never even heard of it. Can any of you explain to me what a callback is and how it is used? I tried google but didn't get a good explanation.


Warmest Regards,

Richard Reeve
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives

This thread ...


Return to Archive home page | Return to MIDRANGE.COM home page