TexAS400 Tutorial



Library Lists and Copy File

More on Library List (LIBL) and Copy File (CPYF)

If you have read through the topics you are probably getting a bit bored. It's time to jump in and start trying things out.

First, it is important to learn a bit more about your library list. I hope you read the earlier topic on LIBRARY LISTS and understood some of it. Sign on to the AS/400, and from a command line, key in DSPLIBL and hit ENTER.

Your LIBRARY LIST should look like:


Opt  Library     Type      Text            
     QSYS        SYS       System Library  
     QHLPSYS     SYS                       
     QUSRSYS     SYS                       
     QTEMP       USR                       
     QGDDM       USR                       
     QGPL        USR                       
This simply means that whenever you key in a command, call a program or go to a menu, the AS/400 will look for what it needs in those libraries and in that sequence.

In fact, when you keyed in the command DSPLIBL, the AS/400 looked for it in the first library, QSYS. Not by accident, that is the library that has all of the AS/400 commands. So, the AS/400 executed the command DSPLIBL that it found in the library QSYS.

Since we will do a lot of things in your personal library, it will make things easier if your library is in the library list. For now, the best way to do this is to make your personal library the CURRENT LIBRARY. The CURRENT LIBRARY is a slightly special designation. The CURRENT LIBRARY is the first user library. Also, if you create files and don't tell the AS/400 where to put them, it will put them in the CURRENT LIBRARY.

Key in the command to change the CURRENT LIBRARY to your personal library. The command is Change Current Library. This is an excellent example of the way the AS/400 usually makes the command name from the 3 letter abbreviations. The command is CHGCURLIB. So, key in:

CHGCURLIB USER999

Of course, replace USER999 with your user ID. When I set up your user ID, I created a library with the same name as your user ID. So, don't get confused and think that this command changes the current library to your user ID. It is changing your current library to a library that happens to be named the same as your ID.

Now display your library list again. You remember, DSPLIBL.

Your library list now looks like:


                                               
 Opt  Library     Type      Text               
      QSYS        SYS       System Library     
      QHLPSYS     SYS                          
      QUSRSYS     SYS                          
      USER999     CUR                          
      QTEMP       USR                          
      QGDDM       USR                          
      QGPL        USR                          
Now let's have some real fun. There is a file in library USER000 named CUST. It has a little over 1,000 records in it. Some people think of a record like a line on a spreadsheet.

We will need some data for a query we will write in a minute. So, let's copy this file to your personal library. In doing this, we will learn about AS/400 commands, the very powerful COPY FILE command and a few other commands as well.

The command to copy the CUST file from the library USER000 to your personal library, USER999 is pretty scary looking. It is:

CPYF FROMFILE(USER000/CUST) TOFILE(USER999/CUST) CRTFILE(*YES)

Memorizing the keywords and options would be impossible. Fortunately, it's not that hard. Let's see how the AS/400 makes it easy to use complex commands.

First, you must remember the command name. This command, CPYF (COPY FILE) is a common command. But if you need help remembering it you could try going to one of the menus that lists the commands.

If you remember that COPY is abbreviated CPY, you could key in:

GO CMDCPY

You would see a list of commands and number 6 is CPYF.

Or, you could key in:

GO MAJOR

You would see a list of the major groups of commands. Since you see "more" in the lower right hand of the screen, you know that you can hit the PAGE-DOWN key to see more. You don't need to though since you can see that selection 5 will show you the FILE COMMANDS. you will find CPYF on that list. Or you could have selected 2 for VERB COMMANDS and found the COPY COMMANDS as #18 on that list.

Are you started to get the idea? This menu (most of them start with CMD) show you all of the commands on the system.

Remember, we were looking for the command to copy a file. It is CPYF. So, let's see how to use a command now that we know its name.

Key in the command on the command line but don't hit ENTER. Instead, hit F4. The AS/400 understands that F4 means that you want to see the options and the prompts for the options.

So, key in CPYF and hit F4. You should see:


                               Copy File (CPYF)                               
                                                                              
Type choices, press Enter.                                                    
                                                                              
From file  . . . . . . . . . . .                 Name                         
  Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB         
To file  . . . . . . . . . . . .                 Name, *PRINT                 
  Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB         
From member  . . . . . . . . . .   *FIRST        Name, generic*, *FIRST, *ALL 
To member or label . . . . . . .   *FIRST        Name, *FIRST, *FROMMBR       
Replace or add records . . . . .   *NONE         *NONE, *ADD, *REPLACE...     
Create file  . . . . . . . . . .   *NO           *NO, *YES                    
Print format . . . . . . . . . .   *CHAR         *CHAR, *HEX                  
                                                                              
                                                                              
                                                                              
                                                                              
                                                                              
                                                                              
                                                                              
                                                                        Bottom
F3=Exit   F4=Prompt   F5=Refresh   F10=Additional parameters   F12=Cancel     
F13=How to use this display        F24=More keys                              
                                                                              
With just a little experimentation, you will learn that the critical values on this screen are:

FROM FILE which we want to be CUST
Library for FROM FILE which we want to be USER000
TO FILE which we want to be CUST
Library for TO FILE which should be your personal library
CREATE FILE which needs to be *YES

So your screen should look like:


From file  . . . . . . . . . . .  > CUST          Name                         
   Library  . . . . . . . . . . . >   USER000     Name, *LIBL, *CURLIB         
 To file  . . . . . . . . . . . . > CUST          Name, *PRINT                 
   Library  . . . . . . . . . . . >   USER999     Name, *LIBL, *CURLIB         
 From member  . . . . . . . . . .   *FIRST        Name, generic*, *FIRST, *ALL 
 To member or label . . . . . . .   *FIRST        Name, *FIRST, *FROMMBR       
 Replace or add records . . . . .   *NONE         *NONE, *ADD, *REPLACE...     
 Create file  . . . . . . . . . . > *YES          *NO, *YES                    
 Print format . . . . . . . . . .   *CHAR         *CHAR, *HEX                  
Of course, replace USER999 with yuour personal library name. Hit ENTER now and see how quickly these 1000 records are copied into a file in your personal library.

You now have a file named CUST in your personal library and it has over 1000 records of data in it.

Now, you can learn some important things about the way commands work. You can hit F9 to RETRIEVE the last command executed. This is a handy shortcut. But it also shows exactly what command was executed and what the options were. So hit F9 and you will see:

CPYF FROMFILE(USER000/CUST) TOFILE(USER999/CUST) CRTFILE(*YES)

For simple commands, the keywords (FROMFILE, TOFILE and CRTFILE) are not needed. That is, if you key in all the right options in the right order, you may leave out the keywords. For a command as complicated as CPYF, that is almost impossible. Most commands are simpler though.

To see the data in the file, you might expect to use a command DSPF for display file. As it turns out the command is actually, DISPLAY PHYSICAL FILE MEMBER and is named DSPPFM.

Now that you know the name of the command, you know that you can key DSPPFM and hit F4 to see the keywords and options. If you do, you'll see:


                     Display Physical File Member (DSPPFM)              
                                                                        
Type choices, press Enter.                                              
                                                                        
File . . . . . . . . . . . . . .                 Name                   
  Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB   
Member . . . . . . . . . . . . .   *FIRST        Name, *FIRST, *LAST    
From record  . . . . . . . . . .   1             Number, *END, *ALLDATA
That's not too bad. The only options are the name of the file, the library the file is in, the member (we'll discuss this in another topic) and the first record number.

Notice that most of the default values are filled in with the value that you probably want. For example, the FROM RECORD# is already set to 1.

So all you really need to fill in is the FILE NAME of CUST and the LIBRARY name where the FILE is located. In fact, it's even simpler than that. The default value for the LIBRARY is *LIBL. This means that the command will look for the FILE in the LIBRARY LIST. And since your personal library is the CURRENT LIBRARY, all you need to enter is the file name.

So if you fill in the FILE name as CUST and hit ENTER, you should see a screen full of customer name and address data:


 001002E LUMPKIN                     123 MAIN STREET               ANYTOWN  
 001084CHISOLM                       123 MAIN STREET               ANYTOWN  
 001105HAGGINS                       123 MAIN STREET               ANYTOWN  
 001109BYRD                          123 MAIN STREET               ANYTOWN  
 001168ROMERO                        123 MAIN STREET               ANYTOWN  
 001177POUNDS                        123 MAIN STREET               ANYTOWN  
 001183HINTON                        123 MAIN STREET               ANYTOWN  
 001184YANCEY                        123 MAIN STREET               ANYTOWN  
 001186MCDOUGLE                      123 MAIN STREET               ANYTOWN  
 001202DAVIS                         123 MAIN STREET               ANYTOWN  
 001208TARVIN                        123 MAIN STREET               ANYTOWN  
 001214GOOSEBERRY                    123 MAIN STREET               ANYTOWN  
 001234REID                          123 MAIN STREET               ANYTOWN  
 001239COLBERT                       123 MAIN STREET               ANYTOWN  
 001259BLACKMON                      123 MAIN STREET               ANYTOWN   
Now to keep learning about how commands are executed, hit F9 to see the command that you just ran. It is:

DSPPFM FILE(CUST)

What happened is that the AS/400 followed a line of logic like this:

I'm supposed to run the command DSPPFM so first I need to find the command in one of the libraries in the library list. The first library in the library list is QSYS and it has a command named DSPPFM so I'll run that.

Next, I need to find a file named CUST. There is no CUST file in the first library QSYS. There isn't a CUST file in QHLPSYS or QUSRSYS either. There isn't a CUST file in QPDA or QADM. There is a CUST file in USER999, which happens to be the CURRENT LIBRARY. So, I'll run the command DSPPFM that I found in the library QSYS and I'll display the file CUST that I found in USER999.

Like many commands, this one is so simply that you don't need to prompt the keywords. You could just key in:

DSPPFM CUST

By the way, you could display the original CUST file that you copied from USER000. Key in DSPPFM , hit F4 and fill in the file name of CUST and the library name of USER000.

The shortcut form of that command is:

DSPPFM USER000/CUST

Just for fun, delete the file you copied and then copy it again.

To delete the file, use the command DELETE FILE, which is DLTF. So if you key in:

DLTF CUST

or

DLTF USER999/CUST

and hit ENTER and you will delete your CUST file.

Now, use the CPYF command to copy it again from the USER000 library. Or, if you are efficient, hit F9 a few times until your CPYF command is retrieved and then hit ENTER and run it again.

The data displayed with the DSPPFM command is unformatted. That is, it is just a string of letters and numbers. Try the command:

RUNQRY QRYFILE(CUST)

This command is a tiny part of the QUERY/400 programming language. It displays the file but separates the data into fields with headings. It should look like:


Position to line  . . . . .              Shift to column  . . . . . .         
Line   ....+....1....+....2....+....3....+....4....+....5....+....6....+....7.
         CSNBR   CSNAME                          CSADR1                       
000001   1,002   E LUMPKIN                       123 MAIN STREET              
000002   1,084   CHISOLM                         123 MAIN STREET              
000003   1,105   HAGGINS                         123 MAIN STREET              
000004   1,109   BYRD                            123 MAIN STREET              
000005   1,168   ROMERO                          123 MAIN STREET              
000006   1,177   POUNDS                          123 MAIN STREET              
000007   1,183   HINTON                          123 MAIN STREET              
000008   1,184   YANCEY                          123 MAIN STREET              
000009   1,186   MCDOUGLE                        123 MAIN STREET              
000010   1,202   DAVIS                           123 MAIN STREET              
000011   1,208   TARVIN                          123 MAIN STREET              
000012   1,214   GOOSEBERRY                      123 MAIN STREET              
000013   1,234   REID                            123 MAIN STREET              
000014   1,239   COLBERT                         123 MAIN STREET              
000015   1,259   BLACKMON                        123 MAIN STREET              
000016   1,264   CRANFORD                        123 MAIN STREET              
You can see from the prompts at the bottom of the screen that you can shift the data to see more by hitting F20. F20 is SHIFT and F8. F19 will shift back.

I hope you're having fun and starting to see the power of the AS/400.

Notice when you shift to the right by hitting SHIFT and F20 that the field name for the STATE is CSSTE.

For the last lesson in executing commands, let's copy the original file but select only customers from Texas (where else?). We know that the field that has the state is CSSTE.

First, delete the file you copied:

DLTF CUST

Now, key in the CPYF command and hit F4. As before fill in the file names and library names and the create file option.

Notice that at the bottom, F10 will show ADDITIONAL PARAMETERS. If you hit F10, you will see "more…' at the bottom right of the screen. This means that you can hit the PAGE DOWN key to see more options.

The CPYF command has many, many options. If you hit PAGE DOWN 4 times, you will see:


                               Copy File (CPYF)                               
                                                                              
Type choices, press Enter.                                                    
                                                                              
Include records by field test:                                                
  Relationship . . . . . . . . .   *NONE         *NONE, *IF, *AND, *OR        
  Field  . . . . . . . . . . . .                 Name                         
  Relational operator  . . . . .                 *EQ, *GT, *LT, *NE, *GE...   
  Value  . . . . . . . . . . . .                                              
                                                                              
                                                                              
                                                                              
               + for more values                                              
Record format field mapping  . .   *NONE         *NONE, *NOCHK, *CVTSRC...    
                                                                              
Source update options  . . . . .   *SAME         *SAME, *SEQNBR, *DATE        
                                                                              
Source sequence numbering:                                                    
  Starting sequence number . . .   1.00          0.01-9999.99                 
  Increment number . . . . . . .   1.00          0.01-9999.99                 
                                                                       More...

Here, you can enter selection values. Fill in the top of the screen to look like:

                                                                           
Include records by field test:                                             
  Relationship . . . . . . . . .   *IF           *NONE, *IF, *AND, *OR     
  Field  . . . . . . . . . . . .   CSSTE         Name                      
  Relational operator  . . . . .   *EQ           *EQ, *GT, *LT, *NE, *GE...
  Value  . . . . . . . . . . . .   'TX'                                    
These values say, "copy only records in which the field CSSTE is equal to "TX""

Now if you hit enter, you will copy CUST from library USER000 to USER999 but it will copy only customers from Texas.

When you have run this command, re-run the RUN QUERY command to see the data:

RUNQRY QRYFILE(CUST)

You should see only data for customers in Texas.

That's it for now. Experiment with your new knowledge. Use CPYF to copy your file. Use DLTF to delete it. Use DSPPFM and RUNQRY to look at the data.

I hope you're looking forward to the next topic. I am.

 

 

Back to Table of Contents   |   Main Page