New Features of RPG in V7R1
2 posters
Page 1 of 1
New Features of RPG in V7R1
New features of RPG in V7R1
The following are the new features of RPG in V7R1
1) Open access
2) Sorting and searching data in Data Structure Arrays
3) New operation extenders
4) %Lookup works with Datastructure Array
5) New BIF %SCANRPL
6) No need to have prototypes for subprocedures that are internal to the module
7) New keyword RTNPARM on the (Procedure Interface level) PI level
ALIAS Longer names defined in DDS /SQL can be accessed in RPG
Sorting and searching data in Data Structure Arrays
Open Access
Now using file manipulation opcodes ( READ, WRITE, CHAIN, EXFMT ) we can access the data that is available not only on the 5250 stream. We can access from browser , Handhelp devices..etc..
For that we need to write the program which handles the request made by the RPG program and these are called “ Handlers”
We can have now sort the data in the Data Structure
Example:
D InvoiceInfo DS Dim(1000)
D Qualified
D Invoice# 8
D Invdate D
D InvAmt 12p 2
// If wanted to SortByName
SortA InvoiceInfo(*).Invoice;
//If wanted to SortBy InvAmt
SortA InvoiceInfo(*).InvAmt;
The * indicates the level at which the sorting should occur. Of course, in this example, it’s pretty obvious, since it’s the only level where sorting is possible. But this sorting capability also works with nested Data Structures, so even very complicated structures can be sorted.
Two new operation extenders are available for SORTA
SORTA(A) - for ascending
SORTA(D) - for descending
%Lookup works with Datastructure Array
Example:
Index = %LookUp( 'ABC': InvoiceInfo(*).Invoice#);
New BIF %SCANRPL ( To scan and replace )
This BIF is combination of %SCAN and %REPLACE
The following are the new features of RPG in V7R1
1) Open access
2) Sorting and searching data in Data Structure Arrays
3) New operation extenders
4) %Lookup works with Datastructure Array
5) New BIF %SCANRPL
6) No need to have prototypes for subprocedures that are internal to the module
7) New keyword RTNPARM on the (Procedure Interface level) PI level
ALIAS Longer names defined in DDS /SQL can be accessed in RPG
Sorting and searching data in Data Structure Arrays
Open Access
Now using file manipulation opcodes ( READ, WRITE, CHAIN, EXFMT ) we can access the data that is available not only on the 5250 stream. We can access from browser , Handhelp devices..etc..
For that we need to write the program which handles the request made by the RPG program and these are called “ Handlers”
We can have now sort the data in the Data Structure
Example:
D InvoiceInfo DS Dim(1000)
D Qualified
D Invoice# 8
D Invdate D
D InvAmt 12p 2
// If wanted to SortByName
SortA InvoiceInfo(*).Invoice;
//If wanted to SortBy InvAmt
SortA InvoiceInfo(*).InvAmt;
The * indicates the level at which the sorting should occur. Of course, in this example, it’s pretty obvious, since it’s the only level where sorting is possible. But this sorting capability also works with nested Data Structures, so even very complicated structures can be sorted.
Two new operation extenders are available for SORTA
SORTA(A) - for ascending
SORTA(D) - for descending
%Lookup works with Datastructure Array
Example:
Index = %LookUp( 'ABC': InvoiceInfo(*).Invoice#);
New BIF %SCANRPL ( To scan and replace )
This BIF is combination of %SCAN and %REPLACE
New Scan/Replace BIF (%SCANRPL)
New Scan/Replace BIF (%SCANRPL)
At first people want to use the %REPLACE BIF but can't figure out how to find and replace a value with %REPLACE. The typical sample code looks like this:
X = %scan(Needle: Haystack);
dow X > 0;
Haystack = %replace(Replacement: Haystack: X: %len(Needle));
X = %scan(Needle: Haystack);
enddo;
Sure, this works, more or less. But it's not as simple as RPG programmers want it to be. The biggest problem is that the %REPLACE BIF doesn't replace one string with another. Instead, it replaces a given substring (identified by start position and length) with a new value. This means that if you want to find and replace you have to use %REPLACE in conjunction with %SCAN and call them in a loop as I did above.
Bugs with this type of loop are common. For example, the above code would get stuck in the loop forever if Replacement happened to contain the characters in Needle.
Sure, you can code around this, but it gets tricky. And it's cumbersome to do this every time you want to find and replace a string. Why can't life be easy, you ask? Well it can in 7.1, if you use the %SCANRPL BIF.
Haystack = %scanrpl( Needle: Replacement: Haystack );
This is especially useful if you find that RPG's concatenation can sometimes be ugly. For example, you might have something like this:
msg = 'Customer ' + %char(CustNo) + ' not found!';
If you find that cumbersome, you might use %SCANRPL instead:
format = 'Customer &1 not found!';
msg = %scanrpl('&1': %char(CustNo): format);
%SCANRPL will replace all occurrences. So the following would also work:
format = 'Customer &1 not found! Where is customer &1?';
msg = %scanrpl('&1': %char(CustNo): format);
At first people want to use the %REPLACE BIF but can't figure out how to find and replace a value with %REPLACE. The typical sample code looks like this:
X = %scan(Needle: Haystack);
dow X > 0;
Haystack = %replace(Replacement: Haystack: X: %len(Needle));
X = %scan(Needle: Haystack);
enddo;
Sure, this works, more or less. But it's not as simple as RPG programmers want it to be. The biggest problem is that the %REPLACE BIF doesn't replace one string with another. Instead, it replaces a given substring (identified by start position and length) with a new value. This means that if you want to find and replace you have to use %REPLACE in conjunction with %SCAN and call them in a loop as I did above.
Bugs with this type of loop are common. For example, the above code would get stuck in the loop forever if Replacement happened to contain the characters in Needle.
Sure, you can code around this, but it gets tricky. And it's cumbersome to do this every time you want to find and replace a string. Why can't life be easy, you ask? Well it can in 7.1, if you use the %SCANRPL BIF.
Haystack = %scanrpl( Needle: Replacement: Haystack );
This is especially useful if you find that RPG's concatenation can sometimes be ugly. For example, you might have something like this:
msg = 'Customer ' + %char(CustNo) + ' not found!';
If you find that cumbersome, you might use %SCANRPL instead:
format = 'Customer &1 not found!';
msg = %scanrpl('&1': %char(CustNo): format);
%SCANRPL will replace all occurrences. So the following would also work:
format = 'Customer &1 not found! Where is customer &1?';
msg = %scanrpl('&1': %char(CustNo): format);
razuk_r- Posts : 65
Join date : 2009-07-31
Location : Chennai
SORTA Can Now Do Both Ascending and Descending
SORTA Can Now Do Both Ascending and Descending
The SORTA opcode has been well established as the way that RPGers sort arrays. It's simple and easy to use and runs faster than any of the APIs. However, you always had to hard-code whether the sort was ASCENDing or DESCENDing on the D-spec for the array.
For example, we had to do this:
D Sales s 9p 2 dim(12) ASCEND
/free
sorta Sales;
If you wanted to be able to sort the data both ways in the same program (i.e., both ascending and descending), you had to do a bit of fooling around. For example, you could use a pointer like this:
D Sales s 9p 2 dim(12) ASCEND
D Sales2 s like(Sales)
D dim(%elem(Sales)) DESCEND
D based(p_Sales2)
/free
p_Sales2 = %addr(Sales);
if (want_ascending);
sorta Sales;
else;
sorta Sales2;
endif;
With 7.1, IBM added (A) and (D) operation extenders to the SORTA opcode. That means you can specify ascending or descending on the opcode rather than the array, which also means you can switch. For example:
D Sales s 9p 2 dim(12)
/free
if (want_ascending);
sorta(a) Sales;
else;
sorta(d) Sales2;
endif;
The SORTA opcode has been well established as the way that RPGers sort arrays. It's simple and easy to use and runs faster than any of the APIs. However, you always had to hard-code whether the sort was ASCENDing or DESCENDing on the D-spec for the array.
For example, we had to do this:
D Sales s 9p 2 dim(12) ASCEND
/free
sorta Sales;
If you wanted to be able to sort the data both ways in the same program (i.e., both ascending and descending), you had to do a bit of fooling around. For example, you could use a pointer like this:
D Sales s 9p 2 dim(12) ASCEND
D Sales2 s like(Sales)
D dim(%elem(Sales)) DESCEND
D based(p_Sales2)
/free
p_Sales2 = %addr(Sales);
if (want_ascending);
sorta Sales;
else;
sorta Sales2;
endif;
With 7.1, IBM added (A) and (D) operation extenders to the SORTA opcode. That means you can specify ascending or descending on the opcode rather than the array, which also means you can switch. For example:
D Sales s 9p 2 dim(12)
/free
if (want_ascending);
sorta(a) Sales;
else;
sorta(d) Sales2;
endif;
razuk_r- Posts : 65
Join date : 2009-07-31
Location : Chennai
Similar topics
» New BIFs in V7R1
» Now V7R1- SQL statements can now reference objects from more than one IBM i system.
» V7R1 Feature: Remove Disk Units Without an IPL
» Now V7R1 - Default parameter values are supported for both SQL and external stored procedures
» Now V7R1- SQL statements can now reference objects from more than one IBM i system.
» V7R1 Feature: Remove Disk Units Without an IPL
» Now V7R1 - Default parameter values are supported for both SQL and external stored procedures
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|