Service Program Catch-22
We have a number of service programs that correspond to business classes. They have names like CUSTOMER, PART, and ORDER. If you wanted a procedure that returned a fully formatted customer name, with title, initials, and full name, you would expect to find it in service program CUSTOMER.
We are constantly adding new procedures to these service programs. Over time, many of these service programs have come to reference each other. Two examples of this might be one procedure named RtvPartName that resides in PART and is called by service program ORDER and another procedure in ORDER named IsPartOrdered that is called by PART.
An outcome of this is that re-creating these service programs from source (i.e., no existing service program objects exist) is not as straightforward as you would think. You can create the modules without any difficulty, but as soon as you try to create service program ORDER, it will fail because it needs PART. Likewise, PART cant be created because it needs ORDER. What do you do?
The solution lies in the OPTION(*UNRSLVREF) parameter in the Create Service Program (CRTSRVPGM) command. If you specify it, the service program will be created even if procedures and field names that are imported from other service programs cant be located. In my example, ORDER could be created without the need for PART. The procedure RtvPartName would be an unresolved reference as far as ORDER is concerned, but the ORDER service program object would be created nonetheless.
Of course, ORDER couldnt be expected to work at runtime if any attempt to call RtvPartName was made. However, you can create PART in the normal way since ORDER now exists. And once youve done that, you can return to ORDER and re-create it without the OPTION(*UNRSLVREF) parameter.
If you want to create an entire ILE environment from source, first create all service programs with the OPTION(*UNRSLVREF) parameter, and then re-create them again without it.
John V. Thompson Honda New Zealand
john v.
Derek Butland
Print Labels with Query
Q: Once upon a time, many OS versions ago, I wrote a query that produced labels. I tried to do this again last week, but the spacing would not stay constant. Can someone help me out?
Jeff Importico
A: Query/400 will produce mailing labels. Take the following into account for designing the query.
Choose Select and sequence fields. Order the selected fields in ascending order based on where they should appear on the form in a left-to-right, from-the-top-down fashion.
Select Specify report column formatting. Set all column headings to *NONE. (The value *NONE must be in all caps.) Adjust column spacing to move a field within a line or to force it to the next line.
Choose Select output type and output form. Set line wrapping to Y and choose a wrap length based on the width of your form. Press Enter.
Set the Form size to the length and width of your form. Specify start and end lines such that the end line minus the start line, plus one, is equal to the number of lines required to produce one page of output. Specify that you do not want to print the query definition. Press Enter twice more.
On the following screens, specify that you do not want to print a cover page, standard page headings, specified page headings, or specified page footers.
Also, make sure that your job is not producing print text (PRTTXT). Chuck Pence
Whats in a Java Class?
To be a power Java programmer, you need to become familiar with the wide variety of classes delivered with standard Java. Not only that, but you also need to be able to quickly pick up and understand a variety of third-party classes.
Javas standard documentation facility, JAVADOC, helps, but I find the HTML help files too wordy and difficult to follow. What I use to quickly understand a class is Suns JAVAP utility. This utility lists the public functions of a class. I dont need the verbose commentsif the function name and its parameters do not define the use of the function, then the class itself is not well-designed.
The following use of JAVAP lists the public API of the Integer class. Note that you must fully qualify the package of the class.
javap.exe java.lang.Integer
The result of executing this instruction is shown in Figure 1. I find this concise listing is all I need to understand a class and its public API.
Don Denoncourt Senior technical editor Midrange Computing
Trigger Tips Learned the Hard Way
Here are a few points Ive learned about triggers in my experience.
1. Never reference the before portion of the trigger buffer on an insert. You may get a data decimal error.
2. Never reference the after portion of the trigger buffer on a delete. You may get a data decimal error.
3. You cannot recompile a trigger program while the file to which the trigger program is attached is open. Even though the compilation listing will show no errors, the program will refuse to compile (Editors note: This could be caused by declaring the file in the trigger program and not setting on the LR indicator. The other issue, not mentioned here, is that all the jobs that have fired the trigger hold a lock on the trigger program. You need to end all those jobs to get a clean recompilation.)
4. Always test your trigger program. Insert a record, delete it, and check the trigger programs response.
Kim Williams Weirs Furniture
Another Handy Date Conversion Routine
My Y2K problems are minimal because my dates are within a 30-year window. The only dates I converted to eight digits were those used as keys. I added the following to my programs to convert dates to YYMMDD and YYYYMMDD formats on the fly.
My convert date (CVTDAT) routine converts a six-digit date in MMDDYY format (I call it the D1 format) to two other formatsYYMMDD (D2) and YYYYMMDD (D3).
The code I include in my programs is shown in Figure 2. Converting a MMDDYY date is a simple matter of moving the date into D1DATE, executing subroutine CVTDAT, and moving D3DATE into an eight-digit or eight-byte field.
I convert D2 dates to D1 format before running the conversion. Figure 3 shows how I would compare the YYMMDD field STOPND to the current date.
If you store dates in your files as eight digits but want to present them as MMDDYY for your users, do as Ive illustrated in Figure 4.
Tim Phinney M G Maher
Dealing with Record Locks in COBOL
Q: I need help understanding the finer points of record locking management in COBOL on the AS/400. If I read a record from a file opened in I/O mode, does OS/400 lock this record for me? How do I read a record without locking it? Can COBOL programs determine which job has a record locked?
Chris Ringer
A: In COBOL, as in RPG, reading a record from a database file opened as I/O places a lock on the record. Check the file status code to see if the record is locked. Locked records are indicated by status code 9D.
The READ statement accepts a WITH NO LOCK clause that does for COBOL what (N) does for RPG IV. For example, consider this:
READ customer-master-file
WITH NO LOCK
INVALID KEY
SET customer-not-found TO TRUE
NOT INVALID KEY
SET customer-found TO TRUE
PERFORM get-customer-info
END-READ.
This READ statement reads the customer master file randomly by key without locking the record being read. If the read is successful, it performs paragraph GET- CUSTOMER-INFO.
Figure 5 illustrates one method of determining who has tied up the record. When the READ returns a status code of 9D, the program calls a CL program (see Figure 6) to retrieve the message containing information about the lock. You can use similar logic for duplicate key problems and referential integrity violations.
For more about dealing with record locks, see Who Locked the Record? in TechTalk, MC, March 1998.
Tom Conover
Mario Martinez
Ernie Malaga Senior technical editor Midrange Computing
Ted Holt Senior technical editor Midrange Computing
Y2K Temporary Fix
Is Y2K sneaking up on you? Are you having trouble finding time to update all those files and applications? Do you still have six-digit dates in your database? Heres a tip to get you through Y2K with little work until you find the time to make the big change.
For each six-digit date field in a file, add a two-digit field to store the first two digits of the year (i.e., 19 or 20). Add a trigger to the file for INSERT and UPDATE operations. Make this trigger check the six-digit date fields and fill in the new fields with the correct century values.
Youll have to change programs that depend on all four digits of a year, such as those that sort by date, but you wont have to change programs that update or write to the file. And the initial load after adding the field to the database is a simple two-line program that READs and then UPDATEs each record in the file.
This is only a temporary fix, but it will help you get through the crunch time and will also be a quick introduction to the power of trigger programs.
Bradley V. Stone
Debugging an ILE Module in Statement View
Q: How can I add a breakpoint when debugging an ILE program compiled with DBGVIEW(*STMT)?
A: On the Display Module Source (DSPMODSRC) command line, enter BREAK PROCNAME/STMT. For the main procedure, PROCNAME is the same as the name of the module; otherwise, its the name of the subprocedure. STMT is the number on the left side of the compiler listing. If you specify OPTION(*STMTNUM) in the control specification, STMT is also the SEU sequence number.
Barbara Morris IBM Toronto Lab RPG Compiler Development
More Ways to Use the Attn Key
Need a program quick? Dont want to go through a menu and option scheme? Do you say, I call this program 50 times a day. I wish there were an easier and quicker way!? Do I have a technique for you!
The ATNPGM parameter of the CRTUSR-PRF and CHGUSRPRF commands, and the Set Attention Program (SETATNPGM) command, provide ways for a user to call a program by pressing the Attn key. I like to make the Attn key give me a command line in a pop-up window, so I included the following command in the initial program (INLPGM) assigned to my user profile:
SETATNPGM PGM(QSYS/QCMD)
QCMD is a good attention key program for system administrators, but not for end users. Instead, I recommend that users call a menu that holds some common options for them. Figures 7 and 8 show the source members for menu ATN007, created with SDA. Figure 9 has the source of a small CL program to display the menu.
Run the following command for any user who should see this menu when he presses the Attn key.
CHGUSRPRF USRPRF(XXX) +
ATNPGM PGM(XXX/ATN007CL)
You can specify any program on your system to be an Attn key handling program, and different users can benefit from different Attn key handling programs. In fact, a user can have different Attn key handling programs in different sessions. Its just a matter of running SETATNPGM.
Tim Johnston Hapco
Editors note: For more ideas on effectively using the Attn key, see A Flexible Attn Key Handler, MC, August 1997; The Attention Program Utility, MC, October 1996; User-defined Pop-up Menus, MC, November 1995; and Getting Started with Group Jobs, MC, October 1995. Youll find these and many other articles on MCs ResourceCD/400.
Sorting Tables in COBOL
Q: I have a table in COBOL that has 100 occurrences in it. I would like a way to order these occurrence based on the values of the elements in the table. Can anyone help me?
Bob Karutis
A: Ive done this before. I saved the records to a temporary keyed database file and read them back in keyed order.
Mario Martinez
(1) Use a bubble sort. It is one of the easiest sort algorithms to understand and is practically as efficient as other sort algorithms if youre sorting a small set of data. An added advantage of the bubble sort is that the only additional storage required is equal in length to one element of the set and is used for the swapping operation.
(2) If you want to get real adventurous, check out the new sorting APIs, QLGSORT and QLGSRTIO.
Tom Conover
A: Pass the table to an RPG program. After entry, the RPG program will have just two lines of executable calculations: a SORTA table name and a RETURN. When your COBOL program gets the table back, all the entries should be sorted.
David Abramowitz AtlasThe Software Co., Inc.
A: I had to do this once. I wrote my table entries to a user index. Check the API reference for creating, filling, and retrieving user indexes.
Martin Neugebauer
A: The COBOL sort is very efficient on the AS/400, so the SORT verb should do a good job. In the input procedure, RELEASE the table elements into the sort file. In the output procedure, RETURN the sort file records into the table.
Ted Holt Senior technical editor Midrange Computing
Compiled from Integer.java
public final synchronized class java.lang.Integer extends java.lang.Number
/* ACC_SUPER bit set */
{
public static final int MIN_VALUE;
public static final int MAX_VALUE;
public static final java.lang.Class TYPE;
public static java.lang.String toString(int, int);
public static java.lang.String toHexString( int);
public static java.lang.String toOctalString(int);
public static java.lang.String toBinaryString(int);
public static java.lang.String toString(int);
public static int parseInt( java.lang.String, int);
public static int parseInt( java.lang.String);
public static java.lang.Integer valueOf(java.lang.String, int);
public static java.lang.Integer valueOf(java.lang.String);
public java.lang.Integer( int);
public java.lang.Integer( java.lang.String);
public byte byteValue();
public short shortValue();
public int intValue();
public long longValue();
public float floatValue();
public double doubleValue();
public java.lang.String toString();
public int hashCode();
public boolean equals(java.lang.Object);
public static java.lang.Integer getInteger( java.lang.String);
public static java.lang.Integer getInteger( java.lang.String, int);
public static java.lang.Integer getInteger(java.lang.String,
java.lang.Integer);
public static java.lang.Integer decode(java.lang.String);
static static {};
}
Figure 1: JAVAP reveals the public contents of the Integer class
* Date conversion routine.
* Date formats: D1=MMDDYY, D2=YYMMDD, D3=YYYYMMDD.
*
ID1DATE DS
I 1 4 D1MMDD
I 5 6 D1YY
I 1 2 D1MM
I 3 4 D1DD
ID2DATE DS
I 1 2 D2YY
I 3 6 D2MMDD
ID3DATE DS
I 1 4 D3YYYY
I 5 8 D3MMDD
I 3 4 D3YY
I 5 6 D3MM
I 7 8 D3DD
C* include the following in *INZSR or some other place
C* where it will be executed at program startup
C*
C MOVE UDATE D1DATE
C EXSR CVTDAT
C MOVE D3DATE D3TODA 8
C************************************************************
C CVTDAT BEGSR
C*
C* set first 2 digits of year according to a 50-year window
C MOVE D1YY WINYY 20
C ADD 50 WINYY
C*
C D1YY IFGT WINYY
C MOVEL19 D3YYYY
C ELSE
C MOVEL20 D3YYYY
C ENDIF
C MOVE D1YY D3YYYY
C MOVE D1MMDD D3MMDD
C*
C MOVE D1YY D2YY
C MOVE D1MMDD D2MMDD
C*
C ENDSR
Figure 2: You can add this code to any program that needs to convert six-digit dates
C MOVE STOPND D2DATE
C MOVE D2MMDD D1MMDD
C MOVE D2YY D1YY
C EXSR CVTDAT
C MOVE D3DATE D3OPND 8
C D3OPND IFLT D3TODA
C* ...do something
C ENDIF
Figure 3: Comparing a YYMMDD field to the current date
C* Convert YYYYMMDD to MMDDYY before displaying date for user
C MOVE HIOPND D3DATE FILE FIELD
C MOVE D3MMDD D1MMDD
C MOVE D3YY D1YY
C MOVE D1DATE X1OPND SCREEN FIELD
C* Convert MMDDYY to YYYYMMDD before updating the database
C MOVE X1OPND D1DATE SCREEN FIELD
C EXSR CVTDAT
C MOVE D3DATE HIOPND FILE FIELD
C* Convert YYYYMMDD to MMDDYY before displaying date for user
C MOVE HIOPND D3DATE FILE FIELD
C MOVE D3MMDD D1MMDD
C MOVE D3YY D1YY
C MOVE D1DATE X1OPND SCREEN FIELD
C* Convert MMDDYY to YYYYMMDD before updating the database
C MOVE X1OPND D1DATE SCREEN FIELD
C EXSR CVTDAT
C MOVE D3DATE HIOPND FILE FIELD
Figure 4: Converting between display and database formats
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
file-control.
SELECT customer-master
ASSIGN TO DATABASE- custmas
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EXTERNALLY-DESCRIBED-KEY
FILE STATUS IS custmas-file-status.
DATA DIVISION.
FILE SECTION.
FD customer-master
... etc.
WORKING-STORAGE SECTION.
01 custmas-file-status PIC X(2).
88 record-is-locked VALUE 9D.
01 msg-txt PIC X(80).
PROCEDURE DIVISION.
main-logic.
OPEN I-O customer-master.
... set key value here
READ customer-master
END-READ.
IF record-is-locked
CALL GETPGMMSG USING msg-txt
END-IF.
Figure 5: Sample COBOL code for determining who has locked a record
GETPGMMSG: PGM PARM(&MSGTXT)
DCL VAR(&MSGTXT) TYPE(*CHAR) LEN(80)
RCVMSG PGMQ(*PRV) MSGTYPE(*LAST) RMV(*YES) +
MSG(&MSGTXT)
ENDPGM
Figure 6: COBOL programs can call this CL program to determine who locked a record
A CHGINPDFT
A INDARA
A PRINT(QSYSPRT)
*=====================================================================
A R ATN007
A LOCK
A SLNO(01)
A CLRL(*ALL)
A CF03
A HELP
A HOME
A HLPRTN
A 1 2ATN007
A COLOR(BLU)
A 1 33ATN007 Menu
A DSPATR(HI)
A 3 2Select one of the following:
A COLOR(BLU)
A 5 71. Work with my spooled output
A 6 72. Work with output queue PRT01
A 7 73. Start printer PRT01
A 8 74. Display messages
A* CMDPROMPT Do not delete this DDS spec.
A 019 2Selection or command
Figure 7: Member ATN007, the display file source for menu ATN007
ATN007QQ,1
0001 WRKSPLF
0002 WRKOUTQ OUTQ(PRT01)
0003 STRPRTWTR DEV(PRT01)
0004 DSPMSG
Figure 8: Member ATN007QQ defines the commands for menu ATN007
/*==================================================================*/
/* To compile: */
/* */
/* CRTCLPGM PGM(XXX/ATN007CL) SRCFILE(XXX/QCLSRC) */
/* */
/*==================================================================*/
PGM
GO MENU(ATN007)
ENDPGM
Figure 9: CL program ATN007CL becomes the users Attn key program
LATEST COMMENTS
MC Press Online