DATA-INTO Failing

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: DATA-INTO Failing

Post by emhill »

Thank you!!!!
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: DATA-INTO Failing

Post by emhill »

Jon,

This got put on the back-burner for a while but now I'm back at it. Still a little confused on where my "dcl-ds" definitions of the json I'm "reading" goes when using the %HANDLER. I really didn't know what you meant when you said "<snip out definitions>" or the "CLAIMPROCESSEDRECORD" comment as "empty". I'm not sure where those data structures go.

Thanks for your patience with this novice!!!!
jonboy49
Posts: 205
Joined: Wed Jul 28, 2021 8:18 pm

Re: DATA-INTO Failing

Post by jonboy49 »

By "<snip out definitions>" I simply meant that for clarity of explanation I had removed all of the other field and nested DS definitions that were within the REPAIRINGOUTLETRECORD part of the data. e.g. the fields ...

Code: Select all

    REPAIRINGOUTLETNAME varchar(30) inz('');     // This was the first one I snipped                  
    REPAIRINGOUTLETADDRESSLINE1 varchar(30) inz(''); 
    ...
    PROCESSMESSAGE varchar(80) inz('');  // And this the last
I don't recall what the "empty" bit was about - probably something I had in my test code that should have been omitted. Sorry if that confused you.

As to where they go - just where I showed them - you need the template and the LikeDS to clone it for the parm.

This:

Code: Select all

dcl-ds REPAIRINGOUTLETRECORD_T  Qualified Template ;
Is the template definition of the structure that will be populated. The actual data will be placed by RPG in the parameter (defined by a LikeDS associated with this template) that is passed to your subprocedure. You have to use LikeDS to define it since you can't define a DS directly in a parameter list.

The processing logic that you had when iterating across the whole result set just gets moved inside the subprocedure as I noted.

Other than writing the complete program for you (and I've already done most of it) I don't know how else to explain it.

I have an article on %Handler with XML-INTO which works the same way here: https://www.mcpressonline.com/programmi ... o-problems The web site have screwed up the code formatting but you should be able to work it out.
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: DATA-INTO Failing

Post by emhill »

I think what is really throwing me is the "dim()". For the procedure it is showing this:

Code: Select all

item   likeDS(REPAIRINGOUTLETRECORD_T)  Dim(1)  Const;
There may be over 100 outlets now and more to come later. Same for the other arrays in the JSON data.

There is no num_REPAIRINGOUTLETRECORD on the template. Will the procedure do the "for" loop based on that if it is not in the template? Same for all the other num_* fields and arrays?

I notice you had your example code look like this:

Code: Select all

for i = 1 to num_repairingoutletrecord;
   // process item(1).repairingOutletRecord(i).REPAIRINGOUTLETBUSINESSPARTNERCODE etc.
   for j = 1 to item(1).repairingOutletRecord(i).num_WORKINPROGRESSCLAIMSRECORD;
      // process item(1).repairingOutletRecord(i).WORKINPROGRESSCLAIMSRECORD(j).TRACKINGNUMBER etc.
   endfor;
   // Process the other nested arrays and other data.
endfor;
Using "1" in the index for the item array. So you're saying the handler will roll through the JSON data if coded like that?

That is what had me scratching my head.

Thanks for all the help.
jonboy49
Posts: 205
Joined: Wed Jul 28, 2021 8:18 pm

Re: DATA-INTO Failing

Post by jonboy49 »

I don't wish to be rude but did you ever actually try and run my code sample or read the article I referenced?

The code I supplied, as I noted at the time, was cut from a WORKING example.

As to your questions.

My code used a hard-coded 1 as the element number because the Dim on the proto requested that I be given only one at a time. I coded it this way since you were unsure how many repeats of lower level DS there were and therefore how big they might be. It may seem odd to specify an array of only one element, but it is just a requirement of the %Handler option that the parm must be an array - even if only 1 element long.

By specifying Dim(1) I was requesting that the handler will receive a maximum of 1 element at a time. No num_ field is required because A) you are only getting one element, B) in the event that you specified (say) Dim(9) the actual count is passed to you in the parameter items passed to the subprocedure and C) By doing it this way it doesn't matter if you have 100 elements at the top level or 1 million - it will still work. You would only encounter an issue if the number of nested repeating elements _within_ REPAIRINGOUTLETRECORD became so huge that it got larger than 16Mb which seems unlikely.

You only to need to run a FOR loop against the nested DS arrays and the num_ fields for those will have been populated, as my example shows. Run the code in debug and you'll see. Don't forget to step INTO the subprocedure.
Post Reply