That's it. I don't need it often, but it comes in handy on occasion.

Thanks
________________________________________
From: Slanina, John [jslanina@xxxxxxxxxx]
Sent: Monday, December 17, 2018 3:08 PM
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] UTF-8 conversion in a REST program

So what you is this ?

Dcl-s varInput varChar(65535) ;
Dcl-s varinputUTF8 like(varName) ccsid(*utf8) ;

if ContentType = 'application/json' or ContentType = 'application/vnd.api+json';
QtmhRdStin(varInputUTF8: RdiLen : RdiRecLen : APIErr);
varInput = varInputUTF8;
else;
QtmhRdStin(varInput: RdiLen : RdiRecLen : APIErr);
endif;

Thanks
John Slanina

On 12/17/18, 2:14 PM, "WEB400 on behalf of Justin Taylor" <web400-bounces@xxxxxxxxxxxx on behalf of JUSTIN@xxxxxxxxxxxxx> wrote:

RPG has built-in CCSID conversion, starting (IIRC) at 7.3.



-----Original Message-----
From: Slanina, John [mailto:jslanina@xxxxxxxxxx]
Sent: Monday, December 17, 2018 1:09 PM
To: Web Enabling the IBM i (AS/400 and iSeries) <web400@xxxxxxxxxxxx>
Subject: Re: [WEB400] UTF-8 conversion in a REST program

Here is my code to so it. If you need a quick fix. There is other ways in YAJL to do it in one program

Thanks
John Slanian



dcl-ds fromCCSID likeds(QtqCode_t) Inz(*LIKEDS);
dcl-ds toCCSID likeds(QtqCode_t) Inz(*LIKEDS);
dcl-ds hConv likeds(iconv_t) Inz(*LIKEDS);

dcl-ds iconv_t Qualified template;
rtn_value int(10);
cd int(10) dim(12) inz(0);
end-ds;

dcl-pr ibmIConvOpen LikeDS(iconv_t) ExtProc('QtqIconvOpen');
*n likeds(QtqCode_t);
*n likeds(QtqCode_t);
end-pr;

dcl-pr ibmIConv int(10) ExtProc('iconv');
*n LikeDS(iconv_t) value;
*n pointer;
*n int(10) Const;
*n pointer;
*n Int(10) Const;
end-pr;

dcl-pr ibmIconvClose int(10) extproc('iconv_close');
*n LikeDS(iconv_t);
end-pr;

monitor;
envrec = *blanks;
EnvName = 'CONTENT_TYPE';
QtmhGetEnv(EnvRec : %size(EnvRec) : RecLen : EnvName : %Len(%Trim(EnvName)) : APIErr);
ContentType = %xlate(uppercase:lowercase:%trim(%Subst(EnvRec : 1 : RecLen))); on-error; endmon;

// Read Body

monitor;
QtmhRdStin(RdiRec : RdiLen : RdiRecLen : APIErr); on-error; endmon;

if ContentType = 'application/json' or ContentType = 'application/vnd.api+json';
monitor;
RdiLenOut = RdiRecLen;
RdiRec_P = %addr(RdiRec);
RdiRecOut_P = %addr(RdiRecOut);

rc = ibmIConv(hConv : RdiRec_P : RdiRecLen : RdiRecOut_P : RdiLenOut);

RdiRec = %trim(RdiRecOut);
RdiRecLen = %len(%trim(RdiRec));

on-error;
endmon;
endif;


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.