So I was trying to see how IWS formats the JSON that is output from an RPGLE SRVPGM. I created a very simple program and while I get the proper results, I also get empty elements output into the JSON. I want to exclude these extra elements from being output. Is this possible with IWS / RPGLE?
Prototype:
Pgm:
Result:
Prototype:
PHP Code:
D H_OK c const(200)
D H_CREATED c const(201)
D H_NOCONTENT c const(204)
D H_BADREQUEST c const(400)
D H_NOTFOUND c const(404)
D H_CONFLICT c const(409)
D H_GONE c const(410)
D H_SERVERERROR c const(500)
D ERR_DUPLICATE_WRITE...
D C const(01021)
DCL-DS families QUALIFIED template DIM(10); <<<< This Array is returned and no extra elements returned
name VARCHAR(25);
num_children INT(10);
DCL-DS children DIM(5); <<<< This is the array(in the above array) I mentioned having the blank elements returned
name VARCHAR(25);
age INT(10);
END-DS;
END-DS;
D getAll PR
D fam_...
D LENGTH 10i 0
D fams likeds(families) dim(1000)
D options(*varsize)
D httpStatus 10i 0
D httpHeaders 100a dim(10)
PHP Code:
h NOMAIN PGMINFO(*PCML:*MODULE:*V7 :*DCLCASE)
/copy tstfamspr
//************************************************** *************
// getAll *
//************************************************** *************
P getAll B EXPORT
D getAll PI
D fam_...
D LENGTH 10i 0
D fams likeds(families) dim(1000)
D options(*varsize)
D httpStatus 10i 0
D httpHeaders 100a dim(10)
/FREE
clear httpHeaders;
clear fams;
// build the output that will become JSON.
fam_LENGTH = 0;
fam_LENGTH = fam_LENGTH +1;
fams(fam_LENGTH).name = 'test1';
fams(fam_LENGTH).num_children = 2;
fams(fam_LENGTH).children(1).name = 'Bo';
fams(fam_LENGTH).children(1).age = 12;
fams(fam_LENGTH).children(2).name = 'Sam';
fams(fam_LENGTH).children(2).age = 9;
fam_LENGTH = fam_LENGTH +1;
fams(fam_LENGTH).name = 'test2';
fams(fam_LENGTH).num_children = 1;
fams(fam_LENGTH).children(1).name = 'Jo';
fams(fam_LENGTH).children(1).age = 8;
httpStatus = H_OK;
httpHeaders(1) = 'Cache-Control: no-cache, no-store';
/END-FREE
P getAll E
PHP Code:
{
"fam_LENGTH": 2,
"fams": [
{
"name": "test1",
"num_children": 2,
"children": [
{
"name": "Bo",
"age": 12
},
{
"name": "Sam",
"age": 9
},
{
"name": "",
"age": 0
},
{
"name": "",
"age": 0
},
{
"name": "",
"age": 0
}
]
},
{
"name": "test2",
"num_children": 1,
"children": [
{
"name": "Jo",
"age": 8
},
{
"name": "",
"age": 0 <<< blank elements returned for this array
},
{
"name": "",
"age": 0
},
{
"name": "",
"age": 0
},
{
"name": "",
"age": 0
}
]
}
],
"httpStatus": 200,
"httpHeaders": [
"Cache-Control: no-cache, no-store",
"",
"",
"",
"",
"",
"",
"",
"",
""
]
}
Comment