× 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.



>>http://archive.midrange.com/rpg400-l/200101/msg00116.html
>
>I've poured over that call but can't
>figure out what it does.

With apologies to the original author (Scott K), here again is the code,
annotated.

Source Member: QRPGLESRC, FOREACH
       * Compile me with:
       *   CRTRPGMOD FOREACH SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
       *   CRTSRVPGM FOREACH EXPORT(*ALL) ACTGRP(*CALLER)
      H NOMAIN

       * What happens here is that the mainline declares a procedure
DsplyNum
       * that matches CallMeBack.

       * It then calls ForEach, passing the %paddr of DsplyNum.

       * What happens then is that ForEach increments a counter then calls

       * CallMeBack, which is "overridden" by the "extproc" to DsplyNum.

       * DsplyNum runs, displaying the number passed to CallMeBack.

       * Note that the actual parameter lists are not verified; it is
implied
       * that the parameter list for CallMeBack and DsplyNum will match at
runtime.

         * this will be called by the mainline
      D ForEach         PR
      D   proc                          *   procptr value

         * this will be called by the mainline
      P ForEach         B                   Export
      D ForEach         PI
      D   proc                          *   procptr value

         * a dummy call, used only as a place holder.
       * this prototype MUST match the procedure passed by ForEach
      D CallMeBack      PR                  ExtProc(proc)
      D   Counter                     10I 0 value

      D X               S             10I 0

         * this is called by the mainline.
       * CallMeBack gets the address of a procedure within the mainline pgm
       * and calls THAT.
      C                   do        10            X
      c                   callp     CallMeBack(X)
      c                   enddo

      c                   return
      P                 E


Source Member: QRPGLESRC, TESTFOR:
       ** Compile me with:
       **    CRTRPGMOD TESTFOR SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
       **    CRTPGM TESTFOR BNDSRVPGM(FOREACH) ACTGRP(*NEW)
      D ForEach         PR
      D   proc                          *   procptr value

      D DsplyNum        PR
      D   Num                         10I 0 value

       * this will call the place-holder "ForEach", passing the address
       * of DsplyNum.  The calcs in ForEach are a 10x do loop that simply
       * increments an integer and calls back to the procedure passed in.

       * since ForEach actually calls DsplyNum, DsplyNum will get called
       * 10 times; once for each iteration of the loop.  The point being
that
       * the external service program can be given access to a function here
       * in the mainline without knowing anything about that function except
       * the parameter list.
      C                   callp     ForEach(%paddr('DSPLYNUM'))
      c                   eval      *inlr = *on

      P DsplyNum        B                   Export
      D DsplyNum        PI
      D   Num                         10I 0 value
      C                   dsply                   Num
      c                   return
      P                 E

  --buck


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.