MS Word Does OV/400
Did you know that Microsoft Word can read OfficeVision/400 documents directly? Just open Word and click on File/Open. If you have QDLS mapped to a drive letter, select that drive. Otherwise, look for your computer name by using the Windows Find command, which is available on the Windows Start menu. Note: You’ll need to search for Computer, not Files or Folders, on the Find command. Once you’ve located the QDLS folder, click on it to open it. Drill down until you find the document you wish to use in Word, and open it. You may get a screen asking whether you want to translate. If you do, select Rich Text Format (RTF) as the document type to convert from. That’s all there is to it! One other thing to keep in mind is that most word processors will be able to translate these documents, too. For example, Corel WordPerfect also has a translator to convert your OV/400 documents.
— David Abramowitz
Editor’s Note: If you are unable to translate the document, you may need to install the Word text converter for RTF. You can find this converter on the Microsoft Web site at officeupdate.microsoft.com/downloaddetails/wdsupcnv.htm. It is not available on the Office Suite CD.
Professional Format
A problem with using numbers in messages in CL is that, when you convert them to text for displaying in the message description, you’re stuck with leading zeros. This looks pretty amateurish, but there is a better way that will give your messages a “professional” look. What you need to do is edit the numbers in the CL program before you convert them to text. Here’s how.
Define a message in a message file by using the Add Message Description (ADDMSGD) command, and specify a message variable with a type of binary and a length of 2 or 4 bytes.
In your CL program, define a 2- or 4-byte character value to contain the binary numeric value. Convert your decimal value to binary by using the %bin function, then use
the converted variable in the Send Program Message (SNDPGMMSG) command. The program in Figure 1 shows an example of how to do this.
— David Morris
/**************************************************************************/
/* To Create: */
/* CRTCLPGM PGM(XXXLIB/DM0001C) SRCFIL(XXXLIB/QCLSRC) */
/**************************************************************************/
PGM
DCL VAR(&BIN) TYPE(*CHAR) LEN(4)
DCL VAR(&DEC) TYPE(*DEC) LEN(9 0)
/* Create a temporary message file */
CRTMSGF MSGF(QTEMP/TESTMSGF)
/* Add a message to the message file */
ADDMSGD MSGID(TST0000) MSGF(QTEMP/TESTMSGF) +
MSG('Number is &1') FMT((*BIN 4))
/* Set the variable to a number */
CHGVAR VAR(&DEC) VALUE(100)
/* Change the variable to a binary value using %BIN */
CHGVAR VAR(%BIN(&BIN)) VALUE(&DEC)
/* Send the message using the SNDPGMMSG command */
SNDPGMMSG MSGID(TST0000) MSGF(QTEMP/TESTMSGF) +
MSGDTA(&BIN)
ENDPGM
Figure 1: Here’s a way to add edited numbers to messages in CL.
Time for a Change
Q: I’m having a problem with something that should be simple but has me baffled. I’m hoping you can help. I would like my RPG IV interactive program to timeout if there’s no response from the workstation after x number of seconds. I have several CL programs that do this very thing. I’ve even done it in RPG III on the System/38, but for the life of me, I can’t seem to get it to work in my RPG IV program.
— John De Young
Compulit, Inc.
A: To make a display file time out after a given number of seconds, you need to do a couple of things. I’ve included a working example to demonstrate how this works.
The display file shown in Figure 2 is pretty generic except for the use of the INVITE keyword. Use this keyword in your display file so you can read from the display device. When you compile display file DSP00D1, place a value on the Wait record (WAITRCD) parameter of the Create Display File (CRTDSPF) command. The value you put here is the number of seconds the program will wait for input from the user before it times out. When I created the file, I put a value of 10 seconds in this parameter so I could very quickly make sure this technique worked. When you use this technique in the real world, you should make this value high enough that the user has at least a fighting chance to get to the keyboard before the program times out.
As shown in Figure 3, the RPG IV program DSP00R1 has a couple of lines that you need to add to your program to make this all work. To get the program to timeout, you need to code an Infds keyword on the F-spec as well as code the Maxdev keyword with a value of 1. This tells the program that there is only one device to read from. On the D-spec,
Infds should be coded to use the *Status keyword. The program will read the values placed in *Status by the display file and perform some appropriate action based on their content.
When you read the display file (with INVITE active), make sure that you WRITE to the record format but READ from the file name itself. This is different from the normal EXFMT op code you’d normally use when working with display files. After the READ, check to see that the STATUS field contains a value of 1331; this status code indicates that the display file has timed out. If it does, you can either end the program or perform some other logic.
— Shannon O’Donnell Senior Technical Editor
Midrange Computing
A**************************************************************
A*
A* CRTDSPF FILE(XXX/DSP00D1) SRCFILE(XXX/QDDSSRC) +
A* MBR(DSP00D1) WAITRCD(10)
A*
A**************************************************************
A DSPSIZ(24 80 *DS3)
A CA03(03 'EXIT')
A INVITE
A R SCREEN1
A 1 19'Test Waitrcd Paramter To Timeout DA isplay'
A DSPATR(HI)
A DSPATR(UL)
A 9 28'Input:'
A INPUT 1A B 9 35
A 22 7'F3=Exit'
A COLOR(BLU)
**********************************************************************
*
* CRTBNDRPG PGM(xxx/Dsp00r1) SRCFILE(xxx/QRPGLESRC) +
* MBR(Dsp00r1)
*
*
**********************************************************************
FDsp00d1 CF E Workstn Infds(Infds)
F Maxdev(1)
D Infds DS
D Status *Status
C Dow *IN03 = *OFf
C Write Screen1
C Read Dsp00d1 99LR
C If *In99 = *On And Status = 1331
C Eval *IN03 = *On
C Endif
C Enddo
C Eval *Inlr = *On
Figure 2: Display file DSP00D1 demonstrates use of the INVITE keyword.
Figure 3: Make sure you use the Maxdev keyword in your RPG IV program to cause it to timeout.
Anarchy in the U.K.?
Q: We have Y2K software to be distributed on an AS/400 in the United Kingdom. When distributing files created on our U.S. machine, such as physical files and logical files, the coded character set ID (CCSID) and language ID (LANGID) parameters are 37 and ENU, respectively. However, they’re 285 and ENG on the U.K. machine. What are the implications or problems, if any, that we risk running into if the files were distributed with
U.S. defaults for CCSID and LANGID parameters?
— Mukesh Shah
A: It is impossible to predict what may happen in a mixed CCSID environment such as you describe without in-depth knowledge of the application you are porting. That is why it is critical that the developers of the application have access to and understanding of the AS/400 National Language Support V4R2 (SC41-5101-01, CD-ROM QB3AWC01) and AS/400 International Application Development V4R2 (SC41-5603-01, CD-ROM QB3AQ501) manuals for the AS/400.
Having said that, I will go through one scenario that may or may not be relevant to your application. Assume that you have a control file for field names and that this file is CCSID tagged with 37. Also assume that one of the valid characters used in field names is the dollar ($) sign (or x‘5B’ in CCSID 37) and that you have a field called $Y2KA, which you generate into target RPG application source. Now assume that your application program runs on the customer systems under job CCSID 285 and modifies RPG source in customer CCSID 285 tagged files. Data management causes your control file dollar sign
(x‘5B’) to become a 285 dollar sign (x‘4A’) when read into the application. If your application then outputs the dollar sign to the customer file, the dollar sign is written as
x‘4A’. If the Original Program Model (OPM) compiler attempts to compile the RPG source containing a field name, the compile fails. The key to making this type of scenario work, then, is proper planning and a good understanding of National Language Support.
— Bruce Vining
IBM Rochester
When the Answer Varies
One of IBM’s V4R2 enhancements to RPG was support for varying-length fields, which you can use as return values in procedures. When the fields are used in this way, you can create procedures that work a lot like RPG IV built-in functions such as %EDITC and %TRIM. Before varying-length character fields were supported, it was necessary to wrap procedures that returned a variable-length value in the %TRIM built-in function. This was cumbersome and, because %TRIM required the returned value to be scanned for the first nonblank value, could add a significant amount of processing time.
The declared length of a varying-length character field is the maximum length for a varying-length field. To determine or set the length of data contained in the varying-length field, use the %LEN built-in function. Setting the length of varying-length fields is seldom necessary when using newer free-format op codes such as EVAL. With older fixed-format op codes, it’s necessary to set the length of a varying-length field prior to using it as a result field.
To demonstrate some of the advantages of varying-length fields, I have included some sample procedures that use varying-length fields to return a translated character field. (Download them atwww.midrangecomputing. com/mc). These procedures allow you to use the XLATE op code as a built-in function in expressions. Procedure XLT receives a character string in the first parameter and converts the characters of the string from values specified in the second parameter to values specified in the third parameter.
The converted string is then returned from the XLT procedure. Because parameters passed to XLT are constants, they can be literals or fixed-length character fields.
Procedure DM001R demonstrates how to use this procedure to convert an input string to uppercase.
Rather than wait for IBM to provide built-in functions for op codes such as XLATE, create them yourself. Not only is this easier to do with varying-length fields, but procedures that use varying-length procedures also run faster than those that use %TRIM to remove blanks from char-acter fields.
— David Morris
Don’t Be DUPed
Q: We have recently restricted all production data on our AS/400. Because the IS staff has only use rights to production data, they cannot use the Create Duplicate Object (CRTDUPOBJ) command. When this command is used, the system returns a “not authorized” error. I know that other shops have their production data secured from the IS staff. How did you deal with this command? CRTDUPOBJ is used primarily to build work files in QTEMP.
— Darlene Kelley
A: I created my own CRTDUPOBJ command and compiled the CL command processing program (CPP) to adopt the authority of the program owner (which is QSECOFR). This allows anyone to use the command with the authority of the security officer. I also added code to allow only the duplicate to be created in a test library.
— Mark McCall
A: At a previous employer, we created a CRTDUPOBJ work-alike called Duplicate Production Object (DUPPRDOBJ) with the same keywords and everything. It adopted sufficient authority to perform CRTDUPOBJ, then granted the object’s creator (the person who ran the command) sufficient authority to the new object.
— Michael Polutta
LATEST COMMENTS
MC Press Online