MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » October 2012

AW: Callback



fixed

There are some situation where callback processing is used, for example if
the RPG Opcodes are used in composition with handler procedures or if you
write an RPG User Defined Table Function.

With call back processing a procedure pointer is passed to a program or
procedure.
The called procedure is run and calls itself the forwarded procedure (the
forwarded procedure is "called back").
For example you have a procedure that reads a file (based on a key) in a
loop. For each record the forwarded procedure is executed. The "loop
procedure" is only coded once, but depending on the situation different
procedures can be executed, for examples you may have a procedure that
outputs the record to a printer file, while another procedure will delete
the record and all dependent records and a third procedure converts the
record into XML and writes the result to an IFS file. In this way the
forwarded procedure is "called back".

Example:
Service Program: Read a file in a loop an execute the forwarded procedure
for each record
D ReadFile PR
D * ProcPtr

D WrkRow PR ExtProc(MyPrcPtr)
D LikeDS(MyFile)

D MyPrcPtr S * ProcPtr

*---------------------------------------------------------------------------
------
P ReadFile B Export
D ReadFile PI
D ParPrcPtr * ProcPtr

D MyRow DS LikeDS(MyFile)
*-----------------------------------
/Free
MyPrcPtr = ParPrcPtr;

DoU %EOF(MyFile);
Read MyFile MyRow;
If %EOF(MyFile);
Return;
Endif;
WrkRow(MyRow);
EndDo;
Return;
/End-Free
P E

Program1: Call the Loop Procedure and exectute SingleRow Procedure for each
row.
D SingleRow...
D PR LikeDS(MyFile)
*--------------------------------------------------------
/Free

ReadFile(%PAddr(SingleRow))
*INLR = *On;
/End-Free
*----------------------------------------------------------
* Procedure to be "called back"
P SingleRow...
P B Export
D SingleRow...
D PI
D ParRow LikeDS(MyFile)
*-----------------------------------
/Free
//Do something with the forwarded record information
Return;
/End-Free
P E

Program 2:
D DeleteRow...
D PR LikeDS(MyFile)
*--------------------------------------------------------
/Free
....
ReadFile(%PAddr(DeleteRow))
....
*INLR = *On;
/End-Free
*----------------------------------------------------------
* Procedure to be "called back"
P DeleteRow...
P B Export
D DeleteRow...
D PI
D ParRow LikeDS(MyFile)
*-----------------------------------
/Free
//Write History;
//Delete Dependent records
//Delete Record
Return;
/End-Free
P E

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"


-----Ursprüngliche Nachricht-----
Von: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] Im Auftrag von Richard Reeve
Gesendet: Monday, 15.10 2012 22:50
An: Midrange Systems Technical Discussion
Betreff: Callback

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.

Thanks.
 
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,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.







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

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact