Sicf Tutorial Part2
Sicf Tutorial Part2
Sicf Tutorial Part2
× Community
Matthijs Mennens
June 28, 2018 | 8 minute read
Follow
Introduction
Like
This blog will guide you through the process of creating a SICF service (REST).
SICF is an SAP transaction which is used to maintain services for HTTP
RSS Feed communication, using the Internet Communication Manager (ICM) and the
Internet Communication Framework (ICF). This can be useful in multiple
situations. For example: A certain system might not have the proper Gateway
installation or configuration to create services there.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 1/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
Go back to the tab ‘Methods’ and you’ll see a method has been added. Add
another method called ‘GET_REST’.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 3/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
This method will first check what type of request we’re dealing with (GET, PUT,
POST, … etc.). It will then append the name to the base class name. So, if a GET
request is executed, the name of the class it will execute is
‘ZCL_REST_TEST_GET’.
METHOD GET_REST.
******************************************************************
" VARIABLES
******************************************************************
DATA: LV_CLASS_NAME TYPE SEOCLSNAME.
DATA: LV_REQUEST_METHOD TYPE STRING.
******************************************************************
" APPEND REQUEST METHOD TO BASE CLASS
******************************************************************
LV_REQUEST_METHOD = IO_SERVER->REQUEST->GET_HEADER_FIELD( '~request
******************************************************************
" RETURN CLASS OBJECT
******************************************************************
TRY.
CREATE OBJECT EO_REST
TYPE (LV_CLASS_NAME)
EXPORTING
IO_REQUEST = IO_SERVER->REQUEST
IO_RESPONSE = IO_SERVER->RESPONSE.
******************************************************************
" ERRORS
******************************************************************
CATCH CX_SY_CREATE_OBJECT_ERROR.
ENDTRY.
ENDMETHOD.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 5/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
" VARIABLES
******************************************************************
DATA: LT_EQUIPS TYPE ZTT_TEST_EQUI.
DATA: LV_STRING_WRITER TYPE REF TO CL_SXML_STRING_WRITER.
DATA: LV_XSTRING TYPE XSTRING.
******************************************************************
" EXECUTE GET_EQUIPMENTS METHOD
******************************************************************
TRY.
******************************************************************
" CONVERT EQUIPMENTS TO JSON
******************************************************************
LV_STRING_WRITER = CL_SXML_STRING_WRITER=>CREATE( TYPE = IF_SXML=>C
CALL TRANSFORMATION ID SOURCE ARRAY = LT_EQUIPS RESULT XML LV_STR
LV_XSTRING = LV_STRING_WRITER->GET_OUTPUT( ).
******************************************************************
" ADD THE JSON EQUIPMENTS TO THE RESPONSE
******************************************************************
ME->ZIF_REST~RESPONSE->SET_DATA( DATA = LV_XSTRING ).
CATCH CX_ROOT.
ENDTRY.
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.
METHOD ZIF_REST~SET_RESPONSE.
ENDMETHOD.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 7/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
Your class will now have the first two methods below. Add a new method:
‘CONSTRUCTOR’.
Add the following parameters to ‘CONSTRUCTOR’. This will instantiate the class
when called upon.
METHOD ZIF_REST~HANDLE_REQUEST.
******************************************************************
" TYPES
******************************************************************
TYPES: BEGIN OF TYPE_EQUI,
EQUNR TYPE STRING,
EQKTX TYPE STRING,
END OF TYPE_EQUI.
******************************************************************
" VARIABLES AND OBJECTS
******************************************************************
DATA: LS_EQUI TYPE TYPE_EQUI.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 9/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
METHOD ZIF_REST~SET_RESPONSE.
ENDMETHOD.
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.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 11/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
This will return an array with data. In this case only the equipment where the
equipment number matches.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 13/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
Related Questions
Transport webservice Entry in SICF to QAS and PRD
By Former Member Aug 10, 2009
10 Comments
in section 3. Creating a Handler Class - missing the proposed name of the handler class is missing
JNN
section 2. Attributes REQUEST and RESPONSE are missing from the interface
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 15/18
04/07/23, 12:25 Writing a SICF service | SAP Blogs
I have a question, and it is about how do you handle the authorisation. If I am not wrong anyone with the
user and password could have access to any published service URL. Is there any way to link the service to a
role as it is done with the web services?
Thanks
Wei Han
October 25, 2022 at 8:00 am
Thank for your sharing. I have one question here. Do you know how to set the " Transport Protocol" to
HTTPS? thanks.
BR
Wei
Hameed Jaafari
November 22, 2022 at 10:21 pm
Hello.
This was a great tutorial, better than most of other postings I have seen. Even I could follow it and make it
work. however there is a little type in the source code. At one location EO_REST must change to EQ_REST.
Otherwise all activated with no errors.
Thank you.
H.
https://blogs.sap.com/2018/06/28/writing-a-sicf-service/ 17/18