DCL (SUBSTR, INDEX) BUILTIN; 
Author Message
 DCL (SUBSTR, INDEX) BUILTIN;

Thought I'd take a shot at explaining the line of code.

First: DCL (I,J,K) FIXED BIN(31) INIT(0); is the same as

       DCL I    FIXED BIN(31) INIT(0);
       DCL J    FIXED BIN(31) INIT(0);
       DCL K    FIXED BIN(31) INIT(0);

Similarily, DCL (SUBSTR, INDEX) BUILTIN; is the same as

            DCL SUBSTR     BUILTIN;
            DCL INDEX      BUILTIN;

There is no relationship between SUBSTR and INDEX.  The only thing they
have in common is that they are both PL1 (psuedo) functions.

What the DECLARE statements is doing is telling the PL1 compiler that
"later in the program when you see SUBSTR or INDEX treat them as the PL1
builtin functions".   In the absence of these explicit declare
statements, PL1 will default define them as variables (which is not what
you want).

Using SUBSTR:

 DCL FIELD1   CHAR(10)  INIT('XY12356ABC');
 DCL FIELD2   CHAR(04)  INIT((4)' ');

You want to move 1235 to FIELD2

 FIELD2 = SUBSTR(FIELD1,3,4);   (which means FIELD2 is equal to FIELD1  
                                 beginning in position 3 for a length
of                                  4).

Using INDEX

DCL FIELD3   CHAR(07)  INIT('ABC.123');

INDEX answers the question "Is there a period in FIELD3?" by returning a
number equal to the position in FIELD3 where the first (only) period is
found.

DCL J    FIXED BIN(31) INIT(0);

J = INDEX(FIELD3,'.');  in this case J is set to 4 because the first
period it finds is in position 4 of FIELD3.

IF J = 0  THEN
   DO;
       What ever you do if there is no period in FIELD3.
   END;
ELSE            
   DO;
       What ever you do if there is a period in FIELD3 because there
is        one in position 4.
   END;

Does that help?



Thu, 04 Nov 1999 03:00:00 GMT  
 DCL (SUBSTR, INDEX) BUILTIN;

 . .

Quote:
>Similarily, DCL (SUBSTR, INDEX) BUILTIN; is the same as

>            DCL SUBSTR     BUILTIN;
>            DCL INDEX      BUILTIN;

>There is no relationship between SUBSTR and INDEX.  The only thing they
>have in common is that they are both PL1 (psuedo) functions.

 . .

=============================

Uhh, unless there is a language extension I don't know about (quite
possible), SUBSTR is a pseudofunction, but not INDEX.  A pseudofuction
can receive an assignment; e.g.,

   X = 'ABC';
   SUBSTR(X,2,1) = '*';

will leave the value of X as 'A*C'.  It isn't obvious to me what an INDEX
pseudofunction would do.



Fri, 05 Nov 1999 03:00:00 GMT  
 DCL (SUBSTR, INDEX) BUILTIN;


<Uhh, unless there is a language extension I don't know about (quite
<possible), SUBSTR is a pseudofunction, but not INDEX.  A pseudofuction
<can receive an assignment; e.g.,
<
<   X = 'ABC';
<   SUBSTR(X,2,1) = '*';
<
<will leave the value of X as 'A*C'.  It isn't obvious to me what an INDEX
<pseudofunction would do.

As far as I know, there is no such thing as a "pseudofunction" in PL/I. A
PSEUDOVARIABLE is a PL/I function that can be used as the receiving field
in an assignment statement. The only functions that can be used that way
(and the only ones that make sense) are SUBSTR and UNSPEC.

The discussion here was BUILTIN functions, and PL/I does have a large number
of these. Because the code for these functions is often inserted in line,
rather doing an actual function call (BALR to you IBM MFers) the term
"pseudofunction" MIGHT apply, but I have never heard it used or seen it in
print, and I have been learning, teaching, programming and maintaining PL/I
code on a number of different operation systems since 1969.
--
Jay McFadyen
Development Tools and Infrastructure, C2PSD, Ford Motor Company

(313) 33-73359



Fri, 05 Nov 1999 03:00:00 GMT  
 DCL (SUBSTR, INDEX) BUILTIN;

        >Thought I'd take a shot at explaining the line of code.

        >First: DCL (I,J,K) FIXED BIN(31) INIT(0); is the same as
        >      
        >       DCL I    FIXED BIN(31) INIT(0);
        >       DCL J    FIXED BIN(31) INIT(0);
        >       DCL K    FIXED BIN(31) INIT(0);

        >Similarily, DCL (SUBSTR, INDEX) BUILTIN; is the same as

        >            DCL SUBSTR     BUILTIN;
        >            DCL INDEX      BUILTIN;

        >There is no relationship between SUBSTR and INDEX.  The only thing they
        >have in common is that they are both PL1 (psuedo) functions.

        >What the DECLARE statements is doing is telling the PL1 compiler that
        >"later in the program when you see SUBSTR or INDEX treat them as the PL1
        >builtin functions".   In the absence of these explicit declare
        >statements, PL1 will default define them as variables (which is not what
        >you want).

In the absence of a spcific declaration for SUBSTR and INDEX,
PL/I will assume that any references to SUBSTR and INDEX
are to the built-in functions, which IS what you want!



Thu, 11 Nov 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. DCL (SUBSTR,INDEX) BUILTIN;

2. INDEX builtin

3. Builtin methods versus Builtin Functions -- help!

4. dcl and undcl in Forth (long)

5. DCL by GPIB-Clear.vi

6. CHAR(0) DCL

7. DCL evaluation

8. Checking existing DCL's??

9. Ruby DCL documentation

10. Fortran+DCL

11. job for VAX/VMS-Fortran developer (+DCL +DEC Forms) in NC

12. DCL to UNIX script?

 

 
Powered by phpBB® Forum Software