× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi All,

Compared with more dynamic languages RPG has no dynamic data structures or
collection types such as lists, maps/dictionaries, etc. To be able to also
use dynamic data structures in RPG i created an implementation of a
key/value store, with ordered keys, for RPG (i.e. ILE RPGIV). Like a Java
TreeMap or a PHP associative array. The implementation has a rich API. The
project is on github.com/jerps/RpgMap. Complete docs are at
jerps.nl/RpgMap/Docs/index.html. Using RpgMap is simple. Just install
library RPGMAP (no dependencies), add "bnddir('RPGMAP/RPGMAP')" to the
control spec, and /include the header file (see the docs).

There is no ready compiled library to download, yet, so for now RpgMap
needs to be built from source, which is straightforward. However, a current
ILE RPG compiler is needed. It needs to support the new on-exit opcode
(i.e. 7.2 TR5).

A quick example:

Create a map with 3 key/item pairs, the keys are all dates and the values -
called "items" - are all integers:
map = rm_m(
rm_d( d'2017-07-01' ) : rm_i( 1 ) :
rm_d( d'2017-07-02' ) : rm_i( 2 ) :
rm_d( d'2017-07-03' ) : rm_i( 3 ) );

Insert two key/item pairs into the same "map" (character key, packed
decimal item):
rm_ins(map :
rm_a( 'a' ) : rm_p( 10.20 ) :
rm_a( 'b' ) : rm_p( 20.40 ) );

Iterating through key/item pairs is done using cursors, which support
set-lower-limit, set-greater-than, read, read-previous, etc, semantics.
Iterate through the key/item pairs starting with 'a', and stop until last
pair or when the current key is greater than 'zzz'. Display each key/item
pair.
cur = rm_sll(rm_cur(map):rm_a('a')); // create cursor, set-lower-limit on
'a'
dow rm_rdn(cur:*null:rm_a('zzz')); // read-next (until key greater than
'zzz')
dsply ( rm_a_(rm_key(cur)) + ': ' + %char(rm_p_(rm_itm(cur))) );
enddo;

Dispose "map" (and its contents) and implicitly dispose "cur".
rm_dis(map);

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.