SAP BTP ABAP Ortamında HTTP Hizmeti Oluşturma
SAP BTP ABAP ortamında tarayıcıdan çağrılabilen bir HTTP servisi oluşturmayı inceleyeceğiz.
Step 1: HTTP Servisi Oluşturma



HTTP Servisi, URL otomatik olarak şu biçimde üretilir: https://<server:port>/sap/bc/http/sap/<service_name>?sap-client=100

Step 2: Handler Class’ın Uygulanması
Bir metnin çıktısıyla handler class’ı test edelim. ‘Handler Class’ linke tıklanır.

- Sınıfın yapısı ve arayüz ifadeleri IF_HTTP_SERVICE_EXTENSION otomatik olarak oluşturulur. Test için aşağıdaki kod bloğu eklenir.
response->set_text('Hello World!').

Step 3: Test
URL bilgisine tıklanarak tarayıcı üzerinden test edilebilir.


Step 4: “get_html” metodu ile sistem verilerinin alınması
Sistem verilerini almak ve bunları HTML’de biçimlendirmek için bir yöntem eklenir.
ABAP ortamında yalnızca write-list alınmış API’leri kullanılabilir. Bu nedenle, örneğin SY-UNAME ifadesin kullanılamaz. Bunun yerine, sınıfının uygun yöntemi olan CL_ABAP_CONTEXT_INFO sınıfının çağrılması gerekmektedir.
- Class’a ‘get_html’ metodu eklenir.
METHODS: get_html RETURNING VALUE(ui_html) TYPE string.
- Metot içerisinde örnek kod eklenir.
DATA(system_date) = cl_abap_context_info=>get_system_date( ).
ui_html = |<html> \n| &&
|<body> \n| &&
|<title>Sistem Bilgi</title> \n| &&
|<p> Günün tarihi: { system_date+6(2) && '.' && system_date+4(2) && '.' && system_date(4) }| &&
|<p> | &&
|</body> \n| &&
|</html> | .
- Output

Kodun tamamı aşağıdaki gibidir:
CLASS zcl_sb_get_date_http DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
METHODS: get_html RETURNING VALUE(ui_html) TYPE string
RAISING
cx_abap_context_info_error.
INTERFACES if_http_service_extension .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_sb_get_date_http IMPLEMENTATION.
METHOD if_http_service_extension~handle_request.
TRY.
response->set_text( get_html( ) ).
CATCH cx_web_message_error cx_abap_context_info_error.
"additional exception handling
ENDTRY.
ENDMETHOD.
METHOD get_html.
DATA(system_date) = cl_abap_context_info=>get_system_date( ).
ui_html = |<html> \n| &&
|<body> \n| &&
|<title>Sistem Bilgi</title> \n| &&
|<p> Günün tarihi: { system_date+6(2) && '.' && system_date+4(2) && '.' && system_date(4) }| &&
|<p> | &&
|</body> \n| &&
|</html> | .
ENDMETHOD.
ENDCLASS.

