Rabu, 03 April 2013

AS400 PDM

Before you work on this topic, there is an important option to change. From the command line, key in the command STRPDM and hit ENTER. Then, key in 1 and hit ENTER. Then hit ENTER again. Your screen should look like:

-------------------------------------------------------------------
                         Work with Libraries Using PDM      
                                                            
 List type  . . . . . . .   *LIBL                           
                                                            
 Type options, press Enter.                                 
   2=Change                    3=Copy       5=Display       
   8=Display description       9=Save       10=Restore      
                                                            
 Opt  Library     Type       Text                           
      QSYS        *PROD-SYS  System Library                 
      QHLPSYS     *PROD-SYS                                 
      QUSRSYS     *PROD-SYS                                 
      QPDA        *PROD-PRD                                 
      QADM        *PROD-PRD                                 
      QTEMP       *TEST-USR                                 
      QGDDM       *PROD-USR                                 
      QGPL        *PROD-USR                                 
--------------------------------------------------------------------
Now, hold down the SHIFT key and hit F6. You should now see:

---------------------------------------------------------------------
                                Change Defaults               
                                                              
 Type choices, press Enter.                                   
                                                              
   Object library . . . . . . .   *SRCLIB      Name, *CURLIB, 
   Replace object . . . . . . .   N            Y=Yes, N=No    
   Compile in batch . . . . . .   Y            Y=Yes, N=No    
   Run in batch . . . . . . . .   N            Y=Yes, N=No    
   Save session defaults  . . .   Y            Y=Yes, N=No    
   Save/Restore option  . . . .   1            1=Single, 2=All
   Job description  . . . . . .   QBATCH       Name, *USRPRF, 
     Library  . . . . . . . . .     *LIBL      Name, *CURLIB, 
   Change type and text . . . .   Y            Y=Yes, N=No    
   Option file  . . . . . . . .   QAUOOPT      Name           
     Library  . . . . . . . . .     QGPL       Name, *CURLIB, 
   Member . . . . . . . . . . .   QAUOOPT      Name           
   Full screen mode . . . . . .   N            Y=Yes, N=No    
   Scan hierarchy . . . . . . .   Y            Y=Yes, N=No    
   Search path  . . . . . . . .   *DFT         Name, *DFT     
   Build scope  . . . . . . . .   1            1=Normal, 2=Lim
                                               4=Direct Chain 
--------------------------------------------------------------------
Hit TAB until the cursor is on the "Compile in batch" line. Change the value from Y to N and hit ENTER. Okay, now you are ready for the PDM topic.
Programs are created from source statements. On the AS/400, source statements are entered using PDM, the Program Development manager. Technically, PDM uses the Source Entry Utility (SEU) as the editor. But you don't have to think of SEU as something different from PDM.
PDM provides a way to enter program source statements and then to compile the statements into executable programs. The source statements are needed only for the compiler. The compiled programs are the objects that are actually run on the AS/400. The source code and the compiled objects are separate things. But it is easy to confuse the two. At times, you may try to open the compiled object with PDM when you really mean to open the source code used to create the compiled object.
Source code is kept in a member of a file. The file is kept in a library. Each file can have many members. Each member is the source code for a program.
The source code files can have any name but conventionally the names start with Q and end with SRC, for source. Typically:
QCLSRC is the file for the CL program source statements
QDDSSRC is for the DDS program source statements
QRPGSRC is for the old RPG language
QRPGLESRC is for the new RPG/ILE language
QMNUSRC or QMENUSRC is for menus
QCBLSRC or QLBLSRC is for COBOL
QCMDSRC is for commands
You could keep most of the source statements is a single file. That is, one member could have CL source statements and another member could have DDS and another could have RPG source statements. Conventionally though, source code is not mixed up like that.
So, let's try it out by writing a simple CL program to change the "Current Library" to your library and to go to the programmer menu. CL is the Control Language of the AS/400. This is a lesson in PDM so don't fret too much about the specifics of CL.
When you got your user ID on this system, a library was also created for you with the same name as your user ID. Suppose that your ID is USER999. That means you have a library available to you named USER999. Some people relate an AS/400 library to a Directory or Folder on a PC.
Your library is probably empty. Since this is the first CL program ever written in your library, you need to create a file to store the CL source statements in.
On the command line, type in:
CRTSRCPF and then hit F4. (F4 always invokes the prompts)
From the earlier lesson in commands, you should remember that commands usually are made up of 3 letter abbreviations of verbs and such. In the case, the command CRTSRCPF stands for Create Source Physical File. That's not exactly intuitive but it's not too hard to remember.
For the library name, key in your library name, similar to USER999. For the Object (or File) name, key in QCLSRC. Now hit ENTER and you've created a source physical file named QCLSRC in the library named USER999. Remember that QCLSRC is not a magic or reserved name. But almost everyone uses this name for their CL source.
Once you use commands for a while, you will learn how to enter simple commands without the prompts. In this case:
CRTSRCPF USER999/QCLSRC
So now you have a place to store your CL source statements. Lets start PDM and try to enter the simple program. PDM can be started from the programmer menu or with the Start PDM command. Most programmers use the Start PDM command. Type in STRPDM and hit ENTER.
Your screen should look something like:

------------------------------------------------------------------------
                  AS/400 Programming Development Manager (PDM)
                                                              
 Select one of the following:                                 
                                                              
      1. Work with libraries                                  
      2. Work with objects                                    
      3. Work with members                                    
      4. Work with projects                                   
      5. Work with groups                                     
      6. Work with parts                                      
                                                              
      9. Work with user-defined options                       
                                                              
                                                              
                                                              
                                                              
                                                              
                                                              
 Selection or command                                         
-----------------------------------------------------------------------
Now for the most confusing part of PDM… And it's not that confusing. PDM will let you navigate to your source statements 3 different ways. Let's try to draw a picture of the organization of the source statements. Suppose you have 2 libraries. One for General Ledger programs and one for Payroll. Each one has CL, DDS and RPG programs. A schematic of this is:

Library  Object or File Member or Program name

GLLIB   QCLSRC            GLC001
                                    GLC003 
           GLC007
   QRPGSRC           GLR001
                                    GLR002
                                    GLR005
   QDDSSRC           GLD001

PRLIB   QCLSRC            PRC100
                                    PRC101
                                    PRC125AB
   QRPGSRC           PRR100
                                    PRR125
   QDDSSRC           PRD105
                                    PRD107
                                    PRD108
The analogy on a PC is that you have two Folders in the root; one is GLLIB and the other is PRLIB. Each of those folders has three folders: QCLSRC, QRPGSRC and QDDSSRC. Each of those folders has a few documents, each one with the source statements for the program. The schematic of your library right now is:

Library   Object or File  Member or Program name

USER99                      QCLSRC
That is, you have one file in your library and that file has no members. I prefer to navigate to my source code using selection 3 (Work with members). So, key in 3 and hit ENTER.
Your screen now looks like:

------------------------------------------------------------------------
                       Specify Members to Work With                        
                                                                           
 Type choices, press Enter.                                                
                                                                           
   File  . . . . . . . . . .   QCLSRC       Name, F4 for list              
                                                                           
     Library . . . . . . . .   USER999      *LIBL, *CURLIB, name           
                                                                           
   Member:                                                                 
     Name  . . . . . . . . .   *ALL         *ALL, name, *generic*          
     Type  . . . . . . . . .   *ALL         *ALL, type, *generic*
------------------------------------------------------------------------                                                                       
Key in the File name of QCLSRC and the library name like USER999. Finally for member name key in *ALL. This is a little like saying on a PC, "Show me all the documents in the folder QCLSRC which is in the folder USER999".
The AS/400 now shows you the "WORK WITH MEMBERS WITH PDM" display and all of the members in QCLSRC. But since QCLSRC has no members it shows "NO MEMBERS IN FILE".
About ¼ from the top, the AS/400 tells you what options you can use in PDM. For example, 2 is to edit or change a member, 3 is to copy a member, 4 to delete a member. If you hit F23, the AS/400 will display more options. Your keyboard has only 12 "F" keys at the top. If you hold down the shift key when you hit an "F" key, it adds 12 to the "F" number. So, if you hold down shift and hit F11, this is the F23 key. When you do this, the AS/400 shows other option numbers.
Similarly, at the bottom, the AS/400 tells you what "F" keys you can use. Hitting F24 (shift while hitting F12) will cause the AS/400 to display more "F" keys. These "F" keys are called FUNCTION KEYS.
So, finally.. Let's add a member and write a simple Control Language program.
At the bottom-right of your screen you should see that F6=Create. This means that hitting F6 will let you create a new member. So, hit F6.
The screen will now show:

------------------------------------------------------------------------
                      Start Source Entry Utility (STRSEU)                   
                                                                            
Type choices, press Enter.                                                  
                                                                            
Source file  . . . . . . . . . . > QCLSRC        Name, *PRV                 
  Library  . . . . . . . . . . . > USER999       Name, *LIBL, *CURLIB, *PRV 
Source member  . . . . . . . . .   FIRSTCL       Name, *PRV, *SELECT        
Source type  . . . . . . . . . .   CLP           Name, *SAME, BAS, BASP...  
Text 'description' . . . . . . .   My First CL Program                                   
                                                                            
------------------------------------------------------------------------
Fill in the Source member name. This will become the program name. Name it FIRSTCL. The Source type is important. It will tell the AS/400 what compiler to use to compile the source code. CL programs are designated as Source type CLP. So, enter CLP.
For the text description, enter a short description.
Now hit ENTER and the screen should look like:

-----------------------------------------------------------------------
Columns . . . :    1  71            Edit                        USER001/QCLSRC
 SEU==>                                                      FIRSTCL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data*************************
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
'''''''                                                                        
-----------------------------------------------------------------------
You now have an empty member to key source code into. If you were to hit ENTER right now, the editor (SEU) would assume that you don't want to keep any of these lines since you haven't entered anything on them. So, to make things simple, key a space on the top line, then TAB twice to the next line and key another space. Do this on about 10 lines.
Now, when you hit ENTER, SEU sees that you keyed something (a space) on those lines and it keeps them for you.
If you did this, SEU replaced the dots on the left with numbers and should look like:

------------------------------------------------------------------------
Columns . . . :    1  71            Edit                        USER001/QCLSRC
 SEU==>                                                       FIRSTCL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data**************************
0001.00                                                                        
0002.00                                                                        
0003.00                                                                        
0004.00                                                                        
0005.00                                                                        
0006.00                                                                        
0007.00                                                                        
0008.00                                                                        
0009.00                                                                        
-----------------------------------------------------------------------
Languages have syntax rules to follow. CL is mostly a free format syntax. Blank lines are allowed and commands can be placed in any column. Also, CL programs must begin with a PGM statement. So, key PGM on the first line and hit ENTER. Your screen should now look like:

------------------------------------------------------------------------
Columns . . . :    1  71            Edit                        USER001/QCLSRC
 SEU==>                                                       FIRSTCL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data**************************
0001.00 PGM                                                                       
0002.00                                                                        
0003.00                                                                        
0004.00                                                                        
0005.00                                                                        
0006.00                                                                        
0007.00                                                                        
0008.00                                                                        
0009.00                                                                        
-----------------------------------------------------------------------
Now, it's time to experiment a bit with the line editor. SEU (the name of the editor being used by PDM) is a line editor. That just means that commands to copy, insert and delete lines are entered in the left portion of the screen where the numbers are. Try a simple line command. Key in D right on top of the number 0001.00 at the top left. your screen should look like:

------------------------------------------------------------------------
Columns . . . :    1  71            Edit                        USER001/QCLSRC
 SEU==>                                                       FIRSTCL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data**************************
D001.00 PGM                                                                       
0002.00                                                                        
0003.00                                                                        
0004.00                                                                        
0005.00                                                                        
0006.00                                                                        
0007.00                                                                        
0008.00                                                                        
0009.00                                                                        
-----------------------------------------------------------------------
This D tells the editor to delete this line when the ENTER key is hit. So, go ahead and hit ENTER and watch that line disappear. Now key the PGM back in on another line.
Just to experiment, copy line 0001 and insert it after line 0005. Do this by keying a C (for "copy") on line 0001 and an A (for "after") on line 0005.
Your screen should look like:

------------------------------------------------------------------------
Columns . . . :    1  71            Edit                        USER001/QCLSRC
 SEU==>                                                       FIRSTCL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data**************************
C001.00 PGM                                                                       
0002.00                                                                        
0003.00                                                                        
0004.00                                                                        
A005.00                                                                        
0006.00                                                                        
0007.00                                                                        
0008.00                                                                        
0009.00                                                                        
-----------------------------------------------------------------------
When you hit ENTER, SEU will copy line 1 and place it on a new line after line 5. If you key C3 on line 0001, SEU will copy three lines and place them after the line with an A.
Or, if you key CC on line 0001 and CC on line 0004, SEU will copy from line 0001 thru 0004.
Similarly, putting DD on line 0001 and DD on line 2000 would delete all lines from line 1 to line 2000.
Okay, let's finish the program. The complete program will do only two things. The first is that it will change your "CURRENT LIBRARY" to your library USER999 and the second thing is it will go to the Program menu on the AS/400.
Since this isn't a lesson in CL programming, trust me and key in the following program. Be sure to use your USERID in place of USER999.

------------------------------------------------------------------------
Columns . . . :    1  71            Edit                        USER001/QCLSRC
 SEU==>                                                       FIRSTCL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data**************************
0001.00 PGM                                                                       
0002.00                                                                        
0003.00 CHGCURLIB USER999                                                                       
0004.00                                                                        
0005.00 GO PROGRAM                                                                       
0006.00                                                                        
0007.00                                                                        
0008.00                                                                        
0009.00                                                                        
-----------------------------------------------------------------------
Now hit F3 to tell PDM that you are done. Hit ENTER to accept the values on the screen. PDM has saved your program and you can now see it in your PDM list of members. The screen should now show:

---------------------------------------------------------------------
                           Work with Members Using PDM          
                                                                                
 File  . . . . . .   QCLSRC                                                     
 Library . . . .     USER999              Position to  . . . . .              
                                                                                
 Type options, press Enter.                                                     
  2=Edit         3=Copy  4=Delete 5=Display       6=Print     7=Rename          
  8=Display description  9=Save  13=Change text  14=Compile  15=Create 
                                                                                
 Opt  Member      Type        Text                                              
      FIRSTCL     CLP         My First Cl Program                               
                                                                                

---------------------------------------------------------------------
So, you have now entered the statements needed by the AS/400 compiler to compile a CL program. Each time you add a member, this list of members will grow. Just for fun, key a 2 next to FIRSTCL under OPT on the screen. Hit ENTER and PDM will open the source file up again so you can see and change it. Hit F3 and ENTER to get back. To compile the program, key 14 under OPT next to FIRSTCL and hit enter. This tells PDM to compile the statements that are in the member named FIRSTCL.
If all went well, in a few seconds, the AS/400 will have compiled your program. Hit TAB to get to the bottom of the screen. This is the command line.
Key CALL USER999/FIRSTCL on the command line (be sure to use your USERID in place of USER999). If your program compiled, you should now see:

-----------------------------------------------------------------------
PROGRAM                          Programming                
                                                            
Select one of the following:                                
                                                            
     1. Programmer menu                                     
     2. Programming Development Manager (PDM)               
     3. Utilities                                           
     4. Programming language debug                          
     5. Structured Query Language (SQL) pre-compiler        
     6. Question and answer                                 
                                                            
     8. Copy screen image                                   
     9. Cross System Product/Application Execution (CSP/AE) 
                                                            
    50. System/36 programming                               
                                                            
    70. Related commands                                    
                                                            
Selection or command                                        
-----------------------------------------------------------------------
That's the end of this lesson. Try not to be frustrated with the lack of user friendliness of PDM. The wonderful news is that 99% of AS/400's use PDM. So anytime you log on to an AS/400, you will be familiar with the source code editor. It takes most people a week or so of using PDM to get comfortable with it. But you must learn PDM well. You will use it to create files, logical files (indexes), display screens, print files, RPG programs, CL programs and more.

Tidak ada komentar:

Posting Komentar