send a table between 2 pgms in freeform

Any IBM i topic that does not fit in another forum
Post Reply
OlivierPierre04
Posts: 17
Joined: Fri Jan 07, 2022 2:56 pm

send a table between 2 pgms in freeform

Post by OlivierPierre04 »

Hi folks
i have a program X who call a pgm Y
this pgm Y feed a table and i want to consume it in the X pgm
i know i have to use pointer but i dont know how
my pgms are in free form


this the table in the pgm Y


// *** Definition de la DS de reception du Json
dcl-s num_sample int(5);
dcl-ds sample qualified dim(003);
codeActiviteFm char(10);
isAs400FiniPousserDansFm char(9);
isOverlogFiniPousserDansFm char(9);
isPrevisionsPretesPourIntegration char(20);
modificateur char(20);
dcl-ds traceabilites dim(002);
propriete char(20);
horodatage char(20);
modificateur char(20);
end-ds;
end-ds;
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: send a table between 2 pgms in freeform

Post by jonboy49 »

It is not really clear exactly what you are trying to do. There are many possible answers none of which involve pointers - unless of course you are using the C APIs from RPG to process files.

The "table" you show is just a DS - not a file so I'm confused.

To answer the questions as posed though:

1) You can actually pass a file AS a parameter from one program to another. This is normally most useful where the first program positions the file and the second program reads the subsequent records. In your case though you could pass the file from X to Y, fill it in Y and the data would be there for X to read on return.

2) You can always just write a file in program Y and open it for reading in program Y. You may need to make the program Y force write the buffer (Use FEOD(N) after the last record was written) to be sure it is available for X to process.

If though you are looking to pass the DS that you have shown then you simply do that. Ideally you would convert the DS as shown to a template like so:

Code: Select all

dcl-ds sample_T qualified template;
   codeActiviteFm char(10);
   isAs400FiniPousserDansFm char(9);
   isOverlogFiniPousserDansFm char(9);
   isPrevisionsPretesPourIntegration char(20);
   modificateur char(20);
   dcl-ds traceabilites dim(002);
      propriete char(20);
      horodatage char(20);
      modificateur char(20);
   end-ds;
end-ds;
This would be placed in a /Copy member and included in both programs X and Y.

Program X:

Code: Select all

/Copy DS_sample
Dcl-ds  sampleData  LikeDS(sample_T);
// Call program Y
Y( sampleData);
// Now process data placed in sampleData by Y
Program Y:

Code: Select all

/Copy DS_sample
Dcl-PI ...
   sampleData LikeDS(sample_T);
...
// Populate DS and return to X
That's it - no pointers needed. At least not visibly that is.
Dcl-ds sampleData LikeDS(sample_T);
OlivierPierre04
Posts: 17
Joined: Fri Jan 07, 2022 2:56 pm

Re: send a table between 2 pgms in freeform

Post by OlivierPierre04 »

tks
Post Reply