Newsletters Subscriptions Media Kit About Us Contact Search Home

OS/400 Edition
Volume 3, Number 48 -- July 25, 2003

Odds and Ends

Ladies and Gentlemen:

It's time once again for "Odds and Ends," the show that attempts to provide something for everybody! Today Midrange Guru features some basic questions that readers have asked over the past few months.



I have a physical file with a date field. How do I put the current date into the date field when writing a record from an RPG program?


Here are two ways.

For the first method, define a date variable in the RPG program for the current date in the definition specs. Initialize it to *SYS or *JOB. INZ(*SYS) refers to the date of the system clock. INZ(*JOB) refers to the date when the job was started. I use *JOB unless I have a reason to use *SYS. Copy this field to the date field in the database.

D CurrentDate     s               d   inz(*job)

C                   eval      mydate = CurrentDate
C                   write     rec

The second method works for any language, but only if the date field does not allow the null value. Create a logical file in which the date field is not included. When you add a record to the file, the system will place the current date in the date field.


Is it possible to assign or alter the value of a character field (column) of a file (table) using SQL UPDATE by specifying all or some of the new value in hexadecimal format?


You can use hex literals in your SQL commands. Here are two examples.

insert into qtemp/xyz values(x'c1c2')


update qtemp/xyz set fld = x'D1D2'


I have found a problem with the QTEMP library. I have a program that creates a work file in library QTEMP. If the program is run in batch, the system deletes the file before the program runs again. But if I run the program interactively, the file remains in existence. What's the deal?


Every job has its own QTEMP library. When you submit the program to run in batch mode, the batch job has its own QTEMP, which is created when the job begins and is destroyed when the job ends. When you submit the program to batch a second time, the system creates a QTEMP library for that job, so there is no way the second job can see the objects in the first job's QTEMP.

But when you run twice in the same interactive job, you are using the same QTEMP library both times. For that reason, the work file already exists when the program begins running the second time.


Why doesn't my RPG program stop when I set on the LR indicator?


Setting on the LR indicator doesn't stop the program. There is a point in the RPG cycle where the program tests the LR indicator to see whether it is on. If the LR indicator is on, the program shuts down.

If you want the program to end immediately, place a RETURN op code after the one that sets on LR.


We recently installed V5R2, and I am trying to use free-format RPG. I wish to copy a six-digit numeric variable to the first six positions of a 15-byte character variable. In traditional, fixed-format RPG, I would use a MOVEL operation.

C                     MOVEL      NUMVAR      CHARVAR

However, MOVEL is not supported in free-format RPG. How do I accomplish this?


There is no direct way in free-format RPG. You can use a data structure and overlay the first six positions of the character variable with a six-digit zoned decimal variable. You can use the X edit code to convert the numeric value to character, like this:

       %subst(CHARVAR:1:6) = %editc(NUMVAR:'X');

I hope IBM will come up with something better in a future release. I face the same sorts of problems at my day job.


Can I debug a System/36 program, step by step, with the full-screen debugger? Can I set breakpoints? Can I set conditional breakpoints?


Yes. Yes. Yes. Follow these steps.

  1. If you are not already in the S/36 environment, use the STRS36 command to get there.
  2. Issue the STRISDB command, telling it not to invoke the program.
  3. When the command entry screen comes up, type the name of the OCL procedure that runs the program. ISDB starts, displaying the program source on the screen.

You can set a breakpoint by placing the cursor on a line and pressing F6 or by using the break command with the sequence number on the left side of the display.

break 800

To set a conditional breakpoint, add a "when" clause.

break 800 when count = 2

Bug-Free Code

The following section of code comes from a program I worked on recently.

C           RECTYP    CABEQ'1'       CONT
C           RECTYP    CABEQ'3'       CONT
C           CONT      TAG

For those who do not know RPG, or are not familiar with the CAB opcode, this is a form of GOTO. The first line means "if RECTYP = 1, goto CONT."

I feel very certain that this section of code is bug-free.

Have a wonderful day.


Sponsored By

600 Billion

That's how much a recent independent study estimated U.S. businesses spend on dirty data. How much of that 600 billion is spent by your company? Cleanse your dirty ZIP Codes and mailing addresses with our software and save big bucks.

WorksRight Software, Inc.
Phone: 601-856-8337
Web site:


Damon Technologies
WorksRight Software



Printing to Specialized Printers on the iSeries

Odds and Ends

Reader Feedback and Insights: COBOL API Resources

Howard Arner
Joe Hertvik
Ted Holt
David Morris

Managing Editor
Shannon Pastore

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.