ibm-information-center/dist/eclipse/plugins/i5OS.ic.apiref_5.4.0.1/apiexscapat.htm

215 lines
11 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 lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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="DC.Type" content="reference" />
<meta name="DC.Title" content="Examples: Scanning string patterns" />
<meta name="abstract" content="These examples use the QCLSCAN API. A typical use of the QCLSCAN API is to allow the work station user to retrieve all records that contain a specified pattern." />
<meta name="description" content="These examples use the QCLSCAN API. A typical use of the QCLSCAN API is to allow the work station user to retrieve all records that contain a specified pattern." />
<meta name="DC.Relation" scheme="URI" content="apiexmp.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="apiexscapat" />
<meta name="DC.Language" 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. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Examples: Scanning string patterns</title>
</head>
<body id="apiexscapat"><a name="apiexscapat"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Examples: Scanning string patterns</h1>
<div><p>These examples use the QCLSCAN API. A typical use
of the QCLSCAN API is to allow the work station user to retrieve all records
that contain a specified pattern.</p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code license and disclaimer information</a> for important
legal information.</div>
</div>
<div class="section"><h4 class="sectiontitle">Example 1</h4><p>Assume a 20-character database field containing
only uppercase characters and the pattern 'ABC' is scanned for. The user program
calls the QCLSCAN API for each database record read. The parameters would
be as follows:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr><th valign="top" id="d0e29">Field Name</th>
<th valign="top" id="d0e31">Result</th>
</tr>
</thead>
<tbody><tr><td valign="top" headers="d0e29 "><em>STRING</em></td>
<td valign="top" headers="d0e31 ">The 20-byte field to be scanned</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>STRLEN</em></td>
<td valign="top" headers="d0e31 ">20</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>STRPOS</em></td>
<td valign="top" headers="d0e31 ">1</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>PATTERN</em></td>
<td valign="top" headers="d0e31 ">'ABC'</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>PATLEN</em></td>
<td valign="top" headers="d0e31 ">3</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>TRANSLATE</em></td>
<td valign="top" headers="d0e31 ">'0'</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>TRIM</em></td>
<td valign="top" headers="d0e31 ">'0'</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>WILD</em></td>
<td valign="top" headers="d0e31 ">' '</td>
</tr>
<tr><td valign="top" headers="d0e29 "><em>RESULT</em></td>
<td valign="top" headers="d0e31 ">A value returned to your program</td>
</tr>
</tbody>
</table>
</div>
<p>The following describes some fields and the results of the scan:</p>
<pre>Scan String Result Comments
1 ABCDEFGHIJKLMNOPQRST 001
2 XXXXABCXXXXXXXXXXXXX 005
3 abcXXXXXXXXXXXXXXXXX 000 Translation not requested
4 XXXABCXXXXXABCXXXXXX 004 First occurrence found; see note
5 ABABABABBCACCBACBABA 000 Not found
6 ABABABCABCABCABCABCA 005</pre>
<div class="note"><span class="notetitle">Note:</span> In scan 4, the string has two places where the pattern could
have been found. Since the STRPOS value is 1, the first value (position 004)
was found. If the value of STRPOS had been 4, the result would still have
been 004. If the STRPOS value had been in a range of 5 through 12, the result
would have been 012.</div>
</div>
<div class="section"><h4 class="sectiontitle">Example 2</h4><p>Assume a 25-character database field containing
only uppercase characters and a user program that will prompt for the pattern
to be scanned, which will not exceed 10 characters. The work station user
is allowed to enter 1 through 10 characters to search with and trailing blanks
will be trimmed from the pattern. The program would call the QCLSCAN program
for each database record read. The program parameters would be as follows:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr><th valign="top" id="d0e105">Field Name</th>
<th valign="top" id="d0e107">Result</th>
</tr>
</thead>
<tbody><tr><td valign="top" headers="d0e105 "><em>STRING</em></td>
<td valign="top" headers="d0e107 ">The 25-byte field to be scanned</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>STRLEN</em></td>
<td valign="top" headers="d0e107 ">25</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>STRPOS</em></td>
<td valign="top" headers="d0e107 ">1</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>PATTERN</em></td>
<td valign="top" headers="d0e107 ">Varies</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>PATLEN</em></td>
<td valign="top" headers="d0e107 ">10</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>TRANSLATE</em></td>
<td valign="top" headers="d0e107 ">'0'</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>TRIM</em></td>
<td valign="top" headers="d0e107 ">'1'</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>WILD</em></td>
<td valign="top" headers="d0e107 ">' '</td>
</tr>
<tr><td valign="top" headers="d0e105 "><em>RESULT</em></td>
<td valign="top" headers="d0e107 ">A value returned to your program</td>
</tr>
</tbody>
</table>
</div>
<p>The following describes some fields and the results of the scan:</p>
<pre>Scan String Pattern Result Comments
1 ABCDEFGHIJKLMNOPQRSTUVWXY 'CDE ' 003
2 ABCDEFGHIJKLMNOPQRSTUVWXY 'CDEFGH ' 003
3 ABCDEFGHIJKLMNOPQRSTUVWXY 'CDEFGHIJKL ' 003
4 XXXXABCXXXXXXXXXXXXXXXXXX 'ABCD ' 000 Not found
5 abcXXXXXXXXXXXXXXXXXXXXXX 'ABC ' 000 Not translated
6 ABCXXXXXABC EXXXXXXXXXXXX 'ABC E ' 009
7 XXXABCXXXXXABCXXXXXXXXXXX 'ABC ' 004 See note</pre>
<div class="note"><span class="notetitle">Note:</span> In scan 7, the string has two places where the pattern could
be found. Since the STRPOS value is 1, only the first value (position 004)
is found. If the value of STRPOS were 4, the result would still be 004. If
the STRPOS value were in the range of 5 through 12, the result would be 012.</div>
</div>
<div class="section"><h4 class="sectiontitle">Example 3</h4><p>Assume a 25-character database field containing
either uppercase or lowercase characters. The user program prompts for the
pattern to be scanned, which does not exceed 5 characters. The work station
user can enter 1 through 5 characters to be found. The system trims trailing
blanks from the pattern. If the user enters an asterisk (*) in the pattern,
the asterisk is handled as a wild character. The program calls the QCLSCAN
program for each database record read. The parameters are as follows:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr><th valign="top" id="d0e181">Field Name</th>
<th valign="top" id="d0e183">Result</th>
</tr>
</thead>
<tbody><tr><td valign="top" headers="d0e181 "><em>STRING</em></td>
<td valign="top" headers="d0e183 ">The 25-byte field to be scanned</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>STRLEN</em></td>
<td valign="top" headers="d0e183 ">25</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>STRPOS</em></td>
<td valign="top" headers="d0e183 ">1</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>PATTERN</em></td>
<td valign="top" headers="d0e183 ">Varies</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>PATLEN</em></td>
<td valign="top" headers="d0e183 ">5</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>TRANSLATE</em></td>
<td valign="top" headers="d0e183 ">'1' (See note 1)</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>TRIM</em></td>
<td valign="top" headers="d0e183 ">'1'</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>WILD</em></td>
<td valign="top" headers="d0e183 ">'*'</td>
</tr>
<tr><td valign="top" headers="d0e181 "><em>RESULT</em></td>
<td valign="top" headers="d0e183 ">A value returned to your program</td>
</tr>
</tbody>
</table>
</div>
<p>The following describes some fields and the results of the scan:</p>
<pre>Scan String Pattern Result Comments
1 ABCDEFGHIJKLMNOPQRSTUVWXY 'CDE ' 003
2 ABCDEFGHIJKLMNOPQRSTUVWXY 'C*E ' 003
3 abcdefghijklmnopqrstuvwxy 'C***G ' 003 See note 1
4 abcdefghijklmnopqrstuvwxy 'ABCD ' 001
5 abcXXXXXXXXXXXXXXXXXXXXXX 'C*E ' 000 Not found
6 XXXAbcXXXXXabcXXXXXXXXXXX 'ABC ' 004 See note 2
7 ABCDEFGHIJKLMNOPQRSTUVWXY '*BC ' -003 See note 3
8 ABCDEFGHIJKLMNOPQRSTUVWXY ' ' -004 See note 4</pre>
<div class="note"><span class="notetitle">Notes:</span> </div>
<ol><li>When field translation is specified (the TRANSLATE parameter is specified
as '1'), the string is translated to uppercase characters before scanning
occurs; the data in the string is not changed.</li>
<li>In scan 6, the string has two places where the pattern could have been
found. Since the STRPOS value is 1, the first value (position 004) was found.</li>
<li>In scan 7, the wild character (*) is the first character in the trimmed
pattern. Wild characters cannot be the first character in a pattern.</li>
<li>In scan 8, the trimmed pattern is blank.</li>
</ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apiexmp.htm" title="Contains example programs that use APIs and exit programs.">Examples: APIs</a></div>
</div>
</div>
</body>
</html>