0% found this document useful (0 votes)
4 views7 pages

Client Spend Analysis and API Report

This rogram consumes external AI data into SA.and rocess the retrived data in SA

Uploaded by

naseema.begum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Client Spend Analysis and API Report

This rogram consumes external AI data into SA.and rocess the retrived data in SA

Uploaded by

naseema.begum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Project/client spend in percentage

BSID – 50 %

Vguard – 20%

Algoriq – 30 %

Project/Client Percentage
BSID 50%
Vguard 20%
Algoriq 30%

Program to Consume External API

REPORT zdemo rest_api_consumption.

DATA:1v_url TYPE string.

TYPES:BEGIN OF ty_data,

user_name TYPE string,

first name TYPE string,

last name TYPE string,

middle name TYPE string,

gender TYPE string,

age TYPE string,

emails TYPE string,

favorite feature TYPE string,

features TYPE string,

addressinfo TYPE string,

homeaddress TYPE string,

END OF ty_data.

DATA:It_output TYPE TABLE OF ty_data.

DATA:1v_url TYPE string.


lv_url ="http:// [Link]/users'.

Step1:

cl_http_client->create_by_url(

EXPORTING

url

IMPORTING

client

EXCEPTIONS

argument_not_found

plugin_not_active

internal_error

OTHERS

sy-subre-0.

Step2:

lo_http->send(

EXPORTING

timeout

EXCEPTIONS

.lv_url

-DATA(lo_http)

OTHERS

http_communication failure

http_invalid_state

http_processing failed

http_invalid_timeout

-15
-2

-3

<-4

IF sy-subrc<>8.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Step3:

lo_http->receive(

EXCEPTIONS

http_communication

http_invalid_state

failure1

-2

http_processing failed -3

OTHERS

).

IF sy-subrc<>8.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Step4

DATA(result)lo_http->response->get_cdata().

"Step5

cl_abap_browser->show_html(

EXPORTING

title
).

html_string-result

ENDIF.

Step5

cl_abap_browserw>show_html(

EXPORTING

title

htel string result

-)..

).

SPLIT result AT[INTO DATA(lv_string1)DATA(lv_string2).

lv_string2 =|{ '[' && lv_string2 }|.

DATA(lv_final_string) = substring(val=lv_string2 off=0 len=strlen(lv_string2)-1).

Step6:

/ui2/cl_json->deserialize(

EXPORTING

json - lv_final_string

pretty_name - /ui2/cl_json->pretty_mode-camel_case

*SAPYARD Rest API Training

CHANGING

data - lt_output

).
DATA : http_client TYPE REF TO if_http_client.
DATA : l_str_length TYPE i.
DATA : mime TYPE w3mimetabtype.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-s01.


PARAMETERS: p_inv TYPE belnr_d DEFAULT '12345'.
SELECTION-SCREEN: END OF BLOCK b1.

START-OF-SELECTION.

*HTTP Client Abstraction


DATA lo_client TYPE REF TO if_http_client.

*Data variables for storing response in xstring and string


DATA : lv_xstring TYPE xstring,
lv_string TYPE string,
lv_node_name TYPE string.

CLEAR : lv_xstring, lv_string, lv_node_name.

*Pass the URL to get Data


** lv_string = |[Link] p_inv }|.
lv_string = '[Link]

*Creation of New IF_HTTP_Client Object


cl_http_client=>create_by_url(
EXPORTING
url = lv_string
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
).

IF sy-subrc IS NOT INITIAL.


* Handle errors
ENDIF.

http_client->propertytype_logon_popup = http_client->co_disabled.
http_client->request->set_method( 'POST' ).

CALL METHOD http_client->request->set_header_field


EXPORTING
name = 'Content-Type:'
value = 'application/x-www-form-urlencoded'.

CALL METHOD http_client->request->set_header_field


EXPORTING
name = 'grant_type:'
value = 'password'.

CALL METHOD http_client->request->set_header_field


EXPORTING
name = 'username:'
value = 'myubname@[Link]'.

CALL METHOD http_client->request->set_header_field


EXPORTING
name = 'password:'
value = 'abc123'.

*Structure of HTTP Connection and Dispatch of Data


http_client->send( ).
*Receipt of HTTP Response

CALL METHOD http_client->receive


EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.

IF sy-subrc NE 0.
DATA subrc TYPE sysubrc.
DATA errortext TYPE string.

CALL METHOD http_client->get_last_error


IMPORTING
code = subrc
message = errortext.

WRITE: / 'communication_error( receive )',


/ 'code: ', subrc, 'message: ', errortext.
EXIT.
ELSE.
****Get the response content in Character format
* content = client->response->get_cdata( ).
ENDIF.

** lo_client->receive( ).
** IF sy-subrc IS NOT INITIAL.
*** Handle errors
** ENDIF.

END-OF-SELECTION.

**Return the HTTP body of this entity as binary data


*lv_xstring = http_client->response->get_data( ).

*Return the HTTP body of this entity as string data


DATA(lv_string2) = http_client->response->get_cdata( ).
data: cadena2 TYPE string.
cadena2 = lv_string2+255(89).

BREAK-POINT.

http_client->close( ).
l_str_length = xstrlen( lv_xstring ).

CALL FUNCTION 'RSFO_XSTRING_TO_MIME'


EXPORTING
c_xstring = lv_xstring
i_length = l_str_length
TABLES
c_t_mime = mime.

You might also like