简体   繁体   English

RPG-将数字DS复制到Alpha DS

[英]RPG - copy Numeric DS to Alpha DS

I want to copy Numeric DS to Alpha DS. 我想将数字DS复制到Alpha DS。 First Idea was MOVEA, but that does not seem to work. 第一个想法是MOVEA,但这似乎行不通。 Error: "The Factor 2 or Result-Field of a MOVEA does not refer to an array" 错误:“ MOVEA的因子2或结果字段未引用数组”

D Alpha       DS                                                 
D  TBR1                         5A                                  
D  TBR2                         5A                                  

D Num         DS                                                 
D  TBR1N                        5  0                                
D  TBR2N                        5  0                                

C                   MOVEA     Alpha     Num

There seem to be a lot of misconceptions about data structures in RPG. 关于RPG中的数据结构,似乎存在很多误解。 In the past month there have been two questions because someone thought he could coerce the data structure to be a UCS2 value. 在过去的一个月中,出现了两个问题,因为有人认为他可以将数据结构强制为UCS2值。 It won't work. 它不会工作。 The data structure is a fixed length character field using the job's CCSID. 数据结构是使用作业的CCSID的固定长度字符字段。 The fact that it has some internal structure is meaningless if you are using the data structure name as your variable. 如果使用数据结构名称作为变量,则它具有某些内部结构的事实是没有意义的。

This seems to be compounded by fixed form RPG's ability to implicitly define a field as character or numeric without giving it a data type. 固定形式RPG可以隐式地将字段定义为字符或数字而无需为其提供数据类型,这似乎使这种情况更加复杂。 Stand alone fields and data structures treat this condition differently. 独立字段和数据结构对这种情况的处理方式有所不同。 See the following table: 见下表:

field type  | decimal positions | Implicit data type
----------------------------------------------------
stand alone |    blank          |   A
            |  not blank        |   P
----------------------------------------------------
data        |    blank          |   A
 structure  |  not blank        |   S

So for your definitions: 因此,对于您的定义:

D Alpha       DS                                                 
D  TBR1                         5A                                  
D  TBR2                         5A                                  

D Num         DS                                                 
D  TBR1N                        5  0                                
D  TBR2N                        5  0

Alpha is CHAR(10) Alpha是CHAR(10)
TBR1 is CHAR(5) TBR1是CHAR(5)
TBR2 is CHAR(5) TBR2是CHAR(5)
Num is CHAR(10) Num是CHAR(10)
TBR1N is ZONED(5 0) TBR1N为ZONED(5 0)
TBR2N is ZONED(5 0) TBR2N为ZONED(5 0)

There are no arrays so you can not use MOVEA with any of these on both sides., but MOVEL would work to assign Alpha to Num like this: 没有数组,因此您不能在两面都使用MOVEA 。但是MOVEL可以像这样将Alpha分配给Num

C                   MOVEL     Alpha     Num

That being said, you should not be using Fixed Form any more. 话虽如此,您不应该再使用固定格式。 All supported versions of the OS support Free Form RPGIV, and you can gain some advantages by using it. 操作系统的所有受支持版本均支持Free Form RPGIV,您可以通过使用它获得一些好处。 Specifically to this case, the implicit numeric data type is not possible in Free Form. 专门针对这种情况,隐式数值数据类型在自由格式中是不可能的。 So you would have something like this: 所以你会有这样的事情:

dcl-ds Alpha Qualified;
  tbr1       Char(5);
  tbr2       Char(5);
end-ds;

dcl-ds Num   Qualified;
  tbr1n      Zoned(5:0);
  tbr2n      Zoned(5:0);
end-ds;

Num = Alpha;

Data types are now explicit, and you can even qualify your data structures so that you can say something like this: 数据类型现在是显式的,您甚至可以限定数据结构,以便您可以这样说:

num.tbr1n = %dec(alpha.tbr1:5:0);

First off, there's no such thing as a "numeric DS". 首先,没有“数字DS”之类的东西。

A data structure in RPG is just a collection of bytes. RPG中的数据结构只是字节的集合。 And since the compiler doesn't have a BYTE type, it simply treats it as SBCS characters. 并且由于编译器没有BYTE类型,因此仅将其视为SBCS字符。

You're issue is that your numeric subfields are defaulting to packed decimal. 您的问题是数字子字段默认为压缩十进制。 So your DS named NUM is only 6 bytes. 因此,名为NUM的DS仅6个字节。

Define them as ZONED instead, so that both DS will be 10 bytes. 而是将它们定义为ZONED,以便两个DS均为10个字节。

 D Alpha           DS                                                 
 D  TBR1                          5A                                  
 D  TBR2                          5A                                  

 D Num             DS                                                 
 D  TBR1N                         5S 0                                
 D  TBR2N                         5S 0

   Num = Alpha;

But this kind of code really isn't a good idea in RPGIV.. 但是在RPGIV中,这种代码确实不是一个好主意。

Why can't you explicitly convert? 您为什么不能显式转换?

tbr1n = %dec(tbr1:5:0);
tbr2n = %dec(tbr2:5:0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM