We have around 4000 users in our system and would like to work with the "user catalog" in order to assign different script directories to different user groups. How can we avoid putting all 4000 user names into the user catalog? It is possible to use the SAP roles?

Yes, this is possible. Example:

// User groups
M1   \\P5008\GuiXT\General \\P5008\GuiXT\M1
M2   \\P5008\GuiXT\General \\P5008\GuiXT\M2
MX   \\P5008\GuiXT\General
XX none

// Assign user groups according to SAP roles
Role=SD_FACTORY_SALES     M1
Role=SAP_FI*                         M2

Please observe that the RFC user needs the appropriate authorization to read user roles:

S_RFC: RFC_TYPE=FUGR, RFC_NAME=SU_USER, ACTVT=16

S_USER_GRP: CLASS=*,ACTVT=03

S_USER_SYS: CLASS=*,ACTVT=90 (if central user management is used)