The Compile Error Was in the Upload
DEV Community

The Compile Error Was in the Upload

What the compiler said, and what was actually wrong

I edit RPG on my laptop and push it to IBM i with a script. One afternoon a program that had compiled cleanly the day before failed with RNF0256, "Specification found between procedures", on every line from about line 1,565 to the end. I hadn't touched that part of the program.

The code on my laptop was fine. The member on the server wasn't. This post covers what went wrong, how to spot it quickly, and the upload method I switched to. None of the library, program or file names here are real.

The listing pointed at a line that looked like it belonged to two different places. It began with the tail end of an end-proc statement and ended with the start of a dcl-pr. In my local file those pieces were on separate lines a few statements apart. Somewhere between my laptop and the source member, one record had been put together from the wrong bytes.

From the compiler's point of view, a half-finished procedure end followed by a prototype in the middle of a procedure body is nonsense. Every line after it was parsed in the wrong context, so the errors cascaded to the end of the member.

A cascade like that sends you to the first error, and the first error here was a line I never wrote. (I wrote about telling causes apart from cascades in 1,619 Compiler Messages, Four Real Causes. Same idea, different cause.)

The clue was the position. The damaged record was the one that crossed the 64 KB mark in the file, at about byte 65,880 of a 112 KB member. Smaller members had always uploaded fine, which is why the method had looked safe for months.

The habit worth taking from this: when a compile error makes no sense, look at the member on the server (DSPPFM, or open it in your editor from the IBM i side) before you look at your local copy. If the two differ, stop debugging the code. It's the transfer.

Why ASCII FTP straight into a member is fragile

An ASCII-mode FTP put into /QSYS.LIB/.../FILE/MBR asks the FTP server to do two jobs at once while the data streams in:

  • convert the characters from ASCII to the source file's EBCDIC CCSID, and
  • cut the stream into fixed-length records at each line end.

Both happen on the fly, a buffer at a time. In our case a record that crossed a buffer boundary came out wrong. I haven't found this documented as a known problem, and I didn't chase the exact root cause on the server side. Once I separated the two jobs, it stopped happening, and the fix is a better design anyway. Treat the explanation as my best reading of the evidence, not a confirmed diagnosis.

There's a second reason not to rely on it: you can't see what went wrong. The FTP session reports success. Nothing tells you a record was assembled badly until the compiler trips over it, and for a comment line or a string constant it might not trip at all.

The two-step upload

The fix keeps the transfer and the conversion apart.

Step 1. Send the file in binary to an IFS folder. Binary mode copies bytes exactly, with no conversion and no record splitting, so what lands on the IBM i is byte-for-byte what was on the laptop. With curl that's just a normal upload, because curl's FTP transfers are binary unless you ask for ASCII:

curl --user ME -T MYPGM.sqlrpgle \
"ftp://ibmi.example/%2Ftmp/srcup_me/QRPGLESRC_MYPGM.txt"

Given a user name with no password, curl asks for the password at the terminal. A script needs a slightly different approach, covered further down.

Step 2. Copy the stream file into the member on the IBM i. CPYFRMSTMF reads whole lines from the stream file, converts them and writes one record per line:

CPYFRMSTMF FROMSTMF('/tmp/srcup_me/QRPGLESRC_MYPGM.txt') TOMBR('/QSYS.LIB/SRCLIB.LIB/QRPGLESRC.FILE/MYPGM.MBR') MBROPT(*REPLACE) STMFCCSID(1208) DBFCCSID(*FILE) ENDLINFMT(*LF)

The parameters that matter:

  • STMFCCSID(1208) says the file is UTF-8. Say it explicitly. A file created by a binary FTP upload gets whatever CCSID tag the server gives new files, and that may not be what your editor wrote.
  • DBFCCSID(*FILE) converts into the source file's own CCSID (37 in our case), so the member matches everything else in that file.
  • ENDLINFMT(*LF) matches files written on macOS or Linux. Use *CRLF if your files come from a Windows editor that writes CR LF.

Then tidy up and set the member attributes:

RMVLNK OBJLNK('/tmp/srcup_me/QRPGLESRC_MYPGM.txt')
CHGPFM FILE(SRCLIB/QRPGLESRC) MBR(MYPGM) SRCTYPE(SQLRPGLE) TEXT('Order dashboard CGI')

My script sends every changed file in one curl call, then runs the CPYFRMSTMF, RMVLNK and CHGPFM commands for each member through FTP RCMD in a second call. The member type and text are set at upload time from a header line in the source itself, the same rule our change management tool uses, so a build never has to guess them.

If you use SFTP or scp instead of FTP, the same split applies: put the file in the IFS, then CPYFRMSTMF it into the member.

Checks to run before anything leaves the laptop

The two-step upload fixes the transfer. It doesn't fix source that can't fit in a member. My script runs these checks locally and refuses to upload if any of them fail:

  • Line width against the record length. A source file created with RCDLEN(112) holds 12 bytes of sequence number and date, and 100 bytes of source. A longer line can't fit. Don't count on any upload method to warn you clearly. Check widths yourself.
  • Column 80 for free-form RPG without **FREE. Free-form code in a member that doesn't start with **FREE only uses columns 8 to 80. Anything past column 80 is ignored, so a statement that runs long loses its end without an obvious error.
  • Characters outside plain ASCII. Curly quotes, em dashes and other characters that editors slip into comments may not have a match in the source file's CCSID. They turn into substitution characters, and inside a string constant that changes what the program does.
  • Member names of 10 characters or fewer, with a known source type. A file called ORDER_DASHBOARD.sqlrpgle has nowhere to go.

These take a fraction of a second and catch most of the problems that would otherwise show up as a confusing compile.

Keep the sign-on out of the script

An upload script signs on to the IBM i, so two details matter:

Never put the password in the script, an environment file it echoes, or the command line. My script asks for it with getpass and passes it to curl on standard input with --config -. It never shows up in the process list, a shell history or a log. (How I Encrypt and Use Credentials on IBM i covers the server side of the same problem.)

Stop at the first refused sign-on. If the FTP server answers 530, the script exits right away instead of trying again. A retry loop with a wrong password can reach the system's QMAXSIGN limit and disable the profile, which turns a typo into a call to the security team.

A short checklist

  • Don't ASCII-FTP straight into a source member. Send the file in binary to the IFS, then CPYFRMSTMF it into the member.
  • Name the stream file's CCSID with STMFCCSID, and convert into the source file's CCSID with DBFCCSID(*FILE).
  • Match ENDLINFMT to your editor's line endings.
  • Check line width, column 80 and non-ASCII characters before the upload, not after a compile fails.
  • When a compile error makes no sense, compare the member on the server with your local file. A line you never wrote means it's the transfer.
  • Test with a member over 64 KB. Small members passing proves nothing about big ones.
  • Keep the password out of the script and stop on the first refused sign-on.

Moving files onto IBM i safely is a theme I keep coming back to. The FTP Execution Engine, Line by Line applies the same idea to production data: land it somewhere safe first, check it, and only then put it where it's used.

Jaya Krushna Mohapatra is a Warehouse Management Systems Architect focused on enterprise integrations, IBM i modernization, and scalable backend systems.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.