IBM i e-Book
A Developer’s Guide to Mastering IBM i Concepts
IBM i Index
IBM i History and Overview
System Architecture
Development Tools
Deep Dive into DDS and DDL
Control Language (CL)
Report Program Generator (RPG)
Integrated Language Environment
SQL on IBM i
Jobs & Logs
RPG Built in Functions
- Char
- Check
- Date
- Diff
- Div
- Elem
- Eof
- Error
- Found
- List
- Lower
- Max
- Minutes
- Months
- Occur
- Open
- Parms
- Range
- Rem
- Scanrpl
- Sqrt
- Abs
- Checkr
- Days
- Dec
- Decpos
- Editc
- Equal
- Hours
- Inth
- Len
- Lookup
- Maxarr
- Min
- Minarr
- Replace
- Scan
- Scanr
- Seconds
- Size
- Split
- Status
- Subdt
- Subst
- Timestamp
- Trim
- Triml
- Trimr
- Uns
- Upper
- Xfoot
- Xlate
- Years
RPGLE Opcodes
- Z-add(H)
- Unlock
- Scan(E)
- Readpe
- Read
- Open
- Mult & Mult(H)
- Monitor
- Lookup
- LeaveSr
- Leave
- Exsr
- Do
- Cat
- Callp
- Callb
- Call
- BegSr
- Z-sub(H)
- Time
- Z-sub
- Z-add
- Xlate(E P)
- Xlate
- Xfoot
- Write
- When
- Update
- Subst(E P)
- Subdur
- Sorta
- Seton
- Setoff
- Setll
- Setgt
- Select
- Return
- Readp
- Reade
- Plist
- Parm
- Other
- Opcode Extender for File Operations
- On-Error
- Occur
- Mvr
- Movel
- Klist
- Kfld
- Iter
- In & Out
- IfXX
- If
- For
- Extrct
- Exfmt
- Except(Rpgle)/Excpt(Rpg)
- Eval(R)
- Eval (M)
- Eval
- Dump(A)
- Dsply
- DoW
- DoU
- Div
- Delete
- Define
- Comp
- Close
- Check(E)
- Chain
- Cat(P)
- Adddur
- Add(H)
- Add
RPG Built in Functions
Char
%CHAR converts the value of the expression from character, graphic, UCS-2, numeric, date, time or timestamp data to type character.
Syntax: %CHAR (expression)
Example:
**free Dcl-s Var1 Packed(8) Inz(123); Dcl-s date DATE Inz(D'2024-05-24'); Dcl-s Chr1 Char(20); Dcl-s Chr2 Char(20); Dcl-s Chr3 Char(30); Chr1 = 'Character Is ' + %Char(Var1); //Converting Decimal into Character Chr2 = 'Date is ' + %Char(date); //Converting Date into Character Chr3 = 'Current time is ' + %Char(%Time()); //Converting Current Time into Character dsply Chr1; // Character Is 123 dsply Chr2; // Date is 2024-05-24 dsply Chr3; // Current time is 06.10.53 *inlr = *on;
Result:
DSPLY Character Is 123 DSPLY Date is 2024-05-24 DSPLY Current time is 06.10.53
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Check
%CHECK returns the first position of the string in Factor 2 that contains a character that does not appear in string in Factor 1. If all of the characters in Factor 1 also appear in Factor 2, the function returns 0.
The check begins at the starting position and continues to the right until a character that is not contained in the comparator string is found. The starting position defaults to 1.
Syntax: %CHECK(comparator : base : start pos)
Example:
**free Dcl-s Char1 Char(1) Inz(' '); Dcl-s Char2 Char(20) Inz(' PROGRAMMERS.IO'); Dcl-s Pos Packed(2) Inz(0); Pos = %Check(Char1 : Char2); dsply Pos; // 3 *inlr = *on;
Result:
DSPLY 3
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Date
%DATE converts the value of the passed expression from character, numeric, or timestamp data to type date.
The first parameter is the value to be converted. If you do not specify a value, %DATE() will return the system date.
The second parameter denotes the date forma. Regardless of the input format, the output is returned in *ISO format.
Syntax: %DATE (Factor1 : Date Format)
Example:
**free Dcl-s Char1 Char(9) Inz('052324'); Dcl-s Char2 Char(30); Dcl-s Char3 Char(30); Char2 = 'Current Date Is ' + %Char(%Date()); //Extract the Current Date and Convert into character Char3 = 'Previous Day Date Is ' + %Char(%Date(Char1:*MDY0)); //Change the format of the passed date dsply Char2; // Current Date Is 2024-05-24 dsply Char3; // Previous Day Date Is 2024-05-23 And that’s how %DATE can be used to manipulate and display dates in A S 400 RPGLE programming. Stay tuned for more tutorials on A S 400 and RPGLE programming! *inlr = *on;
Result:
DSPLY Current Date Is 2024-05-24 DSPLY Previous Day Date Is 2024-05-23
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Diff
To find the difference between two date, time, or timestamp values, use the %DIFF function. The difference (duration) between two date or time data is generated by %DIFF. The types of the first and second parameters must be the same or compatible.
The combinations mentioned below can be used to obtain the difference:
- Differences between the two dates
- Difference between the two times
- Difference between two timestamps
- Difference between Date and timestamp (only the time portion of the timestamp)
- Difference between Time and timestamp (only the time portion of the timestamp)
The unit of evaluating for the difference is indicated by the third parameter. The units mentioned below are Valid:
- Difference between two dates or between a timestamp and a date: *DAYS, *MONTHS, *YEARS.
- *SECONDS, *MINUTES, *HOURS, for two times, or a time and a timestamp.
- The *MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, and *YEARS timestamps differ from each other.
Syntax: %DIFF(op1 : op2 : unit {: frac })
Example:
**free Dcl-s TIME1 TIME INZ(T'10.50.55'); Dcl-s TIME2 TIME INZ(T'09.49.55'); Dcl-s DATE1 DATE INZ(D'2024-12-25'); Dcl-s DATE2 DATE INZ(D'2024-10-05'); Dcl-s DAYSDIFF PACKED(2:0); Dcl-s TIMEDIFF PACKED(2:0); DAYSDIFF = %DIFF(DATE1 : DATE2 : *DAYS); // Extract the difference between two dates TIMEDIFF = %DIFF(TIME1 : TIME2 : *MINUTES); // Extract the difference between two times dsply DAYSDIFF; // 81 dsply TIMEDIFF; // 61 *inlr = *on;
Result:
DSPLY 81 DSPLY 61
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Div
The integer part of the quotient obtained by dividing operands n by m is returned by the function %DIV.
It is required that the two operands have decimal values with zero decimal places.
The result is packed numeric if the operand is either a zoned, packed, or binary numeric value. The result is an integer if either operand has an integer numeric value. If not, the outcome is an unsigned number.
Numerical operands that float are prohibited. If the operands are constants that can fit in 8-byte integers or unsigned fields, constant folding is applied to the built-in function.
In this scenario, the definition specifications can be used to code the built-in %DIV function.
Syntax: %DIV(n:m)
Example:
**free Dcl-s VAR1 PACKED(2:0) INZ(20); Dcl-s VAR2 PACKED(2:0) INZ(2); Dcl-s RESULT PACKED(2:0); RESULT = %DIV(VAR1 : VAR2); // Dividing the two numbers to get quotient. dsply RESULT; // 10 *inlr = *on;
Result:
DSPLY 10
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Elem
The %ELEM function can be used to get the total number of elements present in a table, array, or multiple-occurrence data structure.
Stated alternatively, this function allows us to get the dimension.
Syntax: %ELEM(table_name)
%ELEM(array_name)
%ELEM(multiple_occurrence_data_structure_name)
Example:
**free Dcl-s MyArray char(10) dim(5); Dcl-s NumElements int(10); MyArray(1) = 'S'; MyArray(2) = 'O'; MyArray(3) = 'V'; MyArray(4) = 'A'; MyArray(5) = 'N'; NumElements = %Elem(MyArray); // Getting the total number of elements present in a array = dsply ('Total Number Of Elements Are :' + %char(NumElements)); *inlr = *on;
Result:
DSPLY Total Number Of Elements Are :5
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Eof
When carrying out a file action equal to the resultant indicator, this built-in function is utilized to identify end-of-file, beginning-of-file, or subfile full situations.
Therefore, we only use %EOF to determine whether the file’s end has been reached rather than looking for any resulting indications.
%EOF returns ‘1’ if the whole condition of the end-of-file, beginning-of-file, or subfile is detected; if not, it returns ‘0’.
If the file ends, READ, READC, and READE return %EOF=*ON.
If the beginning of the file is reached, READP and READPE return %EOF=*ON. If a subfile detail record is provided with a subfile-full condition, the WRITE operation returns %EOF=*ON.
CHAIN operation on successful search sets %EOF=*OFF if %EOF=*ON and we execute the CHAIN operation.
In the event where %EOF=*ON occurs and a CHAIN operation is carried out, the successful search sets %EOF=*OFF.
On successful operations, SETGT, SETLL, OPEN, and %EOF=*OFF are set.
Syntax: %EOF(file_name)
Example:
**free Dcl-f TASK_PF USAGE(*input:*output) extfile(‘LIBBIF/TASK_PF); Ctl-Opt Option(*nodebugio:*srcstmt:*nounref); Dcl-s EndofFile ind; Open task_pf; Dow (1 = *on); Read Task_PF; EndOfFile = %EOF(TASK_PF); If (EndofFile); Leave; Else; Dsply ‘Record: ‘ + %trim(Task_PF.EMP_NAME) + ‘ ’ + %trim(Task_PF.EMP.NAME); Endif; Enddo; Close Task_PF; *Inlr =*On;
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Error
If an error condition was encountered during the most recent operation using the requested extender ‘E,’ then %ERROR returns ‘1.
This is equivalent to having the operation’s error indicator turned on. Before an operation with extender ‘E’ specified begins, %ERROR is set to return ‘0’ and remains unchanged following the operation if no error occurs.
The built-in function %ERROR can be set by any action that allows the use of an error indicator. The CALLP operation can also set %ERROR.
Example:
**free Dcl-f Cust Disk usage(*update:*output); Setll(E) 1 CustR; Exsr Err_Sub; Csname =’Smith’; Update(E) Custr; Exsr ERR_Sub; *Inlr =*On; Begsr Err_Sub; If %Error(); If %Status(Cust) = 1211; Open Cust; Elseif %Status(Cust) = 1211; Read(E) Cust; Csname =’Smith’; Update(E) Custr; Dsply ‘File Cust Will Be Updated Successfully.’; Endif; Endif; Endsr;
Result:
Dsply File Cust Will Be Updated Successfully.
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Found
If the most recent operation finds out a relevant or matching record, %FOUND returns ‘1’; however, an exact match is not assured.
In the event that no match is found, ‘0’ is returned.
Syntax: %FOUND{(file_name)}
Example:
**free Dcl-f Custs Disk(*EXT) Usage(*Input) Keyed; Chain Cust Custs; // Chaining the file with keyfield If %Found(Custs); // program is checking if matching value is found or not Eval a = 1; // if found , then doing some operation EndIf; *inlr = *on;
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
List
%LIST returns a temporary array whose elements have the values of the items listed in its operands.
%LIST can be used in calculation expressions wherever an array can be used except:
- SORTA
- %ELEM
- %LOOKUP
- %SUBARR
Syntax: %LIST(item1:item2:item3:item4…)
Example:
**Free Dcl-s colours varchar(20) dim(5); colours = %List('red':'blue':'green':'orange':'grey'); // loading the array using List function dsply colours(1); // red dsply colours(2); // blue dsply colours(3); // green dsply colours(4); // orange dsply colours(5); // grey *inlr = *on;
Result:
DSPLY red DSPLY blue DSPLY green DSPLY orange DSPLY grey
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Lower
Yields the string operand after it has been partially or fully converted to lowercase.
The string that needs to be changed from uppercase to lowercase is the first operand.
It may be UCS-2 or alphanumeric in type.
The conversion’s starting point is represented by the second operand.
Its value must be between one and the string’s length, and it must be a numeric expression with zero decimal places. It’s Optional.
The conversion begins at the first position in the string if it is not specified.
The length to be converted is the third operand. It must be less than or equal to the length of the string beginning at the start point, and it must be a numeric expression with zero decimal places. It might be zero. It’s not required.
Syntax: %LOWER(string {: start { : length } })
Example:
**free dcl-s str1 varchar(10); dcl-s str2 varucs2(10); dcl-s str3 varucs2(10); dcl-s string ucs2(5); str1 = %lower('HELLO'); // Transforming the string into Lower string = 'HELLO'; str2 = %lower(string:2); // Transforming the string to lower starting from 2nd position str3 = %lower('HELLO':2:3); // Transforming the string to lower starting from 2nd position and length of 3 dsply str1; // Hello dsply str2; // Hello dsply str3; // HellO *inlr = *on;
Result:
DSPLY hello DSPLY Hello DSPLY HellO
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Max
The maximum value of its operands is returned by %MAX.
The operands must all have data types that are compatible for comparison with each other.
In the case that one item in the list is alphanumeric, the others in the list may be graphic, UCS-2, or alphanumeric. The others can be packed as integers, unsigned integers, binary decimal, float, zoned numeric, or packed numeric if one is packed numeric.
Operands cannot include items of type object or procedure-pointer.
There must be at least two operands. There is no practical upper limit for the number of operands.
Syntax: %MAX(item1 : item2 {: item3 { item4 … } })
Example:
**free dcl-s Num1 zoned(2) Inz(60); dcl-s Num2 zoned(2) Inz(71); dcl-s Num3 zoned(2) Inz(88); dcl-s result zoned(2) ; result = %Max(Num1:Num2:Num3); // Comparing the numbers and extracting the Maximum number among them dsply result; // 88 *inlr = *on;
Result:
DSPLY 88
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Minutes
A number is converted to a duration (number of minutes) using %MINUTES. This duration can be used to increase or decrease the value of a time or timestamp. Thus, we may obtain any past or future time by using %MINUTES.
Syntax: %MINUTES(number)
Example:
**free dcl-s CurTime Time; dcl-s ResultTime Time; CurTime = %Time(); // Extracting current time dsply CurTime; ResultTime = CurTime + %Minutes(40); // adding 40 minutes with the current time dsply ResultTime; *inlr = *on;
Result:
DSPLY 09.35.21 DSPLY 10.15.21
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Months
%MONTHS converts a number into a duration that can be added to a date or timestamp value.
%MONTHS can only follow the plus or minus sign in an addition or subtraction expression. The value before the plus or minus sign must be a date or timestamp. The result is a date or timestamp value with the appropriate number of months added or subtracted. For a date, the resulting value is in *ISO format.
Example:
**free dcl-s CurDate Date; dcl-s ResultDate Date; CurDate = %Date(); // Extract Current Date dsply CurDate; // 2024-05-27 ResultDate = CurDate + %Months(3); // Add three months with the date dsply ResultDate; // 2024-08-27 *inlr = *on;
Result:
DSPLY 2024-05-27 DSPLY 2024-08-27
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Occur
%OCCUR gets or sets the current position of a multiple-occurrence data structure.
When this function is evaluated for its value, it returns the current occurrence number of the specified data structure. This is an unsigned numeric value.
When this function is specified on the left-hand side of an EVAL statement, the specified number becomes the current occurrence number. This must be a non-float numeric value with zero decimal places
Example:
**free dcl-ds mds Occurs(10) end-ds; dcl-s n zoned(2); n = %Occur(mds); dsply n; %Occur(mds) = 7; n = %Occur(mds); dsply n; *inlr = *on;
Result:
DSPLY 1 DSPLY 7
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Open
When a file is given and opened, %OPEN returns ‘1’. When a file is opened by the RPG module at initialization or through an OPEN operation and hasn’t been closed since, it’s referred to be “open”.
>The file is considered to be closed and %OPEN returns ‘0’ if it is dependent on an external indicator and that indicator was turned off during module initialization.
Syntax: %OPEN(file_name)
Example:
**free dcl-f Cust Disk Usage(*update:*output); If Not %Open(Cust); // Checking if the file is open or not Open Cust; // if the file is not open, then open the file EndIf; *inlr = *on;
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Parms
The number of parameters given to the procedure where %PARMS is used is returned by %PARMS. *PARMS and %PARMS are the same for the main procedure.
Example:
**Free Ctl-opt Dftactgrp(*no); DCALL# PR DPARMI 2 0 Value DPARMS 2 0 Value DPARMCNT S 2 0 INZ(*ZEROS) C CALLP CALL#(11:22) C SETON LR PCALL# B PCALL# PI DPARMI1 2 0 VALUE DPARMS2 2 0 VALUE C EVAl PARMCNT = %PARMS + PARMS2 + PARMI1 C PARMCNT DSPLY PCALL# E
Result:
DSPLY 35
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Range
The IN operator is used with %RANGE. %RANGE can only be specified by following the IN operator; it does not return a value.
The IN operator determines to see if the first operand is within the range given by %RANGE when it is used with %RANGE.
The expression using the IN operator with %RANGE is true if the first operand of the IN operator is greater than or equal to the first operand of %RANGE and less than or equal to the second operand of %RANGE.
An array cannot be the IN operator’s initial operand.
The operands of %RANGE must be able to be compared to each other and to the first operand of the IN operator.
Example:
**Free dcl-s Num1 zoned(4) Inz(5); If Num1 in %Range(10:50); // checking if the passed number is within the range dsply 'Number lies between 10 & 50'; // if not in the range, then show this message. Else; dsply 'Number Out Of Range'; // if in the range, then show this message EndIf; *inlr = *on;
Result:
DSPLY Number Out Of Range
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Rem
%REM returns the remainder that results from dividing operands n by m. The two operands must be numeric values with zero decimal positions.
If either operand is a packed, zoned, or binary numeric value, the result is packed numeric. If either operand is an integer numeric value, the result is integer. Otherwise, the result is unsigned numeric. Float numeric operands are not allowed. The result has the same sign as the dividend.
Syntax: %REM(n:m)
Example:
**Free Dcl-s num1 zoned(3) Inz(113); Dcl-s num2 zoned(3) Inz(22); Dcl-s Result zoned(3); Result = %rem(num1:num2); // Getting the remainder dsply Result; *inlr = *on;
Result:
DSPLY 3
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Scanrpl
All instances of the scan string in the source string are replaced with the replacement string, and the resultant string is returned by the %SCANRPL function.
Starting at the scan start position and continuing for the scan length is the search for the scan string.
The parts of the source string that are outside the range specified by the scan start position and the scan length are included in the result.
The first, second and third parameters must be of type character, graphic, or UCS-2. They may come in formats with variable lengths or set lengths.
Each of these factors needs to be CCSID and of the same type.
The starting position, expressed in characters, where the search for the scan string must begin is represented by the fourth argument. The start position is set to one by default if it is not given. The value could be anything from one to the source string’s current length.
The fifth parameter represents the number of characters in the source string to be scanned. If the parameter is not specified, the length defaults to remainder of the source string starting from the start position.
Syntax: %SCANRPL(scan string : replacement : source { : scan start { : scan length } )
Example:
**Free dcl-s Str1 Varchar(50) Inz; dcl-s Str2 Varchar(50) Inz; Str1 = 'This is SCANRPL BIF'; // assigning the string value dsply Str1; Str2 = %ScanRpl('BIF' : 'Built-in Function' : Str1); // scanning for first position of comparator and replacing with second parameter dsply Str2; // This is SCANRPL Built-in Function *inlr = *on;
Result:
DSPLY This is SCANRPL BIF DSPLY This is SCANRPL Built-in Function
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Sqrt
%SQRT returns the square root of the specified numeric expression. If the operand is of type float, the result is of type float; otherwise, the result is packed decimal numeric. If the parameter has a value less than zero, exception 00101 is issued.
Syntax: %SQRT(numeric expression)
**Free Dcl-s n zoned(10); n = %sqrt(239874); // Extracting the Square Root dsply ('Square Root Of 239874 Is ' + %Char(n)); *inlr = *on;
Result:
DSPLY Square Root Of 239874 Is 489
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Abs
The absolute value of the numeric expression specified as the parameter is returned by %ABS.
The value is returned unchanged if the numeric expression’s value is non-negative. To find the Absolute value (Positive value) of a numerical expression, use the %ABS function.
When we want the expression results to be positive, we can use the %ABS () function.
Syntax: %ABS (numeric expression)
Example:
**free Dcl-s Var1 Packed(8) Inz(-1); Dcl-s Var2 Int(10) Inz(-12345); Dcl-s Var3 Packed(8:3) Inz(-12345.678); Var1 = %Abs(Var1); Var2 = %Abs(Var2); Var3 = %Abs(Var3); dsply Var1; //1 dsply Var2; //12345 dsply Var3; //12345678 *inlr = *on;
Result:
DSPLY 1 DSPLY 12345 DSPLY 12345678
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Checkr
%CHECKR returns the last position of the string Factor1 that contains a character that does not appear in string Factor2. If all of the characters in Factor1 also appear in Factor2, the function returns 0.
The check begins at the reverse of the Factor2 and continues to the left until a character that is not contained in the Factor1 string is found. The starting position defaults to the end of the string.
Syntax: %CHECKR(comparator : base string {: Start position})
Example:
**free Dcl-s Char1 Char(1) Inz(' '); Dcl-s Char2 Char(20) Inz('PROGRAMMERS.IO '); Dcl-s Pos Packed(2) Inz(0); Pos = %Checkr(Char1 : Char2); //Checking for the non-existence of Space in the base string dsply Pos; // Returned Position is 14 *inlr = *on;
Result:
DSPLY 14
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Days
%DAYS converts a number into a duration that can be added to a date or timestamp value.
%DAYS can only follow the plus or minus sign in an addition or subtraction expression.
Syntax: %DAYS (NUMBER)
Example:
**free Dcl-s Curdate DATE ; Dcl-s nextdate DATE ; // Curdate Curdate = %DATE(); // Curdate content system current date Dsply Curdate ; // It will display current date ex 26.05.2024 Nextdate = Curdate + %Days(4) ; // Current date + 4 days Dsply nextdate; // Output 30.05.2024 *inlr = *on;
Result:
DSPLY 2024-05-26 DSPLY 2024-05-30
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Dec
%DEC converts the value of the first parameter to decimal (packed) format. It helps to convert Date into Decimal format.
Syntax: %DEC (FACTOR1 : LENGTH : DECIMAL PLACES)
%DEC(date time or timestamp expression {:format})
Example:
**Free Dcl-s Char1 Char(2) Inz('23'); Dcl-s Num1 Packed(2) ; Dcl-s Today Packed(8:0); Dcl-s TodayTime Packed(20:0); Num1 = 0 + %Dec(Char1:2:0) ; // Converting the character into Decimal dsply Num1; //23 Today = %dec(%date()); // Converting Today’s date into Decimal dsply Today; // 2024-05-28 TodayTime = %dec(%time()); // Converting Current time into Decimal dsply TodayTime; //81842 *inlr = *on;
Result:
DSPLY 23 DSPLY 20240528 DSPLY 81842
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Decpos
%DECPOS returns the number of decimal positions of the numeric variable or expression. The value returned is a constant, and so may participate in constant folding.
The numeric expression must not be a float variable or expression.
Syntax: %DECPOS(Numeric Expression)
Example:
**Free Dcl-s Num1 Packed(7:3) Inz(8236.567); Dcl-s Num2 Packed(9:5) Inz(23.73442); Dcl-s Result zoned(5); Result = %DECPOS(Num1); // This will return decimal position as 3 dsply Result; Result = %DECPOS(Num2); // This will return decimal position as 5 dsply Result; Result = %DECPOS(Num1 * Num2); // This will return decimal position as 8 dsply Result; *inlr = *on;
Result:
DSPLY 3 DSPLY 5 DSPLY 8
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Editc
Numerical values can be formatted with special characters such as asterisk (*), period (. ), comma (, ), cent sign (¢), pound sign (£), dollar sign ($), minus sign (-), credit sign (CR), etc. using the %EDITC function. To produce a date format, it can also be used to suppress zeros or format numbers with a slash (/).
Real-world scenarios frequently need us to provide reports with amount fields that look like $12,345.67-, $12,345.67CR, or ‘***12345.67-‘ rather than showing the amount as -12,345.67. We can use the %EDITC Function in such report production programs to generate the results we desire.
Syntax: %EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol})
Here, the input numeric value that we wish to change is the first parameter.
2nd parameter is the edit code option used to generate the required edited string.
Another format choice, the third parameter, is used to create the necessary manipulated string.
3rd parameter is an optional parameter.
Example:
**Free Dcl- s Num1 packed(7:0) INZ(0123456); Dcl- s Num2 packed(7:2) INZ(01234.56); Dcl- s Num3 packed(10:2) INZ(0123456.78); Dcl-s EditedNum1 Char(50); Dcl-s EditedNum2 Char(50); Dcl-s EditedNum3 Char(50); EditedNum1 = %EDITC(NUM1:’1’); EditedNum2 = %EDITC(NUM1:’2’); EditedNum3 = %EDITC(NUM1:’3’); Dsply EditedNum1; Dsply EditedNum2; Dsply EditedNum3; *INLR = *ON;
Result:
DSPLY 123,456 DSPLY 123,456 DSPLY 123456
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Equal
In addition to the two operation codes SETLL and LOOKUP, %EQUAL is used. It is used by the SETLL operation to indicate that it detected a record in the file with a key equal to that of the value specified in Factor 1.
Therefore, to verify that the record is present, we can use SETLL along with %EQUAL. For the SETLL operation, this function returns ‘1’ if a record is present whose key or relative record number is mentioned in factor-1.
If an element is found that exactly matches the element in factor-1, this method returns ‘1’ for the LOOKUP operation.
Syntax: %EQUAL(file_name);
Example:
**free Dcl-f Myfile ssage(*input) Extfile(‘MYFILE’) ; Dcl-s Srchkey Char(10) inz(‘srchkey ‘); Dcl-s Found ind; Setll Srchkey MYFILE; Found = %Equal(srchkey : MYFILE); IF Found; Read myfile; Else; Dsply (‘Record not found’); Endif; *Inlr =*On;
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Hours
A number is converted to a duration (number of hours) using %HOURS.
This duration can be used to increase or decrease the value of a time or timestamp.
Therefore, we may obtain any past or future time by using %HOURS.
Syntax: %HOURS(number)
Example:
**Free dcl-s CurTime Time; dcl-s ResTime Time; CurTime = %Time(); // Extracting Current Time dsply CurTime; ResTime = CurTime + %Hours(2); // Adding Two more hour with extracted current time dsply ResTime; *inlr = *on;
Result:
DSPLY 12.11.42 DSPLY 14.11.42
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Inth
%INTH and %INT are equivalent, with except that when converting an expression to an integer type, half of the expression’s value is adjusted if it is a decimal, float, or character value. No message is issued if half adjust cannot be performed.
Syntax: %INTH(numeric or character expression)
Example:
**Free dcl-s Var zoned(5) Inz(10); dcl-s Var1 zoned(5) Inz(20); dcl-s Result zoned(5); result = %inth(var); // Converting the Zoned variable to Integer dsply result; // 10 result = %inth(var1); // Converting the Zoned variable to Integer dsply result; // 20 *inlr = *on;
Result:
DSPLY 10 DSPLY 20
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Len
You can set the current length of a variable-length field, find the maximum length of a varying-length expression, or retrieve the length of a variable expression using %LEN.
A figurative constant cannot be the parameter.
Syntax: %LEN(expression) or %LEN(varying-length expression : *MAX)
Example:
**free Dcl-s Str1 Char(40) Inz('IBMI'); Dcl-s Str2 Char(30) Inz('PIO'); Dcl-s Num zoned(4) Inz(666); Dcl-s Output zoned(4); Output = %len(Str1); // Extracting the length of a string without trimming Dsply Output; // 40 Output = %len(%trim(Str2)); // Extract the length of a string after trimming Dsply Output; // 3 Output = %len(Num); // Extract the length of a Numeric field Dsply Output; // 4 *inlr = *on;
Result:
DSPLY 40 DSPLY 3 DSPLY 4
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Lookup
Lookup is used to look for an element in the array.
%LOOKUP will give you an exact match,
%LOOKUPLT will give you the value that is closest to search argument but less than search argument.
%LOOKUPLE will give you an exact match, or the value that is closest to arguement but less than arguement.
%LOOKUPGT will give you the value that is closest to arguement but greater than arguement.
%LOOKUPGE will give you An exact match, or the value that is closest to arguement but greater than arguement.
If no value matches the specified condition, zero is returned.
Syntax: %LOOKUP(Search Argument : Array {:Start_Index})
Example:
**free dcl-s n zoned(4); dcl-s arr char(10) dim(6) Ascend; // Declaring an Sequenced Array arr(1) = 'Bangalore'; arr(2) = 'Chennai'; arr(3) = 'Kolkata'; arr(4) = 'Mumbai'; arr(5) = 'Pune'; arr(6) = 'Ravet'; n = %lookup('Kolkata':arr) ; // Finding the index where search arguement is present in the array dsply n; // 3 n = %lookup('Chennai':arr:3); // Finding the index starting from 3rd element of the array ‘ dsply n; // 0 n = %lookuplt('kochin':arr); // Finding the index where the element is less than the search argument. dsply n; // 0 n = %lookupgt('Bombay':arr); // Finding the index where the element is greater than the search argument. dsply n; // 2 *inlr = *on;
Result:
DSPLY 3 DSPLY 0 DSPLY 0 DSPLY 2
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Maxarr
%MAXARR returns the index of the maximum value in the array, or the subsection of the array identified by the start-element operand and the number-of-elements operand.
Syntax: %MAXARR(array {: start-index {:number-of-elements}})
Example:
**free dcl-s Arr1 Char(10) Dim(5); dcl-s Chr1 Like(Arr1); Arr1 = %List('Kolkata':'Pune':'Bangalore':'Mumbai':'Chennai'); // Creating an array with List Built in Function Chr1 = Arr1(%MaxArr(Arr1)); // Extracting the maximum value from the array Dsply Chr1; // Pune *inlr = *on;
Result:
DSPLY Pune
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Min
The minimum value of its operands is returned by %MIN.
The operands must all have data types that are compatible for comparison with each other.
In the case that one item in the list is alphanumeric, the others in the list may be graphic, UCS-2, or alphanumeric. The others can be packed as integers, unsigned integers, binary decimal, float, zoned numeric, or packed numeric if one is packed numeric.
Operands cannot include items of type object or procedure-pointer.
There must be at least two operands. There is no practical upper limit for the number of operands.
Syntax: %MIN(item1 : item2 {: item3 { item4 … } })
Example:
**free dcl-s Num1 zoned(2) Inz(60); dcl-s Num2 zoned(2) Inz(71); dcl-s Num3 zoned(2) Inz(88); dcl-s result zoned(2) ; result = %MIN(Num1:Num2:Num3); // Extract the minimum value by comparing three numbers dsply result; *inlr = *on;
Result:
DSPLY 60
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Minarr
%MINARR returns the index of the maximum value in the array, or the subsection of the array identified by the start-element operand and the number-of-elements operand.
Syntax: %MINARR(array {: start-index {:number-of-elements}})
Example:
**free dcl-s Arr1 Char(10) Dim(5); dcl-s Chr1 Like(Arr1); Arr1 = %List('Kolkata':'Pune':'Bangalore':'Mumbai':'Chennai'); // Creating an array with %list BIF Chr1 = Arr1(%MINArr(Arr1)); // Extracting minimum value from array Dsply Chr1; *inlr = *on;
Result:
DSPLY Bangalore
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Replace
The segment of a string with the replacement string is used with the %REPLACE function.
Syntax: %REPLACE(replacement string: source string{:start position {:source length to replace}})
Example:
**Free Dcl-s Input Char(30) Inz('rpgle programming'); Dcl-s Output Char(30); dsply Input; // displaying the input string Output = %replace('RPGLE' : Input : 1 : 5); // Replacing a part of the input string dsply output; // RPGLE programming *inlr = *on;
Result:
DSPLY rpgle programming DSPLY RPGLE programming
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Scan
To determine the search argument’s first position in the source string, use the %SCAN function.
Position of the matching position is returned if a match is found; else, 0 is returned. The search element that is being looked up in the source string is the function’s first parameter.
The source string that we are searching in is the second parameter. The third parameter indicates the starting point for the search within the given string.
The type of the second argument should match with the first. These parameters may be UCS-2, graphic, or character-based.
Seek arguments or source String can contain blanks in form of string or string padded with blank. Those blanks are also taken into consideration when performing the search.
Syntax: %SCAN(search argument : source string {: start position {: length}})
Example:
**Free dcl-s Str1 Char(30) Inz('IBMI'); dcl-s Pos zoned(5); Pos = %Scan('I':Str1); // checking for the first position of the comparator dsply Str1; // IBMI dsply Pos; // 1 *inlr = *on;
Result:
DSPLY IBMI DSPLY 1
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Scanr
To determine the search argument’s first position in the source string from the reverse end, use the %SCANR function.
Position of the matching position is returned if a match is found; else, 0 is returned. The search element that is being looked up in the source string is the function’s first parameter.
The source string that we are searching in is the second parameter. The third parameter indicates the starting point for the search within the given string.
The type of the second argument should to match with the first. These parameters may be UCS-2, graphic, or character-based.
Seek arguments or source String can contain blanks in form of string or string padded with blank. Those blanks are also taken into consideration when performing the search.
Syntax: %SCANR(search argument : source string {: start position {: length}})
Example:
**Free dcl-s Str1 Char(30) Inz('Hello IBMI'); dcl-s Pos zoned(5); Pos = %ScanR('I':Str1); // checking the comparator’s existence from the reverse dsply Str1; dsply Pos; *inlr = *on;
Result:
DSPLY Hello IBMI DSPLY 10
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Seconds
To modify the duration of seconds in a time or timestamp, add a duration to the number using %SECONDS.
Syntax: %SECONDS(number)
Example:
**Free dcl-s CurTime Time; dcl-s ResTime Time; CurTime = %Time(); // extracting the current time dsply CurTime; ResTime = CurTime + %seconds(50); // adding 50 seconds to the current time dsply ResTime; *inlr = *on;
Result:
DSPLY 12.14.53 DSPLY 12.15.43
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Size
The number of bytes that the element occupies is returned by the %SIZE function.
A named constant, data structure, array, field, literal, etc. can all be used as arguments.
%SIZE returns full length for a field with a null value.
For an array or multiple occurrence data structure, the elements or occurrences size is additionally considered if *ALL is given as the second option for %SIZE.
Syntax:
%SIZE(variable)
%SIZE(array{:*ALL})
%SIZE(table{:*ALL})
%SIZE(multiple occurrence data structure{:*ALL})
Example:
**Free Dcl-s Var1 Packed(10); Dcl-s Var2 Zoned(10); Dcl-s Var3 Char(10); Dcl-s Result Packed(5); Result = %Size(Var1); // Check the No Of Bytes occupied by Packed Decimal dsply Result; // 6 Result = %Size(Var2); // Check the No Of Bytes occupied by Zoned Docimal dsply Result; // 10 Result = %Size(Var3); // Check the No Of Bytes occupied by Character dsply Result; // 10 *inlr = *on;
Result:
DSPLY 6 DSPLY 10 DSPLY 10
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Split
%SPLIT splits a string into an array of substrings. It returns a temporary array of the substrings.
%SPLIT can be used in calculation statements wherever an array can be used except:
- SORTA
- %ELEM
- %LOOKUP
- %SUBARR
The first operand is the string to be split. It can be alphanumeric, graphic, or UCS-2.
The second operand is the list of characters that indicate the end of each substring. It is optional. It must have the same type and CCSID as the first operand. If it is not specified, %SPLIT defaults to splitting at blanks. If the length of the second operand is greater than 1, any of the characters in the second operand indicate the end of each substring. For example, %SPLIT(‘abc.def-ghi’ : ‘.-‘) has two separator characters, ‘.’, and ‘-‘, so it returns an array with three elements: (‘abc’,’def’,’ghi’).
Syntax: %SPLIT(string {: separators })
**Free Dcl-s Arr1 Char(40) dim(3); Dcl-s ArrStr Char(40); ArrStr = 'This is Programmers.io'; // assigning the string Arr1 = %split(ArrStr:’ ‘); // splitting the string with space dsply Arr1(1); // This dsply Arr1(2); // is dsply Arr1(3); // Programmers.io *inlr = *on;
Result:
DSPLY This DSPLY is DSPLY Programmers.io
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Status
The program or file status’s most recent value is returned by the %STATUS function. %)STATUS is set anytime there is a change in the status of any file or program, usually as a result of an error.
The most recent program or file status update is returned if %STATUS is used without the optional file_name parameter. If a file is specified, the value contained in the INFDS *STATUS field for the specified file is returned. It is not necessary to specify the INFDS for the file.
%STATUS starts with a return value of 00000 and is reset to 00000 before any operation with a ‘E’ extender specified begins.
Syntax: %STATUS{(file_name)}
**Free Dcl-f Cust Disk usage(*update:*output); Setll(E) 1 CustR; Exsr Err_Sub; Csname = 'Paul'; Update(E) CustR; Exsr Err_Sub; *inlr = *on; BegSr Err_Sub; If %Error(); If %Status(Cust) = 1211; // This Status denotes that program attempted to read a file which was not open Open Cust; ElseIf %Status(Cust) = 1221; // This Status denotes that program attempted to update a file prior to read Read(E) Cust; Csname = 'Paul'; Update(E) CustR; Dsply 'File will be updated successfully'; EndIf; EndIf; EndSr; *inlr = *on;
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Subdt
A subset of the data in a date, time, or timestamp value is extracted using %SUBDT.
It returns an unsigned numeric value.
The date, time, or timestamp value is the first parameter.
The part you wish to extract is the second parameter.
Syntax: %SUBDT(value : unit { : digits { : decpos } })
**Free dcl-s Date1 Date Inz(D'2024-05-28'); dcl-s Time1 Time Inz(T'10.52.30'); dcl-s Result zoned(10); //Extract Month from Date Result = %Subdt(Date1:*Months); dsply Result; // 5 //Extract Year from Date Result = %Subdt(Date1:*Years); dsply Result; // 2024 //Extract Minutes from Time Result = %Subdt(Time1:*Minutes); dsply Result; // 52 *inlr = *on;
Result:
DSPLY 5 DSPLY 2024 DSPLY 52
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Subst
The string is partially extracted from any point using the %SUBST method. The source string, from which we wish to extract a portion of the string, is the first parameter in this case.
The beginning point from which we will begin the string extraction process is the second argument.
The length to extract is the third argument.
Syntax: %SUBST(string:start{:length})
**Free dcl-s Str1 Varchar(50) Inz('12345678'); dcl-s Output Varchar(50); dsply str1; // 12345678 Output = %subst(str1 : 1: 4); // Truncating the string from 1st position with length of 4 dsply Output; // 1234 *inlr = *on;
Result:
DSPLY 12345678 DSPLY 1234
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Timestamp
To convert a string into a timestamp data type, use the %TIMESTAMP method.
Syntax: %TIMESTAMP (value : *ISO | *ISO0 )
The input value that we wish to convert to a timestamp is the first parameter in this case.
The second option, which informs us of the input string’s timestamp format, can also be mentioned.
**Free Dcl-s CharTime Char(26) Inz('2024-05-30-14.53.50.012345'); Dcl-s CurTime Timestamp; CurTime = %TimeStamp(CharTime:*ISO); // Convert the Character to Timestamp dsply CurTime; CurTime = %TimeStamp(*Sys); // Convert the system date and time to Timestamp format dsply CurTime; CurTime = %TimeStamp(*Sys:1); // Show the fraction of seconds upto 1st positon dsply CurTime; CurTime = %TimeStamp(*Sys:2); // Show the fraction of seconds upto 2nd position. dsply CurTime; *inlr = *on;
Result:
DSPLY 2024-05-30-14.53.50.012345 DSPLY 2024-05-30-09.39.19.194688 DSPLY 2024-05-30-09.39.19.500000 DSPLY 2024-05-30-09.39.19.810000
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Trim
To remove blank space from a string on both sides, use the %TRIM function.
Other than blanks, it can also be used to trim characters. In argument 2, we can specify which characters should be removed.
Syntax: %TRIM(string {: characters to trim})
**Free dcl-s Str1 Varchar(50) Inz(' RPGLE '); dcl-s Str2 Varchar(50) Inz('$*****5.27**** '); dcl-s Res1 Varchar(50); dcl-s Res2 Varchar(50); Res1 = %Trim(Str1); // Trimming the leading and trailing zeros dsply Res1; // RPGLE Res2 = %Trim(Str2 : '$*'); // Trimming the passed characters from the string dsply Res2; // 5.27**** *inlr = *on;
Result:
DSPLY RPGLE DSPLY 5.27****
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Triml
The %TRIML method is used to remove a string’s leading blank spaces.
Other than blanks, it can also be used to trim characters. In argument 2, we can specify which characters should be cut.
Syntax: %TRIML(string {: characters to trim})
**Free dcl-s Str1 Varchar(50) Inz(' RPGLE '); dcl-s Str2 Varchar(50) Inz('$*****5.27**** '); dcl-s Res1 Varchar(50); dcl-s Res2 Varchar(50); Res1 = %Triml(Str1); // Trim only the leading zeros dsply Res1; // RPGLE Res2 = %Triml(Str2 : '$'); // Trim the given characters from the left of the string dsply Res2; // *****5.27**** *inlr = *on;
Result:
DSPLY RPGLE DSPLY *****5.27****
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Trimr
The %TRIMR function is used to remove a string’s trailing blank spaces.
Other than blanks, it can also be used to trim characters. In argument 2, we can specify which characters should be cut.
Syntax: %TRIMR(string {: characters to trim})
**Free w dcl-s Str1 Varchar(50) Inz(' RPGLE '); dcl-s Str2 Varchar(50) Inz('$*****5.270000 '); dcl-s Res1 Varchar(50); dcl-s Res2 Varchar(50); Res1 = %Trimr(Str1); dsply Res1; Res2 = %Trimr(Str2 : '0 '); dsply Res2; *inlr = *on;
Result:
DSPLY RPGLE DSPLY *****5.27****
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Uns
The expression’s value is converted to unsigned format using %UNS. Any decimal digits are truncated. An array index can be created by truncating the decimal places of a float or decimal value using %UNS.
If a character expression is used as the parameter See Rules for converting character values to numeric values using built-in functions for the rules for character expressions for %DEC.
Floating point data cannot be used, such as ‘1.2E6’.
Floating point data is not allowed. In other words, when the numerical value is followed by an exponent (as in ‘1.2E6’) and E.
If invalid numeric data is found, an exception occurs with status code 105
Syntax: %UNS(numeric or character expression)
**free dcl-s var1 char(15) inz(' 12345.6789 +'); dcl-s var2 char(15) inz(' + 5 , 6 7 '); dcl-s result packed(15); result = %uns(var1); dsply result; result = %uns(var2); dsply result; *inlr = *on;
Result:
DSPLY 12345 DSPLY 5
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Upper
%UPPER returns the string operand, with all or part of the operand converted to upper case. The conversion’s starting point is represented by the second operand.
Its value must be between one and the string’s length, and it must be a numeric expression with zero decimal places. It’s Optional. The conversion begins at the first position in the string if it is not specified.
The length to be converted is the third operand.
It must be less than or equal to the length of the string beginning at the start point, and it must be a numeric expression with zero decimal places. It might be zero. It’s not required.
Syntax: %UPPER(string {: start { : length } })
**free dcl-s str1 varchar(10); dcl-s str2 varucs2(10); dcl-s str3 varucs2(10); dcl-s string ucs2(5); str1 = %upper('hello'); // transforming full string from lower to upper string = 'hello'; str2 = %upper(string:2); // transforming lower to upper from 2nd position str3 = %upper('hello':2:3); // transforming lower to upper starting from 2nd position with length 3 dsply str1; // HELLO dsply str2; // hELLO dsply str3; // hELLo *inlr = *on;
Result:
DSPLY HELLO DSPLY hELLO DSPLY hELLo
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Xfoot
The total of each element in the given numeric array expression is produced by using %XFOOT.
The precision of the result is the minimum that can hold the result of adding together all array elements, up to a maximum of 63 digits. The result’s decimal places are always the same as the array expression’s decimal places.
Syntax: %XFOOT (array-expression)
**Free Dcl-s Amount zoned(2) dim(5); Dcl-s result zoned(4); Amount = %List(30:20:10:20:20); // loading the array with values Result = %xfoot(amount); // adding the elements of the array dsply result; // 100 *inlr = *on;
Result:
DSPLY 100
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Xlate
The string is translated by %XLATE based on the values of startpos, from, and to.
A list of characters that need to be replaced is contained in the first parameter, and the replacements are given in the second. The third character in to is replaced for every occurrence of the character in from, for instance, if the string contains the third character in from.
The string that needs to be translated is the third parameter. The translation’s starting point is the fourth parameter. Translation starts at position 1 by default.
The additional characters in the first parameter are ignored if it is longer than the second parameter.
The first three of parameters can belong to either character, graphic, or UCS-2 types. All three must have the same type.
Syntax: %XLATE(from:to:string{:startpos})
**Free dcl-s Str1 Varchar(50) Inz('12345678'); dcl-s Output Varchar(50); Output = %Xlate('1234' : 'ABCD' : Str1); // Translating the string containing ‘From’ part with ‘To’ part. dsply Output; // ABCD5678 *inlr = *on;
Result:
DSPLY ABCD5678
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch
Years
%YEARS converts a number into a duration that can be added to a date or timestamp value.
%YEARS can only follow the plus or minus sign in an addition or subtraction expression. The value before the plus or minus sign must be a date or timestamp. The result is a date or timestamp value with the appropriate number of years added or subtracted. For a date, the resulting value is in *ISO format.
Syntax: %XLATE(from:to:string{:startpos})
**free dcl-s CurDate Date; dcl-s ResultDate Date; CurDate = %Date(); dsply CurDate; // 2024-05-21 ResultDate = CurDate + %Years(3); dsply ResultDate; // 2027-05-31 *inlr = *on;
Result:
DSPLY 2024-05-31 DSPLY 2027-05-31
For additional insights on this topic, check out our detailed YouTube video from Programmers.io. Click here to watch