ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

YAJLINTO - The document for the DATA-INTO operation does not match the RPG var

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • YAJLINTO - The document for the DATA-INTO operation does not match the RPG var

    hi

    I get "The document for the DATA-INTO operation does not match the RPG variable; reason code 5. " error when I am trying to move the JSON into a DS.

    I get the json as a variable in the program. The json validate cleanly when I check it on JSONLint.com. I do not understand mapping error. Any help will be appreciated

    data-into takeOnRequest %DATA(myJSON: 'case=convert +
    allowmissing=yes +
    allowextra=yes +
    countprefix=num_')
    %PARSER('YAJLINTO');

    It only partially complete the datastructure when I view it in debug mode as I get the error

    The DS is:


    dcl-ds takeOnRequest qualified;
    annuityCategory char(50) inz('');
    annuityType char(50) inz('');
    annuitantType char(50) inz('');
    productJurisdiction char(2) inz('');
    tableCode char(4) inz('');
    packageCode packed(3:0) inz(0);
    isAnnuityCompulsory ind inz('0');
    paymentDate char(10) inz('');
    num_income int(10) inz(0);
    dcl-ds income dim(10);
    paymentDate char(10) inz('');
    dcl-ds purchaseAmount;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    end-ds;
    inceptionDate char(10) inz('');
    specialQuote ind inz('0');
    dcl-ds adjustmentFactor;
    value packed(7:6) inz(0);
    end-ds;
    dcl-ds totalPurchaseAmountInclInterest;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    incomeFrequency packed(2:0) inz(0);
    dcl-ds incomeIncreasePattern;
    increaseType char(50) inz('');
    dcl-ds fixedIncomeIncreaseRate;
    value packed(7:6) inz(0);
    end-ds;
    end-ds;
    isFirstPaymentInArrears ind inz('0');
    guaranteedTerm packed(3:0) inz(0);
    dcl-ds commissionSacrificeRate;
    value packed(7:6) inz(0);
    end-ds;
    dcl-ds annuityCommissionInclVAT;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    dcl-ds grossIncome;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    dcl-ds taxablePortionAmount;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    dcl-ds taxablePortionRate;
    value packed(9:6) inz(0);
    end-ds;
    dcl-ds taxPayable;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    dcl-ds taxRate;
    value packed(9:6) inz(0);
    end-ds;
    dcl-ds netIncome;
    currency char(3) inz('');
    value packed(15:2) inz(0);
    end-ds;
    dcl-ds rolePlayers;
    dcl-ds payer;
    taxStatus char(50) inz('');
    ownerRelationship char(50) inz('');
    partyReferenceNumber packed(13:0) inz(0);
    end-ds;
    dcl-ds owner;
    partyType char(50) inz('');
    partyReferenceNumber packed(13:0) inz(0);
    end-ds;
    dcl-ds paymentBeneficiary;
    partyReferenceNumber packed(13:0) inz(0);
    end-ds;
    dcl-ds taxPayer;
    dcl-ds juristic;
    dcl-ds registrationNumber;
    country char(2) inz('');
    number char(50) inz('');
    identifierType char(50) inz('');
    end-ds;
    dcl-ds taxRateOverrideRate;
    value packed(7:6) inz(0);
    end-ds;
    end-ds;
    dcl-ds naturalPerson;
    birthDate char(10) inz('');
    dcl-ds nationalIdentity;
    country char(2) inz('');
    number char(50) inz('');
    identifierType char(50) inz('');
    end-ds;
    dcl-ds taxRateOverrideRate;
    value packed(7:6) inz(0);
    end-ds;
    end-ds;
    end-ds;
    dcl-ds annuitants;
    dcl-ds singleLife;
    dcl-ds annuitant;
    gender char(20) inz('');
    birthDate char(10) inz('');
    partyReferenceNumber packed(13:0) inz(0);
    end-ds;
    end-ds;
    end-ds;
    dcl-ds jointLife;
    dcl-ds firstAnnuitant;
    gender char(20) inz('');
    birthDate char(10) inz('');
    dcl-ds paymentReductionRateOnDeath;
    value packed(7:6) inz(0);
    end-ds;
    end-ds;
    dcl-ds secondAnnuitant;
    gender char(20) inz('');
    birthDate char(10) inz('');
    dcl-ds paymentReductionRateOnDeath;
    value packed(7:6) inz(0);
    end-ds;
    end-ds;
    end-ds;
    end-ds;
    num_financialAdvisers int(10) inz(0);
    dcl-ds financialAdvisers dim(10);
    brokerHouseCode char(6) inz('');
    brokerCode char(6) inz('');
    marketingAdviserCode char(6) inz('');
    branchCode char(6) inz('');
    correspondence char(1) inz('');
    dcl-ds split;
    value packed(7:6) inz(0);
    end-ds;
    end-ds;
    end-ds;


    The JSON

    myJSON =
    {
    "annuityCategory": "TRADITIONAL_AAAAAAA",
    "annuityType": "LIFE",
    "annuitantType": "JOINT_LIFE",
    "productJurisdiction": "ZA",
    "tableCode": "777C",
    "packageCode": "135",
    "paymentDate": "2020-10-20",
    "income": [{
    "paymentDate": "2020-10-27",
    "purchaseAmount": {
    "currency": "ZAR",
    "value": 10000000.00
    }
    }],
    "inceptionDate": "2020-11-01",
    "specialQuote": true,
    "adjustmentFactor": {
    "value": "0.017500"
    },
    "totalPurchaseAmountInclInterest": {
    "currency": "ZAR",
    "value": "18493753.12"
    },
    "purchaseAmount": {
    "currency": "ZAR",
    "value": "18493753.12"
    },
    "incomeFrequency": 12,
    "incomeIncreasePattern": {
    "increaseType": "INFLATION_LINKED_PLUS_FIXED_INCOME_INCREASE",
    "fixedIncomeIncreaseRate": {
    "value": "0.05"
    }
    },
    "isFirstPaymentInArrears": false,
    "guaranteedTerm": 5,
    "commissionSacrificeRate": {
    "value": "1.00"
    },
    "annuityCommissionInclVAT": {
    "currency": "ZAR",
    "value": "0.0"
    },
    "grossIncome": {
    "currency": "ZAR",
    "value": "64000.00"
    },
    "taxablePortionAmount": {
    "currency": "ZAR",
    "value": "64000.00"
    },
    "taxablePortionRate": {
    "value": "0.00"
    },
    "taxPayable": {
    "currency": "ZAR",
    "value": "0.00"
    },
    "taxRate": {
    "value": "0.00"
    },
    "netIncome": {
    "currency": "ZAR",
    "value": "64000.00"
    },
    "rolePlayers": {
    "payer": {
    "taxStatus": "TRUST",
    "ownerRelationship": "SAME",
    "partyReferenceNumber": "1111111111111"
    },
    "owner": {
    "partyType": "JURISTIC",
    "partyReferenceNumber": "2222222222222"
    },
    "paymentBeneficiary": {
    "partyReferenceNumber": "3333333333333"
    },
    "annuitants": {
    "singleLife": {
    "annuitant": {
    "gender": "FEMALE",
    "birthDate": "1963-03-03",
    "partyReferenceNumber": 4444444444444
    }
    }
    }
    },
    "financialAdvisers": [{
    "brokerHouseCode": "232323",
    "brokerCode": "000011",
    "marketingAdviserCode": "abcdef",
    "branchCode": "ghijkl",
    "correspondence": "N",
    "split": {
    "value": "0.750000"
    }
    }]
    }

  • #2
    I am digging through this but all I have spotted so far is that you have many more structures defined than exist in the json. I suspect that the levels are wrong but ...

    What field is indicated as the problem point in the error message?

    Comment


    • #3
      OK - I got all your stuff on my system and ran it - no errors!

      So - either:

      a) You are missing some RPG PTFs
      b) You have an old version of YAJLINTO which has a bug
      c) The code you posted is not what you are running!

      P.S. PLEASE use the [code] tags around your samples - otherwise all indentation is lost and you are forced to copy/paste the stuff into an editor to view it

      Comment


      • #4
        This is your code, except that I reformatted it to make it easier for other people to help you, and I made it into a runnable program. Hopefully this makes it more likely that someone will help you.

        Note that I would've been able to look at this and help you 10 hours earlier had I not had to manually reformat it. Please use [code] tags like JonBoy said, it'll make it much more likely that people will take the time to help you.

        Code:
        **free
        
        dcl-ds takeOnRequest qualified;
          annuityCategory     char(50) inz('');
          annuityType         char(50) inz('');
          annuitantType       char(50) inz('');
          productJurisdiction char(2)  inz('');
          tableCode           char(4)  inz('');
          packageCode         packed(3:0) inz(0);
          isAnnuityCompulsory ind inz('0');
          paymentDate         char(10) inz('');
          num_income          int(10) inz(0);
        
          dcl-ds income dim(10);
            paymentDate char(10) inz('');
            dcl-ds purchaseAmount;
              currency char(3) inz('');
              value packed(15:2) inz(0);
            end-ds;
          end-ds;
        
          inceptionDate char(10) inz('');
          specialQuote ind inz('0');
        
          dcl-ds adjustmentFactor;
            value packed(7:6) inz(0);
          end-ds;
        
          dcl-ds totalPurchaseAmountInclInterest;
            currency char(3) inz('');
            value packed(15:2) inz(0);
          end-ds;
        
          incomeFrequency packed(2:0) inz(0);
        
          dcl-ds incomeIncreasePattern;
            increaseType char(50) inz('');
            dcl-ds fixedIncomeIncreaseRate;
              value packed(7:6) inz(0);
            end-ds;
          end-ds;
        
          isFirstPaymentInArrears ind inz('0');
          guaranteedTerm packed(3:0) inz(0);
        
          dcl-ds commissionSacrificeRate;
            value packed(7:6) inz(0);
          end-ds;
        
          dcl-ds annuityCommissionInclVAT;
            currency char(3) inz('');
            value packed(15:2) inz(0);
          end-ds;
        
          dcl-ds grossIncome;
            currency char(3) inz('');
            value packed(15:2) inz(0);
          end-ds;
        
          dcl-ds taxablePortionAmount;
            currency char(3) inz('');
            value packed(15:2) inz(0);
          end-ds;
        
          dcl-ds taxablePortionRate;
            value packed(9:6) inz(0);
          end-ds;
        
          dcl-ds taxPayable;
            currency char(3) inz('');
            value packed(15:2) inz(0);
          end-ds;
        
          dcl-ds taxRate;
            value packed(9:6) inz(0);
          end-ds;
        
          dcl-ds netIncome;
            currency char(3) inz('');
            value packed(15:2) inz(0);
          end-ds;
        
          dcl-ds rolePlayers;
        
            dcl-ds payer;
              taxStatus char(50) inz('');
              ownerRelationship char(50) inz('');
              partyReferenceNumber packed(13:0) inz(0);
            end-ds;
        
            dcl-ds owner;
              partyType char(50) inz('');
              partyReferenceNumber packed(13:0) inz(0);
            end-ds;
        
            dcl-ds paymentBeneficiary;
              partyReferenceNumber packed(13:0) inz(0);
            end-ds;
        
            dcl-ds taxPayer;
        
              dcl-ds juristic;
                dcl-ds registrationNumber;
                  country char(2) inz('');
                  number char(50) inz('');
                  identifierType char(50) inz('');
                end-ds;
                dcl-ds taxRateOverrideRate;
                  value packed(7:6) inz(0);
                end-ds;
              end-ds;
        
              dcl-ds naturalPerson;
                birthDate char(10) inz('');
                dcl-ds nationalIdentity;
                  country char(2) inz('');
                  number char(50) inz('');
                  identifierType char(50) inz('');
                end-ds;
                dcl-ds taxRateOverrideRate;
                  value packed(7:6) inz(0);
                end-ds;
              end-ds;
        
            end-ds;
        
            dcl-ds annuitants;
              dcl-ds singleLife;
                dcl-ds annuitant;
                  gender char(20) inz('');
                  birthDate char(10) inz('');
                  partyReferenceNumber packed(13:0) inz(0);
                end-ds;
              end-ds;
            end-ds;
        
            dcl-ds jointLife;
              dcl-ds firstAnnuitant;
                gender char(20) inz('');
                birthDate char(10) inz('');
                dcl-ds paymentReductionRateOnDeath;
                  value packed(7:6) inz(0);
                end-ds;
              end-ds;
              dcl-ds secondAnnuitant;
                gender char(20) inz('');
                birthDate char(10) inz('');
                dcl-ds paymentReductionRateOnDeath;
                  value packed(7:6) inz(0);
                end-ds;
              end-ds;
            end-ds;
          end-ds;
        
          num_financialAdvisers int(10) inz(0);
        
          dcl-ds financialAdvisers dim(10);
            brokerHouseCode char(6) inz('');
            brokerCode char(6) inz('');
            marketingAdviserCode char(6) inz('');
            branchCode char(6) inz('');
            correspondence char(1) inz('');
            dcl-ds split;
              value packed(7:6) inz(0);
            end-ds;
          end-ds;
        
        end-ds;
        
        dcl-s myJSON varchar(65535);
        
        
        myJSON = '+
        {+
          "annuityCategory": "TRADITIONAL_AAAAAAA",+
          "annuityType": "LIFE",+
          "annuitantType": "JOINT_LIFE",+
          "productJurisdiction": "ZA",+
          "tableCode": "777C",+
          "packageCode": "135",+
          "paymentDate": "2020-10-20",+
          "income": [{+
            "paymentDate": "2020-10-27",+
            "purchaseAmount": {+
              "currency": "ZAR",+
              "value": 10000000.00+
            }+
          }],+
          "inceptionDate": "2020-11-01",+
          "specialQuote": true,+
          "adjustmentFactor": {+
            "value": "0.017500"+
          },+
          "totalPurchaseAmountInclInterest": {+
            "currency": "ZAR",+
            "value": "18493753.12"+
          },+
          "purchaseAmount": {+
            "currency": "ZAR",+
            "value": "18493753.12"+
          },+
          "incomeFrequency": 12,+
          "incomeIncreasePattern": {+
            "increaseType": "INFLATION_LINKED_PLUS_FIXED_INCOME_INCREASE",+
            "fixedIncomeIncreaseRate": {+
              "value": "0.05"+
            }+
          },+
          "isFirstPaymentInArrears": false,+
          "guaranteedTerm": 5,+
          "commissionSacrificeRate": {+
            "value": "1.00"+
          },+
          "annuityCommissionInclVAT": {+
            "currency": "ZAR",+
            "value": "0.0"+
          },+
          "grossIncome": {+
            "currency": "ZAR",+
            "value": "64000.00"+
          },+
          "taxablePortionAmount": {+
            "currency": "ZAR",+
            "value": "64000.00"+
          },+
          "taxablePortionRate": {+
            "value": "0.00"+
          },+
          "taxPayable": {+
            "currency": "ZAR",+
            "value": "0.00"+
          },+
          "taxRate": {+
            "value": "0.00"+
          },+
          "netIncome": {+
            "currency": "ZAR",+
            "value": "64000.00"+
          },+
          "rolePlayers": {+
            "payer": {+
              "taxStatus": "TRUST",+
              "ownerRelationship": "SAME",+
              "partyReferenceNumber": "1111111111111"+
            },+
            "owner": {+
              "partyType": "JURISTIC",+
              "partyReferenceNumber": "2222222222222"+
            },+
            "paymentBeneficiary": {+
              "partyReferenceNumber": "3333333333333"+
            },+
            "annuitants": {+
              "singleLife": {+
                "annuitant": {+
                  "gender": "FEMALE",+
                  "birthDate": "1963-03-03",+
                  "partyReferenceNumber": 4444444444444+
                }+
              }+
            }+
          },+
          "financialAdvisers": [{+
            "brokerHouseCode": "232323",+
            "brokerCode": "000011",+
            "marketingAdviserCode": "abcdef",+
            "branchCode": "ghijkl",+
            "correspondence": "N",+
            "split": {+
              "value": "0.750000"+
            }+
          }]+
        }';
        
        data-into takeOnRequest %DATA(myJSON: 'case=convert +
                                               allowmissing=yes +
                                               allowextra=yes +
                                               countprefix=num_')
                                %PARSER('YAJLINTO');
        
        *inlr = *on;
        The reason that JonBoy (and hopefully you) aren't getting any errors is because you have both allowmissing=yes and allowextra=yes. This will prevent data-into from detecting errors with missing or extra elements in the document (which is exactly what your post mentioned -- which doesn't make sense. When you received those errors, you must not have had the allowmissing=yes and allowextra=yes defined.)

        The JSON document is missing these subfields:
        • takeOnRequest.isAnnuityCompulsory
        • takeOnRequest.rolePlayers.taxPayer
        • takeOnRequest.rolePplayers.jointLife


        The DS definition is missing this subfield:
        • takeOnRequest.purchaseAmount


        An easy way to find out what the JSON doc is missing is to remove the 'allowmissing=yes' and run it. It will give an error code 4 that explains one of the missing elements. Add a num_isAnnuityCompulsory (or whichever element was in the error) and run it again and it'll tell you the next missing element. Repeat this until you've added num_xxxx fields for all of them.

        To find out what the DS is missing, keep the allowextra=yes you have to go through the data field-by-field and compare it to the DS to see what's missing. (This is somewhat tedious.)

        Personally for a document like this, if I don't need the 'purchaseAmount' field, I'd be okay with leaving it out of the DS and just using allowextra=yes. But the other fields, the ones that are missing from the JSON I would NOT use allowmissing=yes, but instead would define num_FIELDNAME so that it sets num_FIELDNAME to 0 when the field is missing, or 1 if it was provided. That way, your program can determine whether it was passed or not, and treat it as optional. Use if if found, but ignore it if not.

        Good luck.

        Comment


        • #5
          Hi JonBoy and Scott

          Thanks for your super fast response.

          My appologies for the incorrect formatting. This was my first post and I did not know about the [code] tags. Will include it in future. I wanted to add an attachment with the correct formatting but i did not have authority to do that.

          I have received confirmation that we have the latest PTF's installed
          PTFs
          7.2:
          • ILE RPG runtime: SI67186
          • ILE RPG compiler: SI67184:
          • Source files in library QOAR for DATA-INTO: SI67182
          7.3:
          • ILE RPG runtime: SI67187
          • ILE RPG compiler: SI67185
          • ILE RPG compiler, TGTRLS(V7R2M0): SI63445
          • Source files in library QOAR for DATA-INTO: SI67183


          Busy checking the version of YAJLINTO. It seems we have a 2018 version. Will install latest version

          Comment


          • #6
            Hi JonBoy and Scott

            Ok, i have to confess. It was a basic program error. the myJSON variable was not defined as varchar(65535) as what Scott did in his code sample. I think the myJSON was cut off and I did not send in a complete JSON structure and then the DATA-INTO failed.

            After I fixed the myJSON variable it is working.

            Again, thank you for the quick response and taking time on a newbie like myself to assist.

            We will still load the latest version of YAJLINTO

            Comment

            Working...
            X