• No results found

Creating an Externally Described Database File

The process of creating and populating an externally described database physical fi le involves three distinct steps:

1. Describe—You must fi rst describe the fi le’s record format and fi eld-level attributes at the source-language level, much as you would fi rst write a computer program in a source language (e.g., Basic, C, COBOL, RPG).

2. Create—After you describe the fi le, you can create the fi le object by compiling the source-language fi le description. This step is analogous to creating an executable machine-level object program by compiling a COBOL or RPG source program. 3. Insert data—When you’ve successfully compiled the source description into a *FILE

type object, you can insert, or load, data into the fi le.

In this chapter, you learn in more detail how to describe a database fi le. In Chapter 6, you learn more about creating the database fi le and inserting data into it.

Methods of Describing Database Files at the Field Level

There are two approaches to describing fi les at the fi eld level. You can use SQL, or you can use DDS.

SQL

SQL is a powerful relational database language that lets you describe and create physical or logical fi les. You can also use SQL to limit access to, maintain, and retrieve information from fi les, regardless of whether they were created with SQL.

SQL is a standardized database language used extensively not only in IBM OSs but all viable platforms. SQL’s wide support means SQL-based applications are highly portable, which provides a signifi cant incentive for learning SQL.

You should understand that using SQL to exclusively defi ne, control, and manipulate database fi les does have certain challenges:

First, to develop SQL applications, you need IBM DB2 Query Manager and SQL

Development Kit for iSeries products, which are not part of the IBM i base OS support. You must purchase these products separately, just as you would a C, COBOL, or RPG compiler.

Second, SQL is a powerful tool capable of using huge numbers of DASD input/output

(I/O) operations and CPU machine cycles if misused, and mastering it requires a fair amount of time and practice.

Third, the object overhead created by SQL schemas, catalogs, indexes, data

dictionaries, views, journals, and journal receivers is substantial compared to DDS- described physical and logical fi les.

Last, you cannot use SQL alone to describe and create a display fi le with any degree

of sophistication for screen interactive I/O. Regardless of your profi ciency with SQL, you need another tool for display fi les.

DDS

As mentioned, we focus on DDS in this chapter because it is a commonly used method to code source descriptions for several types of fi les, including physical and logical database fi les, display fi les, and printer fi les on the system. Although the complexity of DDS precludes anything more than a brief introduction here, you will get at least some initial exposure to the language and an indication of its capabilities.

SDA, a generator of display-fi le screens for interactive jobs, converts user-supplied screen layout specifi cations into DDS source. For physical and logical fi les, SEU, a general- purpose editor, lets you enter and syntax-check DDS source statements. The availability of these utilities, along with the convenience and fl exibility they provide for describing physical and logical fi les, makes learning DDS worthwhile.

Before we discuss DDS further, however, we need to introduce two important software tools, both of which are part of Application Development ToolSet (ADTS). Although not included in the base OS, ADTS is such a valuable aid for creating and maintaining programs and fi les of all kinds that it would be inconceivable to attempt such work without it.

The fi rst tool is PDM, which provides a convenient way to create source members and

access SEU and includes many other useful tools for programmers.

The second tool, SEU, is used to enter all kinds of source code on the system. SEU

is a “smart editor” that not only knows the line formats of different languages’ source statements but also can check for syntax errors in the source code of various languages, including CL, COBOL, DDS, and RPG. Although SEU has been

indispensable for programming as well as for describing physical and logical database fi les using DDS for many years, IBM’s new Rational Development tools are quickly replacing it.

Note

There were no enhancements to the ADTS toolset for i6.1. IBM recommends that you use the Eclipse-based workstation tool Rational Developer for Power (RDP) for development of traditional IBM i applications. We introduce these traditional tools to the new user because of the widely continued use of these products. We have an in-depth introduction to RDP in Chapter 11.

Introduction to PDM

Programming Development Manager is a workbench environment that allows programmers and system operators to navigate the three levels of the OS’s object-based architecture: the library level, the object level, and the member level. PDM, which provides access to system functions through a standard list interface, lets you move easily from one level to the next. For instance, you can start at the library level and then drop down to the object level. From the object level, you can either go back up to the library level or drop down to the member level.

Through PDM you can work with libraries, objects, or members by selecting from

predefi ned options; or you can defi ne your own options, similar to creating macros in other software products. You can start PDM by following a menu path: From the system Main menu, select option 5 to reach the PROGRAM menu and then option 2 to reach the PDM menu. As an alternative, to go directly to the PDM menu, you can simply type the STRPDM

(Start PDM) command on any command line. You can also use the appropriate “work with” command (e.g., the WRKOBJPDM, or Work with Objects Using PDM, command) to go immediately to PDM lists of libraries, objects, or members.

The STRPDM Command

The PDM menu you reach when you follow the menu path or execute the STRPDM command is similar to the one in Figure 5.3.

Figure 5.3: PDM Menu Screen

As you can see, the three levels of the IBM i object hierarchy (libraries, objects, and members) are listed as menu choices. A fourth choice, Work with user-defined options, lets you defi ne or change your own PDM options. We examine user-defi ned PDM options later; for now, we will describe how the PDM library, object, and member levels are connected. Selecting choice 1, Work with libraries, results in an entry screen that asks for the name of the library or libraries with which you want to work. At this screen, you can request a list of user libraries—a list of libraries whose names all begin with, end with, or contain certain characters (for example, you could enter JAF* to list all libraries beginning with JAF). If you leave the fi rst-time default *LIBL, the system will list all libraries in your library list.

When you take the default, the system displays a Work with Libraries Using PDM screen similar to the one in Figure 5.4 (the composition of the library list will vary from user to user).

Figure 5.4: Work with Libraries Using PDM Screen

Work with Libraries Using PDM

The Work with Libraries Using PDM screen displays a library name, type, and text (if any) for each library. Each list item occupies an entire line of the display. Because of this, the entire library list for some users’ jobs will not fi t on a single screen (that is why you see More . . . near the bottom of the screen in Figure 5.4). If you press F11 (which does not appear on the initial function key list—to see it, press F24), the list is formatted to show library names and types only. When the Text fi eld is not displayed, as many as three

columns of listed items can appear at once, as in Figure 5.5. (Although the display has room for three columns, the library list shown here needs only two columns.)

Figure 5.5: Work with Libraries Using PDM Screen (Alternate Format)

Notice that you can take various actions on the listed libraries by entering the appropriate option number on the input fi eld for a particular list item. More options are available than those displayed above the list; to view the additional options, press F23. You can also display IBM-supplied user-defi ned PDM options (which use letters instead of numbers) by pressing F16. When you select an option, PDM invokes the appropriate CL command. PDM supplies the required command parameters based on a list item’s name and type, and on the name of the library or fi le from which the PDM list item came.

Because PDM draws from information contained in its list, you are spared considerable keying effort. In addition, you can select the same option for multiple objects in the list, and PDM will repeat the necessary command automatically. For example, you can specify option 7—to rename an object—for several different libraries, as Figure 5.6 illustrates for libraries RPGMARINA, BOATS, BUCKJ, and TSTLIB1.

Figure 5.6: Selecting the Same Option for Multiple Libraries

Before you pres Enter, you might want to see the actual command that the specifi ed option invokes. You can do so by pressing F4 after you type the option number in the option fi eld. You will then see the command prompt screen—in this case, for the Rename Object

Figure 5.7: Rename Object (RNMOBJ) Command Prompt Screen

You can see that all parameters have been given values. The Object (name) and Object type

values came from the PDM list item for which the option was taken. The New object value is the same as the current object name. Executing the command would make no sense in this example and would result in an error (you cannot rename an object to the same name), but PDM still assigns the value to facilitate the change. The point is that all PDM options invoke commands; and when you type an option and request prompting, you see the prompt screen for the command that PDM is prepared to execute. You can also see how list-item values have been substituted for the command as parameter values.

If you press Enter at this screen, the system displays the Rename Libraries input screen (Figure 5.8), where you can supply new names for all the selected libraries at once.

Figure 5.8: Rename Libraries Input Screen

For example, in the list above you could change all of the names by simply keying over the displayed library names. Changing library names or typing in new ones is the closest you would come in this case to entering parameter values.

As you have seen, when using PDM, you can select an option on several list items at the same time, and the options will either be grouped together, as for renaming, or be processed one after another. You can also select different options on different list items, in which case the options will be processed from top to bottom and grouped (e.g., all the Rename options together) where applicable.

Now that you have seen how PDM handles options selected on list items, let us see how the Work with Libraries Using PDM function connects to the next level (objects) in the OS object-based hierarchy. Now let us cancel the prompt (F12) and return to the PDM screen in Figure 5.6.

Work with Objects Using PDM

If you simply execute the command WRKOBJPDM with default parameter values, a list of all objects in a specifi ed library is displayed. When no library is specifi ed, PDM uses the library name from the preceding PDM session. You can reach the Work with Objects Using PDM screen from the PDM menu (Figure 5.3) by selecting choice 2, Work with objects. If you are already at a Work with Libraries Using PDM screen, you can get to the Work with Objects Using PDM screen by selecting option 12, Work with, on one of the libraries in the list. For example, for the Work with Libraries Using PDM screen in Figure 5.6, selecting option 12 on library CIS001 takes you to the Work with Objects Using PDM screen you see in Figure 5.9.

Figure 5.9: Work with Objects Using PDM Screen (Three-Column Format, Page 1)

Tip

In PDM, you can return to the library list from the Work with Objects Using PDM screen by pressing F12 when you are fi nished with the object list.

The Work with Objects Using PDM screen, in a format similar to the Work with Libraries Using PDM screen, lists all objects in a single library and—in the three-column format you see in Figure 5.9—displays the object type. If you press F11 to change the screen’s format,

only a single column of objects is displayed, but attribute and text are shown for each (Figure 5.10).

Figure 5.10: Work with Objects Using PDM Screen (Single-Column Format, Page 1)

The attribute information that PDM lists for *FILE- and *PGM-type objects can be useful if you are trying to fi nd the source code used to create the object. For *PGM-type objects, the attribute indicates the language in which the program was written. For example, starting at the top of the list in Figure 5.10 and Table 5.1: The *PGM-type objects show attributes that display the language in which the program was written. The last two objects listed are of type *FILE. CSCFINJL has an attribute of LF, meaning it is a logical fi le, and CSCFINP has the attribute PF-DTA, indicating that this object is a database physical fi le.

Table 5.1: Examples of Object Type and Attributes

Name Type Attribute Description

DATECALC *PGM CLLE ILE Control Language (CL) program

LAB08NEACC *PGM RPGLE ILE RPG program

PROCEDURE1 *PGM CLE ILE C program

CIS001Q *OUTQ Printer output queue

RPGMENU *MSGF Message fi le for a menu

CSCFINJL *FILE LF Logical fi le

Another example of the Work with Objects Using PDM display, Figure 5.11, shows several fi les with the attribute PF-SRC, indicating that these fi les are source physical fi les, which hold source programs, fi le descriptions, and so on.

Figure 5.11: Work with Objects Using PDM Screen (Single-Column Format, Page 3)

The fi le named QDDSSRC is a source physical fi le intended to hold source code for database and display fi les described using DDS. The name itself is symbolic. Although a name beginning with Q is usually an IBM-supplied name, a user created this particular fi le. Programmers commonly use IBM’s naming convention as an aid in recognizing source physical fi les. The names of IBM’s default source physical fi les begin with a Q and include the type of source the fi le is intended to store. For example, default source physical fi les in IBM-supplied library QGPL are named QCLSRC (if they contain CL source programs),

QRPGSRC (if they hold RPG source programs), and so on. The DDS part of the name

QDDSSRC indicates that the source physical fi le holds members coded in DDS; the SRC part of the name stands for source.

As IBM i developers continue to the Integrated Language Environment (ILE), they name source fi les containing these programs by adding LE to the traditional names. For example, a source fi le containing RPG ILE programs would be stored in a fi le named RPGLESRC. Notice that most of the options displayed on the Work with Objects Using PDM screen are similar to those on the Work with Libraries Using PDM screen, and additional options are

available for working with objects, including 4=Delete and 11=Move. Option 12=Work with

has been bumped to a second display of options, which you can view by pressing F23. Just as you can use the Work with option on a selected library from the Work with Libraries Using PDM list to get to this list of objects, you can use the Work with option on a specifi ed object from the Work with Objects Using PDM screen to get to some kind of a “work-with” list. The nature of the list screen you see depends on the type and attribute of the list item upon which you take the option. A *FILE object whose attribute is PF, whether a source or a database physical fi le, usually contains one or more data components called members. Members are the lowest level of a physical fi le object. All physical fi les have a lower level that is referred to as a member. A source physical fi le has members that contain source code, and physical data fi les have members that contain the actual data. On older systems, you might have a physical fi le named ORDERS and the members in the physical fi le might be named JAN1990, FEB1990, and so on. These members would contain the orders for the respective month (JAN) and year (1990). Taking the Work with option on such an object brings you to the lowest level of PDM, Work with Members Using PDM.

Work with Members Using PDM

Selecting option 12 on source physical fi le QDDSSRC results in a Work with Members Using PDM screen like the one in Figure 5.12. (The list of members will be different for different users.)

When you want to create or change a source member in a source physical fi le, the Work with Members Using PDM screen provides an effi cient work environment.

The File and Library fi elds in the screen’s upper-left corner remind you which member list you are viewing. Because these fi elds are both input enabled, you can change to the member list of another fi le and/or library by keying over the displayed value (or values) and pressing

Enter.

The options list for working with members is different from the options list for working with objects. Although no save/restore capability is available for individual members, you can use option 9 to save the fi le of which the member is a part. In addition, for source physical fi les, an edit option (2) lets you change existing source-fi le members, and a print option (6) lets you create hard copy of the source code.

Creating a Member via SEU

To create a new member from the Work with Members Using PDM screen, you use F6. Pressing F6 invokes the STRSEU (Start Source Entry Utility) command and takes you to the command prompt screen for that command (Figure 5.13).

As the fi gure shows, PDM supplies the fi rst two parameter values (source-fi le name and library name) based on the fi le and library information on the preceding Work with Members Using PDM screen. For the Source member parameter, you enter the name of the source program or fi le description you plan to create. Usually, you use the same name that