News
Abstract
Information about the PTFs to provide the enhancement for ILE RPG to support built-in functions %LEFT and %RIGHT.
Content
You are in: RPG Cafe Fall 2023: Built-in functions %LEFT and %RIGHT
Short URL: https://ibm.biz/rpgcafe_fall_2023_bifs_left_right
Fall 2023: Built-in functions %LEFT and %RIGHT
- %LEFT: Return the leftmost characters in a string
- %RIGHT: Return the rightmost characters in a string
Details
%LEFT
Built-in function %LEFT(parameter_name) returns the leftmost characters in a string.
dcl-s string char(10) inz('abcdefghij'); dcl-s string2 varchar(10); string2 = %LEFT(string : 3); // string2 = "abc"
%RIGHT
Built-in function %RIGHT(parameter_name) returns the rightmost characters in a string.
dcl-s string char(10) inz('abcdefghij'); dcl-s string2 varchar(10); string2 = %RIGHT(string : 3); // string2 = "hij"
Using %LEFT and %RIGHT where characters have different sizes, such as for UTF-8 data.
When the data can have characters with different lengths, the CHARCOUNT mode is important. See https://www.ibm.com/docs/en/ssw_ibm_i_75/rzasd/charcount.htm for information about how to set the CHARCOUNT mode for a statement or an individual built-in function.
When your statement is in natural mode, the second parameter represents the number of characters, which can be different from the number of bytes or the number of double bytes for UTF-16 data.
When your statement is in standard-character-size mode, the second parameter represents the number of bytes or double-bytes.
In the following example, UTF-8 characters 'á', 'ç', and 'ë' have two bytes and characters 'b' and 'd' have one byte. Assume this code defaults to standard mode, so the second parameter represents the number of bytes or double-bytes.
- The built-in function returns the leftmost 3 bytes, which represent the two UTF-8 characters "áb".
- The built-in function returns the rightmost 3 bytes, which represent the two UTF-8 characters "dë".
- The built-in function returns the leftmost 3 characters, which represent the two UTF-8 characters "ábç".
- The built-in function returns the rightmost 3 characters, which represent the two UTF-8 characters "çdë".
dcl-s string varchar(10) ccsid(*utf8) inz('ábçdë'); dcl-s string2 varchar(10) ccsid(*utf8); string2 = %LEFT(string : 3); // 1. STDCHARSIZE mode, 3 bytes // string2 = "áb" string2 = %RIGHT(string : 3); // 2. STDCHARSIZE mode, 3 bytes // string2 = "dë" string2 = %LEFT(string : 3 : *NATURAL); // 3. NATURAL mode, 3 characters // string2 = "ábc" string2 = %RIGHT(string : 3 : *NATURAL); // 4. NATURAL mode, 3 characters // string2 = "çdë"
. .
. .
PTFs for 7.4, and 7.5
7.4:
- ILE RPG compiler: 5770WDS SI84886
7.5:
- ILE RPG compiler: 5770WDS SI85009
- ILE RPG compiler, TGTRLS(V7R4M0): 5770WDS SI85043
The PTFs are also available with Db2 for i Fix Packs. See Db2 for IBM i 2023 PTF Group Schedule.
RDi support
A later update for RDi will support these enhancements.
Documentation
The 7.4, and 7.5 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.4", or "What's new since 7.5" section in the Reference.
- What's new since 7.4? https://www.ibm.com/docs/en/ssw_ibm_i_74/rzasl/rpgrelv7r4post.htm
- What's new since 7.5? https://www.ibm.com/docs/en/ssw_ibm_i_75/rzasl/rpgrelv7r5post.htm
Was this topic helpful?
Document Information
Modified date:
02 November 2023
UID
ibm17047134