Rabu, 03 April 2013

AS/400 Chapter 5: Physical Files

You can use files to define tables, executable code, etc. In this chapter we'll try to explain some basic concepts of working with files.
We've created a table using SQL, now we'll create the remaining tables with DDS.
Source files are files that can have several members. Each member represents the source code from an executable object or an executable object. A source file is similar to a folder where you can organize its members.
The source file naming follows an established convention:
  • QRPGLESRC – file that holds the members written in RPG-ILE language.
  • QDDSSRC – holds the members written in DDS.
  • QRPGSRC – holds the members written in the traditional RPG language.
As you can see, all the names start with a Q and end with SRC. You don't need to follow this convention and there isn't any problem at the system level if you don't. But since it's a well established convention and it really helps with the code organization, you should follow it.
Let's create our first source file where we will later add our DDS tables.
If you're currently in the DEMO library you don't need to specify it in the command.

PDM (Programming Development Manager)

We're going to use the PDM application that enables the user to write the source code and compile it, among other things. PDM uses the SEU (Source Entry Utility) text editor, we will see how to use it in this chapter. To start the PDM type the command:
A screen similar to this will appear:
PDM Screen
Choose the option '3. Work with members'. We are going to create some members in the QDDSSRC source file. With the option 2 you can work with compiled objects and with option 1 work with libraries.
On the next screen you will be asked for the filename and the library where it's stored. Insert the information you see in the image below:
Creating a source file
Note: Your current library and the library you are working with in PDM are two different things. You can be working with members from DEMO and your current library can be DEMO2, for example. Now you should see the screen bellow. You will find all the options for working with file members.
Source file listing
Press F6 so you can create your first member (you can see in the options bellow the prompt: “F6=Create”). Insert the information as you see below:
Creating a physical file

Working with SEU (Source Entry Utility)

SEU screen:
SEU screen
RPG and DDS are positional languages, wich means that each element has a specific line and column were it should be placed in the source code. SEU gives us a little help to position each element in its place. If you put the cursor in any of the SEU's lines and press F4 a prompt will appear, like the one in the next image, where you can write each element and the SEU will place it its right position. To close the prompt press F12.
Working with SEU

Insert a new line

Write an “i” (without quotes) on any position of the numbered column on the left. Press Enter, and a new line will be added bellow.

Delete a line

Write a “d” (without quotes) on any position of the numbered column on the left and press Enter.

Delete several lines

Place “dd” (without quotes) on the numbered column of the first line you want to delete and another set of “dd” on the last line to delete, press Enter.

DDS Syntax

Let's start by defining the member SHOPS as it's written bellow. After the code you'll find the explanation of what each line means.
                     UNIQUE               R SHOPR                  ID_SHP              10P                  NAME_SHP            25A                 MANAGER_SH           50A              K ID_SHP

Line 1

To ensure that the primary key has an unique value for each record you must specify the keyword UNIQUE in the first line of the table definition. Press F4 and write unique in the functions field.

Line 2

Here you define the table record name. The record identifies all the fields in a table. We will see an example of its use in the Display Files chapter. Insert a new line bellow the first, as we explained previously and press F4. Place an “R” in the Name Type field and SHOPR in the Name field.

Line 3, 4 e 5

Definition of the table fields. In the third line, for instance, in the F4 prompt you should place “ID_SHP” in the Name field, 10 in the Length (must be right justified in the field), “P” in the Data Type (because it's a numeric value).
Most common data types :
For more information on data types press F1 after you placed the cursor on the Data Type field. Or visit ILE RPG Reference.

Line 6

Definition of the primary key field. “K” is the Name Type and in the Name you should write the name of the field exactly as it is written above. For more than one primary key you should have a different “K” starting line for each primary key field.
When you finish writing the code press F3 to leave the editor and save the changes you've made.

Useful DDS Functions

If you want to use any of these functions place it in the Functions field.


CHECK(AB): Allows the field to be blank CHECK(ME): Mandatory Enter. The field must have a value (not blank).
CHECK(MF): Mandatory Fill. For example, if you have a string of size 50 all the 50 characters must be filled.


Compares values. The syntax is COMP(relational-operator value), where relational-operator can be one of these values:
  • EQ (equal)
  • NE (not equal)
  • LT (less than)
  • NL (not less than)
  • GT (greater than)
  • NG (not greater than)
  • LE (less than or equal to)
  • GE (greater than or equal to)


Specifies the format of a Date field. Some of the possible formats are:
  • *ISO: yyyy-mm-dd
  • *EUR: dd.mm.yyyy
  • *USA: mm/dd/yyyy
  • *MDY: mm/dd/yy
  • *DMY: dd/mm/yy
  • *YMD: yy/mm/dd


Specifies the format of a Time field. Some of the possible formats are:
  • *ISO: hh.mm.ss
  • *EUR: hh.mm.ss
  • *USA: hh:mm AM/PM
  • *HMS: hh:mm:ss


Defines the maximum and minimum value a field can have.
  • For a numeric field: RANGE(4 9)
  • For a non-numeric field: RANGE('4' '9')


Specifies all the valid values on a field.
  • For a numeric field: VALUES(4 5 6 7 8 9)
  • For a non-numeric field: VALUES('a' 'b' 'c' 'd')


Specifies a default value.


Specifies that a field refers to a field in another table (foreign key). In this case you don't specify the Data Type or the Length of the field, but you must place an “R” in the Ref field in the F4 prompt.

Compiling Files

To create the object that will save the data (the file you've just created only stores the source code) choose option '14- Compile' in the file you've created.
File listing
This tutorial won't teach you to analyse the resulting files from a compilation, but if you want to give it a go write the command WRKSPLF (Work spool file) in the system prompt. The most important messages from the compilation usually appear on the file with the same name as the one you compiled (the most recent compilation appears on the bottom of the list).
A quick way to check if a file's compilation was successful is to see if the new object was created. To do so you must go to the opening screen in the PDM choose option '2 – Work with objects' and put the options as you see in the image bellow and press Enter.
PDM: Work with objects
Now check to see if there's a member named SHOPS (the same name you gave to the source code member).
If you do this you need to be careful because this only works correctly for the first compilation, because an object always keeps the data from the last successful compilation. So, if after a successful compilation you alter the source code and compile it again, even if this compilation ends in error, the object will still be in the system with the definitions of a previous compilation.
You can however delete the compiled object before a new compilation (in the same menu where you checked if the file exists) - this way you can be sure that the compilation was successful.
You have now all the information you need to create DDS tables. Create the CARDS and MOVEMENTS tables, using the same fields names as in the data model, because we will be using those later on. When you're finished, or if you have any doubt, check the files with the final results.

Tidak ada komentar:

Posting Komentar