Home > AS/400 Tips > iSeries programmer tips > Ways to put QSHELL to work in your day-to-day programming life
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Ways to put QSHELL to work in your day-to-day programming life


Jagannath Lenka
09.08.2005
Rating: -4.59- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


I have been reading a lot about QSHELL since it was introduced for the iSeries. After learning about this shell I started promoting this piece of technology to my colleagues. Time and time again I was asked, "What is the usage of this technology when most of the functionalities can be done with CL or RPG?" Due to the lack of shell commands at that time, I restricted my answer to, "It helps in compiling Java programs." At that time, Java was an unusual language for iSeries users.

I have since discovered that QSHELL has become much more. It is now the equivalent of any other UNIX shell. However, now I'm asked, "Why should we adopt UNIX, when we have such a good operating system as OS/400 and the advance scripting language CLLE?" The answer is that QSHELL helps CL rather than competes with it. Here are few ways that you can use QSHELL in your day-to-day life of programming.

Usage for database operation

CL has a major restriction of using Data Manipulation Language (DML) such as Update, insert or selected delete with the DB2/400 database. To achieve this, we use roundabout ways such as RUNSQLSTM, writing new RPG program, etc.

Qshell makes life easier by using the following command:
Syntax: QSH CMD('db2 "<Db2/400 sql statement">)

Example:
QSH CMD('db2 "UPDATE MYLIB.MYFILE SET MYFLD = ''P''" ')
QSH CMD('db2 "INSERT INTO MYLIB.MYTABLE VALUES(''jagannath'', 104.20)"')

Things to note:

Usage for IFS operation

It is always a headache to handle IFS files using RPG programs. We have to write separate RPG programs using C APIs to handle this functionality. But QShell commands ease this process.

Syntax:

To replace the contents of the IFS and write the fresh text
QSH CMD('print It is working > /home/mydir/myfile.txt')

To append to the contents of the IFS file in next line
QSH CMD('print It is working >> /home/mydir/myfile.txt')


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
iSeries programmer tips
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Running PHP open source applications: NOBODY needs authority
Programming for the Web on the IBM i, what is possible
Using geocoding on AS/400 to enhance your Web presence
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
Documenting nested program structures on the AS/400
What is an integrated database?
An automated CL method of moving a query from AS/400 to Excel

iSeries CL programming
Checking in on your IBM i authorization lists
Running PHP open source applications: NOBODY needs authority
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
CL program for daily backups
An automated CL method of moving a query from AS/400 to Excel
Changing user password expiration
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Advanced Job Scheduler help
How do I retrieve the source for an output queue description to put in to a CL program?

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


>To use other features of print, go through the QSHELL manual of IBM.

I found this functionality helped me while creating CSV files out of database files using CPYTOIMPF. With this command we create the comma separated files out of the database file. To add the report headings, field descriptions, etc., the print command helps a lot.

Example:

Redirecting

The output of the QSHELL commands is normally displayed in the standard output. (In UNIX terms, standard output (screen) is also called as a kind of file.) However, we can redirect this output to an IFS file. Since regular programmers are more acquainted with DB2/400 files, let's see how we can redirect the output to the DB2/400 files.

Let's first look at the mapping of the naming conventions between OS/400 and IFS.

[TABLE]

In QSHELL 'ls' is used similarly to WRKOBJ *ALL in OS/400. If you want to redirect the output result of ls to a DB2/400 file, do the following:

Searching objects

If I want find the name of the file that ends with "PGL" in MYLIB library, what should I do? WRKOBJ command does not support WRKOBJ *PGL. We can use one of the versatile file searching utilities called find.

Things to note:

Counting the results

Want to count how many programs are in one library? You could do a WRKOBJ and then transfer to a file and use query. But it can be done using wc:
Qsh CMD('find /qsys.lib/MYLIB.LIB -name ''*'' | wc -l')

Searching strings

The only way to find strings or a pattern of strings in the members of the source physical file is with the FNDSTRPDM command. This command has lots of restrictions, such as it does not let you search more than one pattern (string) at one time. One of the best searching utilities in the industry is grep, which is used in UNIX shells. Let's see how we can use it to replace FNDSTRPDM.

Example:

More you can do

There are many other useful commands that can help you program lots of complicated stuff in CL using QSH. Try going through Rfile to read or write to the OS/400 files or jar to zip the IFS files to transmit them by mail. Explore the other QSH commands in the iSeries Infocenter.

---------------------------
About the author: Jagannath Prasad Lenka is a programmer/analyst at Infosys Technologies Ltd. He has worked as programmer and senior programmer on the iSeries for this company for the past five years.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts