PeopleCode Built-in Functions and Language Constructs: H
The PeopleCode built-In functions and language constructs beginning with the letter H are listed in alphabetical order within this topic.
Syntax
Hash(cleartext_string)
Description
Use the Hash function to generate a hashed string that is always 28 characters in length. The input is variable length, with no maximum size.
Regardless of the operating system platform, underlying character encoding, or hardware byte order, identical character strings always generate identical hash values regardless of the platform on which the hash generation is run. Because of this, hash output should not be used as a unique key to a table of data. Given the output of hash, it is impossible to determine the input.
Some of the original data is deliberately lost during the conversion process. This way, even if you know the algorithm, you can't “un-hash” the data.
Generally the Hash function is used like a checksum—for example, to compare hashed values to ensure they match.
Parameters
Field or Control |
Definition |
---|---|
cleartext_string |
Specifies the string, such as a password, to be hashed. |
Returns
A hash string.
Example
MessageBox("Please confirm password");
&HASHPW = Hash(&PASSWD);
&OPERPSWD = USERDEFN.OPERPSWD.Value;
If not (&HASHPW = &OPERPSWD) Then
/* do error handling */
End-if;
Syntax
HashSHA256(cleartext_string)
Description
Use the HashSHA256 function to generate a hashed string that is always 44 characters in length. The input is variable length, with no maximum size.
Generally the HashSHA256 function is used like a checksum—for example, to compare hashed values to ensure they match.
Parameters
Field or Control |
Definition |
---|---|
cleartext_string |
Specifies the string, such as a password, to be hashed. |
Returns
A hash string.
Example
&HASHVALUE = HashSHA256(&newtext);
&HASHPRIOR = REC.STOREDHASH.Value;
If Not (&HASHVALUE = &HASHPRIOR) Then
/* do error handling */
End-If;
Syntax
HashWithSalt(cleartext_string [, &salt_string] [, hash_type] [, disallow_emptystring])
Description
Use the HashWithSalt function to generate a hashed (or “salted”) string. The output is Base64 encoded. For example, use the HashWithSalt function to generate a password for storage in the database. Because the HashWithSalt function generates output from the clear text password and a randomly generated salt value, it provides more secure hashing than the Hash function.
Important! When you store a hashed password generated by HashWithSalt in PSOPRDEFN.OPERPSWD, you must also store the salt string used in PSOPRDEFN.OPERPSWDSALT.
To compare a clear text input value with an hashed value, use either the VerifyOprPassword function (for hashed and stored passwords) or the VerifyHash function for other salted strings.
Parameters
Field or Control |
Definition |
---|---|
cleartext_string |
Specifies the string, such as a password, to be hashed. |
&salt_string |
Specifies the randomly generated salt value as a string value. Important! If the supplied salt value is a null value, then the HashWithSalt function will generate a salt value that will be returned as the value of this variable or record field. |
hash_type |
Specifies the hashing algorithm to be used as a quoted literal string:
|
disallow_emptystring |
Specifies a Boolean value indicating whether to disallow an empty string as the text to be hashed. Note: The default value is False. |
Returns
A String value.
Examples
The following examples demonstrate three methods for generating and storing a hashed password:
Method 1 – Presents a loop that could process a series of passwords. In this specific case, only one salt value is generated and the loop is executed once only. Because SecureRandomGen is based on the Java security SecureRandom function, it is more efficient to call it once to return an array of required salt values than it is to call it for each salt value required.
/* method 1 */ Local array of string &operpwsdsalt; Local string &resultSalt; &operpwsdsalt = SecureRandomGen(); If (&operpwsdsalt <> Null) Then For &i = 1 To &operpwsdsalt.Len &resultSalt = &operpwsdsalt [&i]; &pswd = HashWithSalt(&OPRPSWD, &operpwsdsalt [&i]); PSOPRDEFN.OPERPSWD = &pswd; PSOPRDEFN.OPERPSWDSALT = &resultSalt; End-For; End-If;
Method 2 – Uses the &resultSalt variable as a salt value to generate the hashed password. When the &resultSalt variable is null, HashWithSalt generates a salt value, which in turn is automatically returned back to the variable. Both the hashed password and the salt value are stored together in the database.
/* method 2 */ Local string &resultSalt; &pswd = HashWithSalt(&OPRPSWD, &resultSalt); PSOPRDEFN.OPERPSWD = &pswd; PSOPRDEFN.OPERPSWDSALT = &resultSalt;
Method 3 – Uses the PSOPRDEFN.OPERPSWDSALT field as a salt value to generate the hashed password, which is then stored in the database. When PSOPRDEFN.OPERPSWDSALT is null, HashWithSalt generates a salt value, which in turn is automatically returned back to the PSOPRDEFN.OPERPSWDSALT field.
/* method 3 */ &pswd = HashWithSalt(&OPRPSWD, PSOPRDEFN.OPERPSWDSALT); PSOPRDEFN.OPERPSWD = &pswd;
Syntax
HermiteCubic(DataPoints)
Description
Use the HermiteCubic function to compute a set of interpolating equations for a set of at least three datapoints. This particular Hermitian cubic is designed to mimic a hand-drawn curve.
Parameters
Field or Control |
Definition |
---|---|
DataPoints |
This parameter takes an array of array of number. The array’s contents are an array of six numbers. The first two of these six numbers are the x and y points to be fit. The last four are the four coefficients to be returned from the function: a, b, c and d.a is the coefficient of the x0 term, b is the coefficient of the x1 term, c is the coefficient of the x2 term, and d is the coefficient of the x3 term. |
Returns
A modified array of array of numbers. The elements in the array correspond to the elements in the array used for DataPoints.
Syntax
Hide(scrollpath, target_row, [recordname.]fieldname)
where scrollpath is:
[RECORD.level1_recname, level1_row, [RECORD.level2_recname, level2_row, ]] RECORD.target_recname
To prevent ambiguous references, you can also use SCROLL.scrollname, where scrollname is the same as the scroll level’s primary record name.
Description
Use the Hide function to make a page field invisible.
Note: This function remains for backward compatibility only. Use the Visible field class property instead.
You can display the field again using Unhide, but Unhide has no effect on a field that has been made display-only in the page definition.
Gray, Hide, Ungray, and Unhide usually appear in RowInit programs that set up the initial display of data, and in FieldChange programs that change field display based on changes the user makes to a field. Generally, you put the functions on the same scroll level as the field that is being changed. This reduces the complexity of the function’s syntax to:
Hide(fieldname)
The more complex syntax can be used to loop through a scroll on a lower level than the PeopleCode program.
Note: This function shouldn't be used in any event prior to RowInit.
Parameters
Field or Control |
Definition |
---|---|
scrollpath |
A construction that specifies a scroll level in the component buffer. |
target_row |
An integer specifying the row on the target scroll level where the referenced buffer field is located. |
[recordname .]fieldname |
The name of the field to hide. The field can be on scroll level one, two, or three of the active page. The recordname prefix is required if the call to Hide is not on the record definition recordname |
Returns
Boolean (optional). Hide returns a Boolean value indicating whether it executed successfully.
Example
This example hides the page’s address fields if SAME_ADDRESS_EMPL is equal to "Y":
If SAME_ADDRESS_EMPL = "Y" Then
Hide(STREET1);
Hide(STREET2);
Hide(CITY);
Hide(STATE);
Hide(COUNTRY);
Hide(HOME_PHONE);
End-if;
Syntax
HideMenuItem(BARNAME.menubar_name, ITEMNAME.menuitem_name)
Description
Use the HideMenuItem function to hide a specified menu item. To apply this function to a pop-up menu, use the PrePopup Event of the field with which the pop-up menu is associated.
If you’re using this function with a pop-up menu associated with a page (not a field), the earliest event you can use is the PrePopup event for the first “real” field on the page (that is, the first field listed in the Order view of the page in Application Designer.)
When a menu is first displayed, all menus are visible by default, so there is no need for a function to re-display a menuitem that has been hidden.
Restrictions on Use With a Component Interface
This function is ignored (has no effect) when used by a PeopleCode program that’s been called by a Component Interface.
Parameters
Field or Control |
Definition |
---|---|
menubar_name |
Name of the menu bar that owns the menuitem, or, in the case of pop-up menus, the name of the pop-up menu that owns the menuitem. |
menuitem_name |
Name of the menu item. |
Returns
None.
Example
HideMenuItem(BARNAME.MYPOPUP1, ITEMNAME.DO_JOB_TRANSFER);
Syntax
HideRow(scrollpath) [, target_row])
Where scrollpath is:
[RECORD.level1_recname, level1_row, [RECORD.level2_recname, level2_row, ]] RECORD.target_recname
To prevent ambiguous references, you can also use SCROLL. scrollname, where scrollname is the same as the scroll level’s primary record name.
Description
Use the HideRow function to hide a row occurrence programmatically.
Note: This function remains for backward compatibility only. Use the Visible row class property instead.
It hides the specified row and any associated rows at lower scroll levels.
Hiding a row just makes the row invisible, it does not affect database processing such as inserting new rows, updating changed values, or deleting rows.
When you hide a row, it becomes the last row in the scroll or grid, and the other rows are renumbered accordingly. If you later use UnHideRow to make the row visible again, it is not moved back to its original position, but remains in its new position. When HideRow is used in a loop, you have to process rows from the highest number to the lowest to achieve the correct results.
Note: HideRow cannot be executed from the same scroll level as the row that is being hidden, or from a lower scroll level. Place the PeopleCode in a higher scroll level record.
Parameters
Field or Control |
Definition |
---|---|
scrollpath |
A construction that specifies a scroll level in the component buffer. |
target_row |
An integer specifying which row in the scroll to hide. If this parameter is omitted, the row on which the PeopleCode program is executing is assumed. |
Returns
Boolean (optional). HideRow returns a Boolean value indicating whether the function executed successfully.
Example
This example hides all rows in scroll level 1 where the EXPORT_SW field is equal to "Y". Note that the loop has to count backwards from ActiveRowCount to 1.
For &ROW = ActiveRowCount(RECORD.EXPORT_OBJECT) to 1
step - 1
&EXPORT_SW = FetchValue(EXPORT_OBJECT.EXPORT_SW, &ROW);
If &EXPORT_SW "Y" Then
HideRow(RECORD.EXPORT_OBJECT, &ROW);
Else
/* WinMessage("not hiding row " | &ROW);*/
End-if;
End-for;
Syntax
HideScroll(scrollpath)
Where scrollpath is:
[RECORD.level1_recname, level1_row, [RECORD.level2_recname, level2_row, ]] RECORD.target_recname
To prevent ambiguous references, you can also use SCROLL. scrollname, where scrollname is the same as the scroll level’s primary record name.
Description
Use the HideScroll function to programmatically hide a scroll bar and all data items within the scroll.
Note: This function remains for backward compatibility only. Use the HideAllRows rowset class method instead.
Typically this function is used in RowInit and FieldChange PeopleCode to modify the page based on user action.
Parameters
Field or Control |
Definition |
---|---|
scrollpath |
A construction that specifies a scroll level in the component buffer. |
Returns
HideScroll returns a Boolean value indicating whether the function executed successfully.
Example
This example, from RowInit PeopleCode, initializes the visibility of the scroll based on a field setting:
If %Component = COMPONENT.APPR_RULE Then
If APPR_AMT_SW = "N" Then
HideScroll(RECORD.APPR_RULE_LN, CurrentRowNumber(1), RECORD.APPR_RULE_DETL, CurrentRowNumber(2), RECORD.APPR_RULE_AMT);
Else
UnhideScroll(RECORD.APPR_RULE_LN, CurrentRowNumber(1), RECORD.APPR_RULE_DETL, CurrentRowNumber(2), RECORD.APPR_RULE_AMT);
End-If;
End-If;
The corresponding FieldChange PeopleCode dynamically changes the appearance of the page based on user changes to the APPR_AMT_SW field:
If APPR_AMT_SW = "N" Then
HideScroll(RECORD.APPR_RULEs_LN, CurrentRowNumber(1), RECORD.APPR_RULE_DETL, CurrentRowNumber(2), RECORD.APPR_RULE_AMT);
&AMT_ROWS = ActiveRowCount(RECORD.APPR_RULE_LN, CurrentRowNumber(1), RECORD.APPR_RULE_DETL, CurrentRowNumber(2), RECORD.APPR_RULE_AMT);
For &AMT_LOOP = &AMT_ROWS To 1 Step - 1
DeleteRow(RECORD.APPR_RULE_LN, CurrentRowNumber(1), RECORD.APPR_RULE_DETL, CurrentRowNumber(2), RECORD.APPR_RULE_AMT, &AMT_LOOP);
End-For;
Else
UnhideScroll(RECORD.APPR_RULE_LN, CurrentRowNumber(1), RECORD.APPR_RULE_DETL, CurrentRowNumber(2), RECORD.APPR_RULE_AMT);
End-If;
Syntax
HistVolatility(Closing_Prices, Trading_Days)
Description
Use the HistVolatility function to compute the historical volatility of a market-traded instrument.
Parameters
Field or Control |
Definition |
---|---|
Closing_Prices |
An array of number. The elements in this array contain a vector of closing prices for the instrument. |
Trading_Days |
The number of trading days in a year. |
Returns
A number.
Syntax
Hour(time_value)
Description
Use the Hour function to extract a Number value for the hour of the day based on a time or DateTime value. The value returned is a whole integer and is not rounded to the nearest hour.
Parameters
Field or Control |
Definition |
---|---|
time_value |
A DateTime or Time value. |
Returns
Returns a Number equal to a whole integer value from 0 to 23 representing the hour of the day.
Example
If &TIMEOUT contains a Time value equal to 04:59:59 PM, the following example sets &TIMEOUT_HOUR to 16:
&TIMEOUT_HOUR = Hour(&TIMEOUT);