Sunteți pe pagina 1din 7

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 t ime to jump in and start trying things out. First, it is important to learn a bit more about your library list. I hope you r ead 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 QSYS QHLPSYS QUSRSYS QTEMP QGDDM QGPL Type SYS SYS SYS USR USR USR Text System Library

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 sequ ence. 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 e asier if your library is in the library list. For now, the best way to do this i s to make your personal library the CURRENT LIBRARY. The CURRENT LIBRARY is a sl ightly 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 th em in the CURRENT LIBRARY. Key in the command to change the CURRENT LIBRARY to your personal library. The c ommand 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 crea ted a library with the same name as your user ID. So, don't get confused and thi nk 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 QSYS QHLPSYS QUSRSYS USER999 QTEMP QGDDM QGPL

Type SYS SYS SYS CUR USR USR USR

Text System Library

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 thi s file to your personal library. In doing this, we will learn about AS/400 comma nds, 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 libr ary, 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 t hat 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 c ommon 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 th e 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 selec ted 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 yo u 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 promp ts for the options. So, key in CPYF and hit F4. You should see: Copy File (CPYF)

Type choices, press Enter. From file . . . . . . Library . . . . . . To file . . . . . . . Library . . . . . . From member . . . . . To member or label . . Replace or add records Create file . . . . . Print format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *LIBL *LIBL *FIRST *FIRST *NONE *NO *CHAR Name Name, *LIBL, *CURLIB Name, *PRINT Name, *LIBL, *CURLIB Name, generic*, *FIRST, *ALL Name, *FIRST, *FROMMBR *NONE, *ADD, *REPLACE... *NO, *YES *CHAR, *HEX

F3=Exit F4=Prompt F5=Refresh F13=How to use this display

F10=Additional parameters F24=More keys

Bottom F12=Cancel

With just a little experimentation, you will learn that the critical values on t his 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 . . . . . . . . . . . Library . . . . . . . . . . . To file . . . . . . . . . . . . Library . . . . . . . . . . . From member . . . . . . . . . . To member or label . . . . . . . Replace or add records . . . . . Create file . . . . . . . . . . Print format . . . . . . . . . . > CUST > USER000 > CUST > USER999 *FIRST *FIRST *NONE > *YES *CHAR Name Name, *LIBL, *CURLIB Name, *PRINT Name, *LIBL, *CURLIB Name, generic*, *FIRST, *ALL Name, *FIRST, *FROMMBR *NONE, *ADD, *REPLACE... *NO, *YES *CHAR, *HEX

Of course, replace USER999 with yuour personal library name. Hit ENTER now and s ee how quickly these 1000 records are copied into a file in your personal librar y. You now have a file named CUST in your personal library and it has over 1000 rec ords of data in it. Now, you can learn some important things about the way commands work. You can hi t F9 to RETRIEVE the last command executed. This is a handy shortcut. But it als o shows exactly what command was executed and what the options were. So hit F9 a nd 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 impossibl e. 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 . . . . Library . Member . . . From record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *LIBL *FIRST 1 Name Name, *LIBL, *CURLIB Name, *FIRST, *LAST Number, *END, *ALLDATA the file, the library the f topic) and the first record with the value that you pro set to 1.

That's not too bad. The only options are the name of ile is in, the member (we'll discuss this in another number. Notice that most of the default values are filled in bably want. For example, the FROM RECORD# is already

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 val ue 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 f ull of customer name and address data: 001002E LUMPKIN 001084CHISOLM 001105HAGGINS 001109BYRD 001168ROMERO 001177POUNDS 001183HINTON 001184YANCEY 001186MCDOUGLE 001202DAVIS 001208TARVIN 001214GOOSEBERRY 001234REID 001239COLBERT 001259BLACKMON 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN STREET STREET STREET STREET STREET STREET STREET STREET STREET STREET STREET STREET STREET STREET STREET ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN ANYTOWN 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 on e 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 libra ry QSYS. There isn't a CUST file in QHLPSYS or QUSRSYS either. There isn't a CUS T 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 QS YS 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 keyw ords. You could just key in: DSPPFM CUST By the way, you could display the original CUST file that you copied from USER00 0. 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 t he 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 000012 000013 000014 000015 000016

1,208 1,214 1,234 1,239 1,259 1,264

TARVIN GOOSEBERRY REID COLBERT BLACKMON CRANFORD

123 123 123 123 123 123

MAIN MAIN MAIN MAIN MAIN MAIN

STREET STREET STREET STREET STREET 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 sele ct 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 li brary 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 hi t 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 Relationship . . . . . Field . . . . . . . . Relational operator . Value . . . . . . . . test: . . . . . . . . . . . . . . . . *NONE *NONE, *IF, *AND, *OR Name *EQ, *GT, *LT, *NE, *GE...

+ for more values Record format field mapping . . Source update options . . . . . Source sequence numbering: Starting sequence number . . . Increment number . . . . . . .

*NONE *SAME 1.00 1.00

*NONE, *NOCHK, *CVTSRC... *SAME, *SEQNBR, *DATE 0.01-9999.99 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 . . . . Field . . . . . . . Relational operator Value . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

*IF CSSTE *EQ 'TX'

*NONE, *IF, *AND, *OR Name *EQ, *GT, *LT, *NE, *GE...

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 fil e. 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.

S-ar putea să vă placă și