|
|||||||
|
|
![]() |
|
|
|
|
||
|
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. --Ted Question: 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? Answer: 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. Question: 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? Answer: You can use hex literals in your SQL commands. Here are two examples. insert into qtemp/xyz values(x'c1c2') Or update qtemp/xyz set fld = x'D1D2' Question: 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? Answer: 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. Question: Why doesn't my RPG program stop when I set on the LR indicator? Answer: 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. Question: 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? Answer: 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. Question: Can I debug a System/36 program, step by step, with the full-screen debugger? Can I set breakpoints? Can I set conditional breakpoints? Answer: Yes. Yes. Yes. Follow these steps.
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. --Ted
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |