/* REXX */
/* CLS2REXXed by FSOX001 on 31 May 2017 at 11:48:27  */
Signal On NoValue
Call On Error
Signal On Failure
Signal On Syntax
Parse source opsys . exec_name .
Address ISREDIT
 
"MACRO"               /* CARM0005 EDIT RACFCMDS.RPT(LISTGRP|LGT) */
/*********************************************************************/
/* 05/05/2004 JL.NELSON CHANGED TO COLLECT NEW RACF FINDINGS.        */
/* 06/15/2004 JL.NELSON ADDED EXIT CODE.                             */
/* 11/11/2004 JL.NELSON Added profiles to group entries.             */
/* 02/03/2005 JL.NELSON Changed undefined UZIDs for reporting        */
/*            access.                                                */
/* 02/03/2005 JL.NELSON Added USER= entry for empty groups for       */
/*            PDI check.                                             */
/* 02/07/2005 JL.NELSON Correct FIND/CHANGE to avoid problems.       */
/* 02/07/2005 JL.NELSON Lookup USERIDs once and save names.          */
/* 02/24/2005 JL.NELSON Changed constants to variables before        */
/*            rename.                                                */
/* 06/09/2005 JL.NELSON Pass MAXCC in ZISPFRC variable.              */
/* 08/25/2005 JL.NELSON Added code to remove & in Name field.        */
/* 03/08/2006 JL.NELSON Made changes to avoid abend 920/932.         */
/* 03/13/2006 JL.NELSON Set/test RCode for critical ISREDIT          */
/*            commands.                                              */
/* 05/03/2006 JL.NELSON Cancel changes until PDSE problem is         */
/*            fixed.                                                 */
/* 08/23/2007 CL.FENTON Rewritten to speed up process by creating    */
/*            formatted records for each group in the member.        */
/* 02/24/2009 CL.FENTON Correct 824 return code in processing        */
/*            user entries.                                          */
/* 06/08/2017 CL.FENTON Converted script from CLIST to REXX.         */
/*            Removed writing records to TEMP5 dataset, STS-017060.  */
/* 07/19/2019 CL.FENTON Changes include a limit of 1000 userids      */
/*            being extracted until all userids are collected for    */
/*            groups with excessive number of userids to avoid an    */
/*            error on variable LIDLIST, STS-022967.                 */
/*                                                                   */
/*                                                                   */
/*                                                                   */
/*                                                                   */
/*********************************************************************/
pgmname = "CARM0005 07/19/19"
sysprompt = "OFF"                /* CONTROL NOPROMPT          */
sysflush = "OFF"                /* CONTROL NOFLUSH           */
sysasis = "ON"                 /* CONTROL ASIS - caps off   */
Address ISPEXEC "CONTROL NONDISPL ENTER"
Address ISPEXEC "CONTROL ERRORS RETURN"
 
/*******************************************/
/* VARIABLES ARE PASSED TO THIS MACRO      */
/*******************************************/
maxcc = 0
return_code = 0
Address ISPEXEC "VGET (CONSLIST COMLIST SYMLIST TERMMSGS",
  "UZID SORTSW) ASIS"
rm05vget = return_code
If return_code <> 0 then do
  Say pgmname "VGET RC =" return_code zerrsm
  Say pgmname "CONSLIST/"conslist "COMLIST/"comlist,
    "SYMLIST/"symlist "TERMMSGS/"termmsgs "UZID/"uzid,
    "SORTSW/"sortsw
  return_code = return_code + 16
  SIGNAL  ERR_EXIT
  end
Address ISPEXEC "VGET (PDIMBR RPTMBR LIDRC LIDLINE) ASIS"
 
If CONSLIST = "ON" | COMLIST = "ON" | SYMLIST = "ON" ,
  then Trace ?r
 
/*******************************************/
/* TURN ON MESSAGES                        */
/*******************************************/
syssymlist = symlist          /* CONTROL SYMLIST/NOSYMLIST */
sysconlist = conslist         /* CONTROL CONLIST/NOCONLIST */
syslist = comlist          /* CONTROL LIST/NOLIST       */
sysmsg = termmsgs         /* CONTROL MSG/NOMSG         */
lidlist = ""
"(MEMBER) = MEMBER"
return_code = 0
"(ENDER) = LINENUM .ZLAST"
If return_code <> 0 then,
  SIGNAL  ERR_EXIT       /* empty member */
return_code = 0
 
"FIND 'INFORMATION FOR GROUP ' 1"
If return_code = 0 then do
  ind = ""
  Say pgmname "Records in" member "before processing is" ender"."
  Call reformat_data
  "(ENDER) = LINENUM .ZLAST"
  Say pgmname "Records in" member "after processing is" ender"."
  end
"FIND '"left(uzid,8)"' ALL 1"
"(A,ACNTS) = FIND_COUNTS"
"CURSOR = 1 0"
 
if uzid = "" then signal END_EDIT
 
If sortsw = "A" then,
  "SORT 1 16 A"
ELSE,
  "SORT 1 16 D"
 
/*******************************************/
/* MAIN LOOP                               */
/*******************************************/
GROUP_LOOP:
return_code = 0
cnt = 0
"CURSOR =" lidline 0
do forever
  "FIND '"left(uzid,8)"' 1"
  If return_code > 0 then do
    lidrc = return_code
    leave
    end
  "(DATA) = LINE .ZCSR"
  "(LIDLINE) = LINENUM .ZCSR"
  lidlist = lidlist""substr(data,9,28)
  cnt = cnt + 1
  if cnt = 1000 then leave
  end
 
 
END_EDIT:
return_code = 0
 
 
ERR_EXIT:
If maxcc >= 16 | return_code > 4 then do
  Address ISPEXEC "VGET (ZISPFRC) SHARED"
  If maxcc > zispfrc then,
    zispfrc = maxcc
  Else,
    zispfrc = return_code
  Address ISPEXEC "VPUT (ZISPFRC) SHARED"
  Say pgmname "ZISPFRC =" zispfrc
  end
rm005rc = return_code
/*say pgmname left(pdimbr,8) left(uzid,8) right(lidline,8,"0"),
  lidrc "COUNT:"right(cnt,5,"0")*/
Address ISPEXEC "VPUT (RM05VGET RM005RC LIDLIST LIDLINE LIDRC) ASIS"
"CANCEL"
Exit 0
 
 
REFORMAT_DATA:
"CAPS OFF"
"(ENDER) = LINENUM .ZLAST"
"CURSOR = 1 0"
return_code = 0
 
 
NEXT_USER:
do curline = 1 to ender
  return_code = 0
  "(DATA) = LINE" curline
  data = data
  If left(data,11) = "INFORMATION" then do
    "CURSOR =" curline 0
    ind = ""
    grpid = substr(data,23,8)
    return_code = 0
    "FIND 'USER' 1 13"
    If return_code <> 0 then,
      call NO_USERS
    Else do
      "(CURLINE) = LINENUM .ZCSR"
      "(DATA) = LINE" curline
      If substr(data,12,1) <> "=" then,
        call NO_USERS
      Else,
        ind = "ON"
      end
    iterate
    end
  if ind <> "" & data = " " then do
    ind = ""
    iterate
    end
  user = substr(data,7,8)
  If left(user,1) = " " | ind = "" then iterate
  return_code = 0
  "FIND '"user"' 9"
  If return_code = 0 then do
    "(DATA) = LINE .ZCSR"
    ac = left(grpid,8)substr(data,9)
    "LINE_AFTER .ZLAST = DATALINE (AC)"
    iterate
    end
  name = "Unknown"
  return_code = 0
  x = outtrap("line.",3)
  return_code = 0
  cmd = "LISTUSER" user
  Address TSO cmd
  If return_code = 0 then do
    do x = 1 to 3
      If "U" = left(line.x,1) then,
        parse var line.x . "NAME=" name " OWNER=" .
      end
    end
  Else
    Do
      name = "Not found RC =" return_code" "
    end
 
 
  SKIP_LOOKUP:
  return_code = 0
  ac = left(grpid,8)left(user,8)name
  "LINE_AFTER .ZLAST = DATALINE (AC)"
  curline = curline
  end
 
 
FINISH_FORMAT:
"DELETE 1" ender
"SAVE"
return
 
 
NO_USERS:
return_code = 0
user = "Empty*"
ac = left(grpid,8)left(user,8)"No USERS in GROUP"
"LINE_AFTER .ZLAST = DATALINE (AC)"
return
 
 
NoValue:
Failure:
Syntax:
say pgmname 'REXX error' rc 'in line' sigl':' strip(ERRORTEXT(rc))
say SOURCELINE(sigl)
SIGNAL ERR_EXIT
 
 
Error:
return_code = RC
if RC >= 16 then do
  say pgmname "LASTCC =" RC strip(zerrlm)
  say pgmname 'REXX error' rc 'in line' sigl':' strip(ERRORTEXT(rc))
  say SOURCELINE(sigl)
  end
if RC = 20 then,
  say pgmname "PDIMBR="PDIMBR "RPTMBR="RPTMBR "UZID="UZID "CNT="ACNTS
if return_code > maxcc then
  maxcc = return_code
return
 
 
