Using JSON Nested Data Structures in Multiple Programs
Using JSON Nested Data Structures in Multiple Programs
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
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:
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-DS myDS_T Qualified Template;
field1 char(10);
field2 int(5);
Dcl-DS nestedDS Dim(20);
field3 varchar(40);
End-DS;
End-DS;
Code: Select all
Dcl-Pr myProcedure;
structure likeDS(myDS_T);
End-Pr;
-
- Site Admin
- Posts: 670
- Joined: Sun Jul 04, 2021 5:12 am
Re: Using JSON Nested Data Structures in Multiple Programs
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.
I'd never pass a pointer. Passing a pointer does not make sense for this.
Re: Using JSON Nested Data Structures in Multiple Programs
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.
-
- Site Admin
- Posts: 670
- Joined: Sun Jul 04, 2021 5:12 am
Re: Using JSON Nested Data Structures in Multiple Programs
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.