Updating a file in CL?

Can we update a file in CL? If so how?

Answer Wiki

Thanks. We'll let you know when a new response is added.

There are a variety of ways to update a file from a CL program.

The standard i5/OS provided commands do not provide this capability, but a CLLE program can utilize the C language runtime APIs (giving CL the same capability for file IO which is found in the C language) assuming you are on V5R4. These C runtime APIs are provided as part of i5/OS independent of whether or not you have the C language compiler installed.

There are also several ways to execute a SQL function within a CL program.

Bruce Vining
Bruce Vining Services


As noted, the answer is “Yes.” But the answer might continue with “Why would you want to?” Using CL to update files is more troublesome and complicated than simply writing a RPG routine to do the work and calling it. If not RPG, then COBOL and sometimes even C.

If lack of compilers is the problem, then calling a REXX procedure can even be a better choice. REXX can use embedded SQL even without the SQL Development Kit installed.

Whether it can be done isn’t exactly the same as whether it should be done. Using system quirks isn’t always the best technique.



A few things have changed since 2007 when the question was originally posed (thanks Tom for updating this question so it’s “seen” again).

Vendor response:

With the Control Language for Files (CLF) product CL commands are now available to update records in a file (along with read, write, delete, etc — in fact, CLF provides database capabilities that are not availabe with RPG, COBOL, and/or C!).

Calling another program, rather than using a CL command, to update a record is certainly an alternative. Some though find passing, back and forth, all of the fields as parameters to be error prone and not necessarily a good use of a developers times (that is, providing the initial linkage between programs and maintenance if/when the record layout changes).

End vendor response


And with time things have changed yet again.
In 2014 IBM provides the RUNSQL CL command which allows you to directly update files using SQL. CLF is still a good option for reading files (and using *DSPFs, *PRTFs) but a simple database update can now be done directly from a CL program.
Bruce Vining

Discuss This Question: 1  Reply

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Iordache
    go here and read a little about updating files using cl ! https://search400.techtarget.com/tip/0,289483,sid3_gci1098569,00.html
    65 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: