Previous Page | Next Page

Functions and CALL Routines

PEEKC Function



Stores the contents of a memory address in a character variable on a 32-bit platform.
Category: Special
Restriction: Use on 32-bit platforms only.

Syntax
Arguments
Details
Comparisons
Examples
Example 1: Listing ASCB Bytes
Example 2: Creating a DATA Step View
See Also

Syntax

PEEKC(address<,length>)


Arguments

address

is a numeric constant, variable, or expression that specifies the memory address.

length

is a numeric constant, variable, or expression that specifies the data length.

Default: 8, unless the variable length has already been set (by the LENGTH statement, for example)
Range: 1 to 32,767

Details

If you do not have access to the memory storage location that you are requesting, the PEEKC function returns an "Invalid argument" error.

You cannot use the PEEKC function on 64-bit platforms. If you attempt to use it, SAS writes a message to the log stating that this restriction applies. If you have legacy applications that use PEEKC, change the applications and use PEEKCLONG instead. You can use PEEKCLONG on both 32-bit and 64-bit platforms.


Comparisons

The PEEKC function stores the contents of a memory address into a character variable. The PEEK function stores the contents of a memory address into a numeric variable.

Note:   SAS recommends that you use PEEKCLONG instead of PEEKC because PEEKCLONG can be used on both 32-bit and 64-bit platforms.   [cautionend]


Examples


Example 1: Listing ASCB Bytes

The following example, specific to the z/OS operating environment, uses both PEEK and PEEKC, and prints the first four bytes of the Address Space Control Block (ASCB).

data _null_;
   length y $4;
      /* 220x is the location of the ASCB pointer */
   x=220x; 
   y=peekc(peek(x));
   put 'y= ' y;
run;


Example 2: Creating a DATA Step View

This example, specific to the z/OS operating environment, also uses both the PEEK and PEEKC functions. It creates a DATA step view that accesses the entries in the Task Input Output Table (TIOT). The PRINT procedure is then used to print the entries. Entries in the TIOT include the three components outlined in the following list. In this example, TIOT represents the starting address of the TIOT entry.

TIOT+4

is the ddname. This component takes up 8 bytes.

TIOT+12

is a 3-byte pointer to the Job File Control Block (JFCB).

TIOT+134

is the volume serial number (volser) of the data set. This component takes up 6 bytes.

Here is the program:

   /* Create a DATA step view of the contents    */
   /* of the TIOT. The code steps through each   */
   /* TIOT entry to extract the ddname, JFCB,    */ 
   /* and volser of each ddname that has been    */ 
   /* allocated for the current task. The data   */
   /* set name is also extracted from the JFCB.  */
  
data save.tiot/view=save.tiot;
   length ddname $8 volser $6 dsname $44;
      /* Get the TCB (Task Control Block)address */ 
      /* from the PSATOLD variable in the PSA    */
      /* (Prefixed Save Area).  The address of   */ 
      /* the PSA is 21CX. Add 12 to the address  */
      /* of the TCB to get the address of the    */
      /* TIOT. Add 24 to bypass the 24-byte      */  
      /* header, so that TIOTVAR represents the  */ 
      /* start of the TIOT entries.              */

   tiotvar=peek(peek(021CX)+12)+24;

      /* Loop through all TIOT entries until the */
      /* TIOT entry length (indicated by the     */
      /* value of the first byte) is 0.          */
         
   do while(peek(tiotvar,1));

      /* Check to see whether the current TIOT   */
      /* entry is a freed TIOT entry (indicated  */
      /* by the high order bit of the second     */
      /* byte of the TIOT entry). If it is not   */
      /* freed, then proceed.                    */
            
      if peek(tiotvar+1,1)NE'l.......'B then do;
         ddname=peekc(tiotvar+4);
         jfcb=peek(tiotvar+12,3);
         volser=peekc(jfcb+134);
            /* Add 16 to the JFCB value to get  */ 
            /* the data set name.  The data set */
            /* name is 44 bytes.                */

         dsname=peekc(jfcb+16);
         output;
         end;

         /* Increment the TIOTVAR value to point */
         /* to the next TIOT entry. This is done */
         /* by adding the length of the current  */ 
         /* TIOT entry (indicated by first byte  */ 
         /* of the entry) to the current value   */
         /* of TIOTVAR.                          */

      tiotvar+peek(tiotvar,1);
   end;

      /* The final DATA step view does not       */ 
      /* contain the TIOTVAR and JFCB variables. */

   keep ddname volser dsname;
run;

     /* Print the TIOT entries.                  */
proc print data=save.tiot uniform width=minimum;
run;

In the PROC PRINT statement, the UNIFORM option ensures that each page of the output is formatted exactly the same way. WIDTH=MINIMUM causes the PRINT procedure to use the minimum column width for each variable on the page. The column width is defined by the longest data value in that column.


See Also

CALL Routine:

CALL POKE Routine

Functions:

ADDR Function

PEEK Function

Previous Page | Next Page | Top of Page