Page 1 of 1

Using JSON Nested Data Structures in Multiple Programs

Posted: Wed Nov 01, 2023 8:22 pm
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.

Re: Using JSON Nested Data Structures in Multiple Programs

Posted: Wed Nov 01, 2023 9:33 pm
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;

Re: Using JSON Nested Data Structures in Multiple Programs

Posted: Thu Nov 02, 2023 10:41 am
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.

Re: Using JSON Nested Data Structures in Multiple Programs

Posted: Fri Nov 03, 2023 4:39 am
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.

Re: Using JSON Nested Data Structures in Multiple Programs

Posted: Sat Nov 04, 2023 12:48 pm
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.