RPG(LE) 中的数据结构定义/模板
假设我有一个数据结构,例如
d dog DS qualified
d name 20
d breed 20
d birthdate 8 0
我可以定义
d poochie likeds(dog)
和使用 poochie.name 等。
但是我可以将“狗”设置为模板而不在内存中创建结构吗?
Say I have a data structure, such as
d dog DS qualified
d name 20
d breed 20
d birthdate 8 0
I can then define
d poochie likeds(dog)
and use poochie.name, etc.
But can I just set up the 'dog' as a template without creating the structure in memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在V6R1中会有另一个关键字,称为TEMPLATE。 具有 It 的数据结构不会在内存中创建,仅供编译器参考。 您还可以将其与 inz() 结合使用,以在您的 likes() 中拥有默认值。
In V6R1 there will be another keyword that is called TEMPLATE. Datastructures with It are not created in the memory and are just used by the compiler for reference. You can also combine it with inz() to have default values in your likeds().
我想到了两个选择。 第一个是使用狗属性的 d-spec 创建一个源成员,而不是使用 likes(dog),而是在每个将使用该子字段定义的数据结构之后添加一个 /copy。 在我看来,这可能会导致一些草率的代码,并且可能会导致后续分析变得困难。 另一方面,如果您在多个程序中使用相同的数据结构,则会有好处。
我想到的第二个选项是在狗数据结构上使用 Based() 关键字,然后定义一个指针字段。 指针字段会占用一些内存,但狗数据结构不会占用任何内存,直到您的程序分配它。 Based() 关键字不会转移到使用 LikeDS() 针对它定义的其他数据结构中。 这样您就可以在程序源中定义数据结构。 您不必为其分配内存,也不必将指针设置为任何值。 它默认为空。 请注意不要访问代码中的狗数据结构。 您将收到一个指针错误,该错误看起来与在没有必需参数的情况下调用程序一样。
Two options come to mind. The first is to create a source member with the d-specs for the dog attributes and instead of using likeds(dog), have a /copy after each data structure that will use that subfield definition. In my opinion, this can make for some sloppy code and can make things difficult for someone to analyze down the road. On the other hand, if you are using this same data structure in multiple programs, there are benefits.
The second option that comes to mind is to use the Based() keyword on the dog data structure and then define a pointer field. The pointer field will take up some memory, but the dog data structure will not take up any memory until your program allocates it. The Based() keyword does not carry over into other data structures defined against it with LikeDS(). So that way you have your data structure defined in your program source. You don't have to allocate memory for it and you don't have to set your pointer to any value. It defaults to Null. Just be careful not to access the dog data structure in your code. You'll get a pointer error that looks the same as if your program was called without a required parameter.
这样做: BASED(pointer-name)
使用指针是不必要的——我认为会做你想要的。
Do this: BASED(pointer-name)
Using the pointer is unnecessary---I think will do what you want.
据我所知,没有。 但也许可以对子过程做类似的事情。
将此问题发布到 Midrange.com RPG-L 上,比我聪明的人也许可以回答你的问题。
To the best of my knowledge, no. But it might be possible to do something similar with subprocedures.
Post this question on Midrange.com RPG-L and someone smarter than me might be able to answer your question.