If you expect null values are returned, you can define a null indicate for
the appropriate field and add it immediately after the variable separated
only be by a blank into which the data is fetched.
If you are working with an output datastructure, you can also generated an
array of indicator variables with as much elements as values are returned
(i.e. as much sub-fields are defined in your data structure), i.e. one
indicator for each field.
Then you can check the indicator for each field.
The other option would be to used the COALESCE scalar function within the
DECLARE CURSOR ... SELECT statement to convert a possible NULL value into a
default value.
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of
(WalzCraft) Jerry Forss
Sent: Dienstag, 5. November 2019 15:12
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: SQL consume json with null values
Hi All,
I call a web service to get current time info in json. Mainly did for
learning purposes a while back.
The json can contain null for 2 fields (dst_until and dst_from) when NOT in
DST. During DST they contain data.
When I ran into this when creating the pgm I had trouble figuring out where
to use the null indicator when fetching into a DS. To get around this I
just load into the DS fields.
Is there a way to fetch into the DS identifying the null indicator?
NullUntil and NullFrom are defined as Int(5).
I know about using YAJL but want to understand both ways.
// Parse json Results From API Call using SQL Dcl-ds SQLResults Qualified;
week_number Int(10);
utc_offset VarChar(100);
utc_datetime VarChar(100);
unixtime Int(10);
timezone VarChar(100);
raw_offset Int(10);
dst_until VarChar(100);
dst_offset Int(10);
dst_from VarChar(100);
dst VarChar(10);
day_of_year Int(10);
day_of_week Int(10);
datetime VarChar(100);
client_ip VarChar(100);
abbreviation VarChar(100);
End-Ds;
Exec SQL declare C1 cursor for
Select *
from JSON_TABLE(Get_CLOB_From_File('/iaccess/html/currenttime.json'),
'lax $'
Columns(week_number Integer Path '$.week_number',
utc_offset VarChar(100) Path '$.utc_offset',
utc_datetime VarChar(100) Path '$.utc_datetime',
unixtime Integer Path '$.unixtime',
timezone VarChar(100) Path '$.timezone',
raw_offset Integer Path '$.raw_offset',
dst_until VarChar(100) Path '$.dst_until'
Default ' ' On Empty
Default ' ' On Error,
dst_offset Integer Path '$.dst_offset',
dst_from VarChar(100) Path '$.dst_from'
Default ' ' On Empty
Default ' ' On Error,
dst VarChar(10) Path '$.dst',
day_of_year Integer Path '$.day_of_year',
day_of_week Integer Path '$.day_of_week',
datetime VarChar(100) Path '$.datetime',
client_ip VarChar(100) Path '$.client_ip',
abbreviation VarChar(100) Path '$.abbreviation')) x;
Exec SQL Open C1;
DoU Done;
// Exec SQL Fetch next from C1 into :SQLResults;
Exec SQL Fetch next from C1 into :SQLResults.week_number,
:SQLResults.utc_offset,
:SQLResults.utc_datetime,
:SQLResults.unixtime,
:SQLResults.timezone,
:SQLResults.raw_offset,
:SQLResults.dst_until :NullUntil,
:SQLResults.dst_offset,
:SQLResults.dst_from :NullFrom,
:SQLResults.dst,
:SQLResults.day_of_year,
:SQLResults.day_of_week,
:SQLResults.datetime,
:SQLResults.client_ip,
:SQLResults.abbreviation;
Subject to Change Notice:
WalzCraft reserves the right to improve designs, and to change
specifications without notice.
Confidentiality Notice:
This message and any attachments may contain confidential and privileged
information that is protected by law. The information contained herein is
transmitted for the sole use of the intended recipient(s) and should "only"
pertain to "WalzCraft" company matters. If you are not the intended
recipient or designated agent of the recipient of such information, you are
hereby notified that any use, dissemination, copying or retention of this
email or the information contained herein is strictly prohibited and may
subject you to penalties under federal and/or state law. If you received
this email in error, please notify the sender immediately and permanently
delete this email. Thank You
WalzCraft PO Box 1748 La Crosse, WI, 54602-1748
www.walzcraft.com<
http://www.walzcraft.com> Phone: 1-800-237-1326
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a
message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.