扩展模板化数据结构(继承)

时间:2014-02-20 23:02:34

标签: rpgle rpg

我一直在阅读LIKEDSTEMPLATEBASED,试图确定是否有办法创建具有继承的数据结构模板(原型)。我有:

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一样。

感谢阅读。

2 个答案:

答案 0 :(得分: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;

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

答案 1 :(得分: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'
);