DATA-INTO Question

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
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

DATA-INTO Question

Post by emhill »

I have my DATA-INTO data structure created like this:

Code: Select all

dcl-ds jsonDoc qualified;                            
  STATUS varchar(10) inz('');                        
  MESSAGE varchar(50) inz('');                       
  INTERFACENAME varchar(50) inz('');                 
  num_BATCHCLAIMRESPONSE int(10) inz(0);             
  dcl-ds BATCHCLAIMRESPONSE dim(150);                
    dcl-ds CLAIMINFO;                                
      TRACKINGNUMBER varchar(10) inz('');            
      SUBMITTALINDICATOR varchar(1) inz('');         
      SERIALNUMBER varchar(20) inz('');              
      RMASTATUSDESCRIPTION varchar(80) inz('');      
      RMASTATUSCODE varchar(3) inz('');              
      REPAIRORDER varchar(8) inz('');                
      REPAIRINGOUTLET varchar(10) inz('');           
      IDENTIFIER varchar(50) inz('');                
      DISPOSITIONCODEDESCRIPTION varchar(80) inz('');
      DISPOSITIONCODE varchar(5) inz('');            
      DATETIMEPROCESSED varchar(24) inz('');         
      CLAIMSTATUSDESCRIPTION varchar(20) inz('');    
      CLAIMSTATUSCODE varchar(3) inz('');            
      num_CLAIMPROCESSMSGINFO int(10) inz(0);        
      dcl-ds CLAIMPROCESSMSGINFO dim(300);           
        LINENUMBER varchar(5) inz('');               
        PROCESSCODE varchar(4) inz('');
        PROCESSCATEGORYDESCRIPTION varchar(20) inz(''); 
        PROCESSMESSAGE varchar(80) inz('');             
      end-ds;                                           
      CLAIMNUMBER varchar(20) inz('');                  
      APPROVEDDOLLARAMOUNT varchar(20) inz('');         
    end-ds;                                             
    BUSINESSPARTNERCODE varchar(10) inz('');            
  end-ds;                                               
end-ds;                                                                      
This is my DATA-INTO statement:

Code: Select all

data-into jsonDoc %DATA( ifsPathname                               
         : 'doc=file case=convert countprefix=num_ allowextra=yes')
                %PARSER( 'YAJLINTO'                                
                       : '{ "document_name": "jsonDoc", +          
                            "number_prefix": "YAJL_" }');          
All works well until I get the following response for my request where a claim number "posted" is invalid:

Code: Select all

{
  "status": "Success",
  "message": "Claim not Found",
  "interfaceName": "I-207 - Batch Claim Submittal Response",
  "batchClaimResponse": null
}
How do I handle that error in the DATA-INTO statement? Would the 'allowmissing=yes' option and then checking the 'num_BATCHCLAIMRESPONSE' value for zero? Or do I need a monitor wrapped around the statement?

Thanks!!!!
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-INTO Question

Post by Scott Klement »

RPG (including DATA-INTO) expects the data type of variables to be set at compile time, and not changed after it has been compiled.

As such BatchClaimResponse can't be both null AND a data structure. It must be one or other... DATA-INTO really only works if the fields are always the same type. If they are sometimes data structures, and sometimes something else (like null) it doesn't work very well.

So... no... allowmissing=yes won't help, because the field isn't missing! Checking the count of batchClaimResponse for 0 won't work, because the document doesn't contain 0 -- it contains 1. ( But, the one sent is null.)

One way to handle this would be to use the YAJL subprocedures instead of DATA-INTO. That will be able to check the contents of the batchClaimResponse to see if it's null without problems.
Post Reply