IMP - RESTfull Webservice in ABAP Returning JSON - SAP Blogs
IMP - RESTfull Webservice in ABAP Returning JSON - SAP Blogs
Products Industries
Industries Services and Support
Services and Support Training
Training Community
Community Developer
Developer Partner
Partner
About
About
Ask a Question Write a Blog Post Login
Diogo Awaihara
August 5, 2016 3 minute read
It is very simple to create a webservice using only ABAP, thanks to Naresh Bammidi that showed us the way!
The trick is to concatenate everything in a single string, using the JSON style, and set the content type by using the method
set_header_ eld.
CALL METHOD server->response->set_status( code = ‘405’ reason = ‘Method not allowed’ ).
EXIT.
ENDIF.
CHANGING
elds = it_inputparams.
ENDLOOP.
READ TABLE it_inputparams INTO ls_inputparams WITH KEY name = ‘PO’.
CALL METHOD server->response->set_status( code = ‘404’ reason = ‘Empty parameters are not allowed’ ).
CALL METHOD server->response->set_cdata( data = ‘There are one or more missing parameters’ ).
EXIT.
ENDIF.
ENDSELECT.
IF sy-subrc = 0.
ENDIF.
ENDMETHOD.
After that just publish it in SICF, into Handler list and test it.
I tested it in SoapUI 5.2.1.
Alert Moderator
Assigned tags
View more...
Reference doc: http://scn.sap.com/docs/DOC-46463
3 Comments
Horst Keller
Like (0)
Horst Keller
Like (0)
Rüdiger Plantiko
And it is a great moment when you made it work the rst time and see how easy it actually is!
Make one service responsible for di erent types of requests – which leads to some kind of parsing the request and
delegating a work to a “worker class”.
Instead of producing JSON with strings, produce it the right way with transformations or with a builder class working on
base of IF_IXML_DOCUMENT. Find examples for the di erent ways to do it in the ABAP docu! It is easier, less error
prone, and the right level to work with “foreign” data formats like JSON or XML.
For each request, di erent resonse data types may occur. Separate the general HTTP communication, i.e. transforming
data to JSON and putting them into the response, from the speci c tasks of the handler which refer to concrete data in
the ABAP world and retrieve ABAP data to the general part.
I outlined some of these tasks in this blog from 2013. For some of the things described there, there are better ways in the
meantime. The main gap of that blog is that there even is a complete API framework for restful services nowadays.
Best regards
Rüdiger
Like (0)
Trademark Sitemap
Newsletter