RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Blog - Content Section Layout
Get Commitment Status Using QTNRCMTI API
User Rating: / 0
Written by Chamara Withanachchi   
       // Data Structures
       // ----------------------------------------------------------------------
       Dcl-DS comStatus;
         byteReturned Int(10:0);
         byteAvailable Int(10:0);
         commitStatus Char(1);

       Dcl-DS APIError;
         byteProvided Int(10:0);
         eByteAvailable Int(10:0);
         exceptionID Char(7);
         recerved Char(1);
         exceptData Char(100);

       Dcl-S wCmd Char(110);
       Dcl-S wCmdLen Packed(15:5);
       Dcl-S wLenRcvVar Int(10:0);
       Dcl-S wFormatName Char(8);

       Dcl-PR callCLCmd ExtPgm('QCMDEXC');
         Dcl-Parm cmd Char(110);
         Dcl-Parm cmdLen Packed(15:5);

       Dcl-PR callCommitStsAPI ExtPgm('QTNRCMTI');
         Dcl-Parm pComStatus Like(comStatus);
         Dcl-Parm comLen Int(10:0);
         Dcl-Parm pFormatName Like(wFormatName);
         Dcl-Parm pAPIError Like(APIError);

       wFormatName = 'CMTI0100';
       wLenRcvVar = %Len(comStatus);
       wCmdLen = %len(%trim(wCmd));
       callCLCmd(wCmd : wCmdLen);

       callCommitStsAPI(comStatus : wLenRcvVar : wFormatName : APIError);

       wCmd = 'ENDCMTCTL';
       wCmdLen = %len(%trim(wCmd));
       callCLCmd(wCmd : wCmdLen);

       callCommitStsAPI(comStatus : wLenRcvVar : wFormatName : APIError);

       *INlr = *on; 
Write Comment (0 comments)
Concatenation in CL
User Rating: / 0
Written by Chamara   

You can you *CAT, *TCAT or *BCAT in CL programming to Concatinate alphanumeric variables or constant values'

*CAT or || - Joins two variables/strings "as is"

*BCAT or |> -Joins two variables/strings with a single blank space between

*TCAT or |< - Joins two strings after trimming trailing spaces

Write Comment (0 comments)
IBM i Access Client Solution
User Rating: / 0
Written by Chamara   

IBM i Access Client Solutions is the newest member of the IBM i Access family. It provides a Java based, platform-independent interface that runs on most operating systems that support Java, including Linux, Mac, and Windows™.

Features include:

5250 display and printer emulation based on IBM's Host-on-Demand

5250 Session Manager support modeled after IBM Personal Communications Session Manager

Multiple language support for concurrent 5250 emulation sessions on the same client

Data Transfer similar to IBM i Access for Windows Data Transfer plus support for OpenDocument spreadsheet (*.ods), Excel Workbook (*.xlsx), and other file formats

Data Transfer integration with Excel and OpenOffice

Simplified SSL Configuration

Download and viewing of spool files

IBM i Virtual Control Panel for LAN and HMC consoles

5250 emulation for LAN and HMC consoles

Consolidation of hardware management interface configurations, including ASMI, IVM, and HMC

Installing and updating IBM i Access Client Solutions is as simple as unpacking the zip archive. And it can be deployed to a network shared drive providing a single location to update for all users.

IBM i Access Client Solutions uses the same IBM i host servers as the other IBM i Access Family products and requires the same

IBM i Access Family license (XW1) in order to use the 5250 emulation and Data Transfer features.

IBM i Access Client Solutions also provides two optional platform-specific packages which include middleware for using and developing client applications.

IBM i Access Client Solutions - Windows Application Package for Windows operating systems. Features include:

Connectivity to DB2® for i using ODBC, .Net, and OLE DB

Programming Toolkit for accessing IBM i system objects

Support for TLS/SSL connections

AFP printer driver

IBM i Access Client Solutions - Linux Application Package for Linux operating systems. Features include:

Connectivity to DB2® for i using ODBC

Full support for 64-bit ODBC data types

TCP/IP connectivity

Visit IBM official site to learn more about IBM i Access Client SolutionWrite Comment (0 comments)
Monitoring With Watches
User Rating: / 0
Written by Chamara   

In V5R3, IBM i introduced watches as a way to automate the ending of traces. In 5.4, watches were supported independent of the trace commands.

Watches provide a way to automate tasks when certain events occur. An event can be a message, a Licensed Internal Code (LIC) log (also known as a VLOG), or, in 6.1, a Problem Activity Log (PAL) entry. The primary motivation for adding watches to the operating system was initially to provide a way for improved diagnostics, but watches, particularly message watches, can be used for automated monitoring of system conditions. Watches provide a way to be notified programmatically when the event occurs so immediate action can be taken. Additionally, watches can be very useful at detecting situations that occur intermittently since the actions can be automated. Watches have minimal system overhead when they’re defined, but not “hit.” When the watch condition occurs, the actions taken depend upon the how the watch is defined. When using watches independent of traces, the actions taken are what the watch exit program is coded to do.

To start a watch, use the Start Watch (STRWCH) command or QSCSWCH API. To end a watch, use the End Watch (ENDWCH) command or QSCEWCH API. You can also use a Work With Watches (WRKWCH) command to display and set actions on watches. Up to 10,000 watches can be active at one time.

Watching for LIC logs or PAL entries is probably something you won't need to do, but watching for messages can be an effective way to perform proactive and automated monitoring of system conditions. You can watch for messages sent to any message queue, the history log or job logs. When you define the watch condition, you can specify several different conditions you want to check for to limit the situations under which the watch will trigger. When the watch condition is matched, your exit program will get control and you can take whatever actions you deem appropriate for the condition.

Using watches to automate monitoring of messages is much more efficient than using the Management Central Message Monitors. Management Central Message Monitors use a polling technique to retrieve messages, which has more overhead and is less timely than watches. With Management Central Job Monitors, you can monitor for job log messages, however, monitoring job log messages with Management Central Job Monitors is expensive in terms of the system resources used due to its polling nature. Message watches are a great alternative since they provide essentially the same support with significantly fewer system resources used. However, it isn’t as easy to set up Message Watches since there’s no GUI for watches; only command and API interfaces have one. In addition, with watches you have to write your own watch exit program, whereas Management Central has a nice interface to define the actions taken when the monitored condition occurs. IBM has provided an example watch exit program in the Information Center.

When watches are defined, additional jobs run on the system. These jobs are different on the various releases. On 5.4, there’s one batch job per watch in the QUSRWRK subsystem. These jobs run until the watch is ended. In 6.1, watches were changed to use batch prestart jobs. There’s a single batch job, QSCWCHMS, in QUSRWRK for message watches; when a message watch condition is hit, the user exit program is called in a prestart batch job, QSCWCHPS. This change in 6.1 reduces the number of jobs in the QUSRWRK subsystem. IBM i has a function called Service Monitor that uses watches as its notification mechanism. Service Monitor was added in the 5.4 release. Service Monitor is controlled by the QSFWERRLOG system value; when this system value is set to *LOG, service monitor will be active. Service Monitor uses many watches, and you’ll see evidence of this by the jobs running in QUSRWRK, as well as when you work with watches. I'll talk more about Service Monitor in a future blog article.

Originally by Dawn May

User Rating: / 0
Written by Chamara   


Grep has the following form:

grep [options] regular-expression [input-files]

The brackets around the options and input-files parameters to indicate that these two parameters are optional. You will probably specify options sometimes and not specify options other times, but you will probably use the input files parameter more often than not.

The regular-expression parameter is the string for which you are searching. The simplest form of regular expression is an exact sequence of characters for which the system is to search.


If you omit the input-files parameter, grep reads from the standard input device, which by default is the keyboard. This may seem goofy, but it's in keeping with the way other Unix utilities operate. Since you will not need grep to find strings in input that you type yourself, you are not likely to omit the input-files parameter when running grep from the keyboard under Qshell.

The only time you are likely to omit the input-files parameter is when grep is reading the output of another command through a pipeline. In the following example, output of the List Directory Contents (ls) command is the input to grep:

ls   |   grep   -i   '[A-Z][12]' 

The vertical bar creates the pipeline. This example lists files whose names contain a letter of the alphabet, followed by either a one or a two. (It will make more sense to you when you read about regular expressions, below.)

There are several different ways to fill in the input-files parameter. One way is to list a file name, like this:

grep '22.34'  mydata.csv

In this case, only one file (mydata.csv) is searched for in the current directory. You can specify a full path on the file name, of course:

grep '22.34'  /home/jsmith/mydata.csv

You may want to use wildcard characters to search more than one file. The following command searches all the .csv files in the current directory:

grep   '22.34'  *.csv

In these two examples, the input-files parameter has only one argument. You can list more than one file, if you wish. Separate them with white space. This command searches three files:

grep '22.34' fileone.csv filetwo.csv filethree.csv

All of these example search IFS files, but you can search source physical file members, too. The following command searches all members of MYLIB/MYSRC for the string pgm:

grep   'pgm'   /qsys.lib/mylib.lib/src.file/*.*

This command searches all members of a source physical file, as well as all HTML and text files in the current IFS directory:

grep 'pgm' /qsys.lib/js.lib/src.file/*.*  *.htm*  *.txt

One comment about output files: By default, output goes to the display. If you want to send the output to a file, use a redirection operator to send it there. The output of this grep command goes to an IFS file called grep2.out.

grep     '22.34'    *.csv    >/home/jsmith/grep2.out

Here's an example of directing grep output to a source physical file member:

grep  -i  'class'  *.java  >/qsys.lib/js.lib/src.file/one.mbr

Simple Searches

Now that you know the syntax of grep, look at a few simple searches:

grep   int   *.java


grep   'int'   *.java


grep   "int"   *.java

The grep command, in either of these three forms, instructs the system to search all files with a .java extension in the current directory for the string int. Output might look something like this:

J1.java:        System.out.println("\nThis is class J1\n");
J2.java:        System.out.println("\nThis is class J2\n"); 
Mkc.java:        System.out.println("  file = LF"); 
Mkc.java:        ex.printStackTrace(); 
Mkc.java:    int count = 0; 
Mkc.java:            for (int i=1; i<=numCols; i++) {

Do you see int somewhere in each line? In some lines, int is a word unto itself, while in others int is part of another word, such as println.

Output goes to the display, but you can redirect it to an IFS file instead, as in the following example:

grep  'int'   *.java    >grepout.data

Grep produces the same output but writes the records to file grepout.data.

Notice that the search string may or may not be surrounded by apostrophes or quotation marks. If you omit the apostrophes or quotation marks, Qshell will try to replace certain characters with other values. For example, it will replace a tilde (~) with the name of the current working directory. For that reason, it is a good idea to use either apostrophes or quotation marks as a rule and omit them only when you want Qshell to expand special values. Be aware that some implementations of grep will accept quotation marks but not apostrophes.


These are the options grep supports under Qshell (you may find other options in grep on other platforms):

Option Description
-c write count of selected lines
-e use a list of search patterns
-f use a file of search patterns
-h do not print filename headers
-i or -y ignore case
-l write names of files
-n show line numbers
-q do not print messages (quiet mode)
-s suppress error messages for nonexistent or unreadable files
-v write lines that do not match patterns
-w search as whole word
-x Match if pattern is the only thing on the line
-E Use Extended Regular Expressions (EREs)
-F Do not recognize regular expressions

Here are examples of how some of these work.

Suppose you want to find declarations of integer variables in Java programs but no print commands. Use the–w option to tell grep to find int when it is a stand-alone word, not part of another word..

grep   –w   'int'   *.java

Grep responds with the following:

Mkc.java:    int count = 0; 
Mkc.java:            for (int i=1; i<=numCols; i++) {

Maybe you'd like to know where those lines are found in the source files. If so, add the –n option to ask grep to show line numbers:

grep  -w   -n  'int'   *.java


grep  -wn   'int'   *.java

Note that you may specify the options separately or combine them behind one hyphen. Grep responds with the following:

Mkc.java:45:    int count = 0; 
Mkc.java:92:            for (int i=1; i<=numCols; i++) {

The line number follows the file name and precedes the line image.

To get all lines that don't fit the pattern, use the -v option:

grep   -v   'int'   *.java

Grep lists the lines of Java source code that do not contain int. To remember this option, think of the word invert.

Two other Qshell commands incorporate some of these options. The egrep command is equivalent to grep with the –E option. The fgrep command is equivalent to grep with the –F option.

Regular Expressions

If you're going to do any work at all in a Unix-like environment--and that includes Qshell--you need to familiarize yourself with regular expressions. Regular expressions are used in various languages and utilities, including Perl, Tcl, sed, Python, and awk, as well as within various text editors.

A regular expression describes a search string. It may contain characters that are to be matched exactly, as when searched for int above. But a regular expression may also contain symbols that tell what types of characters are to be sought. For example, [0-9] means look for any character between 0 and 9, inclusive.

The following table describes the special symbols and their meanings:

Symbol Meaning
. (period) Matches any character except end of line
* Matches zero or more occurrences of the preceding character
^ Matches beginning of line
$ Matches end of line
[] Matches any character within brackets; ranges may be specified with hyphen
\{x\} Matches exactly x occurrences of the preceding character
\{x,\} Matches x or more occurrences of the preceding character
\{x,y\} Matches x to y occurrences of the preceding character
\ Turns off special meaning of following character 

To illustrate how regular expressions work, here are some grep commands within Qshell, along with explanations of what each one accomplishes:

Expression Meaning
'b.b' Lines containing two b's separated by any character
'<script' Lines containing <script
'</*script' Lines containing <script or </script
'[a-z][0-9]' Lines containing a lowercase letter followed by a digit
'[a-z|A-Z][0-9]'  Lines containing a letter (in either case) followed by a digit
'.com' Lines containing any character followed by com
'\.com' Lines containing a period followed by com
'3\{2\}' Lines containing exactly two 3's together

You may run into a few limitations when using grep under Qshell. For starters, you may not be able to get the caret (^) symbol to work.

Here are some regular expressions that couldn't get to work under Qshell but worked fine under grep on PC:

Expression Meaning
'</p>$' Lines that end with an HTML paragraph tag (</p>)
'^a' Lines that begin with the letter a
'[^g-i]x' Lines with an x preceded by any letter except g, h, or i

There is no shortage of information about regular expressions on the Web. Here are two links to get you started (a search engine will turn up many more):

  • http://etext.lib.virginia.edu/helpsheets/regex.html
  • www.netaxs.com/people/nerp/automata/regexp0.html
  • Keep in mind that some of the special characters you come across may not be supported by Qshell's grep. If you run into this issue, the best thing to do is to key the special characters into a Word document, or some other PC file, and copy and paste it to your Qshell environment. It may seem a bit hokey, but it works.Write Comment (0 comments)

    << Start < Previous 1 2 3 4 5 6 7 8 9 10 Next > End >>

    Results 1 - 10 of 626