The More Digits, the Merrier
Q: I have a calculation that requires field lengths of more than 30 digits. Unfortunately, RPG IV allows up to only 30 digits for a numeric field definition. Is there any way to get around this?
Premkumar Hexaware InfoSystems Ltd.
Chennai, India
A: If you need more than 30 digits of precision, try using REXX instead of RPG IV. REXX allows you to set the precision for numeric calculation via the NUMERIC DIGITS command. Using this command, you can make the size of the numeric field as large as you need. If you need to handle only very large or very small numbers and 17 or so digits of precision is enough, define your RPG IV numeric field as a floating point field on the D- spec:
D Numeric_Fld S 8f
Note: Floating point fields are supported only on V3R7 and above.
Barbara Morris
IBM Toronto Lab RPG Compiler Development
In That CASE...
SQL-based conditional processing was added to DB2 UDB for AS/400 in V4R2 with the SQL CASE expression. However, Query/400 can use the SQL CASE expression indirectly to perform conditional processing in a Query/400 report. The idea is to create an SQL view that uses CASE to perform the necessary conditional processing. The SQL Create View statement creates a logical file that can then be referenced in your Query/400 definition.
Figure 1 shows how to use CASE to determine different vehicle license fees conditionally. The SQL Create View statement can be executed in any SQL interface, such as an AS/400 or PC client communicating with the AS/400. Once youve created the new
view, start a Query/400 session, create a new query, and specify the name of the new view as the file to be queried (in this case, Licview, which was created in library mylib).
Kent Milligan
This email address is being protected from spambots. You need JavaScript enabled to view it.
CREATE VIEW mylib/licview (license,licfee) AS
SELECT license,
CASE type WHEN 'Car' THEN 0.05 * weight
WHEN 'Truck' THEN 75 * nbr_wheels
WHEN 'Motorcyle' THEN 35.00 END
FROM vehicles
Figure 1: Use SQL to create a view that can then be queried by Query/400.
End Your Applications on a Good Note
When you end certain TCP/IP applications such as the HTTP server, you need to be careful not to end someone elses instance. For example, to end the HTTP application, you dont really need to use ENDTCPSVR SERVER(*HTTP), because the default value of the HTTPSVR parameter is *ALL. Instead, end your instance this way:
ENDTCPSVR SERVER(*HTTP) +
HTTPSVR(your_instance_name)
Bradley Stone Associate Technical Editor
Midrange Computing
Richard Shaler Midrange Computing This email address is being protected from spambots. You need JavaScript enabled to view it.
Join Me in Updating This File
OS/400 V4R3 has a feature many of us have requested for a long time. With V4R3, it is possible to update data in one file with field-level data from another file. In other words, you can now update through a join. Figure 2 illustrates how its done.
David Babashanian
ValueOptions Norfolk, Virginia
UPDATE DABLIB/MYRECON2 SET (SMIFLG, SEDFLG, ASSSMI, ASSSED) = (SELECT
SMIFLG, SEDFLG, ASSSMI, ASSSED FROM MHSFLA/CISINT WHERE CISINT.CLIENT =
MYRECON2.CLIENT AND CISINT.INTDAT = MYRECON2.INT
Figure 2: V4R3 updates through a join.
Getting Around the Rounding Problem
Q: I have an end-of-day report I created in Query/400 that summarizes inventory adjustments by type. The problem is that the adjustments are accurate to the penny, but the report displays only whole dollars. Im afraid the numbers are inaccurate because the cents
arent being accumulated. Figure 3 shows how I defined the fields in Query/400 on the Define Result Fields screen.
The problem is that the first result field, CSTDLR, does not truncate the cost field but rounds it up when the cents are greater than or equal to 50. Can you show me how to write this result field definition so the cost number is truncated instead of rounded?
Michael Daly
Senior P/A FreshPoint, Inc.
A: Define your field as 9.2 instead of 7.0. Then, go to field formatting and make it 7.0. That should take care of the rounding problem for you.
Bill Robins This email address is being protected from spambots. You need JavaScript enabled to view it.
Field Expression Column Heading Len Dec
CSTDLR INCST Dollar Amount 7 0
CSTCNT INCST CSTDLR Adjustment Amount 7 2
Figure 3: Note that cents are not accumulated on this Define Results Fields screen.
Looking to Move Your AS/400 Spool Files to the Web?
Heres a handy little utility I created to do just that! It transforms your AS/400 spool files into HTML documents so they can be displayed in almost any Web browser! The utility consists of four objects:
CRTHTM converts your spool files to HTML documents. Give this command your spool file information, such as your name and job information and (optionally) the name and email address of the person to contact if questions about the document arise.
CTLHTMCL is the command-processing program for command CRTHTM. It ensures the spool file exists and copies its contents to a temporary file named REPORT in library QTEMP. It then calls RPG program CRTHTMRG, which reads the REPORT file and generates HTML code from the document. The resulting HTML code is written to a temporary file named REPORTH in library QTEMP. When the RPG program is finished, the CPP FTPs QTEMP/REPORTH to the clients hard drive using the FTP instructions stored in text file FTPSCRIPT.
CRTHTMRG (Figure 4) reads temporary file REPORT and converts its records to HTML code. The resulting records are written to file REPORTH in library QTEMP. The HTML commands and
preserve the formatting of the report. If a user name and email address are entered on the command, theyre added to the bottom of the HTML document using the mailto: tag so the users default email program is displayed when this link is clicked.
FTPSCRIPT is a source file member that tells the FTP where to send the document. You can modify this member as needed. For example, you may want to pass on to it the actual name of the spool file to be created.
Code for CRTHTM, CTLHTMCL, and FTPSCRIPT can be found on the Midrange Computing Web site at www.midrangecomputing.com/mc/99/08.
The new HTML document is generated onto a white background. You can dress up the document using HTML keywords. Here are some possibilities:
Bgcolor changes background colors.
Font-1 changes default fonts.
Meta Tag allows searching inside or outside the document.
Ray Welgosh
Computer Consultant, Palarco, Inc. This email address is being protected from spambots. You need JavaScript enabled to view it.
/title crthtmrg create html from a spool file
**************************************************************
* To Compile:
* CRTBNDRPG(xxx/CRTHTMRG) SRCFILE(xxx/QRPGLESRC) +
* SRCMBR(xxx/QRPGLESRC)
***************************************************************
fReport if f 140 disk
fReporth o f 150 disk
d Lit s 65 dim(2) ctdata perrcd(1)
d A s 1 dim(150)
d Ename s 30
d Fout s 150
d F65 s 65
d Rname s 30
ireport ns
i 1 3 0skip
i 4 4 0spcb
i 5 136 data
*
c read Report 90
c dow *in90 = *off
c if Spcb > 1
c exsr Space
c endif
c exsr Html
c read Report 90
c enddo
*
c if Rname <> *blanks
c exsr Blank
c exsr Blank
c exsr Email
c endif
*
c movel *blanks Fout
c movel '
LATEST COMMENTS
MC Press Online