$Hsh: Difference between revisions
(Automatically generated page update) |
m (more conversion cleanup) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<p>The $ | <p> | ||
The <var>$Hsh</var> function lets you convert a string into a hash value, which is a distinct numeric representation of a given string value. You can use <var>$Hsh</var> to build a memory-resident hash table to be used to join on keys without sorting and merging. </p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The format for the $ | <p> | ||
<p class=" | The format for the <var>$Hsh</var> function is:</p> | ||
<p class="syntax">%variable = $Hsh('string') | |||
</p> | </p> | ||
<p> | <p>Where:</p> | ||
<ul> | <ul> | ||
<li>%variable is a %variable within a | <li>%variable is a %variable within a SOUL procedure</li> | ||
<li>string is an alphanumeric string or a string referenced by a VALUE IN | <li>string is an alphanumeric string or a string referenced by a <var>VALUE IN</var> statement.</li> | ||
</li> | |||
</ul> | </ul> | ||
<b>Example</b> | <b>Example</b> | ||
<p>This example is continued on the next page:</p> | <p>This example is continued on the next page:</p> | ||
Line 47: | Line 50: | ||
<b></b>* | <b></b>* | ||
%IDX = $MOD($HSH(%CUST_REC:NAME),500) | %IDX = $MOD($HSH(%CUST_REC:NAME),500) | ||
IF %CUST_ARRAY:NAME(%IDX) EQ '' THEN | IF %CUST_ARRAY:NAME(%IDX) EQ <nowiki>''</nowiki> THEN | ||
%CUST_ARRAY:NAME(%IDX) = %CUST_REC:NAME | %CUST_ARRAY:NAME(%IDX) = %CUST_REC:NAME | ||
%CUST_ARRAY:RATE(%IDX) = %CUST_REC:RATE | %CUST_ARRAY:RATE(%IDX) = %CUST_REC:RATE | ||
Line 57: | Line 60: | ||
FOR %RETRY FROM 1 TO 5 | FOR %RETRY FROM 1 TO 5 | ||
%IDX = $MOD($HSH(%IDX),500) | %IDX = $MOD($HSH(%IDX),500) | ||
IF %CUST_ARRAY:NAME(%IDX) EQ '' THEN | IF %CUST_ARRAY:NAME(%IDX) EQ <nowiki>''</nowiki> THEN | ||
%CUST_ARRAY:NAME(%IDX) = %CUST_REC:NAME | %CUST_ARRAY:NAME(%IDX) = %CUST_REC:NAME | ||
%CUST_ARRAY:RATE(%IDX) = %CUST_REC:RATE | %CUST_ARRAY:RATE(%IDX) = %CUST_REC:RATE | ||
Line 98: | Line 101: | ||
END | END | ||
</p> | </p> | ||
[[Category:SOUL $functions]] | [[Category:SOUL $functions]] |
Latest revision as of 19:17, 13 January 2015
The $Hsh function lets you convert a string into a hash value, which is a distinct numeric representation of a given string value. You can use $Hsh to build a memory-resident hash table to be used to join on keys without sorting and merging.
Syntax
The format for the $Hsh function is:
%variable = $Hsh('string')
Where:
- %variable is a %variable within a SOUL procedure
- string is an alphanumeric string or a string referenced by a VALUE IN statement.
Example
This example is continued on the next page:
BEGIN * * INPUT CUSTOMER CONTROL DATA IMAGE: * IMAGE CUST_REC NAME IS STRING LEN 20 RATE IS STRING LEN 8 DISCOUNT IS STRING LEN 8 END IMAGE * * MEMORY-RESIDENT HASH TABLE ARRAY: * IMAGE CUST_ARRAY ARRAY OCCURS 500 NAME IS STRING LEN 20 RATE IS FLOAT DISCOUNT IS FLOAT END ARRAY END IMAGE * PREPARE IMAGE CUST_REC PREPARE IMAGE CUST_ARRAY * * OPEN INPUT DATASET * OPEN DATASET CUSTINFO FOR INPUT * READ IMAGE CUST_REC FROM CUSTINFO REPEAT WHILE $STATUS = 0 * * INDEX INTO HASH TABLE IS REMAINDER OF HASH OF KEY / SIZE OF * TABLE * %IDX = $MOD($HSH(%CUST_REC:NAME),500) IF %CUST_ARRAY:NAME(%IDX) EQ '' THEN %CUST_ARRAY:NAME(%IDX) = %CUST_REC:NAME %CUST_ARRAY:RATE(%IDX) = %CUST_REC:RATE %CUST_ARRAY:DISCOUNT(%IDX) = %CUST_REC:DISCOUNT ELSE * * HAVE A HASH CONFLICT, RETRY A FINITE NUMBER OF TIMES * FOR %RETRY FROM 1 TO 5 %IDX = $MOD($HSH(%IDX),500) IF %CUST_ARRAY:NAME(%IDX) EQ '' THEN %CUST_ARRAY:NAME(%IDX) = %CUST_REC:NAME %CUST_ARRAY:RATE(%IDX) = %CUST_REC:RATE %CUST_ARRAY:DISCOUNT(%IDX) = %CUST_REC:DISCOUNT JUMP TO READNEXT END IF END FOR PRINT 'MAKE THE HASH TABLE LARGER TO AVOID CONFLICTS' STOP END IF READNEXT: READ IMAGE CUST_REC FROM CUSTINFO END REPEAT * * NOW FIND ORDER RECORDS, NO NEED TO SORT * FDORD: IN ORDERS FIND ALL RECORDS WHERE - ORD DATE IS NUM IN RANGE FROM 89120 TO 89150 STATUS = 'SHIPPED' END FIND FORORD: FOR EACH RECORD IN FDORD %IDX = $MOD($HSH(CUST NAME)) IF %CUST_ARRAY:NAME(%IDX) EQ CUST NAME THEN CALL PRINT_INVOICE ELSE * * HAVE A HASH CONFLICT, RETRY A FINITE NUMBER OF TIMES * FOR %RETRY FROM 1 TO 5 %IDX = $MOD($HSH(%IDX),500) IF %CUST_ARRAY:NAME(%IDX) EQ CUST NAME THEN CALL PRINT_INVOICE JUMP TO NEXTREC END IF END FOR PRINT 'CUSTOMER NAME NOT FOUND =' AND CUST NAME NEXTREC: END FOR END