Using SQL in RPGLE programs is easier than you think. Making the move from RPG native file IO to SQL database IO is really quite straightforward:  Changing from good old READE loops to SQL FOR Loops simply means using the SQL CURSOR function. SQL has a groovy way of referring to what the stuff that

Read More

Should RPG code be long form or short form? I’ve been working on an interesting project focused on taking some old RPG code and re-factoring it to make it more efficient. Fascinating work for a client that is focused on doubling its IBM i throughput and reducing the CPU load of all its old programs.

Read More

wow – that has got to be the longest url yet   😉

 

QSPGETF AND QSPPUTF APIs AND COMMANDS

IBM Knowledgebase item 8011926 describes two APIs that are undocumented in the AS/400 manuals. The two APIs, Get Spooled File (QSPGETF) and Put Spooled File (QSPPUTF), copy spool files to and restore them from physical files, respectively. The advantage of QSPGETF and QSPPUTF over the well-documented Copy Spooled File command (CPYSPLF) is that the APIs are able to copy Advanced Function Printing Data Stream (AFPDS) and Intelligent Printer Data Stream (IPDS) spool files, whereas CPYSPLF cannot.

You can call the QSPGETF and QSPPUTF APIs directly, or you can call them using command wrappers over the APIs.

  • Calling the APIs Directly

The QSPGETF API call below saves spool file QPRINT to database file SPOOLDB in USER1LIB library, member MBR1, where the spool file number is 1 and the spool file job is 010160/user1/dsp03:

CALL PGM(QSYS/QSPGETF) PARM(‘QPRINT ‘ ‘SPOOLDB USER1LIB ‘ ‘DSP03 USER1 010160′ X’0001’ ‘MBR1 ‘)

...
Read More

Substring in RPGLE SQL This morning, I had to make a little change to an RPG4 program to let it respond to a new parameter being passed into it via JSON. This value had to be stored in the first character of a field in a physical file in the database. Simple Logic and we

Read More

USING COPYRIGHT in the RPG Header Following on from the COPYRIGHT PRIMER blog from a while ago I added a little extra function for CL as well. The extra function means that defining the copyright text in a variable as well as the COPYRIGHT means you can store the copyright statement at OBJECT level and

Read More

Control Language (CL or CLP) has a neat and little used header specification command called ‘COPYRIGHT’ Just like the RPG header level COPYRIGHT parameter we can also do the same thing in CL programs. By using the COPYRIGHT command in CL we can embed our companies copyright statement into the code for the program. What

Read More

I have a NUMERIC in an RPG program that I want to move RIGHT into an Alpha field. In the old days of RPG3 I would use MOVE but in the new days of RPG4 I have a couple of more flexible solutions. So, lets say we have a numeric field containing the number 1234,

Read More

Write Clean RPG Code This morning I was revisiting a program that I wrote last year and looking at my code thinking “Why the hell did I write it like that? #Ugly”. RPG code evolves and lots of code evolution starts in one direction and then branches off, drunkenly in another direction. This means that

Read More

RPG CODE EXAMPLE – “Write to joblog” in Free Format RPGLE Write to the IBM i joblog is a neat way of recording details of any running jobs information. This example lets us send messages from inside a running RPG program. It’s simple using one of IBM’s API’s – QMHSNDPM – and this source code

Read More

RPG CODE EXAMPLE – “Write to joblog” in RPG with Qp0zLprintf Write to joblog lets us send messages from inside a running RPG program. It’s simple using one of IBM’s API’s – Qp0zLprintf Qp0zLprintf() — Print Formatted Job Log DataThe Qp0zLprintf () function prints user data specified by format-string as an information message type to the

Read More

AKA – Why does this compile fail using SQLRPGLE and QUALIFIED data structures? Sometimes I find a problem and scratch my head and just cannot figure it out. I swear a lot. Then I discover the solution by climbing out of my little box, turning my head at a funny angle, squinting and thinking a

Read More

A simple RPG ILE Trigger Program This morning, an old programming chum of mine was chatting to me about writing a program, that would be called every time anything was updated in a given file (table) on the system. This action is very simple in the IBM-i world, using a technique called FILE TRIGGERS. What

Read More