DATA: lv_url TYPE string VALUE 'https://***********/v3/login',
lo_http_client TYPE REF TO if_http_client,
lo_rest_client TYPE REF TO cl_rest_http_client,
lo_request TYPE REF TO if_rest_entity.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url " URL
* proxy_host = " Logical destination (specified in function call)
* proxy_service = " Port Number
* ssl_id = " SSL Identity
* sap_username = " ABAP System, User Logon Name
* sap_client = " R/3 system (client number from logon)
* proxy_user = " Proxy user
* proxy_passwd = " Proxy password
IMPORTING
client = lo_http_client " HTTP Client Abstraction
EXCEPTIONS
argument_not_found = 1 " Communication Parameters (Host or Service) Not Available
plugin_not_active = 2 " HTTP/HTTPS Communication Not Available
internal_error = 3 " Internal Error (e.g. name too long)
OTHERS = 4.
IF sy-subrc = 0.
lo_http_client->request->set_version( lv_protocol ).
lo_rest_client = NEW #( io_http_client = lo_http_client ).
lo_request = lo_rest_client->if_rest_client~create_request_entity( ).
ENDIF.
lo_rest_client->if_rest_client~set_request_header(
EXPORTING
iv_name = 'ACCEPT'
iv_value = 'APPLICATION/JSON'
).
lo_rest_client->if_rest_client~set_request_header(
EXPORTING
iv_name = 'CONTENT-TYPE'
iv_value = 'APPLICATION/JSON'
).
CONCATENATE '{' '"username"' ':' '"' lv_user '"' ',' '"password"' ':' '"' lv_pwd '"' '}' INTO lv_body.
lo_request->set_string_data( lv_body ).
lo_rest_client->if_rest_resource~post( lo_request ).
DATA: lo_response TYPE REF TO if_rest_entity,
lv_response TYPE string.
lo_response = lo_rest_client->if_rest_client~get_response_entity( ).
lv_http_status = lo_response->get_header_field( '~status_code' ).
lv_reason = lo_response->get_header_field( '~status_reason' ).
lv_content_length = lo_response->get_header_field( 'content-length' ).
lv_location = lo_response->get_header_field( 'location' ).
lv_content_type = lo_response->get_header_field( 'conent-type' ).
lv_response = lo_response->get_string_data( ).
IF lv_http_status = lc_status.
CALL METHOD /ui2/cl_json=>deserialize
EXPORTING
json = lv_response " JSON string
pretty_name = /ui2/cl_json=>pretty_mode-user " Pretty Print property names
assoc_arrays = abap_true " Deserialize associative array as tables with unique keys
CHANGING
data = lr_data. " Data to serialize
IF lr_data IS BOUND.
ASSIGN lr_data->* TO <data>.
ASSIGN COMPONENT `PRODUCTS` OF STRUCTURE <data> TO <results>.
ASSIGN <results>->* TO <table>.
LOOP AT <table> ASSIGNING <structure>.
ASSIGN <structure>->* TO <data>.
ASSIGN COMPONENT `BASEAPIURL` OF STRUCTURE <data> TO <field>.
IF <field> IS ASSIGNED.
lr_data1 = <field>.
ASSIGN lr_data1->* TO <field_value>.
ls_final-baseapiurl = <field_value>.
ENDIF.
UNASSIGN: <field> , <field_value>.
APPEND ls_final TO gt_response.
ENDLOOP.
ASSIGN lr_data->* TO <data> .
ASSIGN COMPONENT `USERINFO` OF STRUCTURE <data> TO <results>.
ASSIGN <results>->* TO <data>.
ASSIGN COMPONENT `SESSIONID` OF STRUCTURE <data> TO <field>.
IF <field> IS ASSIGNED.
lr_data = <field>.
ASSIGN lr_data->* TO <field_value>.
ls_final-sessionid = <field_value>.
ENDIF.
UNASSIGN: <field>, <field_value>.
ASSIGN COMPONENT `STATUS` OF STRUCTURE <data> TO <field>.
IF <field> IS ASSIGNED.
lr_data = <field>.
ASSIGN lr_data->* TO <field_value>.
ls_final-status = <field_value>.
ENDIF.
UNASSIGN: <field>, <field_value>.
APPEND ls_final TO gt_response.
ENDIF.
ENDIF.
CONCATENATE '{' '"@type"' ':' '"job"' ' ,' '"taskName"' ':' '"' gv_jobname '"' ' ,' '"taskType"' ':' '"MTT"' '}' INTO lv_body .
lo_rest_client->if_rest_client~set_request_header(
EXPORTING
iv_name = 'IcSessionId'
iv_value = im_ssnid
).
lo_request->set_string_data( lv_body ).
lo_rest_client->if_rest_resource~post( lo_request ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |