YES!  You do need the K=K.
Well, either that or
   SETREM 0 ON K
That's better.  More explicit.
OK, I admit it: I do K=K cuz of 10 yr old PI habits that won't die.  PI
didn't have SETREM.

It is important to reset the remove pointer just in case some future
calling program, over which the subroutine has no control, executes
REMOVE.  To be robust, you could save whereever the calling routine had
it, then set it back when done:

   FUNCTION  ATRANS( F,K,P,X )
   SAVED.RP = GETREM(K)           ;* preserve however calling pgms had
it.
   SETREM 0 ON K                  ;* reset to beginning of array.
   REMOVE DUM FROM K SETTING MORE ;* check for any delimiter
   SETREM SAVED.RP ON K           ;* reset rmv ptr in case calling pgm
cares.
   T = TRANS(F,K,P,X)
   RETURN (IF MORE THEN T ELSE RAISE(T) )

Better yet, set a programming standard in your shop.

K=K doesn't actually move any data around, so it's very cheap (no matter
how big a dynamic array K is), but it does reset the remove pointer.

-------

A little background for the newbies listening in:  Learn about REMOVE.
It can be a tremendous performance booster over using extracts.

REMOVE statement or function (There are 2 syntaxes; both do the same
thing.) will return the next substring of a dynamic array, up to the
next system delimiter.
Behind the scenes UV (or PI or UD) keeps track of a "remove pointer" so
that the next time REMOVE is executed it automatically gets the next
element.
See also REVREMOVE, SETREM, GETREM.  
See this list's archives about a bug with REVREMOVE.

The typical use of REMOVE is in a loop:
    LOOP
       REMOVE DATUM FROM DYN SETTING RMVPTR
       do stuff
    WHILE RMVPTR REPEAT
    SETREM 0 ON DYN

but in the TRANS()-related example, all I cared about was whether or not
the argument K contained any system-delimiter (char255 down to 248) that
would affect how PI lowers or doesn't lower the TRANS results.   I
figured REMOVE was an easy way to get that answer.  The original post
talked about @VMs, but it really applies to other system delimiters too.
I don't recall what happens when K is delimited by @AMs, @Ims, @TMs
and/or below.  Hey, it's been 10 years.

CDS


-----Original Message-----
From: Andrea Charles

Do you need the K = K ?
--------------------------

looks good, except how about something like:

 FUNCTION  ATRANS( F,K,P,X )
 REMOVE DUM FROM K SETTING MORE ; check for any delimiters
 K = K ; * reset rmv ptr in case calling pgm cares. T = TRANS(F,K,P,X)
 RETURN (IF MORE THEN T ELSE RAISE(T) )

or did I get the then-else backwards . . .

cds
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to