Wednesday, December 18, 2013

QCAPCMD another alternative to QCMDEXC

Several of you commented on Capturing QCMDEXC error codes that you preferred to use the C library function SYSTEM( ) or the API QCAPCMD.

I have to confess that I had not used the QCAPCMD API prior to writing this post. So after some playing around with it this is what I found out about using it:

Thursday, December 12, 2013

Easiest way to read all the members in a multiple member file

The idea for this post came from a discussion I saw on Facebook. Someone asked:

  1. In your RPG how can you read from a particular member of a file?
  2. By default which member is read?
  3. How can you read all the members of your PF in your RPG program?
  4. How can you find out which member is being read?

The answer for the first question is to use the EXTMBR in the File specifications. I will not go into details about this as it is covered in Useful keywords for your F-specs.

The answer for the second question is that when a program opens a file with more than one member, by default, it opens the first member, which is the oldest member as that was the one created first.

The third and fourth questions I combined into my own scenario: I want to have a program that reads all the members in a multi member file to find a particular record and identify which member this record is in.

Tuesday, December 10, 2013

SYSTEM( ) as an alternative to QCMDEXC

system qcmdexc error codes

After my post about Capturing QCMDEXC error codes Markus During sent me an alternative method to execute CL commands and retrieve any error message id that might occur.

system() is a runtime C library function that performs the same purpose as the QCMDEXC API. With system() you pass a pointer to the command string and it is executed, no need for the for the command string length.

Tuesday, December 3, 2013

Email IFS files

send ibmi as400 email sndsmtpemm

The subject matter of this post compliments the previous post Zipping files in the IFS, which describes how to copy a file to the IFS and zip it in preparation for sending it via email.

Until recently it was not possible to email a file from the IFS without using a third party tool or an API. There is the command SNDDST that I have used to send emails from an IBM i (AS400) with the contents of files or files located in the QDLS file system as attachments. But it cannot access the IFS.

A new command SNDSMTPEMM has been introduced, via PTF, to IBM i 6.1 and 7.1 that allows you to email a file from the IFS as an attachment.

Tuesday, November 26, 2013

Zipping files in the IFS

 

The original contents of this page have become obsolete, go to this page for up-to-date information.

 

Wednesday, November 20, 2013

Position record to top of subfile

position subfile sflrcdnbr

I recently received a message asking about subfiles:

I know this is a stupid question and I have done this a million times before, but I'm just blocked now and can't figure out what is wrong. My subfile is fully loaded, it is a few pages long. Enter was pressed on a second page, so I need the same page displayed when control is passed back to the subfile. For some reason it goes back to the first page.

The questioner must be asking about a "expanding" or a "load all" type of subfile, as this would not be an issue in the "page a time" subfile.

Fortunately there is a quick, and easy, solution for this problem by the addition of one line of code to the display file's source and a just two lines to the RPGLE/RPG IV's source.

Friday, November 15, 2013

TR7 available today

If like me you have been patiently waiting like a child waits for Santa Claus, today is the day Technical Refresh 7 (TR7) for IBM i 7.1 officially becomes available.

You can see what is included in this Technical Refresh in an earlier post I wrote called IBM i Technical Refresh 7.

It is available as a group PTF, MF99007, you can view the PTF Cover Letter here.

In my opinion the most anticipated part of TR7 is the changes made to RPG/free. Now the Control (H), File (F), Data Definition (D), and Procedure (P) specifications are all in free format. Input (I) and Output (O) specifications remain in fixed format.

Thursday, November 14, 2013

IBM i Virtual User Group TR7 presentation

I thoroughly enjoyed yesterday's presentation by the IBM i (AS400) Virtual User Group called Modern RPG - a look at the new and improved free form and other modernization thoughts which is available for download as a PDF here.

And tomorrow is release date for IBM i 7.1 Technical Refresh 7!

Wednesday, November 13, 2013

Generating random numbers using a C function

Having discussed in previous posts about how to generate pseudo-random numbers using the CEERAN0 API in RPG and the SQL RAND function I received an email showing me a third way to do it, using a C function.

I would like to thank Bob Schmalandt for sending me the example program upon which this post is based upon.

There are two C functions that generate a pseudo-random number, and they both work in the same way.

  • rand, is not threadsafe.
  • rand_r, is.

In my examples below I will be using rand.

Monday, November 11, 2013

A Short History of Free-Form RPG

I found an interesting post written by Hans Boldt, who was part of the team that developed RPG/free at IBM in Toronto, Canada. In it he gives us a brief glimpse into some of the decisions and processes involved in creating RPG/free.

It all started more than twenty years ago, back when RPG IV was being designed. At the time, there were two distinct schools of thought. On one side, there were people who insisted RPG should have a fully free-form syntax. On the other, were those who strongly believed that RPG should remain in its traditional fixed-form layout.

He reminds us that RPG/free is no longer new as it was released 12 years ago in V5R1, and ILE RPG/RPGLE/RPG IV 18 years ago in V3R1.

You can read it here: A Short History of Free-Form RPG

Thursday, November 7, 2013

Renaming one field in a file using EXTFLD

In September I wrote about a problem I had encountered where I had to rename one field in a file, and not rename the other fields, in Renaming one field in a file in RPG. I achieved this using RPG's Input specification, I-spec. BlueBull posted a comment on the post explaining that I could have used the EXTFLD keyword in the Data Definition specification, D-spec, to do the same.

In this post I will show how I would use the EXTFLD to rename a field, and determine if it would fit the scenario I used in my previous post.

Tuesday, November 5, 2013

Validating numbers without TESTN

I have received an email asking me the following question:

How can I validate numbers in RPGLE /free without using testn?

I have spent a considerable amount of time dealing with data from Microsoft Excel spreadsheets that has been uploaded to the IBM i (AS400). It is easy to use the TESTN operation code to test ideally formatted "00123456", but what about "123456  " or "1,234.56  "?