Page 1 of 1

Using DATA-GEN + YAJLDTAGEN for iterative build

Posted: Wed Mar 30, 2022 9:14 pm
by jonboy49
I know I could do this by simply nesting the structures, but I am trying to use the iterative build feature for cases where the array size exceeds RPG's capabilities. Problem is no matter how I try to structure it the resulting JSON is always "close but no cigar". I have these two DS;

Code: Select all

Dcl-ds  orderHeader  Inz;
   CustomerName     varchar(40);
   CustomerId       char(6);
   name_PO_Number   char(9) inz('PO Number');
   PO_Number        varchar(20);
   DueDate          date(*USA);
End-ds;


Dcl-ds  detailLine;
  itemCode  char(8);
  quantity  int(5);
  price     packed(5:2);
End-ds;
And what I want to produce is something like this:

Code: Select all

{
    "CustomerName": "",
    "CustomerId": "",
    "PO Number": "",
    "DueDate": "03/30/2022",
    "Details": [
        {
            "itemCode": "Item-1",
            "quantity": 1,
            "price": 0.60
        },
        repeat items ad naseum
    ]
}
No matter what combo of DATA-GEN I try the best I can get so far is this:

Code: Select all

{
    "CustomerName": "",
    "CustomerId": "",
    "PO Number": "",
    "DueDate": "03/30/2022"
}  <<< this close not wanted ...
[  <<< this array needs a key
    {
        "itemCode": "Item-1",
        "quantity": 1,
        "price": 0.60
I'm guessing that between YAJLDTAGEN and DATA-GEN there is not a combination that will work. Is there any kind of JSON document that can be built iteratively ? I can't think of anything right now but since I know Scott would have tested the capability I feel I am just missing something.

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Posted: Thu Mar 31, 2022 4:01 am
by Scott Klement
Unfortunately, there really isn't a way to do that.

DATA-GEN passes an RPG variable, and YAJLDTAGEN converts that variable to JSON format.

If you think about what you're trying to output -- you're trying to output "part of" a variable. The top of your document is this:

Code: Select all

{               <-- this is a "data structure"
    "CustomerName": "",
    "CustomerId": "",
    "PO Number": "",
    "DueDate": "03/30/2022",
    "Details": [ <-- this is an array
So you are asking DATA-GEN to pass just "part of" a data structure, and part of an array. This just isn't how DATA-GEN works, it always passes an entire variable.

Using the YAJL subprocedures you could do it easily.

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Posted: Thu Mar 31, 2022 1:02 pm
by jonboy49
So effectively the iterative build option is just not usable with YAJLDTAGEN at all then? Or can you think of a case that works?

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Posted: Thu Mar 31, 2022 7:28 pm
by Scott Klement
There are two different things I can think of that might be referred to as an "interative build". I'm assuming you mean sequences where you do *START and *END, right?

You can use sequences with YAJLDTAGEN provided that the top-level element is an array or an object, and that each sub-element is added directly to that array or object (rather than being nested deeper into it.)

Take a look at the sequences stuff in the following slides https://www.scottklement.com/presentati ... TA-GEN.pdf -- the part about sequences begins at slide 24.

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Posted: Thu Mar 31, 2022 11:46 pm
by jonboy49
Thanks Scott - I could have sworn that I had tried that but I guess not.

I'll play with it some more and tease out the limits.

Thanks again.