|
The SQLRPGLE for a display of US Presidents, with details
// _____________________________________________________________________
// ___ _ _ __ __ _ _
// | . > ___ ___ _| |_ | |_ | \ \ ___ _ _ _| |_ <_>._ _
// | . \/ . \/ . \ | | | . | | |<_> || '_> | | | || ' |
// |___/\___/\___/ |_| |_|_| |_|_|_|<___||_| |_| |_||_|_|
//
// Nov, 2019 booth@martinvt.com
// _____________________________________________________________________
// COMMENTS: Consume a web service for US Presidents display
//
// _____________________________________________________________________
ctl-opt option(*nodebugio) dftactgrp(*no) actgrp(*new);
dcl-f WEBPRESD workstn sfile(sfl1: sf1rrna);
dcl-c cURL 'your.i.series/';
dcl-s URL varchar(400);
dcl-c cTrq x'30';
dcl-ds wDataRow;
usname varchar(35);
usbirth varchar(4);
usdeath varchar(4);
usbterm date(*iso);
useterm date(*iso);
usparty varchar(25);
end-ds;
dcl-ds *n;
W2Record char(150);
W2TITLE overlay(w2record);
W2LIFE overlay(w2record: *next);
W2TERM overlay(w2record: *next);
W2PARTY overlay(w2record: *next);
end-ds;
dcl-s wDataAR like(w2record) dim(50);
dcl-s wNdx packed(5);
dcl-s wCount packed(5);
dcl-ds *n PSDS;
USERID char(10) pos(358);
end-ds;
/free
//----------------------------------------------------------------------
// Mainline
//----------------------------------------------------------------------
// The immediately following /EXEC SQL is SQL's version of RPG's H Spec
// It is never executed; just used at compile time.
exec sql set option Commit = *Chg,
DatFmt = *ISO;
//----------------------------------------------------------------------
exsr GetHeading;
exsr FillSfl;
dou *inkc;
exsr ChangeColors;
write FMT01;
write WIN02;
exfmt WIN01;
select;
when *inkc; // done.
when SF1SLCTD > 0;
exsr FillWin02;
endsl;
enddo;
*inlr = *on;
//----------------------------------------------------------------------
// End of Mainline
//----------------------------------------------------------------------
// Fill window 1, subfile
begsr FillSfl;
exsr GetData;
// Clear subfile.
*in90 = *off;
write WIN01;
*in90 = *on;
// Fill the subfile:
SF1RRNA = 0;
for wNdx = 1 to %elem(wDataAR);
W2Record = wDataAR(wNdx);
if W2TITLE <> ' ';
S1NAME30 = W2TITLE;
SF1RRNA += 1;
write SFL1;
endif;
endfor;
clear w2Record; // First cycle, with blank window 2
W2TITLE = 'Details';
// Set subfile size:
if SF1RRNA = 0;
SF1RRNA = 1;
S1NAME30 = 'No Records.';
write SFL1;
endif;
NBRRECS = SF1RRNA;
SF1TOP = 1;
endsr;
//----------------------------------------------------------------------
// Fill Window 2, details
begsr FillWIN02;
W2Record = wDataAR(SF1SLCTD);
SF1TOP = SF1SLCTD;
write WIN02;
endsr;
//-----------------------------------------------------------------------
// Get the Web Service data
begsr GetData;
clear wDataAR;
clear wNdx;
URL = cURL + 'presidents';
exec sql select * into :wCount
from json_table(SYSTOOLS.HTTPGETCLOB(:URL,''),
'lax $' columns("wData_length" dec(5, 0)) );
exec sql declare C1 cursor for
select *
from json_table(SYSTOOLS.HTTPGETCLOB(:URL,''),
'lax $.presidents[*]'
columns(
"name" varchar(35),
"born" varchar(4),
"died" varchar(4),
"beganterm" varchar(10),
"endterm" varchar(10),
"party" varchar(25)) );
exec sql open C1;
dow sqlcode = 0 and wNdx < wCount; // Table read loop
exec sql fetch C1 into :wDataRow;
if sqlcode = 0 and USNAME <> '';
W2TITLE = %trim(USNAME);
W2LIFE = USBIRTH + ' - ' + USDEATH;
W2TERM = %char(USBTERM) + ' to ' + %char(USETERM);
W2PARTY= USPARTY;
wNdx += 1;
wDataAR(wNdx) = W2Record;
endif;
enddo;
exec sql close C1;
endsr;
//-----------------------------------------------------------------------
// Get Screen Heading
begsr GetHeading;
HDG5X40 =
' _ __ __ '
+ ' | | /| / /__ / / -= US Presidents =-'
+ ' | |/ |/ / -_) _ \ -= =-'
+ ' |__/|__/\__/_.__/ -= Details =-';
HDG7X23 =
' '
+ ' '
+ ' ,,, '
+ ' (O-O) '
+ ' ----oo0-(_)-0oo---- '
+ ' '
+ ' ';
exec SQL // Get user's name to display.
select CID.ODOBTX
into :S1USERNAME
from Table( QSYS2/USERS() ) AS CID
where CID.ODOBNM = :USERID;
evalr S1USERNAME = 'with' + cTrq + %trim(S1USERNAME);
endsr;
//-----------------------------------------------------------------------
// Change Heading Colors
begsr ChangeColors;
select;
when *in61;
*in61 = *off;
*in62 = *on;
when *in62;
*in62 = *off;
*in63 = *on;
when *in63;
*in63 = *off;
*in64 = *on;
when *in64;
*in64 = *off;
*in65 = *on;
when *in65;
*in65 = *off;
*in66 = *on;
when *in66;
*in66 = *off;
*in67 = *on;
other;
*in67 = *off;
*in61 = *on;
endsl;
endsr;
/end-free
|
The DSPL file for the US President display
* _______________________________________________________________________
* ___ _ _ __ __ _ _
* | . > ___ ___ _| |_ | |_ | \ \ ___ _ _ _| |_ <_>._ _
* | . \/ . \/ . \ | | | . | | |<_> || '_> | | | || ' |
* |___/\___/\___/ |_| |_|_| |_|_|_|<___||_| |_| |_||_|_|
*
* Nov, 2019 booth@martinvt.com
* _______________________________________________________________________
* Web demo, Presidents
*
* _______________________________________________________________________
DSPSIZ(*DS3)
CHGINPDFT
ERRSFL
CA03
* _______________________________________________________________________
R FMT01
1 2'System i'
2 2'WEBPRES'
HDG5X40 200 B 1 12CNTFLD(40) CHGINPDFT
DSPATR(PR)
67 COLOR(GRN)
61 COLOR(PNK)
62 COLOR(TRQ)
63 COLOR(WHT)
64 COLOR(BLU)
65 COLOR(RED)
66 COLOR(YLW)
HDG7X23 161 B 1 54CNTFLD(23) CHGINPDFT
DSPATR(PR)
61 COLOR(GRN)
62 COLOR(PNK)
63 COLOR(TRQ)
64 COLOR(WHT)
65 COLOR(BLU)
66 COLOR(RED)
67 COLOR(YLW)
S1USERNAME 50 6 2COLOR(YLW)
* _______________________________________________________________________
R SFL1 SFL
S1NAME30 30 1 2
* _______________________________________________________________________
R WIN01 SFLCTL(SFL1)
OVERLAY
WINDOW(9 2 13 34 -
*NORSTCSR *NOMSGLIN)
WDWBORDER((*COLOR TRQ))
WDWTITLE((*TEXT 'US Presidents') +
(*COLOR TRQ) *LEFT *TOP)
PROTECT
PUTOVR
SFLPAG(0011)
SFLSIZ(&NBRRECS)
90 SFLDSP SFLDSPCTL SFLEND(*SCRBAR)
N90 SFLCLR
SFLCSRRRN(&SF1SLCTD)
MOUBTN(*ULP ENTER)
SF1TOP 4S 0H SFLRCDNBR(CURSOR *TOP)
SF1SLCTD 5S 0H
SF1RRNA 4S 0H
NBRRECS 5S 0P
PB1 2Y 0B 13 2PSHBTNFLD((*GUTTER 2))
PSHBTNCHC(1 'Done' CA03)
CHCAVAIL((*COLOR PNK))
* _______________________________________________________________________
R WIN02
OVERLAY
WINDOW(9 42 7 34 *NOMSGLIN)
USRRSTDSP
WDWBORDER((*COLOR YLW))
WDWTITLE((*TEXT &W2TITLE) +
(*COLOR TRQ) *LEFT *TOP)
PROTECT
PUTOVR
2 1'Party '
W2PARTY 25 3 3COLOR(YLW)
4 1'Term '
W2TERM 28 5 3COLOR(YLW)
6 1'Born/Died'
W2LIFE 20 7 3COLOR(YLW)
W2TITLE 30 P
* _______________________________________________________________________
|
|
|