News
Abstract
RPG enhancement delivered through PTFs in the fall of 2021. New built-in functions %MAXARR and %MINARR.
Content
You are in: RPG Cafe > RPG Cafe: Fall 2021: New built-in functions %MAXARR and %MIARR
Short URL: https://ibm.biz/rpgcafe_fall_2021_maxarr_minarr
New built-in functions %MAXARR and %MINARR
- %MAXARR: You can find the index of the maximum value in an array.
- %MINARR: You can find the index of the minimum value in an array.
Details
- Built-in function %MAXARR returns the index of the maximum value in the array.
- Built-in function %MINARR returns the index of the minimum value in the array.
If there is more than one element with the maximum or minimum value, the index of the first element with the maximum or minimum value is returned.
For an array data structure, you can also find the index of the array element with the maximum or minimum value of a subfield by using the keyed array data structure syntax. To find the element of DS_ARR with the maximum value of subfield SUBF, specify %MAXARR(DS_ARR(*).SUBF).
In the following example, %MAXARR is used to find the index of the maximum value in the array.
The result of %MAXARR is used to index the array.
array = %LIST('Jack' : 'Sally' : 'Alice'); maxValue = array(%MAXARR(array)); // maxValue = "Sally"
In the following example, %MINARR is used to find the index of the element of info with the minimum value of subfield quantity, for the elements between 1 and num_elems.
info(1).quantity = 5; info(2).quantity = 8; info(3).quantity = 2; info(4).quantity = 7; num_elems = 4; min_elem = %MINARR(info(*).quantity : 1 : num_elems); // min_elem = 3 dsply info(minimum_quantity).item; // displays "pineapple"
. .
. .
PTFs for 7.3 and 7.4, available in September 2021
7.3:
- ILE RPG compiler: 5770WDS SI77165
7.4:
- ILE RPG compiler: 5770WDS SI77166
- ILE RPG compiler, TGTRLS(V7R3M0): 5770WDS SI77167
The PTFs are also available with the Db2 for i Fix Packs. See Db2 for IBM i 2021 PTF Group Schedule.
Documentation
The 7.3 and 7.4 ILE RPG Reference and ILE RPG Programmer's Guide are updated with full information about these enhancements. Start at the "What's new since 7.3" or What's new since 7.4" section in the Reference.
- What's new since 7.3? https://www.ibm.com/docs/en/ssw_ibm_i_73/rzasd/rpgrelv7r3post.htm
- What's new since 7.4? https://www.ibm.com/docs/en/ssw_ibm_i_74/rzasd/rpgrelv7r4post.htm
Was this topic helpful?
Document Information
Modified date:
09 September 2021
UID
ibm16481909