ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaef_5.4.0.1/rzaefqlspgmx.htm

280 lines
28 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="dc.language" scheme="rfc1766" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<meta name="dc.date" scheme="iso8601" content="2005-09-06" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2000, 2006" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow"/>
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="keywords" content="
copying iSeries database file to integrated file system, example,
iSeries database file to integrated file system, copying, conversion, CCSID,
Create Program (CRTPGM) command, CRTPGM (Create Program), command, CL,
Create Program (CRTPGM), creating, program,
CRTCMOD (Create Bound ILE C for iSeries Program) command,
Create Bound ILE C for iSeries Program (CRTCMOD) command,
CRTCMOD (Create Bound ILE C for iSeries Program),
Create Bound ILE C for iSeries Program (CRTCMOD), bound ILE C/400 program,
bound ILE C for iSeries program, CHGCURDIR (Change Current Directory) command,
Change Current Directory (CHGCURDIR) command,
CHGCURDIR (Change Current Directory), Change Current Directory (CHGCURDIR),
changing, current directory, mapped, drive" />
<title>Example: ILE C for iSeries program to copy an iSeries database
file to QNetWare File System</title>
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
<link rel="stylesheet" type="text/css" href="ic.css" />
</head>
<body>
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
<a name="qlspgmx"></a>
<h4 id="qlspgmx">Example: ILE C for iSeries program to copy an iSeries database
file to QNetWare File System</h4>
<a name="wq108"></a>
<div class="notetitle" id="wq108">Note:</div>
<div class="notebody">Read the <a href="rzaef02.htm#netwcodedisclaimer">Code disclaimer information</a> for important legal
information.</div><a id="idx226" name="idx226"></a><a id="idx227" name="idx227"></a><a id="idx228" name="idx228"></a>
<p>Suppose you have a customer file that you want to make available to all NetWare users,
and that file contains fields that need conversion from packed decimal format. <a href="rzaefcpydatabase.htm#cpydatabase">Example: Copying an iSeries&trade; database file</a> shows you how to
copy and convert that file with a series of integrated file system commands.
You can also copy and convert the necessary field by using an ILE C for iSeries program. Before you use integrated file system APIs on the QNetWare file system, you
should be aware of some <a href="rzaefapiconsiderations.htm#apiconsiderations">considerations</a>.</p>
<p>This sample program is not restricted to the QNetWare file system. You can use it to copy
an iSeries database file into other file systems that the integrated file
system supports. For example, you could change the hard-coded name of the
stream file path to be the current directory: <tt class="xph">./CUST.DAT</tt>. Before
you run the program, use the <tt class="xph">CHGCURDIR</tt> command to change to the
directory in which you want to create the stream file. However, you cannot
copy this file into the QSYS.LIB file system because CUST.DAT is not a valid
name for the QSYS.LIB file system.</p>
<p>The file in this example is in library DATALIB and has the name CUSTCDT.
You can refer to these example displays:</p>
<ul>
<li><a href="rzaefifsql14.htm#ifsql14">Example: DDS for iSeries database file CUSTCDT</a> shows the DDS description of this example file,
which has packed decimal fields.</li>
<li>If you are unfamiliar with DDS definitions, you can refer to <a href="rzaefifsql16.htm#ifsql16">Example: DSPFFD of iSeries database file CUSTCDT</a>,
which shows the output of the <tt class="xph">DSPFFD CUSTCDT</tt> command.</li>
<li><a href="rzaefifsql15.htm#ifsql15">Example: Content of CUSTCDT database file display that Query for iSeries creates</a>.</li></ul>
<p>The following ILE C for iSeries program, NWCUST, uses the external
description of CUSTCDT. To convert the data from EBCDIC to ASCII, it uses
the system APIs from the service program QTQICONV. This service program provides
APIs to convert a buffer of characters from one coded character set identifier
(CCSID) into another CCSID. To create the stream file CUST.DAT, it uses the <span class="bold">open()</span>, <span class="bold">write()</span> and <span class="bold">close()</span> integrated file system APIs.</p><a id="idx229" name="idx229"></a><a id="idx230" name="idx230"></a><a id="idx231" name="idx231"></a><a id="idx232" name="idx232"></a><a id="idx233" name="idx233"></a><a id="idx234" name="idx234"></a><a id="idx235" name="idx235"></a><a id="idx236" name="idx236"></a><a id="idx237" name="idx237"></a><a id="idx238" name="idx238"></a><a id="idx239" name="idx239"></a>
<a name="wq109"></a>
<div class="notetitle" id="wq109">Note:</div>
<div class="notebody">Read the <a href="rzaef02.htm#netwcodedisclaimer">Code disclaimer information</a> for important legal
information.</div>
<p>To create the ILE C for iSeries module and bind it to the QTQICONV
service program to create the NWCUST program, you would use these commands: </p>
<pre class="xmp">CRTCMOD MODULE(NWCUST) SRCFILE(QCSRC) OUTPUT(*PRINT) OPTION(*SHOWUSR)
CRTPGM PGM(NWCUST) BNDSRVPGM(QTQICONV)</pre>
<ol type="1">
<li>Open the stream file with the integrated file system <span class="bold">open()</span> API. Refer to <span><span class="refkey">&nbsp;1&nbsp;</span> in <a href="rzaefqlspgmx.htm#ifsql21">Figure 2</a>.</span>
<p>This function opens the stream file for write only (<span class="italic">O_WRONLY</span> flag). If the file does not exist, it is created (<span class="italic">O_CREAT</span> flag). If it exists, it is truncated to 0 bytes length (<span class="italic">O_TRUNC</span> flag). This ensures that the stream file is
replaced every time the program runs.</p>
<p><span class="italic">S_IRWXU</span> sets file authority bits. </p>
<dl>
<dt class="bold">S_IRWXU</dt>
<dd>Read, write, and search or execute for the file owner.
</dd>
</dl><p class="indatacontent"> The <tt class="xph">open()</tt> API requires authority bits to be set when the
O_CREAT flag is set.</p>
<p>S_IRWU is used to let you read and write to
the file. <a href="rzaefflmdmap.htm#flmdmap">NetWare file mode support</a> has information about which attributes NetWare sets
for owner permission.</p></li>
<li>Build the buffer for the stream file record. Add a comma as the field
delimiter <span class="refkey">&nbsp;2&nbsp;</span>.
<p>The <tt class="xph">sprintf()</tt> function converts
all packed decimal data fields from the database file into characters and
formats them correctly with the format-string, for example: <tt class="xph">"D(6.2)"</tt>.</p></li>
<li>Convert stream file buffer from CCSID 37 to CCSID 850 <span class="refkey">&nbsp;3&nbsp;</span>.
<p>Function <tt class="xph">iconv()</tt> converts the stream file buffer to ASCII code
page 850. Use the code page of your NetWare server. To determine the code page
of the server, use the DSPMFSINF command. For example, to obtain the code
page of directory <tt class="xph">SYSTEM</tt> in volume <tt class="xph">SYS</tt> of server <tt class="xph">NTWSERV1</tt>, enter: </p>
<pre class="xmp"> DSPMFSINF OBJ('/QNetWare/NTWSERV1.SVR/SYS/SYSTEM')</pre><a id="idx240" name="idx240"></a></li>
<li>Add ASCII carriage return and line feed as a record delimiter to the stream
file buffer <span class="refkey">&nbsp;4&nbsp;</span>. The character string <tt class="xph">"\15\12"</tt> represents hex x'0D0A' in octal form.</li>
<li>Write the stream file buffer to the file using the Integrated File System <span class="bold">write()</span> API<span class="refkey">&nbsp;5&nbsp;</span>. The library DATALIB, where the CUSTCDT
database file is, has to be in the library list of the job from which you
run the program.</li></ol>
<p>Here is the source listing for the example program:</p>
<a name="ifsql21"></a>
<div class="fignone" id="ifsql21"><span class="figcap">Figure 2. Example: ILE C for iSeries program using integrated file system APIs</span>
<pre class="xmp"> * * * * * S O U R C E * * * * *
Line STMT SEQNBR INCNO
*...+.....1.....+.....2.....+.....3.....+.....4.....+.....5.....+.....6.....+.....7.....+.....8.....+.....9.....+.....
1 |/* This program copies the AS/400 database file CUSTCDT to a */ | 1
2 |/* stream file in the QNetWare file system. It uses Integrated File System APIs to */ | 2
3 |/* create and write the file. It converts the data from CCSID 37 */ | 3
4 |/* to ASCII codepage 850 using the QTQICONV system API. */ | 4
5 | | 5
6 |#include &lt;stdio.h&gt; | 6
7 |#include &lt;recio.h&gt; | 7
8 |#include &lt;stdlib.h&gt; | 8
9 |#include &lt;string.h&gt; | 9
10 |#include &lt;decimal.h&gt; | 10
11 |#include &lt;fcntl.h&gt; | 11
12 |#include &lt;unistd.h&gt; | 12
13 |#include &lt;qtqiconv.h&gt; | 13
14 | | 14
15 |/* Include the external definition of the database file CUSTCDT. */ | 15
16 | | 16
17 |#pragma mapinc("custmf","CUSTCDT(cusrec)","input","_P") | 17
18 |#include "custmf" | 18
1 |/* ------------------------------------------------------------------------*/ | 19 19
2 |/* PHYSICAL FILE: DATALIB/CUSTCDT */ | 20 19
3 |/* FILE CREATION DATE: 94/08/22 */ | 21 19
4 |/* RECORD FORMAT: CUSREC */ | 22 19
5 |/* FORMAT LEVEL IDENTIFIER: 39C301DBCB10B */ | 23 19
6 |/* ------------------------------------------------------------------------*/ | 24 19
7 |typedef _Packed struct { | 25 19
8 | decimal( 6, 0) CUSNUM; /* Customer number */ | 26 19
9 | /* PACKED SPECIFIED IN DDS */ | 27 19
10 | char LSTNAM[8]; /* Last name */ | 28 19
11 | char INIT[3]; /* First/middle initial */ | 29 19
12 | char STREET[13]; /* Street address */ | 30 19
13 | char CITY[6]; /* City */ | 31 19
14 | char STATE[2]; /* State abbreviation */ | 32 19
15 | decimal( 5, 0) ZIPCOD; /* Zip code */ | 33 19
16 | /* PACKED SPECIFIED IN DDS */ | 34 19
17 | decimal( 4, 0) CDTLMT; /* Credit limit */ | 35 19
18 | /* PACKED SPECIFIED IN DDS */ | 36 19
19 | decimal( 1, 0) CHGCOD; /* Charge code */ | 37 19
20 | /* PACKED SPECIFIED IN DDS */ | 38 19
21 | decimal( 6, 2) BALDUE; /* Balance due */ | 39 19
22 | /* PACKED SPECIFIED IN DDS */ | 40 19
23 | decimal( 6, 2) CDTDUE; /* Credit due */ | 41 19
24 | /* PACKED SPECIFIED IN DDS */ | 42 19
25 |}DATALIB_CUSTCDT_CUSREC_i_t; | 43 19
26 | | 44 19
19 |#define _RCDLEN 100 | 45
20 | | 46
21 |int main(void) | 47
22 |{ | 48
23 | /* Declare rcd, dta of data structure type DATALIB_CUSTCDT_CUSREC_i_t. */ | 49
24 | /* The data structure type was defined from the DDS specified. */ | 50
25 | | 51
26 | DATALIB_CUSTCDT_CUSREC_i_t rcd, *dta = &amp;rcd; | 52
27 | _RFILE *in; | 53
28 | _RIOFB_T *fb; | 54
29 | char dbrcd[_RCDLEN]; | 55
30 | char stmrcd[_RCDLEN]; | 56
31 | char *dbfile = "CUSTCDT"; | 57
32 | char *stmfile = "QNetWare/SERVER.SVR/VOLUME/DATA/CUST.DAT"; | 58
33 | int fildes, stmlen; | 59
34 | | 60</pre>
<pre class="xmp"> 35 | /* Declare necessary variables for code conversion CCSID 37 to 850. */ | 61
36 | | 62
37 | char fromcode[32] = "IBMCCSID000370000000"; | 63
38 | char tocode[32] = "IBMCCSID00850"; | 64
39 | char *ibuf, *obuf; | 65
40 | iconv_t cd; | 66
41 | size_t ilen, olen; | 67
42 | | 68
43 | /* Open and create the stream file using the open() Integrated File System API. */ | 69
44 | | 70
45 1 | fildes = open( stmfile, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU ); <span><span class="refkey">&nbsp;1&nbsp;</span></span> | 71
46 2 | if (fildes == -1) | 72
47 | { | 73
48 3 | printf ( "Open to stream file %s failed\n", stmfile ); | 74
49 4 | exit ( 1 ); | 75
50 | } | 76
51 | else | 77
52 | { | 78
53 | /* Open the database file for processing in arrival sequence. */ | 79
54 | | 80
55 5 | if (( in = _Ropen( dbfile, "rr, arrseq=Y" )) == NULL ) | 81
56 | { | 82
57 6 | printf ( "Open to database file %s failed\n", dbfile ); | 83
58 7 | exit ( 1 ); | 84
59 | } | 85
60 | else | 86
61 | { | 87
62 | /* Open a code conversion descriptor for CCSID 37 to 850 */ | 88
63 | /* conversion. */ | 89
64 | | 90
65 8 | cd = iconv_open( tocode, fromcode ); | 91
66 | | 92
67 9 | fb = _Rreadn( in, dta, in->buf_length, __DFT ); | 93
68 10 | while ( fb->num_bytes != EOF ) | 94
69 | { | 95
70 | /* Create the buffer for the stream file. Each field will be */ | 96
71 | /* separated by a comma. */ | 97
72 | | 98
73 11 | ilen = sprintf( dbrcd, "%D(6,0),", rcd.CUSNUM ); <span><span class="refkey">&nbsp;2&nbsp;</span></span> | 99
74 12 | ilen += sprintf( dbrcd+ilen, "%8.8s,", rcd.LSTNAM ); | 100
75 13 | ilen += sprintf( dbrcd+ilen, "%3.3s,", rcd.INIT ); | 101
76 14 | ilen += sprintf( dbrcd+ilen, "%13.13s,", rcd.STREET ); | 102
77 15 | ilen += sprintf( dbrcd+ilen, "%6.6s,", rcd.CITY ); | 103
78 16 | ilen += sprintf( dbrcd+ilen, "%2.2s,", rcd.STATE ); | 104
79 17 | ilen += sprintf( dbrcd+ilen, "%D(5,0),", rcd.ZIPCOD ); | 105
80 18 | ilen += sprintf( dbrcd+ilen, "%D(4,0),", rcd.CDTLMT ); | 106
81 19 | ilen += sprintf( dbrcd+ilen, "%D(1,0),", rcd.CHGCOD ); | 107
82 20 | ilen += sprintf( dbrcd+ilen, "%D(6,2),", rcd.BALDUE ); | 108
83 21 | ilen += sprintf( dbrcd+ilen, "%D(6,2)", rcd.CDTDUE ); | 109
84 | | 110
85 | /* Set pointers for CCSID 37 to CCSID 850 conversion. */ | 111
86 | /* Use the iconv() function to convert the data. */ | 112
87 | | 113
88 22 | stmlen = olen = ilen; | 114
89 23 | ibuf = &amp;dbrcd[0]; | 115
90 24 | obuf = &amp;stmrcd[0]; | 116
91 25 | iconv( cd, &amp;ibuf, &amp;ilen, &amp;obuf, &amp;olen ); <span><span class="refkey">&nbsp;3&nbsp;</span></span> | 117
92 | | 118
93 | /* Add ASCII carriage return and line feed. */ | 119
94 | | 120
95 26 | stmlen += sprintf( stmrcd+stmlen, "\15\12" ); <span><span class="refkey">&nbsp;4&nbsp;</span></span> | 121
96 | | 122</pre>
<pre class="xmp"> 97 | /* Write the buffer to the stream file using the Integrated File System write() API.*/ | 123
98 | | 124
99 27 | if (( write( fildes, stmrcd, stmlen )) == -1 ) <span><span class="refkey">&nbsp;5&nbsp;</span></span> | 125
100 | { | 126
101 28 | printf ( "Write to stream file %s failed\n", stmfile ); | 127
102 29 | exit ( 1 ); | 128
103 30 | }; | 129
104 31 | fb = _Rreadn( in, dta, in->buf_length, __DFT ); | 130
105 32 | }; | 131
106 33 | iconv_close( cd ); /* Close data conversion descriptor. */ | 132
107 34 | _Rclose( in ); /* Close the database file. */ | 133
108 35 | }; | 134
109 36 | close( fildes ); /* Close the streamfile. */ | 135
110 37 | }; | 136
111 |} | 137
* * * * * E N D O F S O U R C E * * * * *</pre></div>
<p><a href="rzaefqlspgmx.htm#ifsql22">Figure 3</a> shows the contents of the stream file CUST.DAT after
the NWCUST program has run and created it.</p><a id="idx241" name="idx241"></a><a id="idx242" name="idx242"></a><a id="idx243" name="idx243"></a><a id="idx244" name="idx244"></a><a id="idx245" name="idx245"></a><a id="idx246" name="idx246"></a>
<a name="ifsql22"></a>
<div class="fignone" id="ifsql22"><span class="figcap">Figure 3. Content of CUST.DAT from a for DOS or OS/2 TYPE command</span>
<pre class="screen">[C:\]type \\J:cust.dat
938472,Henning ,G K,4859 Elm Ave ,Dallas,TX,75217,5000,3,37.00,0.00
839283,Jones ,B D,21B NW 135 St,Clay ,NY,13041,400,1,100.00,0.00
392859,Vine ,S S,PO Box 79 ,Broton,VT,5046,700,1,439.00,0.00
938485,Johnson ,J A,3 Alpine Way ,Helen ,GA,30545,9999,2,3987.50,33.50
397267,Tyron ,W E,13 Myrtle Dr ,Hector,NY,14841,1000,1,0.00,0.00
389572,Stevens ,K L,208 Snow Pass,Denver,CO,80226,400,1,58.75,1.50
846283,Alison ,J S,787 Lake Dr ,Isle ,MN,56342,5000,3,10.00,0.00
475938,Doe ,J W,59 Archer Rd ,Sutter,CA,95685,700,2,250.00,100.00
693829,Thomas ,A N,3 Dove Circle,Casper,WY,82609,9999,2,0.00,0.00
593029,Williams,E D,485 SE 2 Ave ,Dallas,TX,75218,200,1,25.00,0.00
192837,Lee ,F L,5963 Oak St ,Hector,NY,14841,700,2,489.50,0.50
583990,Abraham ,M T,392 Mill St ,Isle ,MN,56342,9999,3,500.00,0.00
&nbsp;
[C:\]</pre><a id="idx247" name="idx247"></a></div>
<p>In this example, the J: drive was mapped to <tt class="xph">SERVER:VOLUME\DATA</tt> using the NetWare client.</p>
<p>Because the fields in CUST.DAT are separated by a comma, it is very easy
to incorporate the file into a spreadsheet application.</p>
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
</body>
</html>