                          P D S U T I L


      Linkable routine PDSUTIL is useful to manage in MVS Batch environment
members of PDS libraries; so this services are availables to Cobol or
Assembler calling program.

      This routine can be recalled with a CALL statement from any Cobol
or Assembler program writing the following parameters:

      in cobol:

          CALL 'PDSUTIL' USING FUNCT DDNAME MEMBER AREALEN AREAOUT RC

      where:

          FUNCT      PIC     X(6).
          DDNAME     PIC     X(8).
          MEMBER     PIC     X(8).
          AREALEN    PIC    S9(7)   COMP.
          AREAOUT    PIC     X(nnn).
          RC         PIC    S9(7)   COMP.

      in assembler:

          CALL  PDSUTIL,(FUNCT,DDNAME,MEMBER,AREALEN,AREAOUT,RC),VL

      where:

          FUNCT      DS   CL6
          DDNAME     DS   CL8
          MEMBER     DS   CL8
          AREALEN    DS   F
          AREAOUT    DS   CLnnn
          RC         DS   F

      Passed variables have this meaning:
FUNCT   : action to do (see later)
DDNAME  : logical name of library to process; unlike program PDSBATCH,
          library ddname is not fixed but can be choosed as you like
MEMBER  : member name to process; also this parameter is mandatory
          except for 'DIR' function, in which can be leaved blank
AREALEN : length of following parameter 'AREAOUT', in format fullword
          binary; is mandatory variable and is in input/output
AREAOUT : is the exchange data area from calling program and routine;
          with function WRITE is filled with record to write in output,
          in any other case is filled by data returned from routine
          to calling program
RC      : is return code returned by routine, in binary fullword;
          is equal to 0 if is all OK.

      Available commands (in variable FUNCT) are:

DIR      return a directory record in 'AREAOUT'; recalling more times
         function 'DIR' without change pointed librery (that is without
         change DDNAME) one by one are returned all names and
         characteristics of library members, until is reached an
         End Of File condition (i.e. a RC not equal to 0).
         If MEMBER parameter is empty (that is filled of blanks)
         all directory is returned; if MEMBER specify a complete name,
         first directory record returned is that with name equal to
         MEMBER or that immediately following if MEMBER not exist.
         If is specified a partial name with star (*), are returned
         only members beginning with that name; star (*) must be specified
         at end of name, and not at start or in the middle.
         The working selection is that setted the FIRST time is recalled
         function 'DIR' for a certain library.
         chiamata la funzione 'DIR' per una determinata libreria.
         If library is not a load library (with RECFM = U) and is ISPF
         managed (that is User Data Area of directory is 30 bytes long)
         in AREAOUT are returned all this informations:

          AREAOUT.
             NOMEMEM         PIC   X(8).
             UAREALEN        PIC   9(2).
             ALIAS           PIC      X.
             SIZEMEM         PIC   9(6).
             INIT            PIC   9(6).
             MOD             PIC   9(6).
             CREATED.
                 GG-CREA     PIC   99.
                 FILLER      PIC    X.
                 MM-CREA     PIC   99.
                 FILLER      PIC    X.
                 AA-CREA     PIC   99.
             CHANGED-DATE.
                 GG-CHANGE   PIC   99.
                 FILLER      PIC    X.
                 MM-CHANGE   PIC   99.
                 FILLER      PIC    X.
                 AA-CHANGE   PIC   99.
             CHANGED-TIME.
                 HH-CHANGE   PIC   99.
                 FILLER      PIC    X.
                 MM-CHANGE   PIC   99.
             USERID          PIC   X(8).
             VV              PIC   99.
             MM              PIC   99.

         The mean of this variables is the same that specified for program
         PDSBATCH.
         If User Data Area is not 30 bytes long, AREAOUT is:

          AREA.
             NOMEMEM         PIC   X(8).
             UAREALEN        PIC   9(2).
             ALIAS           PIC      X.
             UAREA           PIC  X(nn).

         where UAREA is the User Area not decoded, with length (UAREALEN)
         at most of 62 bytes.

QUERY    verify that member exist and, if found, return the same data
         of function DIR
READ     read a record from specified member; recalling more times READ
         function with DDNAME and MEMBER unchanged, are returned one by one
         all records of member, until End of File is reached, that is
         variable RC (Return Code) is different from 0. 
WRITE    write a record in specified member getting it from 'AREAOUT',
         with record length specified in AREALEN; recalling more times
         routine with DDNAME and MEMBER unchanged, are sequentially 
         written all records in the same member.
DELETE   delete specified member in library pointed by DDNAME
RENAME   rename specified member with new name in 'AREAOUT', in library
         pointed by DDNAME
CLOSE    close member specified

      As you can notice, not exist a 'OPEN' function; this is because
file opening is always implicit in certain commands; opening is done 
every time the routine is recalled for the first time with a certain 
DDNAME and MEMBER.
If the same command next is executed with the same DDNAME and MEMBER,
function continue to use the member previously opened (at least for
functions DIR, READ and WRITE). If the same command have a different
DDNAME or MEMBER, routine:
- automatically close previous member
- automatically open new library or new member
So in this case, even CLOSE is implicit.
Moreover, for QUERY, RENAME and DELETE functions, library is always
opened and closed before returning to calling program.
In short, is necessary recall 'CLOSE' function only before the end of
calling program, for every DIR, READ and WRITE function in which you
don't have a End Of File (so, at least, you MUST do a CLOSE if you
use WRITE function, before ending main program).

      Is possible to use this routine for every available function at the
same time; for example, while a READ of a member is performed, is possible
recall the same routine to do a WRITE of another member, but is not possible
a recall to do another READ of a different member without the close of 
the previous member.
      If you must read or write AT THE SAME TIME two different members, 
you can use this trick:
- copy load member PDSUTIL with a different name, for example 'PDSUTIL1'
- all the times you want access to the second member simultaneously,
  you do a CALL to PDSUTIL1 instead of PDSUTIL

Is not possible use this routine in a CICS program.


      Examples:


       IDENTIFICATION DIVISION.
       PROGRAM-ID. PROVA1.
       AUTHOR. PIERO.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           DECIMAL-POINT  IS  COMMA.
      ****************************************************************
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  FUNZ       PIC     X(6).
       77  DDNAME     PIC     X(8).
       77  MEMBER     PIC     X(8).
       77  LEN        PIC    S9(7)   COMP VALUE +80.
       77  AREAOUT    PIC     X(80).
       77  RC         PIC    S9(7)   COMP.
      ****************************************************************
      * EXAMPLE OF WRITING   IN SYSOUT OF A  MEMBER                  *
      ****************************************************************
       PROCEDURE DIVISION.
       INIZIO.
           MOVE 'READ'     TO FUNZ.
           MOVE 'LIBDD'    TO DDNAME.
           MOVE 'MYMEM   ' TO MEMBER.
       LOOP.
           MOVE +80        TO LEN.
           CALL 'PDSUTIL' USING FUNZ DDNAME MEMBER LEN AREAOUT RC.
           IF RC NOT = 0 THEN GO TO FINE.
           DISPLAY AREAOUT.
           GO TO LOOP.
       FINE.
           DISPLAY 'RC = ' RC.
           STOP RUN.


       Next example print library Directory.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *----------------------------------------------------------------
       77  FUNZ       PIC     X(6).
       77  DDNAME     PIC     X(8).
       77  MEMBER     PIC     X(8).
       77  LEN        PIC    S9(7)   COMP VALUE +80.
       77  RC         PIC    S9(7)   COMP.
       01  AREAOUT.
           05 NAMEMEM         PIC   X(8).
           05 UAREALEN        PIC   9(2).
           05 ALIAS           PIC      X.
           05 SIZE            PIC   9(6).
           05 INIT            PIC   9(6).
           05 MOD             PIC   9(6).
           05 CREATED.
              10  GG-CREA     PIC   99.
              10  FILLER      PIC    X.
              10  MM-CREA     PIC   99.
              10  FILLER      PIC    X.
              10  AA-CREA     PIC   99.
           05 CHANGED-DATE.
              10  GG-CHANGE   PIC   99.
              10  FILLER      PIC    X.
              10  MM-CHANGE   PIC   99.
              10  FILLER      PIC    X.
              10  AA-CHANGE   PIC   99.
           05 CHANGED-TIME.
              10  HH-CHANGE   PIC   99
              10  FILLER      PIC    X.
              10  MM-CHANGE   PIC   99
           05 USERID          PIC   X(8).
           05 VV              PIC   XX.
           05 MM              PIC   XX.
      ****************************************************************
       PROCEDURE DIVISION.
       INIZIO.
           MOVE 'DIR'      TO FUNZ.
           MOVE 'MYDD '    TO DDNAME.
           MOVE '        ' TO MEMBER.
      *    MOVE 'VAL*    ' TO MEMBER. <-- example of selection
       LOOP.
           MOVE +80        TO LEN.
           MOVE '        ' TO AREAOUT.
           CALL 'PDSUTIL' USING FUNZ DDNAME MEMBER LEN AREAOUT RC.
           IF RC NOT = 0 THEN GO TO FINE.
           DISPLAY AREAOUT.
           GO TO LOOP.
      * ---------------------------------------------------------------
       FINE.
           DISPLAY 'RC = ' RC.
           STOP RUN.
      ********************************************************** END *


       Next example copy a member in an another member.

       WORKING-STORAGE SECTION.
       77  FUNC1      PIC     X(6).
       77  DDNAME1    PIC     X(8).
       77  MEMBER1    PIC     X(8).
       77  LEN        PIC    S9(7)   COMP VALUE +80.
       77  AREAOUT    PIC     X(80).
       77  RC         PIC    S9(7)   COMP.
       77  FUNC2      PIC     X(6).
       77  DDNAME2    PIC     X(8).
       77  MEMBRO2    PIC     X(8).
      ****************************************************************
      * EXAMPLE OF A MEMBER COPY                                     *
      ****************************************************************
       PROCEDURE DIVISION.
       INIZIO.
           MOVE 'READ'     TO FUNC1.
           MOVE 'MYDD '    TO DDNAME1.
           MOVE 'INPUTMEM' TO MEMBER1.
           MOVE 'WRITE'    TO FUNC2.
           MOVE 'MIADD'    TO DDNAME2.
           MOVE 'OUTMEM  ' TO MEMBER2.
       LOOP.
           MOVE +80        TO LEN.
           CALL 'PDSUTIL' USING FUNC1 DDNAME1 MEMBER1 LEN AREAOUT RC.
           IF RC NOT = 0 THEN GO TO FINE.
           DISPLAY AREAOUT.
           CALL 'PDSUTIL' USING FUNC2 DDNAME2 MEMBER2 LEN AREAOUT RC.
           GO TO LOOP.
      * ---------------------------------------------------------------
       FINE.
           DISPLAY 'RC = ' RC.
           MOVE 'CLOSE'    TO FUNC2.
           CALL 'PDSUTIL' USING FUNC2 DDNAME2 MEMBER2 LEN AREAOUT RC.
           STOP RUN.


