**free // Customer Maintenance Web Service Example // using Profound UI's Universal Display feature // with the Data-Into handler // // // Input will be expected as: // url: http://your-system:port/profoundui/universal/custserv/xxxx // methods: PUT = update customer address // GET = retrieve customer address // // REQUEST/RESPONSE DATA: May be sent in either XML or JSON // // { // "success": true, // "errorMsg": "", // "cust": { // "id": 1234, // "name": "ACME Inc", // "address": { // "street": "123 Example St", // "city": "New York", // "state": "NY", // "postal": "12345-4321" // }, // } // } // // - or - // // // true // // // ACME Inc //
// 123 Example St // New York // NY // 12345-4321 //
//
//
// ctl-opt dftactgrp(*no) actgrp('WEBSERVICE') option(*srcstmt : *nodebugio ); dcl-f CUSTSERVD workstn handler('UNIVERSAL(HANDLER)'); // getenv() = Get Environment Variable // This is an IBM-supplied API dcl-pr getenv pointer ExtProc(*dclcase); varname pointer value options(*string); end-pr; dcl-ds CUSTADRP extname('CUSTADRP') qualified template end-ds; dcl-ds custService qualified; num_success int(10) inz(1); // added for 'countprefix' success varchar(5) inz('true'); num_errorMsg int(10) inz(1); // added for 'countprefix' errorMsg varchar(500); dcl-ds cust; num_id int(10) inz(0); // added for 'countprefix' id like(CUSTADRP.CUSTNO) inz(0); name like(CUSTADRP.NAME); dcl-ds address; street like(CUSTADRP.STREET); city like(CUSTADRP.CITY); state like(CUSTADRP.STATE); postal like(CUSTADRP.POSTAL); end-ds; end-ds; end-ds; dcl-ds DBREC; NAME like(CUSTADRP.NAME) ; STREET like(CUSTADRP.STREET); CITY like(CUSTADRP.CITY); STATE like(CUSTADRP.STATE); POSTAL like(CUSTADRP.POSTAL); end-ds; dcl-s ptr pointer; dcl-s pos int(10); dcl-s method varchar(20); dcl-s format varchar(4); dcl-s temp varchar(1000); success = 'true'; errMsg = ''; // // If the method was 'GET' we'll retrieve customer info // if not, we'll update it. Default: GET // method = 'GET'; ptr = getenv('REQUEST_METHOD'); if ptr <> *null; method = %str(ptr); else; method = 'GET'; endif; // // determine which format to send back to consumer // - if HTTP 'accept' header specifies XML, use that. // - if HTTP 'content-type' specifies XML, use that // - otherwise, use JSON // // NOTE: the format of the data sent to us does not matter, // since it is automatically handled by PUIUDFINTO. // format = 'json'; ptr = getenv('HTTP_ACCEPT'); if ptr = *null; ptr = getenv('CONTENT_TYPE'); endif; if ptr <> *null; temp = %str(ptr); if %scan('json': temp) = 0 and %scan('xml': temp) > 0; format = 'xml'; endif; endif; // // The URI (sometimes called 'URL') will have the customer id in // it after "custserv". Get that, here. // custService.cust.id = 0; ptr = getenv('PUI_UNIVERSAL_URI'); if ptr <> *null; temp = %str(ptr); monitor; pos = %scan('/custserv/': temp); if pos > 0; pos += %len('/custserv/'); custService.cust.id = %int(%subst(temp:pos)); endif; on-error; // leave cust id at 0 endmon; endif; // // When PUT was given in order to update, get the new field values // if method = 'PUT'; DATA-INTO custService %DATA('': 'case=convert countprefix=num_') %PARSER( 'PUIUDFINTO' : '{ + "value_true": "true", + "value_false": "false", + "document_name": "custService" + }'); custno = custService.cust.id; name = custService.cust.name; street = custService.cust.address.street; city = custService.cust.address.city; state = custService.cust.address.state; postal = custService.cust.address.postal; exec SQL update CUSTADRP set name = :name, street = :street, city = :city, state = :state, postal = :postal where custno = :custno; if sqlstt <> '00000'; errMsg = 'SQL State ' + sqlstt + ' updating CUSTADRP'; success = 'false'; endif; endif; // // Carry out the requested action (PUT or GET) // CUSTNO = custService.cust.id; exec SQL select name, street, city, state, postal into :DBREC from CUSTADRP where custno = :CUSTNO; if sqlstt <> '00000'; errMsg = 'SQL State ' + sqlstt + ' retrieving CUSTADRP'; success = 'false'; endif; if format = 'xml'; write XMLRESP; else; write JSONRESP; endif; *inlr = *on;