06
Fri, Dec
6 New Articles

DSPRCDFMT -- An API Alternative to DSPFFD

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

Here's a utility that allows you to look at physical and single-format logical files in a new way. The command, shown in 1, is called Display Record Format (DSPRCDFMT). It's similar to the OS/400 command Display File Field Description (DSPFFD) because it shows you information about the fields in a file. But DSPRCDFMT also shows you the access path of the file, and the information is presented in a cleaner, easier-to-read format than DSPFFD. Information can either be displayed on the screen or spooled for printing.

Here's a utility that allows you to look at physical and single-format logical files in a new way. The command, shown in Figure 1, is called Display Record Format (DSPRCDFMT). It's similar to the OS/400 command Display File Field Description (DSPFFD) because it shows you information about the fields in a file. But DSPRCDFMT also shows you the access path of the file, and the information is presented in a cleaner, easier-to-read format than DSPFFD. Information can either be displayed on the screen or spooled for printing.

The command processing program for DSPRCDFMT is RCD002CL, shown in 2. The first thing that RCD002CL does is create a user space in QTEMP. Although there is no command in OS/400 to create a user space, it is easy enough to create one. The source code for the command CRTUSRSPC is shown in 3. Make sure that when creating this command, you use the Create User Space (QUSCRTUS) API as the command processing program.

The command processing program for DSPRCDFMT is RCD002CL, shown in Figure 2. The first thing that RCD002CL does is create a user space in QTEMP. Although there is no command in OS/400 to create a user space, it is easy enough to create one. The source code for the command CRTUSRSPC is shown in Figure 3. Make sure that when creating this command, you use the Create User Space (QUSCRTUS) API as the command processing program.

The utility then uses the List Fields (QUSLFLD) API to load the user space with all of the fields in a file, along with their definition. The Display File Description (DSPFD) command is then executed to an OUTFILE in order to retrieve the access path. Unfortunately, IBM's database APIs don't provide this information, so the DSPFD command will have to do. RCD002RG, a RPG program shown in 4, is then called to retrieve the list of fields from the user space. Depending on the user's request, this information -- along with the access path information -- is then written to either a display file, RCD002DF (shown in 5), or to a spool file.

The utility then uses the List Fields (QUSLFLD) API to load the user space with all of the fields in a file, along with their definition. The Display File Description (DSPFD) command is then executed to an OUTFILE in order to retrieve the access path. Unfortunately, IBM's database APIs don't provide this information, so the DSPFD command will have to do. RCD002RG, a RPG program shown in Figure 4, is then called to retrieve the list of fields from the user space. Depending on the user's request, this information -- along with the access path information -- is then written to either a display file, RCD002DF (shown in Figure 5), or to a spool file.

DSPRCDFMT is a utility that should prove to be a real productivity booster. Without it, you would have to page through the output of several OS/400 commands. DSPRCDFMT can be particularly useful from within SEU, since it is usually while coding that you realize you need the name or size of a field, or the record format name, or the names of the key fields. By pressing F21 to pop up a command window, you can use DSPRCDFMT to look at files on the fly. Once you start using this utility, you will wonder how you ever got along without it.


DSPRCDFMT -- An API Alternative to DSPFFD

Figure 1 Command DSPRCDFMT

 DSPRCDFMT: CMD PROMPT('File Field Description') PARM KWD(FILE) TYPE(QUAL) MIN(1) PROMPT('File') PARM KWD(OUTPUT) TYPE(*CHAR) LEN(7) RSTD(*YES) + DFT(*) VALUES(* *PRINT *SRCMBR) + PROMPT('Output') PARM KWD(SRCF) TYPE(Q2) PMTCTL(PC1) + PROMPT('Source file') PARM KWD(MBR) TYPE(*NAME) LEN(10) DFT(*FILE) + SPCVAL((*FILE)) PMTCTL(PC1) PROMPT('Member') PARM KWD(MBROPT) TYPE(*CHAR) LEN(8) RSTD(*YES) + DFT(*REPLACE) VALUES(*ADD *REPLACE) + PMTCTL(PC1) PROMPT('Member options') QUAL: QUAL TYPE(*NAME) LEN(10) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL)) PROMPT('Library') Q2: QUAL TYPE(*NAME) LEN(10) DFT(QPGMSRC) QUAL TYPE(*NAME) LEN(10) DFT(QTEMP) + SPCVAL((*LIBL)) PROMPT('Library') PC1: PMTCTL CTL(OUTPUT) COND((*EQ '*SRCMBR')) 
DSPRCDFMT -- An API Alternative to DSPFFD

Figure 2 CL program RCD002CL

 RCD002CL: + PGM PARM(&FILE &OUTPUT &QUALSRCF &MBR &MBROPT) DCL VAR(&FILE) TYPE(*CHAR) LEN(20) DCL VAR(&FILNAM) TYPE(*CHAR) LEN(10) DCL VAR(&LIBNAM) TYPE(*CHAR) LEN(10) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&OUTPUT) TYPE(*CHAR) LEN(7) DCL VAR(&QUALSRCF) TYPE(*CHAR) LEN(20) DCL VAR(&MBR) TYPE(*CHAR) LEN(10) DCL VAR(&SRCF) TYPE(*CHAR) LEN(10) DCL VAR(&SRCFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MBROPT) TYPE(*CHAR) LEN(8) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) CHGVAR VAR(&FILNAM) VALUE(%SST(&FILE 1 10)) CHGVAR VAR(&LIBNAM) VALUE(%SST(&FILE 11 10)) /* Validate source file name if OUTPUT(*SRCMBR) requested */ CHGVAR VAR(&SRCF) VALUE(%SST(&QUALSRCF 1 10)) CHGVAR VAR(&SRCFLIB) VALUE(%SST(&QUALSRCF 11 10)) IF COND(&MBR *EQ '*FILE') THEN(CHGVAR VAR(&MBR) VALUE(&FILNAM)) IF COND(&OUTPUT *EQ '*SRCMBR') THEN(DO) IF COND(&SRCFLIB *EQ 'QTEMP') THEN(DO) CRTSRCPF FILE(QTEMP/&SRCF) RCDLEN(92) MONMSG MSGID(CPF0000) ENDDO CHKOBJ OBJ(&SRCFLIB/&SRCF) OBJTYPE(*FILE) MBR(&MBR) MONMSG MSGID(CPF9801) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE('Source file' *BCAT &SRCFLIB + *TCAT '/' *CAT &SRCF *BCAT 'not found.') GOTO CMDLBL(SNDERRMSG) ENDDO MONMSG MSGID(CPF9810) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE('Source library' *BCAT &SRCFLIB + *BCAT 'not found.') GOTO CMDLBL(SNDERRMSG) ENDDO MONMSG MSGID(CPF9815) EXEC(DO) ADDPFM FILE(&SRCFLIB/&SRCF) MBR(&MBR) ENDDO ENDDO /* Create user space to begin processing */ CRTUSRSPC USRSPC(QTEMP/RCD002US) TEXT('User space for DSPRCDFMT') MONMSG MSGID(CPF9870) CALL PGM(QUSLFLD) PARM('RCD002US QTEMP ' 'FLDL0100' &FILE + '*FIRST ' '0') DSPFD FILE(&LIBNAM/&FILNAM) TYPE(*ACCPTH) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/RCD002PF) IF COND(&OUTPUT *EQ '*SRCMBR') THEN(DO) IF COND(&MBROPT *EQ '*REPLACE') THEN(CLRPFM + FILE(&SRCFLIB/&SRCF) MBR(&MBR)) OVRDBF FILE(SOURCE) TOFILE(&SRCFLIB/&SRCF) MBR(&MBR) ENDDO OVRDBF FILE(QAFDACCP) TOFILE(RCD002PF) CALL PGM(RCD002RG) PARM(&OUTPUT) DLTOVR FILE(*ALL) GOTO CMDLBL(ENDPGM) ERROR: + RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) SNDERRMSG: + SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) ENDPGM: + ENDPGM 
DSPRCDFMT -- An API Alternative to DSPFFD

Figure 3 Command CRTUSRSPC

 /*********************************************************************/ /* WHEN CREATING THIS COMMAND USE "QSYS/QUSCRTUS" AS THE COMMAND */ /* PROCESSING PROGRAM. */ /*********************************************************************/ CMD PROMPT('Create User Space') PARM KWD(USRSPC) TYPE(QUAL) PROMPT('User space') PARM KWD(ATR) TYPE(*CHAR) LEN(10) + PROMPT('Attribute') PARM KWD(SIZE) TYPE(*INT4) DFT(100000) + PROMPT('Size') PARM KWD(INIT) TYPE(*CHAR) LEN(1) PROMPT('Initial + value') PARM KWD(AUT) TYPE(*CHAR) LEN(10) RSTD(*YES) + DFT(*ALL) VALUES(*ALL *CHANGE *USE + *EXCLUDE) PROMPT('Public authority') PARM KWD(TEXT) TYPE(*CHAR) LEN(50) PROMPT('Text') QUAL: QUAL TYPE(*NAME) LEN(10) MIN(1) QUAL TYPE(*NAME) LEN(10) MIN(1) PROMPT('Library') 
DSPRCDFMT -- An API Alternative to DSPFFD

Figure 4 RPG program RCD002RG

 H * FQAFDACCPIF E DISK FRCD002DFCF E WORKSTN UC F SFLRN KSFILE DSPSFL01 FQPRINT O F 80 OF PRINTER UC FSOURCE O F 92 DISK A UC * E LN 5 1 E KF 25 10 E KN 25 3 0 * I DS I 1 176 #HEADR I B 1 40#OFSET I B 9 120#COUNT I B 13 160#LNGTH I 133 142 FILNAM I 143 152 LIBNAM I 153 162 FILTYP I 163 172 RCDFMT I B 173 1760#RCDLN * * I#INFO DS 288 I 1 10 FIELD I B 17 200#START I B 21 240#CHRLN I B 25 280#NUMLN I B 29 320#DECPS I 33 74 TEXT * I DS I I 125 B 1 40#STPOS I I 176 B 5 80#STLEN I I 'RCD002US QTEMP ' 9 28 #SPC20 * I DS I 1 50LEN I 1 5 LN * C *ENTRY PLIST C PARM #OUTPT 7 * C 1 DO #COUNT C CALL 'QUSRTVUS' C PARM #SPC20 C PARM #STPOS C PARM #STLEN C PARM #INFO C ADD 1 SFLRN 30 C Z-ADD#START FROM C #START ADD #CHRLN TO C SUB 1 TO * C #NUMLN IFGT 0 C MOVE #DECPS DEC 2 C MOVEL',' DEC C Z-ADD#NUMLN LEN C ELSE C MOVE *BLANKS DEC C Z-ADD#CHRLN LEN C END * C Z-ADD1 L 30 C L DOWLE5 C LN,L ANDEQ'0' C MOVE ' ' LN,L C ADD 1 L C END * C MOVEALN SIZE C MOVE DEC SIZE * C Z-ADD0 KEY C #SAVEK IFLE 25 C Z-ADD#SAVEK K C FIELD LOKUPKF,K 99 C *IN99 IFEQ '1' C Z-ADDKN,K KEY C END C END * C #OUTPT IFEQ '* ' C WRITEDSPSFL01 C ELSE C #OUTPT IFEQ '*PRINT ' C EXCPTDETAIL C ELSE C EXCPTWRTSRC C END C END * C ADD #STLEN #STPOS C END * C #OUTPT IFEQ '* ' C WRITEDSPRCD01 C EXFMTDSPCTL01 C END * C SETON LR ***************************************************************** C *INZSR BEGSR ***************************************************************** * C CALL 'QUSRTVUS' C PARM #SPC20 C PARM #STPOS C PARM #STLEN C PARM #HEADR * C #OFSET ADD 1 #STPOS C Z-ADD#LNGTH #STLEN C Z-ADD#RCDLN RCDLEN C Z-ADD#COUNT FIELDS * C #OUTPT IFEQ '* ' C OPEN RCD002DF C ELSE C #OUTPT IFEQ '*PRINT ' C OPEN QPRINT C EXCPTHEADER C ELSE C OPEN SOURCE C EXCPTSRCHDR C END C END * C Z-ADD26 K 30 C READ QWHFDACP 99 C *IN99 DOWEQ'0' C K ANDGT1 C SUB 1 K C MOVE APKEYF KF,K C Z-ADDAPKEYN KN,K C READ QWHFDACP 99 C END C Z-ADDK #SAVEK 30 C CLOSEQAFDACCP C ENDSR * OQPRINT E 2 1 HEADER O OR OF O 51 'File Field Description' * O E 1 HEADER O OR OF O 12 'File . . :' O FILNAM 23 O 42 'Record format . :' O RCDFMT 53 O 74 'Record length . . :' O RCDLEN3 80 * O E 2 HEADER O OR OF O 12 'Library . :' O LIBNAM 23 O 42 'Type of file . . :' O FILTYP 53 O 74 'Number of fields . :' O FIELDS3 80 * O E 1 HEADER O OR OF O 5 'From' O 10 'To' O 18 'Size' O 24 'Key' O 32 'Field' O 42 'Text' * O EF 1 DETAIL O FROM 3 5 O TO 3 10 O SIZE 18 O KEY 4 23 O FIELD 37 O TEXT 80 * OSOURCE EADD SRCHDR O 63 'File Field Description' O EADD SRCHDR O 24 'File . . :' O FILNAM 35 O 54 'Record format . :' O RCDFMT 65 O 86 'Record length . . :' O RCDLEN3 92 O EADD SRCHDR O 24 'Library . :' O LIBNAM 35 O 54 'Type of file . . :' O FILTYP 65 O 86 'Number of fields . :' O FIELDS3 92 O EADD SRCHDR O 17 'From' O 22 'To' O 30 'Size' O 36 'Key' O 44 'Field' O 54 'Text' O EADD WRTSRC O FROM 3 17 O TO 3 22 O SIZE 30 O KEY 4 35 O FIELD 49 O TEXT 92 
DSPRCDFMT -- An API Alternative to DSPFFD

Figure 5 Display file RCD002DF

 A DSPSIZ(24 80 *DS3) A PRINT A CA03(03) A CA12(12) A R DSPSFL01 SFL A FROM 4Y 0O 7 2EDTCDE(3) A TO 4Y 0O 7 7EDTCDE(3) A SIZE 7A O 7 12 A KEY 3Y 0O 7 21EDTCDE(4) A FIELD 10A O 7 28 A TEXT 42A O 7 39 A R DSPCTL01 SFLCTL(DSPSFL01) A SFLSIZ(0016) A SFLPAG(0015) A OVERLAY A PUTOVR A SFLDSP A SFLDSPCTL A N90 SFLEND A 1 30'Display Record Format' A DSPATR(HI) A 3 2'File . . :' A FILNAM 10A O 3 14 A 3 25'Record format . :' A RCDFMT 10A O 3 44 A 3 55'Record length . . :' A RCDLEN 5Y 0O 3 76EDTCDE(3) A 4 2'Library . :' A LIBNAM 10A O 4 14 A 4 25'Type of file . . :' A FILTYP 10A O 4 44 A 4 55'Number of fields . :' A FIELDS 5Y 0O 4 76EDTCDE(3) A 6 2'From' A DSPATR(HI) A 6 9'To' A DSPATR(HI) A 6 15'Size' A DSPATR(HI) A 6 22'Key' A DSPATR(HI) A 6 28'Field' A DSPATR(HI) A 6 39'Text' A DSPATR(HI) A R DSPRCD01 A 23 2'F3=Exit' A COLOR(BLU) A 23 13'F12=Cancel' A COLOR(BLU) 
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: