IBM i e-Book
A Developer’s Guide to Mastering IBM i Concepts
IBM i Index
IBM i History and Overview
System Architecture
Development Tools
Deep Dive into DDS and DDL
Control Language (CL)
Report Program Generator (RPG)
Integrated Language Environment
SQL on IBM i
Jobs & Logs
RPG Built in Functions
- Char
- Check
- Date
- Diff
- Div
- Elem
- Eof
- Error
- Found
- List
- Lower
- Max
- Minutes
- Months
- Occur
- Open
- Parms
- Range
- Rem
- Scanrpl
- Sqrt
- Abs
- Checkr
- Days
- Dec
- Decpos
- Editc
- Equal
- Hours
- Inth
- Len
- Lookup
- Maxarr
- Min
- Minarr
- Replace
- Scan
- Scanr
- Seconds
- Size
- Split
- Status
- Subdt
- Subst
- Timestamp
- Trim
- Triml
- Trimr
- Uns
- Upper
- Xfoot
- Xlate
- Years
RPGLE Opcodes
- Z-add(H)
- Unlock
- Scan(E)
- Readpe
- Read
- Open
- Mult & Mult(H)
- Monitor
- Lookup
- LeaveSr
- Leave
- Exsr
- Do
- Cat
- Callp
- Callb
- Call
- BegSr
- Z-sub(H)
- Time
- Z-sub
- Z-add
- Xlate(E P)
- Xlate
- Xfoot
- Write
- When
- Update
- Subst(E P)
- Subdur
- Sorta
- Seton
- Setoff
- Setll
- Setgt
- Select
- Return
- Readp
- Reade
- Plist
- Parm
- Other
- Opcode Extender for File Operations
- On-Error
- Occur
- Mvr
- Movel
- Klist
- Kfld
- Iter
- In & Out
- IfXX
- If
- For
- Extrct
- Exfmt
- Except(Rpgle)/Excpt(Rpg)
- Eval(R)
- Eval (M)
- Eval
- Dump(A)
- Dsply
- DoW
- DoU
- Div
- Delete
- Define
- Comp
- Close
- Check(E)
- Chain
- Cat(P)
- Adddur
- Add(H)
- Add
System Architecture
Object-Based System
This is possible because any component of executable code or data in file is encapsulated into a secure unit called Object.
Anything available in this system is an object. This provides a common interface to work through them.
This interface allows for standardized commands across different system elements. Each and every object are referenced by a library, under which they reside. Library in IBM i system is also an object. They act as a container for all other objects.There are a set of system libraries supplied by IBM with the machine in OS. Any user created library resides under the system library QSYS.
Single-Level storage
Single level storage in IBM i refers to a single unit of storage, not discriminated as primary storage(RAM) and secondary storage unit(Disk).
The operating system has addresses of all the objects and data pointing to it in the single large pool of virtual storage(known as system ASP or System Auxiliary Storage Pool).
No additional I/O is required by the processor to access any object which is stored in disk, as it is done by other systems which have dedicated RAM and secondary storages.
This is achieved by an address translator. All the storage spaces get treated as single pool of data. This enhances the turnaround time for retrieval of data from table, as well as any object such as libraries, programs, modules, binding directories and so on.
This is an auto tuning feature in IBM i for memory management and disk pooling optimization.
Any add-on to the disk capacity is readily available with optimized feature of single level pool.
There is no need to be concerned about particular disk drives filling up, or moving data from one disk to another to improve performance because all data management is taken care of by the licensed internal code. Licensed internal code also ensures that there is no disk fragmentation.
It saves time and planning for users to allocate disk spaces, IBM i storage manager will do this for you automatically. In USA, almost 80% of business are saving $60K – $160K annually as pay for a part-time or full-time system admin consultant.
It costs less amount of money for business to purchase a disk unit for IBM i rather than buying segregated units for RAM and secondary disk separately. Note that under some circumstances you might create additional storage pools that are called user ASPs and independent ASPs.
Relational Database Integration
Every time a table insert, update, delete, or alter operation is performed, evaluation of all the conditions or rules mentioned in the integrity constraint will be done. The data can be inserted, updated, deleted, or altered only if the result of the constraint comes out to be True. By this, these are useful in preventing any damage to the database by an authorized user.
Types of integrity constraints:
- Domain Constraint
- Entity Constraint
- Referential Integrity Constraint
- Key Constraint
Domain Constraint
Domain constraints can be defined as a set of rules that are valid for an attribute. The domain’s data type includes character, integer, time, string etc. The value must be in the corresponding domain of the attribute.
Example:
Name | Class | Age |
---|---|---|
Prakash | 6 | 11 |
Ravi | 7 | 12 |
Rajesh | 6 | 11 |
Nikhil | 7B | 13 |
In the above table, we can see the Class column, the data type of the domain is an integer, but the attributes data type is a character. This is a violation, so it will not allow.
Here, we tried giving Class column value in Characters.
As we can see, it didn’t insert the record since the Class column is an Integer type.
Entity Constraint
Entity Integrity Constraint is used to ensure that the primary key cannot be null. A primary key is used to identify individual records in a table and if the primary key has a null value, then we can’t identify those records. In a relation, there can be null values, but they must be not the primary key.
Example:
Roll | No Name | Class |
---|---|---|
1 | Nikhil | 9 |
2 | Prasanth | 9 |
3 | Anil | 9 |
Siddharth | 9 |
In the above table, The Roll No column has the Null value in the last row. So, it cannot be assigned as the primary key.
Referential Integrity Constraint
Referential Integrity Constraint ensures that there must always exist a valid relationship between two relational database tables. This constraint is defined between two tables. This valid relationship between the two tables confirms that a foreign key exists in a table. It should always reference a corresponding attribute in the other table or be null.
Example:
Table A
Roll No | Name | Class | Subject Code |
---|---|---|---|
6 | Gowtham | 10 | 4243 |
7 | Chandu | 10 | 9876 |
8 | Naveen | 10 | 0123 |
9 | Rajeev | 10 | 8976 |
Table B
Subject Code | Subject |
---|---|
4243 | Maths |
9876 | Physics |
0567 | Chemistry |
8976 | Social |
Here, we can see that in Table A, Subject Code 0123 is not valid, as this value is not defined in the Table B and the column is assigned as the primary key, and Subject Code in table A is assigned as the Foreign Key.
Key Constraint
In Database, a key is used to uniquely identify an entity in an entity set. There could be multiple keys in a single entity set, but out of these multiple keys, only one key will be the primary key. A primary key can only contain unique and not null values in the relational database table.
Example:
Roll No | Name | Class |
---|---|---|
1 | Nikhil | 9 |
2 | Prasanth | 9 |
3 | Anil | 9 |
2 | Siddharth | 9 |
In the above table, Roll No cannot be defined as a primary key because it contains a duplicate value. That Roll No column row must contain unique values.
Libraries and Library List
Understanding the Role of Libraries in IBM i (formerly AS/400) Systems
In IBM i (formerly AS/400), a library is like a digital folder. It’s where you put similar things together, just like you’d organize your files in folders on your computer. These things can be programs, files, and more. Libraries keep everything neat and help you find what you need. When you want to use something, you say where it is by naming the library. So, libraries are like digital organizers that keep the IBM i system tidy and running smoothly.
In the AS/400 system, libraries, often marked as *LIB, are like virtual folders for organizing objects. Actual AS/400 objects aren’t stored inside libraries; libraries simply group objects together. So, it’s more about association than physical location.
Some AS/400 items, such as databases, storage, and programs, can exist in multiple libraries. When a program wants one of these items, it chooses the correct one from the Library List. Special commands can move items between libraries, and you can link items together when building a program to adjust how the Library List behaves when the program is in action.
Libraries cannot contain other libraries:
- Libraries contain various items. Libraries can’t hold other libraries, except for one special library called QSYS (System provided).
- AS/400 uses a list-like structure, not like Windows, which has a tree-like setup. To find something on AS/400, you need to know the library and the object’s name. Objects on AS/400 are identified by their qualified name, which looks like LIBRARY/OBJECT. For example, if you want to talk about the Employee file in the Company library, you’d say Company/Employee.
- Generally speaking, all libraries created by IBM for use by the operating system begin with the letter ‘Q’.
System Library/ IBM Standard Libraries:
In AS/400, a system library is like a top-secret storage place for important stuff that keeps the whole system running smoothly. This secret library contains essential programs, settings, and data. Here are the key points:
- It’s there by default: System libraries are part of the AS/400 setup, and you can’t easily change them.
- They’re locked down: Only trusted people can make changes to these libraries to protect the system.Examples: System libraries go by names like QSYS and QSYS2, with QSYS being especially important.
- They’re in control: These libraries are like the command centre, making sure everything in AS/400 works properly.
So, think of system libraries as the secret backbone that keeps AS/400 going strong.
-
System Libraries:
- QSYS – System library for the AS/400. It contains the programs and other objects that make up the operating system. QSYS must exist on an AS/400 for the system to work. Other libraries on the AS/400 exist within the context of the QSYS library; it is the only library that can contain other libraries. A few special objects, such as user profiles and I/O configurations, can exist only within QSYS. You should never modify or delete any object within the QSYS library.
- QSYS2 – System Library for CPI’s.
- QHLPSYS – Contains on-line help information that is displayed when the Help key or the extended help function keys are pressed.
- QRECOVERY – Contains objects needed during a recovery procedure.
- QUSRSYS – The system user data library, contains various IBM-supplied objects needed for system functions as well as user message queues for holding messages.
- QTCP – TCP Connectivity Utilities.
- QSPL – holds the spooled, printed output pages that have not yet been printed.
- QAFP – Advanced Function Printing.
- QGPL – General Purpose Library that contains IBM-provided objects. The system places newly created objects that are not specifically placed in a distinct library in QGPL.
Note: It is considered as user defined library.
- QTEMP – Job specific temporary Library (deleted when the job ends), Each time a user signs on, the system creates a QTEMP library for this interactive job. If the user submits a job to the batch queue, another QTEMP library is created for the batch job.
-
User Libraries:
In IBM i (formerly AS/400), a user library is a personalized storage area for users. It’s like a digital room where they can put their own programs, files, and things. This way, users can keep their work separate from others and have their own special place for their stuff.
In many cases, the system administrator sets up user libraries. These are usually created to store the work of individual users. For instance, each programmer might have their personal user library. The administrator can create as many of these user libraries as needed, and the only restriction is the amount of available disk space on the system’s storage device (DASD).
CUR: The library you’re currently in.
The current library in IBM i is the first stop for finding objects a user needs. When a user creates objects and designates *CURLIB, those objects are stored in the current library. It’s a user-specific setting, making it easier to locate and access the user’s work. This setup streamlines the process of finding and using objects, providing a convenient way to organize and retrieve resources.
If the “Limit capabilities” setting in the user profile is set to *YES or *PARTIAL, the user can’t switch their current library.
Library Commands:
-
CRTLIB: (Create Library)
In IBM i (formerly AS/400), you can make a library by using the ‘CRTLIB’ command.
Type ‘CRTLIB’ and then the name you want for your library. For instance, if you want to create a library called PIOLIB,’ you’d do this:
Syntax:
CRTLIB PIOLIB
To open the library creation prompt, just type ‘CRTLIB’ on the command line and press F4. Then, provide the library name and a short description.
Library Type:We can choose ‘Library Type’ above, which can be either *PROD or *TEST, as shown in the CRTLIB screenshot. Let’s now talk about the meaning of each option separately.
- *PROD:When you make a library with CRTLIB, it’s usually set as a *PROD or production library by default. If it’s a *PROD library, it decides whether you can change or add data in the database files when you’re debugging your program.
If you set the ‘update production files’ (UPDPROD) parameter to *NO in the Start Debug (STRDBG) command, it means that you cannot modify database files in production libraries during debug mode. They can only be read but not updated.Syntax:STRDBG COMMAND
- *TEST:In Test libraries, you can make changes to all the objects while testing, even if you’ve set UPDPROD to *NO in the Start Debug (STRDBG) command.
- *PROD:When you make a library with CRTLIB, it’s usually set as a *PROD or production library by default. If it’s a *PROD library, it decides whether you can change or add data in the database files when you’re debugging your program.
-
CHGCURLIB: (Change Current Library)
The CHGCURLIB command changes the current library in the library list.
To switch the current library, use the “CHGCURLIB”/” CHGLIBL” command. The sole essential parameter for this command is the name of the library that will become the new current library. Keep in mind that the current library setting only applies to your current session. When you log off and sign in again, the library you set will not persist in your library list. Instead, it will be replaced by the default current library specified in your user profile.
If you want to review or modify your user profile, you can access it by entering “CHGPRF” and pressing F4. However, if you are new to this system, it’s recommended not to make any changes to your user profile unless you are familiar with the implications of doing so.
*CRTDFT: No library is the current entry of the library list. If objects are created into the current library, the QGPL library is used as the default.
Syntax:
CHGCURLIB CURLIB(PIOLIB)
-
CHGLIB: (Change Library)
The CHGLIB command is used to modify the type attribute, text description, default create authority value, and default object auditing value of a library.
The CHGLIB command mandates a single required parameter, LIB, which designates the library to undergo modification. The TYPE, TEXT, and CRTAUT parameters are employed to adjust the respective attributes of the library. As an illustration, to alter the TEXT attribute of PIOLIB, input the command CHGLIB LIB(PIOLIB) TEXT(New Library Description). To confirm that the alteration has been implemented, utilize the Display Library Description command, DSPLIBD, with the command DSPLIBD LIB(PIOLIB).
Syntax:
CHGLIB LIB(PIOLIB)
-
CLRLIB: (Clear Library)
When you clear a library with the Clear Library (CLRLIB) command, you delete objects in the library without deleting the library.
Syntax:
CLRLIB LIB(PIOLIB)
-
CPYLIB:
In IBM i systems (formerly known as AS/400), the ‘CPYLIB’ command serves the purpose of duplicating an entire library, encompassing all of its objects and associated data, to a different library. Here’s how you can utilize the ‘CPYLIB’ command:
Syntax:
CPYLIB FROMLIB(source-library) TOLIB(target-library)
FROMLIB: This parameter designates the source library from which you intend to replicate both objects and data.
TOLIB: This parameter identifies the destination library where you intend to establish a replica of the source library, encompassing all its objects and data.
For instance, if your aim is to duplicate all the contents of a library named ‘PIOLIB’ into a fresh library named ‘NEWLIB,’ you can achieve this by issuing the following command:
Syntax:
CPYLIB FROMLIB(PIOLIB) TOLIB(NEWLIB)
This command will replicate all the objects and data found in ‘PIOLIB’ within ‘NEWLIB,’ essentially producing an identical copy of the source library in the destination library.
Be aware that you must possess the required permissions and authority to execute the ‘CPYLIB’ command. Additionally, it’s important to remember that the command copies all objects and data from the source library to the target library, so exercise caution when using it.
-
DLTLIB: (Delete Library)
In AS400, there is a command called “DLTLIB” that serves the purpose of removing or erasing a library. Let me guide you through the process of utilizing the DLTLIB command in AS400:
Enter the DLTLIB command followed by the name of the library you want to delete. For example:Syntax:
DLTLIB PIOLIB
Note: In this example, replace PIOLIB with the name of the library you want to delete.
If the library contains objects (such as files, programs, etc.), you will be prompted to delete them as well. Confirm the deletion of the objects if needed.
Once confirmed, the library and its objects will be deleted.
Please be cautious when using the DLTLIB command, as it permanently deletes the library and all its contents. Ensure that you have proper authority and backup any important data before using this command. Deleting a library cannot be undone, so make sure you have a backup or no longer need the data within the library.
-
DSPLIB: (Display Library)
Within the AS400 environment, the DSPLIB command serves the purpose of providing a comprehensive view of a library’s details. To utilize this command effectively, follow these steps:
- Simply input the DSPLIB command, specifying the name of the library you wish to view.Syntax:
DSPLIB PIOLIB
- Replace PIOLIB with the name of the library you want to display information about.
- The system will provide a detailed list of information about the specified library, including its attributes, object counts, and other relevant details.
- You can scroll through the information using the page-up and page-down keys or by following the on-screen instructions.
The DSPLIB command allows you to review information about a library without making any changes to it. This can be useful for verifying the contents and attributes of a library before performing any operations on it.
- Simply input the DSPLIB command, specifying the name of the library you wish to view.Syntax:
-
DSPLIBD: (Display Library Description)
The DSPLIBD command allows you to view comprehensive information about a library. This information encompasses the library’s category, its associated Auxiliary Storage Pool (ASP) number, the ASP device name linked to the library, the default public authority for objects created within the library, the default auditing settings for objects created in the library, as well as a textual description of the library.
Required Parameter:
- Library: Indicate the name of the library for which information is being presented.
-
WRKLIB: (Work with Libraries)
The “WRKLIB” command in AS400 (IBM i) is used to display a list of libraries on the system. This command opens a work library list display that shows the names of libraries on the IBM i server, allowing you to browse and manage library-related tasks. You can use this command to view, create, delete, or perform other library-related operations.
-
EDTLIBL: (Edit Library List)
The “EDTLIBL” command in AS400 (IBM i) is used to edit the library list. The library list determines the order in which libraries are searched for objects in an AS400 environment. By using the “EDTLIBL” command, you can interactively modify the library list, which can be essential for controlling the search path for programs and objects in your system. This command provides a simple interface to add, remove, or reorder libraries in the library list, giving you control over the environment in which your AS400 applications run.
Source Files and Types
SOURCE PHYSICAL FILES
Source files or source physical files are essentially a container of repository that holds individual source code members.
Within a source physical file, each source code file is referred to as a ‘member’. The members are individual source code files that contain the actual code written in a specific programming language. It is a structured way to manage or organize the source code for programs, files, and other objects on the system.
COMMANDS USED
CRTSRCPF
CRTSRCPF is an IBM i command that is used to create the source physical file.
File: Specify the name of the source file which you want to create.
Library: Specify the library where the source file will be created.
Record length: Provide the record length of the source physical file i.e. the number of bytes in the length of records stored in the source physical file.
The record format of the source physical file contains three fields.
- Source sequence number
- Source statement
- Date
The default record length is 92 bytes. The source sequence number contains 6 bytes, Date contains 6 bytes, and the source statement contains 80 bytes.
Similarly, if user makes the record length as 112, the source statement will contain 100 bytes, 6 bytes will be for sequence number & 6 bytes for date.
STRPDM
Program development manager (PDM) can be started using the command STRPDM which shows a menu of options for the level on which the user wishes to work.
User can choose a particular option or directly enter a command for that menu.
To work with libraries user can choose option 1 or directly use WRKLIBPDM command.
The work with objects user can choose option 2 or directly use WRKOBJPDM command.
Similarly to work with members user can choose option 3 or directly use WRKMBRPDM command.
TYPES OF SOURCE FILES
While working with members the user can create a new member by pressing F6 key.
Here users can enter the name of the member/source that they want to create and source type for that member.
Source Types
The source types determine the syntax checker, prompting, and formatting that are used for that member.
Different source types serve different purposes. Different source types are used to organize and define various elements of a program or application.
Many source types can be used in IBM i. To check the entire list of source types supported by IBM i, the user can press F4 key on the source type parameter while creating a new member.
Below are the most frequently used Source types in the IBM i world.
PHYSICAL FILE (PF)
Source type: PF
Physical files define the structure and attributes of a physical database file.
These files are used to store and organize data records.
Object type: PF type sources are compiled using the CRTPF command and are created with *FILE type object.
LOGICAL FILE (LF)
Source type: LF
Logical files provide a logical view of one or more physical files.
They allow users to define alternate record selection criteria & and record sequences. It simplifies data access by specifying different key sequences or filtering criteria.
Object type: LF type sources are compiled using CRTLF command and are created with *FILE type object.
RPG PROGRAM (RPGLE or RPG)
Source type: RPG
RPG stands for report program generator.
RPG source type is used to define the logic and processing instructions for a program. RPGLE source is where you write the business logic, calculations, and data manipulation for your application.
Object type: RPG type sources are compiled using CRTRPGPGM command and are created with *PGM type object.
RPG ILE (RPGLE)
Source type: RPGLE
It is an ILE version of RPG where users can write programs and business logic in a more efficient and modular way which can reduce reusability.
Object type: RPGLE type sources are compiled using CRTBNDRPG command and are created with *PGM type object.
RPGLE type sources can also be compiled using the CRTRPGMOD command and are created with *MODULE type object.
SQLRPG PROGRAM (SQLRPG)
Source type: SQLRPG
SQLRPG source type is used to define the logic and processing instructions for a program. It is like the RPG program along with the ability to use embedded SQL operations within the same program. This way user can manipulate the data using SQL statements within their program.
Object type: SQLRPG type sources are compiled using CRTSQLRPG command and are created with *PGM type object.
SQLRPG ILE(SQLRPGLE)
Source type: SQLRPGLE
It is an ILE version of SQLRPG where users can write programs and business logic with the ability to use embedded SQL operations in a more efficient and modular way which can reduce the reusability.
Object type: SQLRPGLE type sources are compiled using the CRTSQLRPGI command and are created with (OBJTYPE) *PGM or *MODULE type object.
CONTROL LANGUAGE PROGRAMMING(CLP)
Source Type: CLP
CLP stands for Control language programming.
It allows users to write IBM i commands in a program along with the ability to include statements from compiled languages (like RPG, COBOL etc.) to perform specific calculations that will be executed more easily and efficiently.
Object type: CLP type sources are compiled using CRTCLPGM command and are created with *PGM type object.
CONTROL LANGUAGE ILE(CLLE)
Source Type: CLLE
CLLE stands for control language with language extension.
It is an ILE version of CLLE which allows the user to write programs in a modular way. It can be used when the user wants to invoke RPG procedures within a CL program.
Object type: CLLE type sources are compiled using CRTBNDCL command and are created with *PGM type object.
CLLE type sources can also be compiled using CRTCLMOD command and are created with *MODULE type object.
DISPLAY FILE(DSPF)
Source type: DSPF
Display files are used to define the layout and characteristics of interactive screens or user interfaces. They specify how data is presented to users and input is accepted.
Object type: DSPF type sources are compiled using the CRTDSPF command and are created with *FILE type object.
PRINTER FILE(PRTF)
Source type: PRTF
Printer files define the layout and formatting of output generated by your RPGLE programs. They specify how data should be printed on physical printers. It is used to format reports, labels, and other printed output produced by RPG/RPGLE programs.
Object type: PRTFF type sources are compiled using the CRTPRTF command and are created with *FILE type object.
TEXT(TXT)
Source Type: TXT
TXT source is used for including comments and documentation with your source code. It is not compiled or processed by IBM i compiler but serves as a readable note.
Users can use type TXT source members to write SQL queries, and then execute using RUNSQLSTM command.
QUERY(QRY)
Source Type: QRY
QRY source type member is used for creating and storing queries using query/400 language on the IBM i system. Query/400 is a language specifically designed for defining queries to extract, filter, and manipulate data from databases. These sources store definitions of queries that can be run interactively or as a part of a batch job process.
BOUND(BND)
Source type: BND
The binder language is used to define the binding source for ILE programs.
BND members include statements that specify attributes of a program such as a module that contains export names, the activation group it runs in, and other binding-related information.
A BND source might include statements to bind together different modules of an application, ensuring they work together cohesively when a program is executed.
COMMAND DEFINITION (CMD)
Source Type: CMD
CMD source members define custom commands, simplifying complex operations, and improving command line efficiency.
Users can encapsulate specific tasks and can be invoked from CL programs or the command line.
C Programming(C)
Source Type: C
C type source members allow users to write and then run programs written in C programming language in IBMi.
Object type: C type sources are compiled using CRTBNDC command and are created with *PGM type object.
C type sources can also be compiled using CRTCMOD command and are created with *MODULE type object.
CPP Programming(CPP)
Source Type: CPP
CPP type source members allow users to write and then run written in C++ programming language in IBM i.
Object type:CPP type sources are compiled using CRTBNDCPP command and are created with *PGM type object.
CPP type sources can also be compiled using CRTCPPMOD command and are created with *MODULE type object.
COBOL LANGUAGE(CBL)
Source Type: CBL
COBOL stands for common business-oriented language.
CBL source type members contain code written in COBOL a high level programming language designed for business applications.
COBOL is known for its readability and often used in legacy systems for financial and administrative applications.
Object type: CBL type sources are compiled using CRTCBLPGM command and are created with *PGM type object.
CPP type sources can also be compiled using CRTCPPMOD command and are created with *MODULE type object.
COBOL LANGUAGE BOUND(CBLLE)
Source Type: CBLLE
CBLLE source type members also contain code written in COBOL programming language, but they undergo a two-step process. First the source code is compiled into an intermediate form called ‘object module’ using the COBOL compiler. Then the object module is bound into executable programs.
Object type: CBLLE type sources are compiled using CRTBNDCBL command and are created with *PGM type object.
CBLLE type sources can also be compiled using CRTCBLMOD command and are created with *MODULE type object.
Integrated File System
Integrated File System (IFS) in AS/400 (IBM i) is a feature that allows you to work with different types of data, including text files, documents, and directories, in a similar way to traditional file systems on other operating systems. It acts as a bridge between the traditional database-centric world of IBM i and the more common file-based systems.
Why do we use IFS?
The IFS provides a common way to manage and access various types of files and data on your AS/400 system, making it easier to work with different types of information alongside your traditional database files. It’s like having a versatile file storage system within your AS/400 environment, making it more flexible and compatible with various file formats.
Structure of IFS on IBM i
The structure of IFS on IBM I consists of several key elements, including:
1. Libraries: These are collections of objects and files, typically accessed using the QSYS.LIB notation.
2. Files: Files within libraries store various types of data and can be accessed through the IFS.
3. Directories: Directories provide a way to organize and manage files and data within the IFS.
4. Stream Files and Objects: Stream files are a common type of data stored within directories and can be accessed via specified paths. Objects can also be accessed similarly.
5. Folders: These are used to organize and group documents and data in QDLS (Document Library System).
6. Documents: Documents within folders are part of the QDLS structure and are accessible to users.
The IFS allows for the structured organization of data, with libraries holding files and objects that can be accessed through specific paths and directories. Additionally, folders and documents in QDLS provide a further level of organization and accessibility for users.
Stream files
Stream files in AS/400’s Integrated File System (IFS) are a type of data storage used for unstructured content, such as text, documents, images, and more. They provide a flexible way to store and manage various file types alongside traditional database-centric data. Here are some key points about stream files in AS/400’s IFS:
1. Data Type: Stream files can store a wide range of data types, including plain text, binary data, documents (e.g., PDF, DOCX), images, and multimedia files.
2. Flexible Structure: Unlike traditional database files in AS/400, stream files have a flexible structure, making them suitable for various file formats and content.
3. Hierarchical Storage: Stream files are organized in a hierarchical directory structure similar to directories and subdirectories in a file system.
4. Access: Stream files can be accessed and managed through standard file operations and file protocols. This includes reading, writing, copying, moving, and deleting files.
5. Integration: The IFS allows you to seamlessly integrate stream files with traditional database files, making it easy to work with structured and unstructured data in the same environment.
6. File Formats: Stream files can be used to store files in various formats, making them suitable for a wide range of applications, including document management, web content, and more.
7. Security: AS/400 provides security features to control access to stream files, ensuring data confidentiality and integrity.
Stream files in AS/400’s IFS offer a versatile way to handle unstructured data, enabling businesses to manage a variety of file types within the same system, enhancing flexibility and compatibility.
File System | Description | Example |
Root File System (/) | The primary file system uses the forward slash (/) as the separator for directories and files. It’s the top-level directory in the IFS. | `/mydirectory/myfile.txt` |
QSYS.LIB File system | A library-based naming convention is often used to access objects and files associated with libraries on AS/400. This system follows the QSYS.LIB structure. | `QSYS.LIB/MYLIB.LIB/MYFILE.FILE` |
QDLS FILE System | The Document Library System (QDLS) file system for organizing documents and folders. It provides a hierarchical structure for managing documents. | `QDLS/MYFOLDER/MYDOCUMENT.PDF` |
QOPT File System | The QOPT file system is used for optional integrated file systems and may be used to customize the naming and organization of files. | Customized naming and organization rules |
These file systems offer different naming conventions and structures, allowing users to work with files and directories in a way that best suits their requirements. Each file system has its own set of rules and purposes, making it more convenient for managing and accessing data within the IFS on AS/400.
An IFS “Hello World” Application
Below are the simple RPGLE programs in Free and Fixed format to write Hello World as content in the stream file stored at IFS. Both the programs use the C APIs – open, write, and close to create and write a stream file in the IFS of the IBM I operating system.
First, let’s see the Free-format RPGLE program.
Now, let’s see the RPGLE program in Free format.
Output: Before program run
After program run
Common Commands for IFS in AS400
In AS/400 (IBM i), several commands are commonly used for various tasks related to working with objects, libraries, and data. Here’s a brief explanation of the commands you mentioned:
1. WRKLNK (Work with Links):
Syntax:
WRKLNK ‘/DIRECTORY_NAME/FILE_NAME’
– This command allows you to work with symbolic links in the Integrated File System (IFS) on the IBM I platform. Symbolic links are references to other files or directories, providing a convenient way to access or reference files in different locations.
2. DSPF (Display File):
Syntax:
DSPF ‘/ DIRECTORY_NAME/FILE_NAME’
– DSPF is not a specific AS/400 command. It could be an abbreviation for “Display File,” which typically refers to a display file used in programming on the IBM I platform. Display files are used to define the layout and functionality of screens in interactive applications.
3. EDTF (Edit File):
Syntax:
EDTF ‘/ DIRECTORY_NAME/FILE_NAME’
– EDTF is an AS/400 command used to edit source files. Source files contain program source code, scripts, or other text-based data. This command opens a source file for editing, allowing developers to make changes to the code.
4. CPYFRMIMPF (Copy from Import File):
Syntax:
CPYFRMIMPF FROMSTMF(‘/DIRECTORY_NAME/FILE_NAME’) TOFILE(LIBRARY_NAME/FILE_NAME) MBROPT(*REPLACE) RCDDLM(*CRLF)
– This command is used to copy data from an Import File (an external data file) into a database file on the IBM I system. It is often used for importing data from various sources, such as CSV files, into the system’s database files.
5. CPYTOIMPF (Copy to Import File):
Syntax:
CPYTOIMPF FROMFILE(LIBRARY_NAME/FILE_NAME)TOFILE(‘/DIRECTORY_NAME/FILE_NAME’) MBROPT(*REPLACE) RCDDLM(*CRLF) STRDLM(*NONE)
– CPYTOIMPF is the counterpart to CPYFRMIMPF. It is used to copy data from a database file on the IBM I system into an Import File (an external data file). This command is useful for exporting data from the system to other platforms or applications.
These commands are part of the standard set of commands available on the AS/400 (IBM i) platform and are used for managing and manipulating files, objects, and data.
Access IFS using BD2
You can access the IFS (Integrated File System) on an AS400 system by using DB2. Here are DB2 queries to read and write records in the IFS file.
Read Record from IFS
Run the below query:
SELECT CAST(LINE AS CHAR(50)) FROM
TABLE(QSYS2.IFS_READ('/home/piofile.csv))
Write a record to the IFS
Run the below query:
CALL QSYS2.IFS_WRITE('/home/piofile.csv,
'insert record in IFS file using SQL’,
OVERWRITE => 'APPEND',
END_OF_LINE => 'CRLF')