You are trying to convert
from an IFS file
to a DB file.
Therefore the IFS file (by that I assume you mean a stream file outside of 
the QSYS.LIB file system) already has it's "number of records" determined.
So you must be trying to set the number of records to the db2 file.  Then, 
yes, that would be a simple OVRDBF, CHGPF, or doing the CRTPF or CREATE 
TABLE differently.
Let me reread this...
Ok, so on the DB2 file you do not want to use *NOMAX but you want to set 
the maximum to some count of the stream file.  And stream files have no 
concept of 'records'.  However, (after doing a bunch of research), let me 
try this.
STRSQL
CREATE TABLE ROB/TEST (MYCHAR CHAR (10 ) NOT NULL WITH DEFAULT)
  Table TEST created in ROB. 
INSERT INTO ROB/TEST VALUES('ROW 1') 
  1 rows inserted in TEST in ROB. 
INSERT INTO ROB/TEST VALUES('ROW 2') 
  1 rows inserted in TEST in ROB. 
INSERT INTO ROB/TEST VALUES('ROW 3') 
  1 rows inserted in TEST in ROB. 
CPYTOIMPF FROMFILE(ROB/TEST) TOSTMF('/rob/test.txt') STMFCCSID(*PCASCII)
  RCDDLM(*CRLF) STRDLM(*NONE) 
DSPF '/ROB/TEST.TXT'
....+....1....+....2....+....3.
 ************Beginning of data*
ROW 1 
ROW 2 
ROW 3 
 ************End of Data*******
QSH
cat /rob/test.txt 
  ROW 1 
  ROW 2 
  ROW 3 
  $ 
cat /rob/test.txt | wc -l 
         3 
  $ 
So now I see you are looking to retrieve that '3'.
So, when I run
qsh cmd('cat /rob/test.txt | wc -l')
in an interactive session the following displays on the screen:
        3 
 Press ENTER to end terminal session.
When I run
qsh cmd('cat /rob/test.txt | wc -l')
in a batch session.
SBMJOB CMD(QSH CMD('cat /rob/test.txt | wc -l')) 
Job 420557/ROB/QDFTJOBD submitted to job queue QBATCH
wrkJob 420557/ROB/QDFTJOBD
4. Work with spooled files 
I get a spool file with one row displaying 3 in it.
I tried a few things
qsh cmd('cat /rob/test.txt | wc -l > 
/qsys.lib/qtemp.lib/mydtaara.dtaara'
  ) 
  Command ended normally with exit status 2. 
qsh cmd('cat /rob/test.txt | wc -l > /qsys.lib/qtemp.lib/mytable.file') 
  Command ended normally with exit status 2. 
qsh cmd('cat /rob/test.txt | wc -l > /rob/RecordCount.txt') 
  Command ended normally with exit status 0. 
So directing the output to a data area or a db2 file wasn't going to 
happen.  Directing it to a stream file was ok though.
Which leaves you a couple of choices.
- Run in batch and use CPYSPLF.
- Direct to a stream file and read that or do a CPYFRMSTMF on it.
 -Skip CPYFRMIMPF altogether and use Stream file APIs (like the Scott 
Klement tutorial) to read the stream file and write it to a DB2 file.  You 
can either set the DB2 file to *NOMAX and stop you read loop if you read 
too many records and just don't want to process the rest, or continue to 
use a maximum and condition the write to say if it's full abort the read 
loop.
- Continue using your existing process and error trap it.
I don't know why the phobia against nomax.
It would be understandable if you were actually taking the WC output and 
saying if it's over x then don't just do an OVRDBF but instead do...
But if you are just going to set it to whatever the size of the stream 
file is then why not use *NOMAX?
Rob Berendt
As an Amazon Associate we earn from qualifying purchases.