5

我一直在阅读LIKEDS, TEMPLATE, 并BASED试图确定是否有一种方法可以创建具有继承的数据结构模板(原型)。我有:

D costs           DS                  QUALIFIED TEMPLATE
D  material                      6  0
D  cutting                       6  0
D  ...etc...

D boxCosts        DS                  LIKEDS(costs)
D  folding                       6  0
D  ...etc...

D posterCosts     DS                  LIKEDS(costs)
D  laminating                    6  0
D  ...etc...

我希望 boxCosts 看起来像:

boxCosts:
  material
  cutting
  folding
  etc. (no laminating, this isn't a poster)

有没有办法实现这种类型的数据结构模板?我知道我可以这样做:

D boxCosts        DS                  
D  common                             LIKEDS(costs)
D  folding                       6  0
D  ...etc...

但是当我想要一个平面结构时,这会创建一个层次结构。

我也许可以用抄写本来做到这一点,但我不知道是否只有我想要在自己的文件中的数据结构部分有一本抄写本,或者为整个应用程序有潜在复杂的条件抄写本会更糟复制这些信息的区域很小......?模板与我想要的非常接近,我怀疑我一定是遗漏了一些东西。

如果您想知道,我在尝试创建像我展示的那样的继承数据结构时得到的编译错误位于关键字RNF3703: The subfield or parameter definition is not specified within a group.下方的第一个 D 规范中。LIKEDS

谢谢阅读。

4

2 回答 2

3

RPG 数据结构是内存映射。它们定义了一种在内存中以特定方式对变量进行分组和重叠的方法。这就是为什么如果你 LIKEDS() 你得到一个层次结构 - 编译器正在将层次结构从模板复制到你的目的地。

至少有一种方法可以使结构变平:

 d costs           ds                  template
 d  t_material                    6s 0
 d  t_cutting                     6s 0

 d box           e ds                  extname(boxcosts) prefix(t_) template

 d boxCosts        ds                  qualified
 d  material                           like(t_material)
 d  cutting                            like(t_cutting)
 d  folding                            like(t_folding)

   boxCosts.cutting = 1;
   boxCosts.folding = 2;

第一个结构在程序中定义;第二个是基于一个文件。我这样做只是为了展示两种不同的方式来定义子字段。

于 2014-02-21T15:26:34.653 回答
2

如果您愿意使用 SQL 来解决问题,您就可以实现您的目标。虽然 ILE RPG 数据结构没有继承,但 SQL 表可以模拟这一点。

CREATE TABLE costs
(material    num(6,0)  
,cutting     num(6,0)  
);

CREATE TABLE boxCosts
(      LIKE  costs  
,folding     num(6,0)
,sealing     num(6,0)
);

CREATE TABLE postrCosts
(      LIKE  costs
,laminating  num(6,0)
);

如果您只关心字段名称和定义,那么该方法可能没问题,并且您需要在 RPG 中使用这些结构

D boxCosts      E DS                  EXTNAME(boxCosts)

D posterCosts   E DS                  EXTNAME(postrCosts)

如果字段文本或其他属性对您很重要,那么使用稍微不同的策略可能会更好。

CREATE TABLE costs
(material    num(6,0)  
,cutting     num(6,0)  
);

LABEL ON COLUMN costs
(material    text is 'Material Costs'
,cutting     text is 'Cutting Costs'
);

CREATE TABLE boxCosts as
(SELECT * 
     FROM costs
) with no data
;
ALTER TABLE boxCosts 
  ADD COLUMN folding  num(6,0)
  ADD COLUMN sealing  num(6,0)
;
LABEL ON COLUMN boxCosts 
(folding     text is 'Folding Costs'
,sealing     text is 'Folding Costs'
);
于 2014-03-03T23:05:39.557 回答