Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
Can HTTPPOSTCLOBVERBOSE use a variable as the request data? If I replace ':pData)) as UPS;' in the code below with 'GET_CLOB_FROM_FILE('/ifsdir/file.txt') )) as UPS;' the code works as expected and I receive data from UPS. If I use the code below it's like no request data is sent to UPS. So I wondering can the request data be a variable and how would the syntax look? We are on an Iseries V7.1. Thanks.
0172.11 C eval pData =
0172.12 C 'GET_CLOB_FROM_FILE(~'
0172.13 C + %trim(#lcifsfilnam)
0172.14 C + '~)'
0172.15 C $tilde:$quote xlate pData pData
0181.02 C* Transmit PLD upu178.txt to UPS and receive response message from UPS
0181.04 /free
0181.05 replystmf_Name = '/dfreeman/upu178rm.txt';
0181.06 replystmf_NL = %len(%trimr(replystmf_name));
0181.07 replystmf_FO = SQFOVR;
0181.17 exec sql
0181.23 SELECT responseMsg,responseHttpHeader
0181.24 INTO :replyStmf, :replyHdr
0181.25 FROM TABLE(SYSTOOLS.HTTPPOSTCLOBVERBOSE(
0181.29 'https://onlinetools.ups.com/webservices/Track',
0181.30 '<httpHeader> +
0181.31 <header name="Content-type" +
0181.32 value="application/xml"/> +
0181.33 </httpHeader>',
0181.34 :pData) ) as UPS;
Yes but you may need to cast the data to a CLOB or BLOB depending on the situation.
Something like the following for that parameter:
cast(:reqData as clob(10k))
Also, I don't see where you are runing the GETCLOB_FROM_FILE rouitne. Normally I just use the SQL VALUES INTO statement to do that.
Thanks for responding. The code below works as expected - I send a request to UPS and receive a response from UPS. I tried to cast the line GET_ CLOB_FROM_FILE('/path/myfile.txt') but it does not send anything to UPS. I would like to be able to change '/path/myfile.txt' to be '/path/myfile2.txt' or '/path/myfile3.txt', etc. in the SQLRPGLE. I'm not sure how to use CAST or code CAST to accomplish this. Any comments would be appreciated.
0181.02 C* Transmit PLD upu178.txt to UPS and receive response message fro
0181.04 /free
0181.05 replystmf_Name = '/path/responsemsg.txt';
0181.06 replystmf_NL = %len(%trimr(replystmf_name));
0181.07 replystmf_FO = SQFOVR;
0181.17 exec sql
0181.23 SELECT responseMsg,responseHttpHeader
0181.24 INTO :replyStmf, :replyHdr
0181.25 FROM TABLE(SYSTOOLS.HTTPPOSTCLOBVERBOSE(
0181.26 'https://onlinetools.ups.com/webservices/Track',
0181.27 '<httpHeader> +
0181.30 <header name="Content-type" +
0181.32 value="application/xml"/> +
0181.35 </httpHeader>',
0181.36 GET_CLOB_FROM_FILE('/path/myfile.txt')
0181.37 ))as UPS;
0181.50 /end-free
I don't know what GET_CLOB_FROM_FILE('/path/myfile.txt') is so I can't help with it (Some user-written routine?)
But I use the VALUES INTO when I need the data from an IFS file.
Something like this:
EXEC SQL VALUES(:myStmf) INTO :sendData:nullIndy;
Where MYSTMF is another SQLFILE declaration, and then use the SENDDATA varaible as the parameter on the HTTPPOSTCLOBVERBOSE.
A year later and I re-visit this post and notice I know the reason why it failed. I expect you do too Doug.
The PDATA variable is basically being used as a dynamic SQL statement but in a "static" statement. You'd have to build the entire stmt and pass it to EXECUTE IMMEDIATE to get it to work.
That's why if you specify GET_CLOB_FROM_FILE... on the stmt it works, but :PDATA does not.
You could put the file name in a host variable and then specify GET_CLOB_FROM_FILE(:myData)) on the "static" statement and that should work for you.
Note that you can do a fully-dynamic SQL statement in RPG using EXECUTE IMMEDIATE or PREPARE/DECLARE.
In SQL iQuery, you get lot more flexibility with your SQL statements. Including having it work the way you expected it to in your original post.
Hope you solved your challenge a long time ago! :)