0

I am trying to copy a DS to another 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.

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.

I did get it working by looping MYRESULTS and for each occurrence copied it to MYRESULTS2.

Is there a faster way to assign all the occurences from MYRESULTS to MYRESULTS2

V6.1 - IBM

Renier
  • 1,738
  • 3
  • 24
  • 51

2 Answers2

4

I would firstly suggest that you start using dim instead of occur for arrays. Because then it would be a simple one line eval statement.

Anyways you could use the C++ function MEMCPY for the fastest result (assuming that both data structures are exactly the same format and dimensions):

 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 
Adrian Bannister
  • 523
  • 4
  • 11
0

I got it working using a pointer to the 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

Renier
  • 1,738
  • 3
  • 24
  • 51
  • 2
    Just note that if you do this method then MYRESULTS2 will actually just overlay MYRESULTS, so making changes to MERESULTS2 will change MYRESULTS as well. But if this behaviour isn't going to affect you then I would suggest rather doing this method. It uses less system memory :) – Adrian Bannister Sep 08 '16 at 10:14
  • I understand thanks, this wont affect me thanks for the info. – Renier Sep 08 '16 at 10:36
  • 1
    Since this doesn't copy the DS content, it's not clear how it can be said to be "working". It does provide a new name (and possibly new description) for the DS, but it's the same DS and not a "copy". – user2338816 Sep 08 '16 at 17:13