23
Sat, Nov
1 New Articles

TechTalk

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

Can Someone CL-ear This Up?

Q: I have an RPG program that calls a CL program that, in turn, submits a batch job. How can I make the CL program return the submitted job’s job number, name, and user profile to the RPG program?

— Josh Mason

A: The Submit Job (SBMJOB) command sends completion message CPC1221. Receive the message and extract the information you need from the MSGDTA parameter, as shown in Figure 1.

— Gene Gaunt

PGM (&SUBNAME &SUBUSER &SUBNUMB)

DCL &SUBNAME *CHAR 10
DCL &SUBUSER *CHAR 10
DCL &SUBNUMB *CHAR 6
DCL &DATA *CHAR 80

SBMJOB /* something */

RCVMSG MSGTYPE(*COMP) RMV(*NO) +

MSGDTA(&DATA) /* receive CPC1221 */

CHGVAR &SUBNAME %SST(&DATA 1 10)
CHGVAR &SUBUSER %SST(&DATA 11 10)
CHGVAR &SUBNUMB %SST(&DATA 21 6)

Figure 1: The MSGDTA parameter provides all the information you need.

Java and RPG Communication

Q: I have an interesting RPG and Java question: How can I handle an externally described parameter list with Java when interacting with an RPGLE module? Our standard for intermodule communication is to use externally described files, so we place the file we need in the D-spec, prefix it (when necessary), and use it to pass parameters between modules. How can we accomplish the same kind of smooth intercommunication when calling RPGLE modules from Java servlets or applets?

A: Use the record-level access (RLA) classes. You may not use the direct-access mechanism of RLA, but you can still use it to retrieve formats.

First, get an AS/400 object instance to your AS/400. Second, instantiate a record description object. Third, retrieve the appropriate record format. Fourth, create a Record object as a data buffer area. Finally, use the settor methods to populate the record file. Now you have a buffer object in EBCDIC that you can pass to RPG and COBOL via data queues or whatever.

Figure 2 contains a code sample that illustrates this process. Note that, when you retrieve a data buffer, you pull the values into Java with the getField method of the Record object.

— Don Denoncourt Senior Technical Editor

Midrange Computing

AS400 sys =

new AS400("111.111.111.111", "password", "profile");
AS400FileRecordDescription recDesc =

new AS400FileRecordDescription(sys,

"/QSYS.LIB/MYLIB.LIB/MYEXT.FILE");
RecordFormat format = recDesc.retrieveRecordFormat()[0];
Record dataBuffer = dtaqFormat.getNewRecord();
dataBuffer.setField("PACKED92", pckd);
dataBuffer.setField("ZONED60", znd);
dataBuffer.setField("CHAR20", char20);

Figure 2: Java can retrieve and use a record layout without using a file for I/O.

Running rmiregistry in Batch

Q: Is there a way to run the Java rmiregistry command in a batch Qshell session?

— Mark Charles

A: The rmiregistry tool is one of the AS/400 Developer Kit for Java utilities and a Qshell built-in command. It’s used to provide a name service to Java clients who want to invoke object methods remotely on their servers. Since rmiregistry is a server process that produces no output, it would be ideal to run this command in batch mode instead of from the Qshell command line. Using a Qshell script, this is possible with a single Submit Job (SBMJOB) command.

First, add this Qshell script code to a file in your AS/400 Integrated File System (AS/400 IFS) home directory. (You can download the code from www.midrangecomputing.com/mc.) I’ve saved mine to /home/walter/runreg.sh: The export command causes the QIBM_MULTI_THREADED environment variable to be used in processes subsequently started by the script. To run Java programs, this variable must be set to Y. The next line invokes rmiregistry; the trailing ampersand (&) on this command tells Qshell to run the command asynchronously and, in effect, causes it to create a new process that uses the environment variable you just set.

#!/usr/bin/sh
export CLASSPATH=.:/qibm/ProdData/HTTP/Public/ jt400/lib/jt400.jar:
export QIBM_MULTI_THREADED=Y
rmiregistry 1099 &

Submit the command to batch by using a Submit Job (SBMJOB) command similar

to this:

SBMJOB CMD(STRQSH +

CMD(‘/home/walter/runreg.sh’)) +

JOB(RMIREGSTRY)

I’ve named the batch job something familiar with the JOB parameter so I can find it in a Work with Active Jobs (WRKACTJOB) display later. If I want to end the server, I simply do an End Job (ENDJOB). However, since rmiregistry is a Java program, it may create other thread jobs. When ending the server, these thread jobs need to be forcefully removed with ENDJOB, too.

— Walter Goodwin

A Plethora of PDM Options

One of the things I like most about PDM is the ability to create my own options. IBM reserves numeric options for its own use, but the rest of us can create options by using one letter, two letters, or a letter and a number.

Recently, several of the participants in the Midrange Computing Web forums (www. midrangecomputing.com/forums) shared their favorite homegrown PDM options. I’ve listed some of them in Figure 3. Special thanks go to Joe Pluta, Bret Myrick, Gene Gaunt, Barbara Morris, “Dave A.,” and Bill Robins. I didn’t have room for all of them, so I tried to select options that were of special interest or appeared to me to be of wide appeal. Maybe you’ll find something here that can save you keystrokes as you work.

— Ted Holt Senior Technical Editor

Midrange Computing

Option Command
AF /* Create AFPDS printer file */ CRTPRTF FILE(&L/&N) SRCFILE(&L/&F) SRCMBR(*FILE) DEVTYPE(*AFPDS)
AL /* Add to library list */ ADDLIBLE LIB(&L)

B /* Call pgm in batch */ SBMJOB CMD(CALL PGM(&N)) JOB(&N) JOBQ(QBATCH) JOBPTY(5)
BM /* Browse source member */ DSPPFM FILE(&L/&F) MBR(&N)

CF /* Change PF */ CHGPF FILE(&N) SRCFILE(&L/&F) SRCMBR(&N)
CP /* Create program */ CRTPGM PGM(&L/&N) MODULE(&L/&N) ENTMOD(&N)
CQ /* Clear member */ CLRPFM FILE(&L/&F) MBR(&N)

CS /* Create service program */ CRTSRVPGM SRVPGM(&L/&N) MODULE(&L/&N) EXPORT(*ALL)
CT /* Change file with temporary DFU */ STRDFU OPTION(5) FILE(&L/&N)

CV /* Cvt to RPG IV */ CVTRPGSRC FROMFILE(&L/&F) FROMMBR(&N) TOFILE(&L/QRPGLESRC) TOMBR(&N)

LOGFILE(*NONE)
DF /* Delete file from member list */ DLTF FILE(&L/&N)
DP /* Delete pgm from member list */ DLTPGM PGM(&L/&N)
DS /* Display last interactive compile */ DSPSPLF FILE(&N) JOB(*) SPLNBR(*LAST)
DU /* Delete module */ DLTMOD MODULE(&L/&N)

DV /* Delete service program */ DLTSRVPGM SRVPGM(&L/&N)
ED /* End debug */ ENDDBG
JJ /* Compile Java */ QSH CMD(‘javac -g &N.java’)

JS /* Job schedule entries */ WRKJOBSCDE
LL /* Display library list */ DSPLIBL
LL /* Edit library list */ EDTLIBL
OL /* object lock */ WRKOBJLCK OBJ(&L/&N) OBJTYPE(&T)
QC /* call command processor */ CALL PGM(QCMD)

QF /* Query file */ RUNQRY QRYFILE((&L/&N))
RG /* Reclaim ActGrp QILE */ RCLACTGRP ACTGRP(QILE)
RZ /* Reorg file */ RGZPFM FILE(&L/&N) KEYFILE(*FILE)
SD /* start debug */ STRDBG PGM(&L/&N) OPMSRC(*YES)
SD /* Submit CL cmds to batch */ SBMDBJOB FILE(&L/&F) MBR(&N)
SJ /* jobs submitted from this job */ WRKSBMJOB SBMFROM(*JOB)
SL /* Create RPG module */ CRTRPGMOD MODULE(&L/&N) SRCFILE(&L/&F) OPTION(*SECLVL *NOGEN)
SP /* spool files for this job */ WRKJOB OPTION(*SPLF)

WA /* Active jobs */ WRKACTJOB
WQ /* Qtemp objects */ WRKOBJPDM LIB(QTEMP)
WW /* work with writers */ WRKWTR
XS /* Delete last interactive compile listing */ DLTSPLF FILE(&N) JOB(*) SPLNBR(*LAST)

Figure 3: PDM options save time and are easy to develop.

Displaying Serial Dates with Query

Our system stores dates in five-digit packed fields as the number of days from December 31, 1971. To show the date in field DATFLD in a readable format with Query/400, I create a result field, DSPDAT, defined with this expression: To find the correct number to add to DATFLD for another offset date, I would use the expression DAYS(‘mm/dd/yy’) in a temporary query.

This works fine if DATFLD is always filled out, but a date of all zeros shows up in the report as the offset date. To present zeros as blanks, a few more functions must be used. These fields are shown in Figure 4.

First, create a 0/1 field (called SWITCH here) to indicate whether or not DATFLD is zero; do not turn off rounding. Second, create a character field (CHRDAT) containing the converted date. Third, use the substring function to pick zero to eight characters from CHRDAT and place them in field DSPDAT. The value function selects the first element in a list that is not null. Because a substring of length zero is null, blanks print when DATFLD is zero. The whole operation for creating DSPDAT can be specified in a single result field: Note that the multiplier is 9, whereas it was 8 in Figure 4. The reason for this change is that the substring function uses only the integer part of the intermediate result to calculate the length. Therefore, DATFLD/(DATFLD+1) = 0.999..., which must be multiplied by 9 to obtain the right result. As long as meaningful dates are more than eight days from the offset date, this works fine.

— Jørn Nielsen

date(DATFLD + 719892)

value(substr(char(date(DATFLD +
719892)),1,(DATFLD/(DATFLD+1)*9))
,’ ‘)

Field Definition Length Decimals

SWITCH DATFLD/(DATFLD + 1) 1 0 CHRDAT char(date(DATFLD + 719892))

DSPDAT value(substr(CHRDAT,1,(SWITCH*8))”

,’ ‘)

Figure 4: Dates of all zeros print as blanks.

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: