Professional Documents
Culture Documents
Sicf Tutorial Part3
Sicf Tutorial Part3
It will execute the ‘GET_REST’ method to get the class we want to execute to get
or process the data.
METHOD IF_HTTP_EXTENSION~HANDLE_REQUEST.
******************************************************************
" VARIABLES
******************************************************************
DATA: LO_REST_CLASS TYPE REF TO ZIF_REST.
DATA: LO_ERROR TYPE REF TO CX_ROOT.
DATA: LV_REASON TYPE STRING.
******************************************************************
" GET THE CLASS OBJECT
******************************************************************
TRY.
******************************************************************
" EXECUTE THE RETRIEVED CLASS
******************************************************************
LO_REST_CLASS->HANDLE_REQUEST( ).
******************************************************************
" ERROR
******************************************************************
CATCH CX_ROOT INTO LO_ERROR.
LV_REASON = LO_ERROR->GET_TEXT( ).
SERVER->RESPONSE->SET_STATUS( CODE = 500
REASON = LV_REASON ).
ENDTRY.
ENDMETHOD.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 4/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
Your class will now have the first two methods below. Add two new methods:
‘GET_EQUIPMENTS’ and ‘CONSTRUCTOR’.
Add the following parameters to ‘GET_EQUIPMENTS’. This will pass the request
and return the equipments we will retrieve.
Add the following parameters to ‘CONSTRUCTOR’. This will instantiate the class
when called upon.
It will first get the equipments which will be converted to a JSON String. The
String will then be added as output of this method.
METHOD ZIF_REST~HANDLE_REQUEST.
******************************************************************
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 6/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
Now open method ‘CONSTRUCTOR’ and add following code. This method will
instantiate the request and response when the class is called.
METHOD CONSTRUCTOR.
ME->ZIF_REST~RESPONSE = IO_RESPONSE.
ME->ZIF_REST~REQUEST = IO_REQUEST.
ENDMETHOD.
METHOD GET_EQUIPMENTS.
******************************************************************
" VARIABLES
******************************************************************
DATA: LV_EQUI_NUMBER TYPE EQUNR.
******************************************************************
" GET HEADER PARAMETERS VALUE FROM URL
******************************************************************
LV_EQUI_NUMBER = ME->ZIF_REST~REQUEST->GET_FORM_FIELD('equnr').
UNPACK LV_EQUI_NUMBER TO LV_EQUI_NUMBER.
******************************************************************
" GET EQUIPMENTS SELECT
******************************************************************
SELECT EQUI~EQUNR, EQKT~EQKTX
FROM EQUI AS EQUI
LEFT OUTER JOIN EQKT AS EQKT ON EQKT~EQUNR EQ EQUI~EQUNR
INTO TABLE @ET_EQUIPMENTS
WHERE EQUI~EQUNR EQ @LV_EQUI_NUMBER
AND EQKT~SPRAS EQ 'E'.
ENDMETHOD.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 8/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
******************************************************************
" JSON TO ABAP DATA
******************************************************************
LV_JSON_BODY = ME->ZIF_REST~REQUEST->GET_CDATA( ).
LR_JSON_DESERIALIZER->DESERIALIZE(
EXPORTING
JSON = LV_JSON_BODY
IMPORTING
ABAP = LS_EQUI ).
******************************************************************
" CREATE OBJECT
******************************************************************
"DO WHATEVER YOU NEED TO DO HERE WITH THE DATA !!!
******************************************************************
" CONVERT INPUT TO JSON STRING
******************************************************************
LV_STRING_WRITER = CL_SXML_STRING_WRITER=>CREATE( TYPE = IF_SXML=>C
CALL TRANSFORMATION ID SOURCE ARRAY = LT_EQUIS RESULT XML LV_STRING
LV_XSTRING = LV_STRING_WRITER->GET_OUTPUT( ).
******************************************************************
" RETURN CREATED OBJECT AS RESPONSE (CONVENTION)
******************************************************************
ME->ZIF_REST~RESPONSE->SET_DATA( DATA = LV_XSTRING ).
ENDMETHOD.
Now open method ‘SET_RESPONSE’ and add following code. This method will be
executed when ‘HANDLE_REQUEST’ has finished. It will return the data as a
String.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 10/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
Navigate to the ‘Hander List’ tab and add the handler we created
(‘ZCL_REST_TEST’).
Go back to the node list and right click the node you created and click ‘Activate
service’.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 12/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
That’s all there is to it. Thank you for reading and if there is any feedback or
comments at all, you should definitely let me know since this is the first blog I’ve
ever written.
Alert Moderator
Assigned Tags
SAP NetWeaver
ABAP Development
abap
netweaver
sap
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 14/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
Riaan Steenkamp
September 20, 2018 at 11:16 am
I've read dozens of posts and this is the only one that properly addresses this issue - You helped me when
no one else could.
Great post!
Sonia Trepanier
March 13, 2020 at 7:11 pm
As mentioned by another, I've read many posts but this one was very clear and complete with what I
wanted to do!
Rafael Martinez
September 21, 2021 at 9:40 am
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 16/18
04/07/23, 12:26 Writing a SICF service | SAP Blogs
GEORGI KOZINAKOV
April 24, 2023 at 7:00 pm
Is there any free "sandbox" SAP server where we can try the SICF service (or other SAP services)?
Add Comment
Find us on
Newsletter Support
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 18/18