Number 3. means that something in your SQL statement is returning a NULL which requires a NULL indicator field to be defined in your RPG program. For example, the following SQL always results in a null value and will fail here:
dcl-s myField char(1);
: : : :
exec sql :myField = nullif('', '') -- <-- Force a NULL value;
: : : :
..however, using a null indicator field, works:
dcl-s myField char(1);
dcl-s myFieldNi int(5);
: : : :
exec sql :myField :myFieldNi = nullif('', '');
: : : :
if myFieldNi < 0; -- Test for null value....
You can fix this by either adding null indicator fields as above or by preventing NULL occurring in the first place. How you do this depends on which line you're getting the error. In your case it could be that the web-service is returning nothing or that you're getting a NULL where you're deconstructing your JSON object with JSON_TABLE because some object keys you're looking for aren't there. For example, the following code snippet from the article you linked to uses "lax" which means the key is allowed to be missing, and will give you a NULL value if so.
NESTED Path
'$.pet[*]'
Columns(ws_pet_type VarChar(30) Path 'lax $.type',
ws_pet_price decimal(5,2) Path 'lax $.price')
)) As x;
You can prevent this by giving a default value by adding a "default ... on empty" clause.
NESTED Path
'$.pet[*]'
Columns(ws_pet_type VarChar(30) Path 'lax $.type' default '' on empty,
ws_pet_price decimal(5,2) Path 'lax $.price' default 0 on empty)
)) As x;
If the error isn't caused by the JSON_TABLE then you could prevent it by wrapping the offending column in a COALESCE (or VALUES) keyword to provide a default in the event of a NULL result.:
dcl-s myField char(1);
: : : :
exec sql :myField = coalesce(nullif('', ''), '?');
: : : :
One general observation about the example, I've only had a quick look but the article you linked to doesn't appear need the cursor at all. The whole ConsumeWS subroutine could be rewritten as a single SQL statement (something like below). Don't fall into the trap of emulating a SETLL/READE....DOW....READE ENDDO with SQL and cursors in RPG when it's often unnecessary!
exec sql
Insert Into Pet_Post (pet_message, pet_type, pet_price, AddPgm, AddUser, UpdatePgm, UpdateUser)
Select x.*, :pgm_stat.ProgramId, :pgm_stat.User, :pgm_stat.ProgramId, :pgm_stat.User
from
Json_Table(Systools.HttpPostClob(:WebServiceUrl, :WebServiceHeader, :WebServiceBody),
'$'
Columns(ws_pet_message VarChar(30) Path 'lax $.message',
NESTED Path
'$.pet[*]'
Columns(ws_pet_type VarChar(30) Path 'lax $.type',
ws_pet_price decimal(5,2) Path 'lax $.price')
)) As x
Tim.
________________________________
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> on behalf of Giovanni Arturi via MIDRANGE-L <midrange-l@xxxxxxxxxxxxxxxxxx>
Sent: 04 March 2020 00:00
To: 'Kevin Bucknum' <Kevin@xxxxxxxxxxxxxxxxxxx>; midrange-l@xxxxxxxxxxxxxxxxxx <midrange-l@xxxxxxxxxxxxxxxxxx>
Cc: Giovanni Arturi <giovanni.arturi@xxxxxxxxx>
Subject: R: Help with Consuming A REST Web Service Using SQL And POST from ITJungle
Hi Kevin
I tried to read the discussion in RPG400 ;
i tried :
1. to set DCL-S fieldname datatype CCSID(37) , but i receive error in compiling (i’m run V7r2 ) !!
2. I have tried with chgjob CCSID 1141 and when i run the pgm i don’t receive error but the WebService answer with “API_KEY wrong”, but the API_KEY is correct , i tried with Postman (with the same data)
3. I Have tried with chgjob CCSID 1144 (Italian CCSID) and now i receive error that says “An indicator variable is required”
Any suggestion ?
Thanks
Da: Kevin Bucknum [mailto:Kevin@xxxxxxxxxxxxxxxxxxx]
Inviato: martedì 3 marzo 2020 18:29
A: midrange-l@xxxxxxxxxxxxxxxxxx
Cc: giovanni.arturi@xxxxxxxxx
Oggetto: Re: Help with Consuming A REST Web Service Using SQL And POST from ITJungle
You can't use the sql http functions with a job ccsid of 65535.
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ibm.com%2Fsupport%2Fknowledgecenter%2Fssw_ibm_i_73%2Frzajq%2Frzajqhttpoverview.htm&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=tKagQPbwQdBHrZAd5ZVaVpS4Dp9rgCXynaMsKFbVC1g%3D&reserved=0
There was a discussion this morning on the RPG400 list that discusses this same error.
On Tue, 2020-03-03 at 18:14 +0100, Giovanni Arturi via MIDRANGE-L wrote:
Hi all
I have found the example at
<
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.itjungle.com%2F2017%2F10%2F02%2Fguru-consuming-rest-web-service-using-sq&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=icwZ1o2Ip6Qqm61AvtuOa4LqYhn2ww%2BF31Ci2C%2FaGok%3D&reserved=0>
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.itjungle.com%2F2017%2F10%2F02%2Fguru-consuming-rest-web-service-using-sq&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=icwZ1o2Ip6Qqm61AvtuOa4LqYhn2ww%2BF31Ci2C%2FaGok%3D&reserved=0
l-post/ and followed it. I have customized the example, but when i run the
program i receive in SqlCode the value "-332" and as message i receive
"Invalid character conversion between CCSID 65535 and CCSID 1200"
Where am i wrong ? mu job run under 65535 CCSID
Thanks in advance
--
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
<
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.avast.com%2Fantivirus&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=uk3QHiARYzcZCUF8qAz7VsQy8k5IM4D50d6%2BgsD8i9w%3D&reserved=0>
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.avast.com%2Fantivirus&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=uk3QHiARYzcZCUF8qAz7VsQy8k5IM4D50d6%2BgsD8i9w%3D&reserved=0
Kevin Bucknum
Senior Programmer Analyst
MEDDATA / MEDTRON
120 Innwood Drive
Covington LA 70433
Local: 985-893-2550
Toll Free: 877-893-2550
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.medtronsoftware.com&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=pamawcfVXeiuKlxUUeDXjWBJM3IZTpb%2BSK7EJaRMlgA%3D&reserved=0
CONFIDENTIALITY NOTICE
This document and any accompanying this email transmission contain confidential information, belonging to the sender that is legally privileged. This information is intended only for the use of the individual or entity named above. The authorized recipient of this information is prohibited from disclosing this information to any other party and is required to destroy the information after its stated need has been fulfilled. If you are not the intended recipient, or the employee of agent responsible to deliver it to the intended recipient, you are hereby notified that any disclosure, copying, distribution or action taken in reliance on the contents of these documents is STRICTLY PROHIBITED. If you have received this email in error, please notify the sender immediately to arrange for return or destruction of these documents.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fmidrange-l&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=cAiy360QJBx6%2FYdHmoKT2hned5YqogRSlRKoUMbzP%2F8%3D&reserved=0
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fmidrange-l&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=VNmHXYX%2F7g2%2FiHBHHuCdjbJWTX%2BHBwA6C0mii9vlN7U%3D&reserved=0.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Famazon.midrange.com&data=02%7C01%7C%7Caa63cfc5db90408e393808d7bfc674b7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637188731386304269&sdata=t%2F1OEUy7QsCKe7e90VhNpUzB4Zn5RMs%2FMHiFOSWxxHI%3D&reserved=0
As an Amazon Associate we earn from qualifying purchases.