It's interesting that something like Open Query File (OPNQRYF) has become
somewhat of an icon under OS/400. Back in the days of the System/38 (that was
the predecessor to the AS/400 and iSeries for those of you whose world began
with AS/400), we lived with "just" logical files and RPG. Then, IBM decided to
put a command interface (CL command) around the dynamic database component. The
underlying code was being used to "test" the database, according to the author
of OPNQRYF.
The author, George Timms of IBM Rochester, did a fantastic job of providing
the System/38--and subsequently the AS/400 and iSeries--programmers with an
invaluable tool. I remember seeing him receive several standing ovations at
COMMON the year IBM announced the OPNQRYF command. Effectively, OPNQRYF killed
the sort utility on this platform.
But something else was going on parallel with OPNQRYF. A Midwestern company
was busy creating the first implementation of SQL under OS/400 (called CPF at
the time). Interestingly, that SQL product, SEQUEL from Advanced Systems
Concepts (ASC) of Schaumburg, Illinois, actually used the same underlying code
as IBM's OPNQRYF.
Certainly, OPNQRYF followed the traditional CL syntax convention and has been
enhanced over the years to provide even more functionality. But SQL was and is a
multi-platform standard. A few years later, IBM shipped SQL for the System/38,
and it has been a mainstream application development tool ever since.
SQL did not become an overnight success. Unlike OPNQRYF, SQL took years to
get a foothold in the OS/400 market. With SQL, you could generate reports,
update files, delete records, create files, order files and so forth, but you
could not use IBM's version of SQL like OPNQRYF. So, OPNQRYF became the de facto
standard.
But the ASC version of SQL included a little-known command: Open SQL File
(OPNSQLF). In short, this command eliminated the need to learn the complex
syntax of OPNQRYF by allowing you to learn industry-standard SQL and put it to
work in your CL programs, effectively replacing OPNQRYF. Since both tools use
the same underlying engine, there was little, if any, difference in
performance.
Today, tens of thousands of AS/400 and iSeries shops use OPNSQLF with ASC's
Sequel product. That's the good news. The bad news is there are probably
hundreds of thousands of shops that use OPNQRYF file. Why is that bad news?
Well, we're getting a new generation of programmers entering our market, and
they will not be familiar with all those OPNQRYF statements. The new programmers
tend to be familiar with SQL syntax, which means that the applications taking
advantage of OPNSQLF or SQL in general will cause fewer issues for these new
developers than the applications that use OPNQRYF.
The problem with the OPNQRYF command is the syntax. It is too complex. Sure,
the prompter helps, but I find very few developers (although there are some) who
would actually attempt to modify an existing OPNQRYF command. They don't touch
them for fear of breaking the code. The interesting thing is, OS/400 developers
originally thought SQL was too complex and thus avoided it in favor of logical
views and OPNQRYF. Today logical views are still wonderful, but we really need
to consider moving away from OPNQRYF--it just won't be maintainable in the
future.
Replacing Everything with SQL
A couple of years ago, I had the privilege of helping
design a database from scratch. I provided the design requirements for the
database. The database administrator (DBA) created the files. When I asked to
see the DDS for the files, the DBA said, "There isn't any." Needless to say, I
was flabbergasted until he said that he created the files using a design tool
that generated OS/400-compatible SQL statements. These design tools (and there
are several) allow you to create a database using a graphical entity
relationship modeling tool such as ERwin from Computer Associates. Then, you
create the database relationships by connecting the tables (i.e., files) via
their key fields, and then you specify the field properties. When you're ready,
you press the Build-on-host button and--voila--your files are created. Physical
files are created as SQL tables; logical files are SQL views.
As an OS/400 developer, the thing I initially didn't like was the fact that
the DDS was not generated. I've always felt that DDS was easy to read, and
modifying things like default values, column headings, and attributes are
easiest with DDS. On the other hand, you can review the generated SQL CREATE
TABLE and CREATE VIEW statements, which contain similar information. So now my
thinking is that perhaps it's time to stop using DDS for database
definitions.
Eliminating DDS
SQL provides the ability to create any type of
database file. As mentioned, the SQL CREATE TABLE command is used to create a
physical file. The syntax for CREATE TABLE is straightforward. But the cool
thing is that you can also use SQL to change a physical file's definition. The
SQL ALTER TABLE command allows you to actually change the attributes of a given
column (field) in the database, while ALTER VIEW allows you to change the
attributes of a logical view.
Today, there is little reason, shy of legacy habits, to continue to use DDS
at all for database definitions. Perhaps the one thing DDS has over SQL--and
this is a huge issue--is field referencing. SQL doesn't really have field
referencing, but if you use an entity relationship tool, you can obtain similar
functionality. I typically use field referencing for large, new projects, but of
late I've not really liked looking at DDS and seeing a bunch of REFFLD keywords
when I really wanted to see the data. That's why I wrote the Work with File
Field Description (WRKFFD) command. That command displays a list of fields and
their attributes for any database file. I will be posting the source for the
WRKFFD command in the forum associated with this article in a few weeks.
Here's an example of DDS and the corresponding SQL statements needed to
create the same file:
A R CUSTMAST Text('Customer Master') A CUSTNO 7P 0 COLHDG('Customer' 'Number') A COMPANY 30A COLHDG('Company' 'Name') A ADDRESS 25A COLHDG('Address' 'Line 1') A ADDRESS2 25A COLHDG('Address' 'Line 2') A CITY 20A COLHDG('City') A STATE 4A COLHDG('State' 'or' 'Province') A ZIPCODE 10A COLHDG('Postal' 'Code') A CRTDATE D COLHDG('Creation' 'Date') ALWNULL
This same DDS would then need the CRTPF command to create the database file.
In SQL, the data definition and creation statements are one in the same, as
follows:
create table mylib.custmast (custno decimal(7,0) not null with default, company char(30) not null with default, address char(25) not null with default, address2 char(25) not null with default, city char(20) not null with default, state char(4) not null with default, zipcode char(10) not null with default, CRTDATE date with default CURRENT_DATE)
In order to set the COLHDG keyword another SQL statement (COMMENT ON) would
need to be used. To insert the column headings, the following SQL statement
would be used:
COMMENT ON COLUMN mylib.custmast (CustNo is 'Customer Number', Address is 'Address Line-1', Address2 is 'Address Line-2', City is 'City', State is 'State or Province', zipcode 'Postal Code', crtdate is 'Creation date')
Again, if you use a tool like Operation Navigator or ERwin, the tool
generates these statements for you so that you key the data definitions in only
once.
Call to Action
What I recommend is that you go out and buy A Guide to SQL
Standard by C.J. Date. It contains just about everything you need to know
about SQL. Then, I would strongly suggest that you move away from using OPNQRYF
for any more development. If necessary, visit the ASC Web site and find out more about the
SEQUEL product and the OPNSQLF command.
Then, I would consider using SQL to create your future database definitions.
Try out one of the entity relationship tools, but be aware that the good ones
are very expensive, into several thousand dollars for one PC license. But if you
know SQL, you can simply type in the SQL syntax or use the prompter in IBM's
SQL/400 product (whatever its name is this month) or use the one in SEQUEL. Both
are very capable.
SQL vs. OPNQRYF--The Battle Continues Nov 14 2002 20:22:00
I can put an OPNQRYF statment in a CL to add filters to an interactive pgm or reports and elimate the need to change the RPG pgms that follow. This is faster and easier. It also makes it better for the next guy who follows. <p>I do use SQL embedded in RPG. I find it cumbersome to retro-fit in this scenario. <p>Bottomline I use & know both. The main point is, it sure would be nice to have SQL supported fully in CL with dynamic variables, why would anyone disagree with this point??? <p>robberendt- I like SQL but I won't go out of my way to use it when OPNQRYF is the best answer. It is the best answer in some cases. Some esoteric way to use a free third party tool to build a string with dynamice variables then execute an API I'm guessing is not the soloution just to dodge OPNQRYF or to say you can in fact use SQL in CL w/o limitations.
SQL vs. OPNQRYF--The Battle Continues Nov 14 2002 17:52:00
Some notes to discussion. <p>1. One has to get an idea how data looks like before writing any program. You are lucky if your shop has DBU or any other utility. There are plenty examples when the only available tools are DFU, QRY400, QMQRY. You still can create SQL looking like tool within CL and QMQRY at no cost at all. <BR>
OPNQRYF uses dummy file to join several files. It is much easier to use SQL to get data for this join even with EXSQLSTM. <BR>
2. SQL is great tool for testing. In some cases, couple SQL statements could replace several pages RPG program and any step could be easily verified. I have never seen OPNQRYF as a part of testing procedure; usually it is OPNQRYF selection that needs to be tested. <BR>
3. I still use SQL and OPNQRYF because of client requirements, company policy or standards.
SQL vs. OPNQRYF--The Battle Continues Nov 14 2002 06:18:00
I have to respond on this. <p>I do not think you can compare OPNQRYF and embedded SQL entirely. <p>Both make use of the same query engine on the AS/400. <p>OPNQRYF file has the limitations of CL, as it is a CL command. It will not deal with data types like floating point or integers. <p>I see OPNQRYF as an interface to SQL in CLP, and it fulfills two SQL functions: prepare an SQL statement and open a cursor. To process the open data path you need a HLL language. <p>If you want that OPNQRYF is as flexible as SQL, then IBM have to enhance that CL command. But then it should enhance other CL commands as well, which it has not done for a long period now. <p>I agree with you, that using OPNQRYF is cumbersome, but so is embedded SQL in an RPG programme. <p>Just my two Euro-cents. <p>Regards, <BR>
Carel Teijgeler
SQL vs. OPNQRYF--The Battle Continues Nov 13 2002 14:54:00
THULL is probably referring to DRDA (Distributed Relational Database Architecture). This allows an SQL program on one platform like an iSeries to connect and access data on a dissimilar platform. Search this site for "DRDA". <p>Chris
SQL vs. OPNQRYF--The Battle Continues Nov 13 2002 14:32:00
I'll show my ignorance here - "...This allowed me to connect to remote databases..." - Can you point me to a reference book that explains how to do this? <p>Thanks, <p>Joe
SQL vs. OPNQRYF--The Battle Continues Nov 13 2002 14:18:00
It seems strange to me that none of the responses mention MONMSG capabilities. OPNQRYF never gives much explanation when it doesn't work, let alone take any type of action. I used OPNQRYF for many years. Then I worked in a company with many IBM systems. I could embed SQL into my RPG. This allowed me to connect to remote databases, and read each of their inventory files from one system into one single report. I put SQL in my Item master edit program to verify the Item # was already valid on the mainframe, I could prompt a window to read and select the conversion factors from the mainframe DB2 (I haven't seen any SET CURSOR & read a record at a time in OPNQRYF). I could monitor for connection not available (try later), record not found, etc... The SQL book gives the response codes, -negative values are errors, try this with OPNQRYF. Also don't forget IBM's other attempts to support proprietary products (WORDPERFECT on AS/400, Office vision, etc...) I have no guarantees on SQL, but with the rest of the world using it as a de-facto standard, I will put my bet on it staying around longer than OPNQRYF. I have also used SQL on several systems with out the SQL (IBM's 5722-ST1) product, several magazines have given me utility programs to run SQL statements from CL and the command line w/o ST1.
SQL vs. OPNQRYF--The Battle Continues Nov 11 2002 12:40:00
Like Paul, I've been doing this for a very long time on all different platforms. It's been my experience that SQL knowledge is transferrable from platform to platform. Each platform will have it's own quirks, but they are generally not attributeable to SQL but to the OS. <p>Even old horses know can recognize these and adapt well.
SQL vs. OPNQRYF--The Battle Continues Nov 11 2002 11:35:00
In reply to AS400NUT regarding his question about filling out a Request for Design Change form will get any response from IBM. <BR>
I filled one out several years ago requesting IBM add an enhancement to the line/box keywords. It didn't happen overnight, but within the next release or two the functionality I requested was implemented. Now I can't say it was done because I asked for it, but it was added.
SQL vs. OPNQRYF--The Battle Continues Nov 11 2002 11:34:00
Some say they are sticking with OPNQRYF until IBM allows SQL in CL. Excuse me but what can you do with OPNQRYF and host variables that you cannot do with SQL in CL? <BR>
As far as I remember people used OPNQRYF for two things. One, to set up an access path to be used in the RPG program that the CL then called. Easy, skip the OPNQRYF and just use embedded SQL in the RPG. <BR>
Two, CPYFRMQRYF. There are numerous free tools out there to do things like: <BR>
chgvar &mysql = 'update...' <BR>
CHGVAR VAR(&MYSQL) VALUE('update...')
SQL vs. OPNQRYF--The Battle Continues Nov 11 2002 11:16:00
In reference to KCM2, I have just had that same talk with IBM and I have document 5314847 (Request for Design Change) form to fill out and give them back. Maybe if enough of us respond this way we can get SQL to run in CL natively. Mr. Cozzi has this ever worked that the end users requested a change and IBM listened other than people like you and Al Barsa? <p>Lets flood them with the request for change.
SQL vs. OPNQRYF--The Battle Continues Nov 07 2002 17:26:00
ASC's SEQUEL product and SQL overlap and complement each other to different degrees. SEQUEL runs on the QQQQUERY API used by OPNQRYF, and is limited to the same data types. No datalinks or BLOBs. It doesn't do things like Create Index or Grant or create stored procedures or logical files/views. (I used QUERY/400 before I convinced my current employer to buy SEQUEL.) <p>SEQUEL's strength is in data manipulation and presentation using SQL syntax. It's a great tool for that; I've been using it for 11 years. Like SQL, you can display data, print, update, insert, delete, or output to a PF. But you can also send data in various ASCII formats to QDLS or the IFS or to a Windows server over the /QNTC file system or via FTP or email. Formats include text, delimited (customizable!), Excel, dBase, XML, HTML, and PDF. That's all in just the Kernel module. <p>Among others, there's also the Reports module that lets you lay out reports with subtotals and calculations. The Tabler module pivots data. The ESEND module can "burst" reports and send sections independently to different email addresses; I think it's available separately. All this can run on the command line or in CL programs. A former COBOL programmer at my company says he can write a report in 1 hour with SEQUEL that took him a week to do in COBOL. It's the only reporting tool we use here, besides some legacy COBOL reports. (I have no financial relation to ASC except to send them money for maintenance and upgrades.) <p>SQL does the whole DDL/DML/SPL shebang, but doesn't do fancy output and reporting. It can do types of joins that SEQUEL can't. SQL can have things in its SELECT clause that SEQUEL does not (yet) support, like the MIDNIGHT_SECONDS special value, or the ESCAPE part of LIKE. I have started learning SQL recently and can see things I might do with it that SEQUEL can't do as easily, but for reporting, I'd use SEQUEL for my last steps.
SQL vs. OPNQRYF--The Battle Continues Nov 07 2002 16:25:00
SQL should run natively in CL is my biggest complaint. So we can have dynamic variables. Using the RUNSQLSTM is good only for static statements. <p>I do use SQL all the time because it is standard across platforms for database access. <p>I still do use OPNQRYF until this is rectified by IBM. You know the IBM that is to become our next utiltiy.
SQL vs. OPNQRYF--The Battle Continues Nov 07 2002 14:44:00
If your shop religiously uses a field reference file then I can see being hesitant on using SQL to create tables. However, V5R2 will allow SQL to use a Reference when defining fields ( columns ) in a table. ( see <a href="http://www7b.software.ibm.com/dmdd/library/techarticle/0208milligan/0208milligan.html">http://www7b.software.ibm.com/dmdd/library/techarticle/0208milligan/0208milligan.html</a> ) <p>I'm trying to learn as much as I can about SQL and the SQL Procedural Language, mostly in a test/learning environment but I don't want to leave my field reference behind. Since IBM is updating SQL and DB2 and not DDS, I expect all the pieces to eventually be in place, so I'll just wait. <p>This reminds me of the first incarnation if ILE, to me it initially seemed like extra work to create the programs but once IBM added the ability to use binding directories and include the directory name on an RPG pgm's "H spec" my complaints about ILE went away and I'm glad I made the switch.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 22:36:00
In my early career with the AS/400 (1992-1996) we used OPNQRYF to create dynamic access paths for green bar printing. Since I discovered Query Manager, we have effectively thrown away RPG reports in favor of SQL generated reports. The Query Manager interface comes with 5722-ST1, but the runtime is part of base OS/400. Plus, if your shop is too cheap to buy 5722-ST1 and you are good with SQL, you don't need the interface. (I would recommend the interface). <p>I loved OPNQRYF in its day. But I get a great deal of increased programmer productivity from developers using SQL for ad-hoc queries and reports than OPNQRYF & RPG. I have taken skeptical RPG developers who couldn't even spell SQL and turned them into true believers. Plus, I just converted 3 PC developers to iSeries developers and by using SQL I minimized the learning curve. <p>Granted Query Manager has its quirks. But, GET OVER IT and realize how much money you can save by allowing your developers to concentrate on business logic and getting to the web rather than laying out print formats in DDS or O-Specs...
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 21:18:00
You're not going to get me to disagree. But the point is, they DON'T TEACH DDS in College (primarily). <p>As to the issue with JDE, they have an "interesting" database to say the least. I just won't go there. :) <BR>
But, RPG has issues with SQL that are the fault of both IBM Rochester and Toronto. I just hope they work those out before we all just give up and go home.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 21:15:00
Others have already pointed out, SQL is essentially free on the machine. As a software vendor, you can also purchase the IBM product that allows you to use embedded SQL in your RPG code. <p>Your customers will NOT need SQL on their machines in order to run that code. If you use ASC's SEQUEL product, you get a lot more power, but I don't know their pricing, whether or not they have a runtime module that can be liscensed.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 17:55:00
I buy into a lot of what people say in articles I read, but not this time. <BR>
Why should I get rid of my DDS, field reference files and data base integrety, just so I can use SQL. Let's face it, once field reference files are gone, so is your data base integrety. <BR>
How do I know the next programmer that creates a table will create the customer number etc... with the same attributes used in previous data bases? Remember, the reason we love the as400 so is that every programmer knows what the database looks like from one file to another. <p>Sorry,,,,I hope Mr. Cozzie isn't teaching this in his classes.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 14:24:00
I agree that SQL is a strong language and I use it on a daily basis. However, as far as being the source for creating files, I have a few issues. RPG programs are pretty nasty about File Identifiers. We use 3rd party software (JDEdwards) and one of their products uses DDS to create files and their other product uses SQL to create tables. If we try to run an RPG program from the one set of software, over a table generated from their other software, we have problems due to format level id's and format names not matching. Maybe it's just JDE's tool for creating tables using SQL that is not using the correct naming conventions and keywords? Would you save the SQL statements you use to create files in a source file so that you could create the same file with the same format info in different libraries or testing environments and systems (which may have different operating system levels)? <p>Another use for DDS is documentation and data dictionary. When you create a DDS field name reference file and then design all of your files using DDS referencing your original member, you know that a particular field will be created the same throughout the database. I'm not good enough at SQL to be able to use a reference file for fields within a table.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 12:57:00
Shops on a tight budget must have BOTH, otherwise they're spending way too<BR>
much on labor. I know, Sequel (ASC) has made a tremendous impact on<BR>
reducing backlog in our AS/400 shop. We've also given it to 3 end users<BR>
that have created wonderful reports, spreadsheets, email, etc. using Sequel.<BR>
That has reduced our programmer backlog as these users were the ones<BR>
submitting the most requests. The GUI front end called Viewpoint makes<BR>
doing all the work very easy.<BR>
<P>
Sequel can be purchased on a "per user" license and a single license for a<BR>
small AS/400 is very reasonable. Any manager that can't justify Sequel,<BR>
even a single user license, should find another line of work!<BR>
<P>
BTW, I have no affiliation with ASC other than being a satisfied customer.<BR>
<P>
chuck<BR>
Opinions expressed are not necessarily those of my employer.<BR>
<P>
<P>
"robberendt" <robberendt@mcpressonline.com> wrote in message<BR>
news:6ae45e52.4@WebX.WawyahGHajS...<BR>
| Pushing ASC's product might be detrimental for those shops that are on a<BR>
tight budget. If they had to choose between ASC's product and IBM's<BR>
5722-ST1, I'd go for the IBM product for the sole reason to get the SQL<BR>
precompiler.<BR>
<P>
<P>
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 12:13:00
I was one of those who cheered OPNQRYF when it first came out. <BR>
But, I haven't touched OPNQRYF for years. I would never consider using it unless there was a gun to my head or a client forces me to. Once I started using SQL, I never turned back. It's so much easier to use than OPNQRYF.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 12:00:00
I work for a company that has thousands of AS/400 customers. Why should we expect our customers to purchase an additional product(SQL from IBM) when that money could be better spent on more of OUR products? I don't believe that SQL will be a viable replacement until it is included free with the OS.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 11:25:00
I have been involved with IBM midrange systems since 1976. I have gone from Mainframes to System/3 to System/38 to AS/400. If we as programmers and developers wish to continue in this business we need to use SQL and SQL tools. SQL is fast becoming the defacto standard for all development. JDBC is based on SQL. iSeries navigator is empowered to use SQL. If I as a hard and fast RPG coder (plus COBOL, Assembler, Fortran and Basic) can learn ILE concepts and SQL then any other computer professional should be able to do so also. It is not enough to rest on your laurals. The writing is on the wall. Learn SQL.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 10:48:00
Pushing ASC's product might be detrimental for those shops that are on a tight budget. If they had to choose between ASC's product and IBM's 5722-ST1, I'd go for the IBM product for the sole reason to get the SQL precompiler.
SQL vs. OPNQRYF--The Battle Continues Nov 06 2002 10:43:00
I think Paul speaks volumes with this simple statement. While many experienced iSeries developers may feel smug about their knowledge of DDS, OPNQRYF, etc. I am finding that the new people here faster to adapt to SQL.
#112740
There are too many comments to list them all here. See the forum for the full discussion.