To reply to Stephen's question - ways other than CPYTOIMPF to write to CSV files - generate_spreadsheet function can process the CSV option. It was introduced, for sure, at 7.4. And if Stephen is working before 7.4, he can use the cldownload function of ACS, which is the thing that is used in generate_spreadsheet. Of course, that uses QShell, so is not specifically SQL - but that is very much doable in RPG.

There are also the ifs_write procedure.

*Regards*

*Vern Hamberg*

IBM Champion 2025 <cid:part1.RK7tTTzi.SbBz40yD@centurylink.net> CAAC (COMMON Americas Advisory Council) IBM Influencer 2023


On 3/16/2026 2:36 PM, Rob Berendt wrote:
SQL Stored procedures support both the QCMDEXC function, and the QCMDEXC
procedure. The function is useful for stuff like querying syspartitionstat
and firing off a RGZPFM on each member with significant deleted rows The
procedure is useful for one offs in the stored procedure mainline code.
For samples of both:
https://www.ibm.com/docs/en/i/7.6.0?topic=services-qcmdexc-procedure
https://www.ibm.com/docs/en/i/7.6.0?topic=services-qcmdexc-scalar-function



On Mon, Mar 16, 2026 at 3:00 PM Stephen Richter<stephenrichter@xxxxxxxxx>
wrote:

On Sat, Mar 14, 2026 at 6:48 AM Rob Berendt<robertowenberendt@xxxxxxxxx>
wrote:

Have you thought of abandoning CL for SQL stored procedures? There are
SQL
services to check for IFS existence, locks, etc. To me this is a much
better solution than calling out to APIs, shoehorning SQL into CL, etc.

I need the CL to run CPYTOIMPF. Is there an SQL way?

But yes, SQL procedures and functions are terrific. Just be an expert in
terms of debugging. In my case, the CL program uses RUNSQL to call the SQL
procedure. I am creating a lot of CSV files, so the CL does its thing to
organize the IFS folder where the .CSV files are stored.

Grok was a big help in writing the CL program that uses STRQSH to run the
unix "test" command to test for existence of the IFS folder. Only thing,
Grok forgot to tell me to add the QIBM_QSH_CMD_ESCAPE_MSG environment
variable. Good thing Google AI knew about that. Otherwise I would have
had to read some manuals.

Here is the CHKDIR CL program that AI and I came up with:

PGM PARM(&outExists &DIR)
dcl &outExists *char 1
DCL VAR(&DIR) TYPE(*CHAR) LEN(256)
DCL VAR(&CMD) TYPE(*CHAR) LEN(2048)
/* Build shell test command */
CHGVAR VAR(&CMD) VALUE('test -d "' *TCAT &dir *TCAT '" &&
exit 0 || exit 1')

/* important!. Set environment variable to tell QSH to send *escape message
*/
/* when exit code of the shell command is not 0 - success.
*/
ADDENVVAR ENVVAR(QIBM_QSH_CMD_ESCAPE_MSG) VALUE('Y')
REPLACE(*YES)

/* Run it */
CHGVAR VAR(&outEXISTS) VALUE('1')
STRQSH CMD(&CMD)

/* If exit code = 0 ? exists */
MONMSG MSGID(QSH0000) EXEC(CHGVAR VAR(&outEXISTS)
VALUE('0'))

endpgm
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email:MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:https://lists.midrange.com/mailman/listinfo/midrange-l
or email:MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
athttps://archive.midrange.com/midrange-l.

Please contactsupport@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.