-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web requests with Embedded SQL #11
Comments
very neat and complete, any rpg guy can quickly pick it up. I wish they will see this. thanks Liam. |
This was very help full |
Good suggestion.
I receive error SQL4302 with message "Abnormal end of file". |
Sometimes you will need to import certificates. |
Once again I write another blog post about how great I find embedded SQL within RPG - this time we talk about web requests. This isn't really much of a blog post either.. it's really just a 'text version' of a session I am giving at the RPG and DB2 Summit.
These are the things we're going to look at:
SQLTYPE
HTTPGETCLOB
HTTPPOSTCLOB
Not a massive list, but a lot to talk about.
SQLTYPE
SQLTYPE
is a new keyword in RPG for when you're declaring variables.. only really useful if you're using Embedded SQL in your programs. When theSQLTYPE
keyword is used, it secretly creates a data structure under the covers (but only for certain SQL types)These are some of the available types:
So this makes the syntax
Dcl-S gSQLVar SQLTYPE(*[SQLTYPE]*:*[len]*);
.When I say 'creates a data-structure' - I mean it really does. Take a look at this diagram:
HTTPGETCLOB
HTTPGETCLOB has two parameters. The first is the URL which it will send the request to and the second are the headers you want to give the request You can read more about the headers parameter here in the 'Sending customized HTTP header values' section.
In this 'get clob' example, I send a simple GET request to a URL (which you can replace with a host variable) and it will give the response back. It's pretty neat! Notice that when we declare our CLOB, we also give it a type.
If you debug this statement in STRDBG, after you've steped through it you can do
eval WebResponse_Data
to view the response andeval WebResponse_Len
to view the length of the response.You can do this same SQL statement within an SQL client (Run SQL Scripts in ACS or STRSQL..):
SELECT SYSTOOLS.HTTPGETCLOB('https://api.bitcoinaverage.com/ticker/EUR/', '') FROM SYSIBM.SYSDUMMY1
HTTPPOSTCLOB
HTTPPOSTCLOB is kinda like HTTPPOSTCLOB, but with the 'post clob' you get an extra parameter which allows you to pass the body of the request (which makes it a POST request).
I like to keep my code quite tidy, so I have my response variable (
gData
) and I usually have a data structure to store the URL, header and body of the request in - then we initialize them with the relevant data for the request.If you then debug this
EXEC SQL
statement andeval gData
you'll see the response length and the actual response:Well I hope this generally a useful post.. I will go into a lot more detail during the session - this is just the basics.
The text was updated successfully, but these errors were encountered: