13
Fri, Dec
4 New Articles

TechTalk May 1998

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 can’t 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 can’t 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 couldn’t 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 you’ve 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. This email address is being protected from spambots. You need JavaScript enabled to view it.

— 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
This email address is being protected from spambots. You need JavaScript enabled to view it.

What’s 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.

Java’s 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 Sun’s JAVAP utility. This utility lists the public functions of a class. I don’t need the verbose comments—if 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 I’ve 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 (Editor’s 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 program’s response.

— Kim Williams Weir’s Furniture This email address is being protected from spambots. You need JavaScript enabled to view it.

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 formats—YYMMDD (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 I’ve 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 This email address is being protected from spambots. You need JavaScript enabled to view it.

— 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? Here’s 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.

You’ll have to change programs that depend on all four digits of a year, such as those that sort by date, but you won’t 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 This email address is being protected from spambots. You need JavaScript enabled to view it. http://prairie.lakes.com/~bvstone/

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, it’s 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? Don’t 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. It’s just a matter of running SETATNPGM.

— Tim Johnston Hapco This email address is being protected from spambots. You need JavaScript enabled to view it.

Editor’s 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. You’ll find these and many other articles on MC’s 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 This email address is being protected from spambots. You need JavaScript enabled to view it.

A: I’ve done this before. I saved the records to a temporary keyed database file and read them back in keyed order.

— Mario Martinez This email address is being protected from spambots. You need JavaScript enabled to view it. A: Here are two alternatives:
(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 you’re 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 Atlas—The Software Co., Inc.
This email address is being protected from spambots. You need JavaScript enabled to view it.

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 MOVEL’19’ D3YYYY

C ELSE

C MOVEL’20’ 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 2’ATN007’
A COLOR(BLU)
A 1 33’ATN007 Menu’
A DSPATR(HI)
A 3 2’Select one of the following:’
A COLOR(BLU)
A 5 7’1. Work with my spooled output’
A 6 7’2. Work with output queue PRT01’
A 7 7’3. Start printer PRT01’
A 8 7’4. Display messages’

A* CMDPROMPT Do not delete this DDS spec.
A 019 2’Selection 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 user’s Attn key program

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: