Tuesday, March 7, 2023

How to change someone's PDM defaults

I have been asked this question twice this week:

Is there a way to change everyone's PDM settings without them having to into their own settings and making the change themselves?

Both people want to change the "file" that contains these setting either with a SQL statement or they would write a program to do so.

I do not know where the PDM settings are stored. I assume they are in a file, or possibly even files. As the data is IBM's data I would be very wary to change it as I have no idea of what the consequences are if I was to make a mistake.

Fortunately there is a command I could use that allows me to change a user's PDM defaults. The Change PDM Defaults command, CHGPDMDFT, has been around for a long as I can remember. It has one parameter for each of the PDM default values. When I prompt the CHGPDMDFT command the following is shown:

                        Change PDM Defaults (CHGPDMDFT)

Type choices, press Enter.

User . . . . . . . . . . . . . .                 Name
Object library . . . . . . . . .   *SAME         Name, *SAME, *SRCLIB, *CURLIB
Replace object . . . . . . . . .   *SAME         *SAME, *NO, *YES
 Create/compile in batch . . . .   *SAME         *SAME, *YES, *NO
Run in batch . . . . . . . . . .   *SAME         *SAME, *NO, *YES
Save/restore option  . . . . . .   *SAME         *SAME, *SINGLE, *ALL 
Job description  . . . . . . . .   *SAME         Name, *SAME, *USRPRF
  Library  . . . . . . . . . . .                 Name, *LIBL, *CURLIB
Change type and text . . . . . .   *SAME         *SAME, *YES, *NO
Option file  . . . . . . . . . .   *SAME         Name, *SAME
  Library  . . . . . . . . . . .                 Name, *LIBL, *CURLIB
Option file member . . . . . . .   *SAME         Name, *SAME
Full screen mode . . . . . . . .   *SAME         *SAME, *NO, *YES
Log option commands  . . . . . .   *SAME         *SAME, *NO, *YES
Exit lists on ENTER  . . . . . .   *SAME         *SAME, *NO, *YES

                                                                        Bottom

Looking at the command's attributes I see that there is no validation program for it. This means that I will have to be careful what changes I make, as I could put bad data into the user's PDM defaults.

Let's start by changing the PDM default settings for myself, user profile is SIMON.

01  CHGPDMDFT USER(SIMON)
02              CHGTYPTXT(*NO)
03              FILE(MYLIB/TESTFILE)

I have deliberately placed the three parameters I have used on separate lines to make the command easier to understand.

Line 1: The only required parameter is the user profile.

Line 2: I always like not being able to change the type of text of members and objects. This stop me from accidentally wiping out a source type or description by an over enthusiastic use of the Field Exit key.

Line 3: This file is not a copy of the default PDM options file. This is just a random file I had used for some other purpose. I just wanted to prove as there is no validation program I need to be careful what I change.

After the command has been executed the user must exit PDM, and then re-enter it for the new defaults to be loaded.

                              Change Defaults


 Change type and text . . . .   N
 Option file  . . . . . . . .   TESTFILE  
   Library  . . . . . . . . .     MYLIB     

If I have to change a few people's user profiles I would use the CHGPDMDFT directly. If I have a larger number of profiles to change I would do this programmatically. I would use a two step process:

  1. Gather a list of user profiles I want to change
  2. Make the change using the CHGPDMDFT command

First step: If I want to change all the programmers' PDM profiles I would make a list of them using the following SQL statement:

01  CREATE TABLE QTEMP.OUTFILE 
02  (USER)
03  AS
04  (SELECT CHAR(AUTHORIZATION_NAME,10)
05     FROM QSYS2.USER_INFO_BASIC
06    WHERE STATUS = '*ENABLED'
07      AND USER_CLASS_NAME = '*PGMR'
08      AND SUBSTR(AUTHORIZATION_NAME,1,1) <> 'Q')
09  WITH DATA

Line 1: If I am going to have a list of programmers, I am going to need to put that list into a SQL Table or a DDS file. By using the CREATE TABLE SQL statement the definition of the table is dictated by the Select statement contained within.

Line 2: There is only one column of results, the User Profile. I have decided to name this column USER as it is a lot easier to handle than the name of the column this comes from in the Select statement, AUTHORIZATION_NAME.

Line 4: As I said, above, the only column in the results is the value from the AUTHORIZATION_NAME, which is the user profile. I have used the CHAR scalar function to convert this column from variable character, VARCHAR, to fixed length character, CHAR, of ten characters. This makes it easier for a CL program to handle.

Line 5: I am retrieving the results from the USER_INFO_BASIC SQL view as it returns its results faster than the full USER_INFO View.

Line 6: I only want to include enabled user profiles, not disabled ones.

Line 7: All profiles that have the *PGMR, programmer, user class.

Line 8: Exclude any profile where the first character is 'Q'. This is my crude attempt to exclude any IBM user profiles, for example: QPGMR.

Line 9: I need to include the WITH DATA at the end of my Create Table statement to ensure that results are returned and inserted into the created table.

I would then need to look at the results, for example using the following SQL Select statement:

01  SELECT * FROM QTEMP.OUTFILE

I would then review the results from the above SQL Select statement and remove any entries I do not want to change their PDM Defaults, and add others I want to change.

The second step is the program the reads this file and makes the changes using the CHGPDMDFT command.

My CL program looks like:

01  PGM

02  DCL VAR(&LOOP) TYPE(*LGL) VALUE('1')
03  DCLF FILE(QTEMP/OUTFILE)

04  DOWHILE COND(&LOOP)
05    RCVF
06    MONMSG MSGID(CPF0000) EXEC(LEAVE)

07    CHGPDMDFT USER(&USER) +
08                CHGTYPTXT(*NO) +
09                FILE(PGMRLIB/PDMOPTS) +
10                MBR(QAUOOPT)
11  ENDDO

12  ENDPGM

Line 2: This is the indicator variable I will be using to condition the Do-loop contained within this program.

Line 3: Declaration of the input file. This is the file I created with the SQL statement above, and have reviewed and checked before this program would be called.

Lines 4 – 11: The never-ending Do-loop, condition by the indicator &LOOP.

Line 5: Receive (read) the next record from the file.

Line 6: If there was an error with the receive, end-of-file, records, locked, etc., I exit the Do loop with the LEAVE command.

Lines 7 – 10: Changing the PDM defaults from the user profile received from the file, with the CHGPDMDFT command.

After compiling the program, I run it. I can then check the PDM options for some of the user profiles I changed, and they look like:

                              Change Defaults


 Change type and text . . . .   N
 Option file  . . . . . . . .   PDMOPTS   
   Library  . . . . . . . . .     PGMRLIB   

The change was successful. Job well done.

 

You can learn more about the CHGPDMDFT command from the IBM website here.

 

This article was written for IBM i 7.5, and should work for some earlier releases too.

2 comments:

  1. Do the whole thing with a single SQL :)
    --WARNING the "QCMDEXC" means that executing this SQL statement will actually run a bunch of generated "CHGPDMDFT" commands on your server! USE CAUTION!--
    SELECT AUTHORIZATION_NAME, QCMDEXC('CHGPDMDFT USER(' || AUTHORIZATION_NAME || ') CHGTYPTXT(*NO) FILE(PGMRLIB/PDMOPTS) MBR(QAUOOPT)') AS CMD
    FROM QSYS2.USER_INFO_BASIC
    WHERE STATUS = '*ENABLED'
    AND USER_CLASS_NAME = '*PGMR'
    AND SUBSTR(AUTHORIZATION_NAME, 1, 1) <> 'Q';

    ReplyDelete
  2. I would like to do this only for programmers that haven't already changed their option file. It would be nice if there was a DSPPDMDFT or RTVPDMDFT.

    ReplyDelete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.