× 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: Critique requested for my first MI program
  • From: dhandy@xxxxxxxxxxx (Douglas Handy)
  • Date: Thu, 02 Mar 2000 01:56:26 -0500

MI gurus,

It finally dawned on me tonight that a short MI program may easily
circumvent a restriction I have in dealing with V3R2 clients, namely
the lack of pointer arithmetic.

Up to know I've been using the RPG array technique, but it is limited
to 32K chunks.  I'm using more User Spaces now, and wanted a cleaner
way to handle pointers without regard to size constraints.

Enter MI.  Here is my very first MI program, so be gentle with your
critique, but I am asking for constructive criticism.  Here is the
source to what I named PTRMATH:

DCL SPCPTR .PTR     PARM;
DCL SPCPTR PTR      BAS(.PTR);

DCL SPCPTR .INCR    PARM;
DCL DD     INCR     BIN(4)  BAS(.INCR);

DCL SPCPTR .OPCODE  PARM;
DCL DD     OPCODE   CHAR(3) BAS(.OPCODE);

DCL OL *ENTRY(.PTR, .INCR, .OPCODE) PARM EXT MIN(2);

DCL DD     NUM_PARM BIN(4);

/****************************************************************/

ENTRY * (*ENTRY) EXT;
    STPLLEN      NUM_PARM;               /* How many parms?     */
    CMPNV(B)     NUM_PARM,2/EQ(ADD);     /* Assume ADD opcode   */
    CMPBLA(B)    OPCODE,"SUB"/EQ(SUB);   /* Do SUB if parm 3 is */
    CMPBLA(B)    OPCODE,"-  "/EQ(SUB);   /* either SUB or -     */
ADD:
    ADDSPP       PTR, PTR, INCR;         /* Increase pointer    */
    RTX          *;
SUB:
    SUBSPP       PTR, PTR, INCR;         /* Decrease pointer    */
    RTX          *;

PEND;


Then, to use it from RPG, I set up these two prototypes:

     D AddToPtr        PR                  ExtPgm( 'PTRMATH' )
     D  BasePtr                        *
     D  Increment                    10I 0 Const

     D PtrMath         PR                  ExtPgm( 'PTRMATH' )
     D  BasePtr                        *
     D  Increment                    10I 0 Const
     D  OpCode                        3    Const Options( *NoPass )

This lets me perform simple pointer arithmetic, to wit:

     C                   Callp     AddToPtr( ptrLstEnt: ListLen )
     C                   Callp     PtrMath( ptrData: 1: 'SUB' )

Since pointer addition is much more frequent than subtraction (in my
coding anyway), I thought a simple two parm prototype would be the
most readable.  I could have made two distinct programs, one for add
and one for subtract, but wanted to see if I could do it with just one
external program.

The hardest part was figuring out how to handle a variable number of
entry parms -- all of the samples posted to this list so far used a
fixed number AFAIK.

The program appears to work correctly in my testing thus far, but I
have not benchmarked it yet to see how much overhead is added by the
dynamic call.

Question:  Is using RTX * similar to exiting with LR on or off?  Does
it even matter when the code has no initialization routines or files
to open?

Signed,
A MI-wannabe
+---
| This is the MI Programmers Mailing List!
| To submit a new message, send your mail to MI400@midrange.com.
| To subscribe to this list send email to MI400-SUB@midrange.com.
| To unsubscribe from this list send email to MI400-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: dr2@cssas400.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.