简体   繁体   English

如何将多次出现的DS复制到另一个DS RPG

[英]How to copy a multi occurrence DS to another DS RPG

I am trying to copy a DS to another DS. 我正在尝试将一个DS复制到另一个DS。

D  MYRESULTS      DS                  OCCURS(2000)
 D                                     QUALIFIED
 D  PAOPIID                      20A
 D  POPITPE                      10A
 D  POPISTPE                     10A
 D  POPIKNID                     20A
 D  PINSTAT                      10A
 D  PLEAFIND                      1A
 D  CLOPIID                      20A
 D  COPITPE                      10A
 D  COPISTPE                     10A
 D  COPIKNID                     20A
 D  CINSTAT                      10A
 D  CLEAFIND                      1A
 D  INSTAT                       10A

 D  MYRESULTS2     DS                  OCCURS(2000)
 D                                     QUALIFIED
 D  PAOPIID                      20A
 D  POPITPE                      10A
 D  POPISTPE                     10A
 D  POPIKNID                     20A
 D  PINSTAT                      10A
 D  PLEAFIND                      1A
 D  CLOPIID                      20A
 D  COPITPE                      10A
 D  COPISTPE                     10A
 D  COPIKNID                     20A
 D  CINSTAT                      10A
 D  CLEAFIND                      1A
 D  INSTAT                       10A 

So I want to copy MYRESULTS into MYRESULTS2 without looping MYRESULTS and processing each element to copy it to MYRESULTS2 . 所以我想将MYRESULTS复制到MYRESULTS2而不循环MYRESULTS并处理每个元素以将其复制到MYRESULTS2

I did try just assigning it. 我确实尝试过分配它。

 MYRESULTS2 = MYRESULTS;
       %OCCUR(MYRESULTS2) =  3 ;
        opsitem =  %TRIM(MYRESULTS2.PAOPIID);
       PrintLine =opsitem ;
       Except;

The first occurrence works... but it does not copy the rest ie. 第一次出现有效...但是它不会复制其余部分,即。 occurrence 3. 发生3。

I did get it working by looping MYRESULTS and for each occurrence copied it to MYRESULTS2 . 我确实通过循环MYRESULTS使其工作,并且每次出现时都将其复制到MYRESULTS2

Is there a faster way to assign all the occurences from MYRESULTS to MYRESULTS2 有没有一种更快的方法将所有发生的事件从MYRESULTS分配给MYRESULTS2

V6.1 - IBM V6.1-IBM

I would firstly suggest that you start using dim instead of occur for arrays. 我首先建议您开始使用dim而不是对array进行更改。 Because then it would be a simple one line eval statement. 因为那将是一个简单的单行eval语句。

Anyways you could use the C++ function MEMCPY for the fastest result (assuming that both data structures are exactly the same format and dimensions): 无论如何,您都可以使用C ++函数MEMCPY获得最快的结果(假设两个数据结构的格式和维数完全相同):

 hdftactgrp(*no) actgrp(*new)

 dMEMCPY           pr                  extproc('memcpy')
 d TargetPointer                   *   value
 d SourcePointer                   *   value
 d CopyLength                    10u 0 value

 dSample1          ds                  qualified occurs(10)
 dNumber                          3p 0
 dValue                          10a
 dSample2          ds                  qualified occurs(10)
 dNumber                          3p 0
 dValue                          10a

 dresult           s              1a
  /free
   %occur(Sample1) = 1;
   Sample1.Number = 1;
   Sample1.Value = 'One';
   %occur(Sample1) = 10;
   Sample1.Number = 10;
   Sample1.Value = 'Ten';

   %occur(Sample1) = 1;
   %occur(Sample2) = 1;
   MEMCPY(%addr(Sample2): %addr(Sample1): %size(Sample1) * %elem(Sample1));

   %occur(Sample2) = 10;

   dsply Sample2.Value '*EXT' result;

   *inlr = *on;

  /end-free 

I got it working using a pointer to the DS. 我使用指向DS的指针来工作。

 D Mypointer       s               *

 D  MYRESULTS2     DS                  OCCURS(2000) based(Mypointer)
 D                                     QUALIFIED
 D  PAOPIID                      20A
 D  POPITPE                      10A
 D  POPISTPE                     10A     

And then when you want to assign it. 然后在您要分配它时。

 Mypointer = %ADDR(MYRESULTS);

After this you are able to use all the occurrences in the DS 之后,您便可以使用DS中的所有事件

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

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