Aaron,

this looks very similar to the way my powerEXT does the job - why don't
you just make a programgenerator
the based on a DSPFFD generates the code ?

If you, like in Icebreak creates a "blackbox", you will eventual run into
trouble when you wants to add additional or
leave out fields.


Med venlig hilsen/Kind regards
Henrik Rützou
HR Software Development
Ved Stampedammen 39
DK 2970 Hørsholm
Denmark
E-mail: hr@xxxxxxxxxxxx
Phone: +45 2714 8449

Homepage: powerEXT.com




Aaron Bartell <aaronbartell@xxxxxxxxx>
Sent by: web400-bounces@xxxxxxxxxxxx
16-07-2010 17:38
Please respond to
Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>


To
"Web Enabling the AS400 / iSeries" <web400@xxxxxxxxxxxx>
cc

Subject
[WEB400] Convert DS/Record to JSON






Hi all,

Been doing a fair amount of RPGUI coding lately (
http://mowyourlawn.com/rpgui.html) and have been writing many misc RPG sub
procs to help with moving data around. One that has bothered me for
awhile
now is converting an entire record to a JSON string and back again. For
example, I am writing an app right now that displays "person" information
to
the browser from the PERSONTBL DB2 table and my code looks like this:

chain key PERSONTBL PER;
json_putInt( pJson: 'C@PER#': PER.C@PER#);
json_putInt( pJson: 'C@FAM#': PER.C@FAM#);
json_putInt( pJson: 'C@MPER': PER.C@MPER);
json_putInt( pJson: 'C@SEQ#': PER.C@SEQ#);
json_putString(pJson: 'C@RSHP': PER.C@RSHP);
json_putString(pJson: 'C@SSN': %editc(PER.C@SSN:'X'));
json_putString(pJson: 'C@NAML': PER.C@NAML);
json_putString(pJson: 'C@NAMF': PER.C@NAMF);
json_putString(pJson: 'C@NAMM': PER.C@NAMM);
json_putString(pJson: 'C@NSUF': PER.C@NSUF);
json_putString(pJson: 'C@NAME': PER.C@NAME);
json_putString(pJson: 'C@NAMD': PER.C@NAMD);
json_putString(pJson: 'C@AD1#': PER.C@AD1#);
json_putString(pJson: 'C@AD1N': PER.C@AD1N);
json_putString(pJson: 'C@CITY': PER.C@CITY);
json_putString(pJson: 'C@STA': PER.C@STA);
json_putString(pJson: 'C@ZIP': PER.C@ZIP);
json_putString(pJson: 'C@MADC': PER.C@MADC);
json_putString(pJson: 'C@MAD1': PER.C@MAD1);
json_putString(pJson: 'C@MAD2': PER.C@MAD2);
json_putString(pJson: 'C@MCTY': PER.C@MCTY);
json_putString(pJson: 'C@MAST': PER.C@MAST);
json_putString(pJson: 'C@MZIP': PER.C@MZIP);
json_putString(pJson: 'C@PPH#': PER.C@PPH#);
json_putString(pJson: 'C@PPFL': PER.C@PPFL);
json_putString(pJson: 'C@SPH#': PER.C@SPH#);
json_putString(pJson: 'C@SPFL': PER.C@SPFL);
json_putString(pJson: 'C@TPH#': PER.C@TPH#);
json_putString(pJson: 'C@TPFL': PER.C@TPFL);
json_putString(pJson: 'C@EMAD': PER.C@EMAD);
json_putString(pJson: 'C@FSPH': %char(PER.C@FSPH));
json_putString(pJson: 'C@DOB': %char(PER.C@DOB));
json_putString(pJson: 'C@AGE': %char(PER.C@AGE));
json_putString(pJson: 'C@SEX': PER.C@SEX);
json_putString(pJson: 'C@MSTA': %trim(PER.C@MSTA));
json_putString(pJson: 'C@CTZS': %trim(PER.C@CTZS));
json_putString(pJson: 'C@LANG': PER.C@LANG);
json_putString(pJson: 'C@ITPR': PER.C@ITPR);
json_putString(pJson: 'C@ETHN': PER.C@ETHN);
json_putString(pJson: 'C@STAT': PER.C@STAT);
json_putString(pJson: 'C@BYCK': PER.C@BYCK);
json_putString(pJson: 'C@APPD': %char(PER.C@APPD));
json_putString(pJson: 'C@CUSR': PER.C@CUSR);
json_putString(pJson: 'C@CDAT': %char(PER.C@CDAT));

... and instead of the above I want to do something like this...

chain key PERSONTBL PER;
jsonObj = json_cvtRec(PER: 'PERSONTBL');

Then as long as PERSONTBL is externally defined we could get the layouts
of
each field. In theory we should be able to use an incrementing pointer to
"parse" the passed in DS based on the meta data found by calling an API
and
passing in the externally define table definition.

I have done this before at a previous employer in a slightly different web
scenario, but unfortunately I don't have access to that code anymore.
Anybody else have a start on a code base that would do something similar
to
what I describe above?

Aaron Bartell
http://mowyourlawn.com
http://mowyourlawn.com/blog/

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.