In this recipe, we will see how we can programmatically call a web service using the proxy class generated in the previous recipes. We will see the main steps required in coding the program.
For quickly creating the template code within a program, first create a new program in the ABAP editor using SE80
and open the code of the program in the right-hand side pane. Then, in the left-hand side pane navigate to the customer proxy generated under the
Service Consumer node. Select the name of our consumer proxy and simply drag-and-drop from the left-hand side to the right-hand side pane (within the ABAP editor). The template code will be generated and added to your program. You may modify the code according to your requirements.
We will now dive into the details of the program:
ZST8_CO_ZST8_MYSERVICE
proxy class that is generated. We will name the reference MYPROXY
. We then instantiate the object using the CREATE OBJECT
statement. We also specify the logical port name, ZST8_LOGICAL_PORT
, created in the previous recipe. This is written within a TRY
and ENDTRY
statement.INPUT
structure contains three fields (amount
, currency
, and language
) corresponding to the importing parameters of our function module. Appropriate values are assigned to them.ZST8_MY_SPELL_AMOUNT
and pass the input
values via the INPUT
structure. The result of the execution is the Web service execution and is in the OUTPUT
structure. For printing the words, we can print the OUTPUT-IN_WORDS-WORD
.We first declare an object based on our proxy class. Before calling the method for converting the amount into words we fill the INPUT
structure with appropriate values. The two structures INPUT
and OUTPUT
correspond to the importing and exporting parameters of the function module, respectively. The
ZST8MY_SPELL_AMOUNT
method corresponds to the function module we initially used for creating the Web service. We call the method and pass the INPUT
structure containing the relevant input values. The
Web service is called and returns the result (amount in words) in the OUTPUT
structure.
3.14.141.115