More About QQUPRFOPTS
I have a little more information about the QQUPRFOPTS data area, which was described in “TechTalk: Controlling Query/400 Runtime and Output Options” in the September 2000 issue of MC. The first byte of the data area controls the cursor position for the Run Query (RUNQRY) command when the output is to the screen. For instance, I have a QAQQINI file with MESSAGES_DEBUG set to ON, and the cursor is placed in the first position of line 24 when I run the following command:
RUNQRY QRY(*NONE) +
QRYFILE(anylib/anyfile) +
OUTPUT(*)
This happens because of an informational message sent. If you put an N in the first byte of QQUPRFOPTS, the cursor would be positioned in the input field at the top of the screen.
— Michael Price
Editor’s Note: The cursor-positioning behavior Michael describes occurs when you run Query under debug. For more information about QAQQINI, see “Tuning V4R4’s Query Optimizer the Easy Way” (MC, March 2000).
Using Embedded SQL
Since we recently went live with the first phase of a large project that utilizes embedded SQL exclusively for database access, I thought I’d share some of the benefits we’ve enjoyed:
• We can now change the database at a much lower “cost” in terms of affected programs. We always specify field lists in all SQL, as opposed to using an asterisk (*), so we have to touch only those programs that actually need to use the changes in a different way. For example, adding a new column to the Customer table does not, in any way, affect programs that join to it for Customer Name.
• We can now do things not possible in RPG I/O. All our “Work withs” have fully dynamic filters and sorts that let users build their own Where and Order By clauses. The list is then rebuilt using the resulting SQL statement.
• Some actions have been really simplified through the power of SQL. Aggregate functions (such as summation) and scalar functions (such as soundex) can eliminate a lot of complexity if used correctly, and the ability to write our own scalar user-defined functions allows us to hide unneeded complexity from developers.
• The elimination of F-specs means that database I/O can be completely local to a subprocedure or subroutine. This has proven useful for tasks such as checking the existence of an item in a parent table or retrieving the description of an input item.
• Because our database design uses referential integrity (RI) extensively, it contains many null-capable fields. SQL is designed to handle nulls, whereas RPG IV only “tolerates” them at best, with much additional coding required to support them fully.
SQL is becoming the de facto standard for database access. To use other tools (such as Java, Query, Visual Basic, VBA, or Crystal Reports), a working knowledge of SQL is critical. We would be doing our developers a disservice if we didn’t teach them SQL and left them trapped in an RPG-only world.
— Steve Todd
How Are My ASPs Doing?
You can use the Work with System Status (WRKSYSSTS) command to monitor the utilization of disk space. On the first panel, press F24 (More keys) and then F16 (Work with disk status). From the Work with disk status display, you can see which auxiliary storage pool (ASP) the disks are associated with by pressing F24 and then F11 (Display storage use).
— Phil Hope
Ramesys
Edit Packed Decimal Dates with Java
Q: I am using the BigDecimal data type to return an eight-digit, packed-decimal number with no decimal positions from an AS/400 RPG program to a Java program. The number is a date, and I get it in my Java program fine. However, I need to format it with slashes. For example, I need to be able to print 08302000 as 08/30/2000.
I looked in the toolbox programmer guide for a method but had no luck. I tried to cast the BigDecimal type, but that didn’t work either. How can I edit these dates?
— Tom Malin
A: An easy way to edit dates is to substring the month, day, and year portions of the string value of that big decimal and concatenate them with appropriate editing characters, as shown in Figure 1, but doing that wouldn’t drop the zeros on days and months. Another solution is to construct a Calendar object and then use java.text.DateFormat to set a date format that you like.
Your question piqued my interest, so I wrote a utility class called BigDecimalDatePrinter, which you can see in Figure 2 (page 128). The main( ) function tests the SHORT, MEDIUM, and LONG versions of 08302000. When you execute this class directly, it produces this output:
8/30/00
30-Aug-00
August 30, 2000
You can play with the date formatting to make it how you want. It gets funny with locales such as US and SIMPLIFIED_CHINESE.
If you choose to use BigDecimalDatePrinter, enter some generic utility package for your company. You can also improve the utility class by using the SimpleDateFormat class of the java.text package. SimpleDateFormat allows you to assign an edit mask to be used when formatting a date, as illustrated in Figure 3. For example, on September 9, 2000, this routine output 2000-09-09.
— Don Denoncourt Senior Technical Editor
Midrange Computing
String dateStr = zonedReturn.toString();
pw.println(dateStr.substring(0, 1) + “/” +
dateStr.substring(2, 3) + “/” +
dateStr.substring(4, 7) );
Figure 1: Concatenating substrings is the easiest way to edit a packed decimal date.
import java.text.DateFormat;
import java.math.BigDecimal;
import java.util.Calendar;
public class BigDecimalDatePrinter {
private static Calendar cal;
private DateFormat dateFormat;
public static final int SHORT = DateFormat.SHORT;
public static final int MEDIUM = DateFormat.MEDIUM;
public static final int LONG = DateFormat.LONG;
static {
cal = Calendar.getInstance();
}
public BigDecimalDatePrinter (int shortMedOrLong, BigDecimal date) {
dateFormat = DateFormat.getDateInstance(shortMedOrLong);
String dateStr = date.toString();
if (dateStr.length() == 7) {
dateStr = "0"+dateStr;
}
int year = new Integer(dateStr.substring(4,8)).intValue();
int month = new Integer(dateStr.substring(0,2)).intValue();
int day = new Integer(dateStr.substring(2,4)).intValue();
cal.clear();
cal.set(year, month-1, day);
}
public String toString() {
return dateFormat.format(cal.getTime());
}
public static void main(String[] argv) {
BigDecimalDatePrinter testIt =
new BigDecimalDatePrinter(BigDecimalDatePrinter.SHORT,
new BigDecimal("08302000"));
System.out.println(testIt);
testIt =
new BigDecimalDatePrinter(BigDecimalDatePrinter.MEDIUM,
new BigDecimal("08302000"));
System.out.println(testIt);
testIt =
new BigDecimalDatePrinter(BigDecimalDatePrinter.LONG,
new BigDecimal("08302000"));
System.out.println(testIt);
}
}
Figure 2: The BigDecimalDatePrinter class can print packed decimal dates in three formats.
import java.util.*;
import java.text.*;
class TestSimpleDateFormat {
public static void main(String[] plist) {
String dateMask = new String(“yyyy-MM-dd”);
SimpleDateFormat dateFormater = new SimpleDateFormat (dateMask);
System.out.println(dateFormater.format(new Date()));
}
}
Figure 3: SimpleDateFormat allows you to assign an edit mask to a data format.
Little C Stands for “Crummy Prompting”
Do you have trouble getting the SQL prompter to work on your RPG IV programs? If so, make sure you code a capital C in column 6. Coding a lowercase C and pressing F4 prompt a regular calculation spec instead.
— Brian Kautz
Emergency Shutdown of IP Filtering and NAT
If you use Operations Navigator (OpsNav) to start IP filtering on your AS/400, you may discover that you have inadvertently cut off access to things you didn’t intend to. For example, you may set up a Deny All type of filter rule and forget to specify the IP addresses to which it should deny access. This could spell disaster for your network if none of your networked PCs can access your AS/400.
If you find yourself in this situation or just need to shut off IP filtering in a hurry, there is a way to do it from any AS/400 command line. Enter the Remove TCP/IP Table (RMVTCPTBL) command:
RMVTCPTBL *ALL
Used in this manner, this command will stop both IP filtering and Network Address Translation (NAT). You also have the option of using the parameter value *IPFTR or *IPNAT, which stops only IP filtering or NAT, respectively. Once IP filtering or NAT is stopped, you can fix any problems that might have cropped up and then restart it.
— Shannon O’Donnell Senior Technical Editor
Midrange Computing
Positioning the Cursor Without an Indicator
Here is an indicator-free method of positioning the cursor on a display. Define a 3-byte, output-only field in the DDS record, in addition to the input fields. If you want to trigger the regular DDS cursor positioning, move blanks into the three bytes. If you want to override the DDS cursor positioning, move X’13’ + hexrow + hexcolumn into the bytes. For example, X’130625’ positions the cursor at row 6, column 37.
— Gene Gaunt Gene_Gaunt/
Editor’s Note: This is not a supported way to position the cursor. IBM provides the CSRLOC keyword in DDS for this purpose. If you wish to try Gene’s technique for yourself, re-create the display file and RPG III program shown in Figures 4 and 5. POS is the three-character positioning field, and you will be prompted for row and column numbers. When you press Enter, the cursor is positioned according to your entries. If a row or column number is invalid, the program ends.
A DSPSIZ(24 80 *DS3)
A R SCRN01
A 5 6'Position to row:'
A 6 15'column:'
A ROW 2 0B 5 23
A COL 2 0B 6 23
A POS 3 O 1 78
Figure 4: A three-character output-only field determines cursor positioning.
FCSRPOSDFCF E WORKSTN
I DS
I 1 3 POS
I 1 1 POS1
I 2 2 POS2
I 3 3 POS3
I DS
I B 1 20BIN2
I 2 2 BIN1
C *ZERO DOWEQ*ZERO
C EXFMTSCRN01
C ROW IFLT 1
C ROW ORGT 24
C COL ORLT 1
C COL ORGT 80
C LEAVE
C ENDIF
C EXSR CVTHEX
C ENDDO
C SETON LR
C CVTHEX BEGSR
C Z-ADDROW BIN2
C MOVE BIN1 POS2
C Z-ADDCOL BIN2
C MOVE BIN1 POS3
C MOVE X'13' POS1
C ENDSR
Figure 5: This program demonstrates the cursor-positioning technique.
Unconventional Use of QSYS.LIB
One of the great things about the AS/400 Integrated File System (AS/400 IFS) is that it gives you a place to store all the strange (to the AS/400, at least) PC file types, such as
*.JPG image files and *.ZIP compression files. However, what happens if you need to store a nontraditional file in the AS/400’s QSYS.LIB file system? You might think you’re out of luck, but not so. In fact, you can store nontraditional files (i.e., PC files) in QSYS.LIB by using FTP.
Say you want to store a Visual Basic (VB) project, form, and workspace on the AS/400, and you want to put them in QSYS.LIB. To do this, start an FTP session on the PC and put the VB files from the PC onto the AS/400. When you specify the name of the new AS/400 file object to put the file to, use a name with the PC file extension. For example, if you have a VB form named FORM1.FRM and want to put it in the QGPL library on the AS/400, use the following FTP command:
put C:FORM1.FRM QGPL/FORM1.FRM
You just have to make sure that you keep the name within the 10-character naming limit used by the QSYS.LIB file system.
Using FTP, you might be tempted to think that you need to use a binary transfer mode to keep the PC data from being corrupted, but that’s not the case for most PC files you put in QSYS.LIB. Using binary mode actually corrupts the data you put on the PC for most file types, including VB *.FRM files. The exception to this occurs if you put ZIP files or image files (such as *.BMPs, *.TIFs, or *.JPGs) onto the AS/400. The data formats of
these files are already binary representations of their parent data, so you have to use binary mode to maintain data integrity. For example, to put a ZIP file named MyZip.zip on the AS/400, use the following two FTP commands:
bin
put C:MyZIP.zip QGPL/MyZIP.zip
That’s it! Now you have a method for getting and putting nontraditional PC files into the QSYS.LIB file system.
— Shannon O’Donnell Senior Technical Editor
Midrange Computing
Java Programs Are Hidden from View
Q: When I run the Create Java Program (CRTJVAPGM) command for a class or JAR file, where does the compiled code go?
A: The CRTJVAPGM command puts the compiled Java class (*JVAPGM) into the same directory as the .class file, but the file is hidden. As a test, create a new AS/400 Integrated File System (AS/400 IFS) directory, put a Java source in that directory, compile it with javac from QShell, check the size of the directory, then run CRTJVAPGM, and recheck the size of the directory; it’ll be much larger because of the unseen *JVAPGM object. Note that, if you save that IFS directory, the *JVAPGM is also saved and, hence, can be restored.
— Don Denoncourt Senior Technical Editor
Midrange Computing
Is There a Command to Identify Changes Made to IBM Default Values?
Q: Is there a command to produce a listing of OS/400 commands whose default values have been changed?
— Annette Argo
A: Run the Display Object Description (DSPOBJD) command for all *CMD objects in QSYS and store the results in an outfile. Commands having had any of their defaults changed will have an authorized program analysis report (APAR) ID of CHGDFT. The APAR ID field name is ODAPAR. Build a query that selects the CHGDFT APAR ID to get a list of the commands in question. Exactly which defaults have been changed will have to be subject to a manual investigation, though.
— Carsten Flensburg
LATEST COMMENTS
MC Press Online