Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Exercise 1 - Hello World

In this exercise, we will create a very simple HTTP service in ABAP which can then be called from the browser. For more information about system access and package creation, please see the Getting Started section.

Exercise 1.1 Creating Hello World

After completing these steps you will have created an HTTP Service, an HTTP Handler Class, and executed your HTTP service from the browser.

  1. Right-click on your package and choose “New“, “Other ABAP Repository Object“.

  2. Expand “Connectivity” folder and choose “HTTP Service”. Click “Next”.

  3. Name the service as ZHELLO_WORLD_XXX where XXX is your group number. Give a meaningful description. Leave the default name for the Handler Class. Click “Next”. Make sure to replace XXX with your group number.

  4. Click “Finish”.

  5. Click on “Handler Class“.

  6. The shell of the handler class is then shown. Here we need to create the implementation for the handle_request method.

  7. Insert this line of code in the HANDLE_REQUEST method.

response->set_text( |Hello World! | ). 
  1. Your method should now look like this.

  2. Save and activate your work.

  3. Return to the HTTP Service definition and click on URL

  4. The browser should open where you may be asked to log in. Log in and you should get Hello World! Congratulations!

Exercise 1.2 Extending Hello World

After completing these steps you will have modified your HTTP Handler Class to handle passing of URL parameters.

  1. Return to the handler class and modify the handle_request method as shown here. Call the get_form_fields method of the request object to get URL parameters, then check for specific commands such as “hello“ and “timestamp“.
DATA(lt_params) = request->get_form_fields(  ).
READ TABLE lt_params REFERENCE INTO DATA(lr_params) WITH KEY name = 'cmd'.
  IF sy-subrc <> 0.
    response->set_status( i_code = 400
                     i_reason = 'Bad request').
    RETURN.
  ENDIF.
  CASE lr_params->value.
      WHEN `hello`.
        response->set_text( |Hello World! | ).
      WHEN `timestamp`.
        response->set_text( |Hello World! application executed by {
                             cl_abap_context_info=>get_user_technical_name( ) } | &&
                              | on { cl_abap_context_info=>get_system_date( ) DATE = ENVIRONMENT } | &&
                              | at { cl_abap_context_info=>get_system_time( ) TIME = ENVIRONMENT } | ).
      WHEN OTHERS.
      response->set_status( i_code = 400 i_reason = 'Bad request').
  ENDCASE.
  1. You code should now look like this.

  2. Save and activate your work.

  3. Return to the HTTP Service definition and click on URL.

  4. You should get a 400 error because now your service is expecting a URL parameter to determine what it needs to do.

  5. Go to the URL in the browser window and add the parameter as shown.

  6. Now you should once again get the “Hello World!“.

  7. Finally, change the cmd parameter value in the URL to “timestamp“ and hit enter.

  8. Now your service should return something a bit more.

Summary

You've now created your Hello World application using ABAP, and exposed it as an HTTP service.

Continue to - Exercise 2 - Consuming Services via HTTP