Friday, October 24, 2008

Parse a string of XML into a DOM Document object

Java code:

String xmlStr = "something ";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

//This handles string containg special characters (UTF8):
Document doc = builder.parse(new InputSource(new StringReader(xmlStr)));

//This cannot handle UTF8
InputStream is = new ByteArrayInputStream(content.getBytes());
Document doc = builder.parse(is);

Thursday, October 16, 2008

UDF using RPG/RPGLE


(1) create service program

0001.00 H NOMAIN
0001.01 D* Prototype for procedure: ONHAND
0002.00 D ONHAND PR 11P 2
0003.00 D UPBAL 7P 0 CONST
0004.00 D ISSUE 7P 0 CONST
0005.00 D AJUST 7P 0 CONST
0005.01 *------------------------------------------------
0006.00 P ONHAND B EXPORT
0006.01 D ONHAND PI 11P 2
0007.00 D UPBAL 7P 0 CONST
0007.01 D ISSUE 7P 0 CONST
0007.02 D AJUST 7P 0 CONST
0007.04 *
0007.05 D ONHND S 11P 2
0007.06 /free
0007.07 ONHND = UPBAL + ISSUE + AJUST;
0007.08 RETURN ONHND;
0007.09 /end-free
0008.00 P ONHAND E

(2) CRTMOD
(3) CRTSRVPGM SRVPGM(MRCJAVALIB/ONHAND) EXPORT(*ALL)
(4) Create function

create function mrcjavalib/ONHAND (DEC (7,0),DEC (7,0), DEC (7,0)) returns DEC (11,2)
language rpgle
deterministic
no sql
returns null on null input
no external action allow parallel
simple call
external name 'MRCJAVALIB/ONHAND(ONHAND)'

(5) to use
SELECT PRDNO, OPBAL, ISSUE, RECPT, ADJST, onhand(opbal, issue,adjst)
FROM dmpmp100