Data-INTO issue Reason Code 6

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/
Post Reply
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Data-INTO issue Reason Code 6

Post by kathan.p@gmail.com »

Json Received -

Code: Select all

{
  "start_time": "2022-06-06T00:00:06.000Z",
  "data_extract": {
    "expected_end_datetime": "2022-06-07T00:00:00",
    "stop_idle_fuel_used": 0,
    "distance_drive": 353.1,
    "drive_time": 442.25,
    "performance_group_id": "default",
    "odometer_start": 36255.84,
    "engine_time": 442.25,
    "pto_time": 0,
    "over_rpm_count": 13,
    "stop_idle_time": 0,
    "intertrip_idle_time": 0,
    "coast_out_gear_time": 0,
    "top_gear_time": 87.55,
    "total_trip_count": 21,
    "cruise_control_time": 152.92,
    "moving_time": 403.15,
    "over_rpm_time": 0.75,
    "total_idle_fuel_used": 0.6,
    "over_rpm_max_value": 1999,
    "over_speed_count": 0,
    "moving_fuel_used": 40.8,
    "excessive_rpm_time": 0,
    "excessive_overspeed_time": 0,
    "stop_idle_count": 0,
    "total_idle_time": 39.1,
    "over_speed_time": 0,
    "total_fuel_used": 41.4,
    "over_rpm_max_duration": 0.27,
    "excessive_rpm_count": 0,
    "gear_data_source": "J1939",
    "pto_fuel_used": 0,
    "engine_readings_count": 26535,
    "speed_rpm_matrix": [
      [
        0,
        0,
        0.12,
        0.13,
        0.08,
        18.15,
        6,
        2,
        3.25,
        4.92,
        3.12,
        0.82,
        0.23,
        0.17,
        0.07,
        0.03,
        0.02,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        4.63,
        9.02,
        1.03,
        1.12,
        2.9,
        14.3,
        67.55,
        82.02,
        23.07,
        12.68,
        7.42,
        3.72,
        2.65,
        0.85,
        0.33,
        0.12,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        3.48,
        7.33,
        0.3,
        0.37,
        0.48,
        0.25,
        0.38,
        110.2,
        0.47,
        0.03,
        0.62,
        1.25,
        0.02,
        0.02,
        0.25,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        4.48,
        7.62,
        0.23,
        0.23,
        0.1,
        0.18,
        0.22,
        5.73,
        13.25,
        0.02,
        0.05,
        1.97,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        0.62,
        2.57,
        0.17,
        0.07,
        0.03,
        0.12,
        0.13,
        0.07,
        3.55,
        0.02,
        0,
        0.18,
        0.17,
        0,
        0,
        0.05,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        0,
        1.12,
        0.03,
        0,
        0,
        0.02,
        0,
        0,
        0.45,
        0.02,
        0,
        0,
        0.27,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        0,
        0.47,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0.12,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    ],
    "avg_engine_load": 36.08,
    "stop_idle_warning_count": 0,
    "short_idle_fuel_used": 0.6,
    "over_speed_max_duration": 0,
    "short_idle_count": 61,
    "excessive_overspeed_count": 0,
    "short_idle_time": 39.1
  },
  "end_time": "2022-06-07T00:00:01.000Z"
}

Data-Structure created :-

Code: Select all

dcl-ds jsonDoc qualified;                               
  START_TIME varchar(24) inz('');                       
  dcl-ds DATA_EXTRACT;                                  
    EXPECTED_END_DATETIME varchar(19) inz('');          
    STOP_IDLE_FUEL_USED packed(1) inz(0);               
    DISTANCE_DRIVE packed(4: 1) inz(0);                 
    DRIVE_TIME packed(5: 2) inz(0);                     
    PERFORMANCE_GROUP_ID varchar(7) inz('');            
    ODOMETER_START packed(7: 2) inz(0);                 
    ENGINE_TIME packed(5: 2) inz(0);                    
    PTO_TIME packed(1) inz(0);                          
    OVER_RPM_COUNT packed(2) inz(0);                    
    STOP_IDLE_TIME packed(1) inz(0);                    
    INTERTRIP_IDLE_TIME packed(1) inz(0);               
    COAST_OUT_GEAR_TIME packed(1) inz(0);               
    TOP_GEAR_TIME packed(4: 2) inz(0);                  
    TOTAL_TRIP_COUNT packed(2) inz(0);                  
    CRUISE_CONTROL_TIME packed(5: 2) inz(0);            
    MOVING_TIME packed(5: 2) inz(0);                    
OVER_RPM_TIME packed(3: 2) inz(0);               
TOTAL_IDLE_FUEL_USED packed(2: 1) inz(0);        
OVER_RPM_MAX_VALUE packed(4) inz(0);             
OVER_SPEED_COUNT packed(1) inz(0);               
MOVING_FUEL_USED packed(3: 1) inz(0);            
EXCESSIVE_RPM_TIME packed(1) inz(0);             
EXCESSIVE_OVERSPEED_TIME packed(1) inz(0);       
STOP_IDLE_COUNT packed(1) inz(0);                
TOTAL_IDLE_TIME packed(3: 1) inz(0);             
OVER_SPEED_TIME packed(1) inz(0);                
TOTAL_FUEL_USED packed(3: 1) inz(0);             
OVER_RPM_MAX_DURATION packed(3: 2) inz(0);       
EXCESSIVE_RPM_COUNT packed(1) inz(0);            
GEAR_DATA_SOURCE varchar(5) inz('');             
PTO_FUEL_USED packed(1) inz(0);                  
ENGINE_READINGS_COUNT packed(5) inz(0);          
num_SPEED_RPM_MATRIX int(10) inz(0);             
SPEED_RPM_MATRIX varchar(5) dim(25);    
AVG_ENGINE_LOAD packed(4: 2) inz(0);             
STOP_IDLE_WARNING_COUNT packed(1) inz(0);        
SHORT_IDLE_FUEL_USED packed(2: 1) inz(0);        
OVER_SPEED_MAX_DURATION packed(1) inz(0);        
SHORT_IDLE_COUNT packed(2) inz(0);          
    EXCESSIVE_OVERSPEED_COUNT packed(1) inz(0);
    SHORT_IDLE_TIME packed(3: 1) inz(0);       
  end-ds;                                      
  END_TIME varchar(24) inz('');                
end-ds;                                             

Data-into used below:-

Code: Select all

data-into jsonDoc %DATA(jsonstring                               
                       : 'doc=string case=convert countprefix=num_') 
                %PARSER( 'YAJLINTO'                                
                       : '{ "document_name": "jsonDoc", +          
                            "number_prefix": "YAJL_" }');          
Getting below error -
Message . . . . : The information supplied by the parser for the DATA-INTO
operation was in error. Reason code 6.
Cause . . . . . : While parsing an document for an RPG procedure, the
information supplied by the parser was in error. The actual document is *N;
*N indicates that the document was not an external file. The parser is
'YAJLINTO'. *N indicates that the parser is a procedure pointer. The reason
code is 6.

6. A call to QrnDiReportValue, QrnDiReportValueCcsid, QrnDiStartStruct, or
QrnDiStartArray was made, but there was no prior call to QrnDiReportName
or QrnDiReportNameCcsid. Calling QrnDiReportValue, QrnDiReportValueCcsid,
QrnDiStartStruct, or QrnDiStartArray without a prior call to
QrnDiReportName or QrnDiReportNameCcsid is only valid at the beginning of the parse



What am i doing wrong? i can't understand the error? pls advise
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: Data-INTO issue Reason Code 6

Post by Scott Klement »

Your JSON document has a two-dimensional array named "speed_rpm_matrix". Unfortunately, RPG doesn't support two-dimensional arrays, and therefore data-into is getting confused.

Unfortunately, I don't know any way to use data-into with this document. You'd have to use the YAJL functions directly (or another tool, such as SQL.)
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Re: Data-INTO issue Reason Code 6

Post by kathan.p@gmail.com »

Used YAJL and it worked!! Thanks!!
ccacmm2016
Posts: 3
Joined: Tue Dec 28, 2021 4:29 pm

Re: Data-INTO issue Reason Code 6

Post by ccacmm2016 »

How were you able to get it to work with YAJL? I'm able to get the out side arrary but can't get my program to read the array inside the array.

Here is my code but I'm getting blanks when I try to get the string. Data is the array of arrays.

Code: Select all

           @AdvanceNode = yajl_object_find(@Response:'data');
           @Node = yajl_object_find(@Response:'data');
           @AdvCount = 0;

           Dow Yajl_array_Loop(@AdvanceNode:@AdvCount:@Node);
             @InnerCount = 0;
             Dow yajl_array_loop(@Node:@InnerCount:@AdvanceNode);
               Select;
                 When @First;
                   @Type = yajl_get_string(@Node);
                   @First = *Off;
                   @Second = *On;

                 When @Second;
                   @Comcheck = yajl_get_string(@Node);
                   @Second = *Off;
                   @Third = *On;

                 When @Third;
                   @Amount = %Dec(yajl_get_string(@Node):6:2);
                   @Third = *Off;
                   @First = *On;

                EndSl;
              Enddo;
           EndDo;
ccacmm2016
Posts: 3
Joined: Tue Dec 28, 2021 4:29 pm

Re: Data-INTO issue Reason Code 6

Post by ccacmm2016 »

This is the JSON file I'm trying to get the data out of:

Code: Select all

{
   "resultSetMetaData":{
      "numRows":2,
      "format":"jsonv2",
      "partitionInfo":[
         {
            "rowCount":2,
            "uncompressedSize":116
         }
      ],
      "rowType":[
         {
            "name":"ADVANCE_TYPE",
            "database":"MASTERMIND_SHARE",
            "schema":"PUBLIC",
            "table":"ADVANCES",
            "nullable":true,
            "scale":null,
            "byteLength":16777216,
            "collation":null,
            "precision":null,
            "type":"text",
            "length":16777216
         },
         {
            "name":"REF_NUMBER",
            "database":"MASTERMIND_SHARE",
            "schema":"PUBLIC",
            "table":"ADVANCES",
            "nullable":true,
            "scale":null,
            "byteLength":16777216,
            "collation":null,
            "precision":null,
            "type":"text",
            "length":16777216
         },
         {
            "name":"NET_PAYMENT",
            "database":"MASTERMIND_SHARE",
            "schema":"PUBLIC",
            "table":"ADVANCES",
            "nullable":true,
            "scale":5,
            "byteLength":null,
            "collation":null,
            "precision":19,
            "type":"fixed",
            "length":null
         }
      ]
   },
   "data":[
      [
         "Lumper",
         "99974010275394",
         "50.00000"
      ],
      [
         "Fuel Advance",
         "f3a0919b-2ba8-4d42-927f-6e2dae2433d4",
         "5.00000"
      ]
   ],
   "code":"090001",
   "statementStatusUrl":"/api/v2/statements/01ab9586-0b04-6585-0003-14aa00033176?requestId=a4389afc-ff64-4c81-a915-0e5e931fde99",
   "requestId":"a4389afc-ff64-4c81-a915-0e5e931fde99",
   "sqlState":"00000",
   "statementHandle":"01ab9586-0b04-6585-0003-14aa00033176",
   "message":"Statement executed successfully.",
   "createdOn":1681329031963
}
ccacmm2016
Posts: 3
Joined: Tue Dec 28, 2021 4:29 pm

Re: Data-INTO issue Reason Code 6

Post by ccacmm2016 »

I figured it out. No need for a response. Thank you.
Post Reply