Odds and Ends
November 8, 2002 Timothy Prickett Morgan
Dear Readers:
Here, by popular demand, are more “Odds and Ends.” I hope you find something here you like.
|
— Ted
Question:
I’m trying to read a table by key in a CL program, and I am having trouble. I know there has to be a way to do this, but I keep getting either the first record in the table or an error message that states ‘key not found.’ Can you provide an example of a CL program that reads a file randomly by key?
Answer:
It sounds as if the Receive File (RCVF) command didn’t find a matching key. I suggest you use *KEYAE instead of *KEY on the Override with Database (OVRDBF) command. Then after you RCVF, use an IF to make sure you got the record you wanted. I have seen some weird stuff happen when using *KEY:
In the following example, the program attempts to read a record whose key value matches the value in &PCAT. When a record is read, its key field, &CATEG, is compared to &PCAT to see if the proper record was found.
PGM PARM(&PCAT) DCL VAR(&PCAT) TYPE(*CHAR) LEN(2) DCLF FILE(CATEGORIES) OVRDBF FILE(CATEGORIES) POSITION(*KEYAE 1 *N &PCAT) RCVF MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF)) IF COND(&CATCODE *EQ &PCAT) THEN(DO) /* a matching key was found -- do whatever */ ENDDO
Question:
Work with User Profiles (WRKUSRPRF) command will not load a list of user profile names into a database file. Is there some other way to do this?
Answer:
Use the Display Object Description (DSPOBJD) command. I think a lot of us forget this command exists, since so many object-specific commands have *OUTFILE capabilities:
DSPOBJD OBJ(*ALL) + OBJTYPE(*USRPRF) + OUTPUT(*OUTFILE) + OUTFILE(QTEMP/X)
Question:
I am entering two 130-byte note fields on a screen and then using them as parameters on a Submit Job (SBMJOB) command. The system throws away the trailing blanks and appends the following fields to them. Do you know why this happens and how to fix this problem?
Answer:
The problem is that you are using a variable that is longer than 32 bytes as a parameter to a CALL command in the CMD parameter of the SBMJOB command. The system discards the trailing blanks. There are several ways to solve this problem, but the easiest one is to pass one extra non-blank byte. In your case, pass two 131-byte values and make sure the last byte of each one in not blank. Here’s an example:
dcl &msg *char 130 dcl &msgparm *char 131 chgvar &msgparm (&msg *cat 'X') sbmjob cmd(call somepgm (&msgparm))
The called program will define the parameters as 130 bytes, as always, not 131 bytes.
Question:
I am trying to get this API to work, and I can’t get the receiver variable to work correctly. I know there is a trick to using API’s, but can’t remember it.
d InputData ds d BytesRet 4b 0 d BytesAvail 4b 0 d Outque 10 * .... some source code omitted c call 'QSPROUTQ' c parm InputData c parm RecieverLength c parm FormatName c parm OutQueueName c parm ErrorCode
Answer:
This is a common mistake with APIs. The BytesRet, BytesAvail, and other binary variables are supposed to be four-byte integers. You have coded them as four-digit integers, which is not the same. This will solve your problem:
d BytesRet 4i 0 d BytesAvail 4i 0
Question:
We have a junior programmer who messed up an RPG Source member without using our change management system. He then tried to correct his own mistake and only proceeded to make things worse.
My question is, can I restore a specified member from tape from the QRPGSRC file? I know how to restore the whole library, but I really only need one member from the QRPGSRC File.
Answer:
Restore Object (RSTOBJ) command allows you to restore individual file members. You’ll need to use the FILEMBR parameter.
RSTOBJ OBJ(QRPGSRC) + SAVLIB(saved-lib) + DEV(TAP01) + OBJTYPE(*FILE) + FILEMBR((QRPGSRC (member-name))) + RSTLIB(another-lib)
I recommend you restore to another library, and then copy the restored member to the production library.
— Ted
Sponsored By ADVANCED SYSTEMS CONCEPTS |
Business Analytics SEQUEL FYI
User Quote: SEQUEL FYI offers outstanding OLAP business intelligence functionality for a fraction of the cost of comparable solutions. |