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:
  1. Rexx procedure MAX:
  2. /* Test MAX function with RPG */
  3.  
  4. /* RPG has pushed n entries into the queue */
  5. /* Now get them off the queue and concatenate them */
  6. input = ''
  7.  
  8. do while queued() > 0
  9.   pull element
  10.   if input <> '' then
  11.     input = input',' element
  12.   else
  13.     input = element
  14. end
  15.  
  16. /* this is similar to QCMDEXEC */
  17. interpret('big = MAX('input')')
  18.  
  19. /* push the result back onto the queue for RPG to pick up */
  20. push big
  21.  
  22. return
  23.  
  24.  
  25.  
  26.  
  27. RPG program MAXBIF:
  28. **free
  29. ctl-opt dftactgrp(*no) actgrp('QILE');
  30.  
  31. // test MAX BIF by using Rexx
  32.  
  33. // API for Rexx external queue
  34. dcl-pr qrexq extpgm('QREXQ');
  35.   function char(1) const;
  36.   data char(50) const;
  37.   length int(10) const;
  38.   operation uns(10) const;
  39.   rc uns(5) const;
  40. end-pr;
  41.  
  42. dcl-s function char(1) inz('A');     // Add to queue
  43. dcl-s data char(50);
  44. dcl-s length int(10) inz(%size(data));
  45. dcl-s operation uns(10) inz(0);      // add to end of queue
  46. dcl-s rc uns(5);
  47.  
  48. dcl-pr system int(10) extproc('system');
  49.   command pointer value options(*string);
  50. end-pr;
  51.  
  52. // the test entries will live here
  53. dcl-s entries packed(32: 0) dim(100) inz;
  54. dcl-s entry_count int(10) inz(12);
  55.  
  56. dcl-s i int(10);
  57.  
  58. // populate the entry array
  59. for i = 1 to entry_count;
  60.   entries(i) = i * 10;
  61. endfor;
  62.  
  63. // push the entries onto the Rexx queue
  64. for i = 1 to entry_count;
  65.   data = %char(entries(i));
  66.   qrexq(function: data: length: operation: rc);
  67.   if rc <> 0;
  68.     // error!
  69.     dsply rc;
  70.     leave;
  71.   endif;
  72. endfor;
  73.  
  74. // execute Rexx proc
  75. // Rexx will read the queue entries, find the largest,
  76. // and push that back via the queue
  77. system('strrexprc srcmbr(max)');
  78.  
  79. // which one is the largest?
  80. function = 'P';      // pull an entry
  81. qrexq(function: data: length: operation: rc);
  82. if rc <> 0;
  83.   // error!
  84.   dsply rc;
  85. endif;
  86.  
  87. dsply data;
  88.  
  89. *inlr = *on;
  90.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css