02
Sat, Nov
2 New Articles

TechTalk

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

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

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

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

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


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: