× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: OO in RPG
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Mon, 4 Dec 2000 17:22:45 -0600 (CST)


On Mon, 4 Dec 2000, Jim Langston wrote:
> Please give me an example of a procedural pointer's use.  Or reference to
> where I can read about them.
> 
> Regards,
> Jim Langston

Here's an example that I dreamed up of using a procedure pointer.
Hopefully this illustrates their use fairly well :)  

(The only places that I've used procptr's in the past have been VERY
complex programs, and wouldnt make good examples...)

Let me know if it makes sense :)

      **                Procedure Pointer Example
      **
      **  This example illustrates a dynamic decision of how to display
      **  a program's status messages to a user, or to the job log in
      **  case we wanted to be a batch program.
      **
      **
     D p_ShowProc      S               *   ProcPtr
     D ShowMsg         PR                  ExtProc(p_ShowProc)
     D   Msg                         50A   const

     D StatMsg         PR
     D   Msg                         50A   const
     D DiagMsg         PR
     D   Msg                         50A   const
     D DsplyMsg        PR
     D   Msg                         50A   const

     D* API error code data structure
     D dsEC            DS
     D  dsECBytesP             1      4B 0 INZ(256)
     D  dsECBytesA             5      8B 0 INZ(0)
     D  dsECMsgID              9     15
     D  dsECReserv            16     16
     D  dsECMsgDta            17    256

     D SndPgmMsg       PR                  ExtPgm('QMHSNDPM')
     D   MessageID                    7A   Const
     D   QualMsgF                    20A   Const
     D   MsgData                  32766A   options(*varsize) const
     D   MsgDtaLen                   10I 0 Const
     D   MsgType                     10A   Const
     D   CallStkEnt                  10A   Const
     D   CallStkCnt                  10I 0 Const
     D   MessageKey                   4A
     D   ErrorCode                32766A   options(*varsize)

      ** Normally, the users preference of how they want their messages
      **   displayed would come from a file containing user prefs, but
      **   to make the example simple, I'm just using a parm:
      **
     C     *entry        plist
     c                   parm                    MsgType           7

     c                   select
     c                   when      MsgType = '*STATUS'
     c                   eval      p_ShowProc = %paddr('STATMSG')
     c                   when      MsgType = '*DIAG'
     c                   eval      p_ShowProc = %paddr('DIAGMSG')
     c                   when      MsgType = '*DSPLY'
     c                   eval      p_ShowProc = %paddr('DSPLYMSG')
     c                   endsl

      **  Now you might have many, many lines of code, with occasional
      **  messages back to the user here and there...   of course, to
      **  keep the example simple, I'm just going to send a simple
      **  test message, here... :)
     c                   callp     ShowMsg('This is a test message.')

     c                   eval      *inlr = *on


     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  This displays a message as a '*STATUS' message...
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P StatMsg         B                   export
     D StatMsg         PI
     D   Msg                         50A   const
     D MsgKey          S              4A
     c                   callp     SndPgmMsg('CPF9897': 'QCPFMSG   *LIBL':
     c                                Msg: 50: '*STATUS': '*EXT': 0: MsgKey:
     c                                dsEC)
     P                 E


     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  This puts a diagnostic message into the job log
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P DiagMsg         B                   export
     D DiagMsg         PI
     D   Msg                         50A   Const
     D MsgKey          S              4A
     c                   callp     SndPgmMsg('CPF9897': 'QCPFMSG   *LIBL':
     c                               Msg: 50: '*DIAG': '*': 0: MsgKey: dsEC)
     P                 E


     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  This shows a message using RPG's DSPLY op-code
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P DsplyMsg        B                   export
     D DsplyMsg        PI
     D   Msg                         50A   Const
     c     Msg           dsply
     P                 E
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.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 on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.