Using JSON Nested Data Structures in Multiple Programs

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Using JSON Nested Data Structures in Multiple Programs

Post by bbunney »

We use YAJL to parse and publish JSON. In order to do that, like most programmers, we create nested data structures to contain the data back and forth with JSON documents. These nested data structures will be used in more than one program as the data will be passed as a parameter using a pointer to another program. I could create a /COPY source for the data structures. I was wondering if there is a best practice for this or how others would handle this situation. Thanks.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Using JSON Nested Data Structures in Multiple Programs

Post by jonboy49 »

I would (and do) do exactly what you have suggested. In fact I go one step further in that the /COPY contains the DS as a template. Like so:

Code: Select all

       Dcl-DS myDS_T  Qualified  Template;
          field1  char(10);
          field2  int(5);
          Dcl-DS  nestedDS  Dim(20);
             field3  varchar(40);
          End-DS;   
       End-DS;
That way you can simply reference the template in the Pr and PI and also create the required definitions in the called routine by referencing the template.

Code: Select all

       Dcl-Pr  myProcedure;
          structure  likeDS(myDS_T);
       End-Pr;
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Using JSON Nested Data Structures in Multiple Programs

Post by Scott Klement »

I always (this is not an unusual thing, I do it every day) use the sort of technique that Jonboy demonstrated.

I'd never pass a pointer. Passing a pointer does not make sense for this.
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Using JSON Nested Data Structures in Multiple Programs

Post by bbunney »

Thank you for the feedback guys. That makes a lot of sense. As far as using a pointer to the data goes, the way one of our programmers did it was to use a 64k variable size parameter field to move the data from program to program. What I want to do is pass the nested data structure with no pointer as a parameter instead doing a LikeDs to the nested data structure in the PI of the program to be called.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Using JSON Nested Data Structures in Multiple Programs

Post by Scott Klement »

Correct, just pass the data structure. There is no need to pass a pointer or convert it to/from a character parameter.... just pass the data structure. Use LIKEDS to ensure that it has the same format in both programs.
Post Reply