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
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