PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Join the forum, it's quick and easy

PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).
PMS Information Systems
Would you like to react to this message? Create an account in a few clicks or log in to continue.

New Features of RPG in V7R1

2 posters

Go down

New Features of RPG in V7R1 Empty New Features of RPG in V7R1

Post  maran Fri Apr 23, 2010 2:44 pm

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
Cool 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
maran
maran
Admin

Posts : 442
Join date : 2009-07-24

https://pmsinformationsystem.forumotion.net

Back to top Go down

New Features of RPG in V7R1 Empty New Scan/Replace BIF (%SCANRPL)

Post  razuk_r Fri Apr 30, 2010 10:27 pm

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);

razuk_r

Posts : 65
Join date : 2009-07-31
Location : Chennai

Back to top Go down

New Features of RPG in V7R1 Empty SORTA Can Now Do Both Ascending and Descending

Post  razuk_r Fri Apr 30, 2010 10:29 pm

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;

razuk_r

Posts : 65
Join date : 2009-07-31
Location : Chennai

Back to top Go down

New Features of RPG in V7R1 Empty Re: New Features of RPG in V7R1

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum