midrange.com code scratchpad |
Name:
RPG %max() BIF via Rexx
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
08/24/2016 06:19:22 pm
|
IP:
Logged
|
|
Description:
Example of RPG passing parameters to and from Rexx
|
Code:
- Rexx procedure MAX:
- /* Test MAX function with RPG */
-
- /* RPG has pushed n entries into the queue */
- /* Now get them off the queue and concatenate them */
- input = ''
-
- do while queued() > 0
- pull element
- if input <> '' then
- input = input',' element
- else
- input = element
- end
-
- /* this is similar to QCMDEXEC */
- interpret('big = MAX('input')')
-
- /* push the result back onto the queue for RPG to pick up */
- push big
-
- return
-
-
-
-
- RPG program MAXBIF:
- **free
- ctl-opt dftactgrp(*no) actgrp('QILE');
-
- // test MAX BIF by using Rexx
-
- // API for Rexx external queue
- dcl-pr qrexq extpgm('QREXQ');
- function char(1) const;
- data char(50) const;
- length int(10) const;
- operation uns(10) const;
- rc uns(5) const;
- end-pr;
-
- dcl-s function char(1) inz('A'); // Add to queue
- dcl-s data char(50);
- dcl-s length int(10) inz(%size(data));
- dcl-s operation uns(10) inz(0); // add to end of queue
- dcl-s rc uns(5);
-
- dcl-pr system int(10) extproc('system');
- command pointer value options(*string);
- end-pr;
-
- // the test entries will live here
- dcl-s entries packed(32: 0) dim(100) inz;
- dcl-s entry_count int(10) inz(12);
-
- dcl-s i int(10);
-
- // populate the entry array
- for i = 1 to entry_count;
- entries(i) = i * 10;
- endfor;
-
- // push the entries onto the Rexx queue
- for i = 1 to entry_count;
- data = %char(entries(i));
- qrexq(function: data: length: operation: rc);
- if rc <> 0;
- // error!
- dsply rc;
- leave;
- endif;
- endfor;
-
- // execute Rexx proc
- // Rexx will read the queue entries, find the largest,
- // and push that back via the queue
- system('strrexprc srcmbr(max)');
-
- // which one is the largest?
- function = 'P'; // pull an entry
- qrexq(function: data: length: operation: rc);
- if rc <> 0;
- // error!
- dsply rc;
- endif;
-
- dsply data;
-
- *inlr = *on;
-
|
|
|