3

我正在尝试创建一个过程,该过程将采用一个数组并返回已使用元素的计数(为什么这不是 BIF??)。我正在努力寻找一种将未知大小的数组传递给我的程序的方法。

就像是...

P count         B
D count         PI              3  0 
D  array                         *
D  size                        10  0
D  elems                        3  0
 *
D ct            S               3  0
 /free
  // find the first blank or zero element and return 
 /end-free
P count         E

显然我是新手,所以我有几个问题:

  1. 有没有办法将 size 和 max 元素作为参数传递(或者可能是传递一种带有数据详细信息的标头数据包的方法)?
  2. 有没有办法确定数据是什么类型?(所以我知道是要查找 *ZEROS 还是 *BLANKS)
  3. 我是否错过了解决此问题的其他更好的方法?

我知道我可以保留一个单独的计数器变量,每当我在数组中设置一个元素时它就会递增,但我真的很想找到一个更好的解决方案……谢谢你的阅读。

4

2 回答 2

7

我已经在 RPG 中编程了……嗯,很长一段时间了。看到一个新的 RPG 程序员真是太棒了,看到从一开始就使用现代编码概念更是令人惊叹。

RPG 从固定大小的一切开始。固定大小的字符串、固定大小的数字和固定大小的数组。作为一种基于穿孔卡片的强类型语言,这一切都是有道理的。当然,现代计算需求往往需要不同大小的字符串、数字和数组。RPG 仍然是强类型的,所以给定的变量只能是字符串或数字;它永远不能切换类型。这也意味着编译器无法在运行时确定变量类型——变量类型是不可变的,程序员和编译器都知道该类型是什么。那好吧。

至于你的变长数组,有一些希望。Mihael Schmidt 有一个名为 ArrayList 的服务程序,它可以满足您的许多需求。

于 2014-03-05T02:59:44.827 回答
1

It's not clear what operations you want to perform against arrays of unknown sizes. Perhaps some example code can provide a starting point, and things can be added or refined as things progress. So, for a trivial example:

 h dftactgrp( *NO )

 D tmp_Ary1        s             10i 0
 D tmp_Ary2        s             10

 d chk_Arrays      pr
 d  ary1                               like( tmp_Ary1 ) dim( 99 ) const
 d  ary2                               like( tmp_Ary2 ) dim( 99 ) const

 D ary1            s                   like( tmp_Ary1 ) dim( 50 )
 D ary2            s                   like( tmp_Ary2 ) dim( 50 )
  /free
        ary1( 1 ) = 12345 ;
        ary2( 1 ) = 'Some value' ;

        callP chk_Arrays ( ary1 : ary2 ) ;

        *inlr = '1';
  /end-free

 P chk_Arrays      b
 d                 pi
 d  ary1                               like( tmp_Ary1 ) dim( 99 ) const
 d  ary2                               like( tmp_Ary2 ) dim( 99 ) const

 d  foundElems     s             10i 0
  /free

   foundElems = 99 ;

   return;
  /end-Free
 p                 E

The chk_Arrays() proc expects two arrays, one is dim(99) with 10-byte character elements and the other is dim(99) for integer elements. But the proc is called with arrays that are both defined as dim(50), and only a single element is populated in each array.

The proc only has a single executable statement. For the most part, the only reason that statement exists is to give a known spot for a debug breakpoint. Compile and run in debug, and display the two arrays when the breakpoint fires.

From there, a description of what else is needed would be helpful.

于 2014-04-17T11:00:12.490 回答