*&---------------------------------------------------------------------*
*& Report Z_SAMPLE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_SAMPLE.
DATA: lo_http_client TYPE REF TO if_http_client.
DATA: lt_header_fields TYPE tihttpnvp.
DATA: ls_header_fields TYPE ihttpnvp.
DATA: response TYPE string.
DATA(l_url) = |http://<your server:your port>/sap/opu/odata/sap/API_CNSLDTNGRPJRNLITEM/CnsldtnGrpJrnlItem(P_ConsolidationUnitHierarchy='RGCUH'| &&
|,P_ConsolidationPrftCtrHier='$',P_ConsolidationSegmentHier='$',P_KeyDate=datetime'2018-12-31T00:00:00')| &&
|/Results?$select=ConsolidationGroup,ConsolidationUnitForElim,FiscalYearPeriod,FinancialStatementItem,ProfitCenter,SubItem,| &&
|SubItemCategory,ConsolidationUnit,AmountInLocalCurrency,AmountInGroupCurrency| &&
|,CnsldtnQuantityInBaseUnit&$filter=ConsolidationVersion eq '<your value>'|.
"you can provide additional filters as per your convenience
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
" error
ENDIF.
lo_http_client->request->set_method('GET').
ls_header_fields-name = 'Content-Type'.
ls_header_fields-value = 'application/json'.
APPEND ls_header_fields TO lt_header_fields.
CLEAR ls_header_fields.
ls_header_fields-name = 'Accept'.
ls_header_fields-value = 'application/json'.
APPEND ls_header_fields TO lt_header_fields.
CLEAR ls_header_fields.
ls_header_fields-name = 'APIKey'.
ls_header_fields-value = '<API_KEY>'.
APPEND ls_header_fields TO lt_header_fields.
CLEAR ls_header_fields.
CALL METHOD lo_http_client->request->set_header_fields
EXPORTING
fields = lt_header_fields.
CALL METHOD lo_http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc = 0.
CALL METHOD lo_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 5.
ENDIF.
IF sy-subrc <> 0.
"error
ENDIF.
response = lo_http_client->response->get_cdata( ).
DATA(lref_result) = /ui2/cl_json=>generate( json = response ).
ASSIGN lref_result->* TO FIELD-SYMBOL(<lref_result>).
ASSIGN COMPONENT 'D' OF STRUCTURE <lref_result> TO FIELD-SYMBOL(<lv_result>).
ASSIGN <lv_result>->* TO FIELD-SYMBOL(<l_result>).
ASSIGN COMPONENT 'RESULTS' OF STRUCTURE <l_result> TO FIELD-SYMBOL(<l_adso_res>).
ASSIGN <l_adso_res>->* TO FIELD-SYMBOL(<ls_adso_res>).
TYPES:
ty_s_dso_data TYPE /bic/azfullst1, "changes as per your adso
ty_t_dso_data TYPE STANDARD TABLE OF /bic/azfullst1. "changes as per your adso
DATA:
gs_dso_data TYPE /bic/azfullst1, "changes as per your adso
l_char type string,
gt_dso_data TYPE STANDARD TABLE OF /bic/azfullst1, "changes as per your adso,
gv_numrec TYPE i,
gt_log_msgs TYPE rs_t_msg,
gs_log_msg TYPE rs_s_msg,
gt_log_msgs2 TYPE STANDARD TABLE OF abapsource,
gv_log_msg2 TYPE abapsource,
gv_idx TYPE i,
lt_data_250 TYPE bapi6116tda.
*
FIELD-SYMBOLS : <l_adso>,
<l_adsoval>,
<l_CunitElim>,
<l_CunitElimVal>,
<l_FSItem>,
<l_FSItemVal>,
<l_Subit>,
<l_SubitVal>,
<l_Subty>,
<l_SubtyVal>,
<l_cunit>,
<l_cunitVal>,
<l_congr>,
<l_congrVal>,
<l_PRcntr>,
<l_PRcntrVal>,
<l_Lcur>,
<l_LcurVal>,
<l_fiscper>,
<l_fiscperVal>,
<l_Qty>,
<l_QtyVal>,
<l_AmntLC>,
<l_AmntLCVal>,
<l_AmntGC>,
<l_AmntGCVal>.
LOOP AT <ls_adso_res> ASSIGNING <l_adso>.
ASSIGN <l_adso>->* TO <l_adsoval>.
* ASSIGN COMPONENT 'D' OF STRUCTURE <l_adso> TO FIELD-SYMBOL(<l_result>).
ASSIGN COMPONENT 'AMOUNTINGROUPCURRENCY' OF STRUCTURE <l_adsoval> TO <l_AmntGCVal>.
ASSIGN COMPONENT 'AMOUNTINLOCALCURRENCY' OF STRUCTURE <l_adsoval> TO <l_AmntLCVal>.
ASSIGN COMPONENT 'CNSLDTNQUANTITYINBASEUNIT' OF STRUCTURE <l_adsoval> TO <l_QtyVal>.
ASSIGN COMPONENT 'CONSOLIDATIONUNITFORELIM' OF STRUCTURE <l_adsoval> TO <l_CunitElimVal>.
ASSIGN COMPONENT 'FINANCIALSTATEMENTITEM' OF STRUCTURE <l_adsoval> TO <l_FSItemVal>.
ASSIGN COMPONENT 'FISCALYEARPERIOD' OF STRUCTURE <l_adsoval> TO <l_fiscperVal>.
ASSIGN COMPONENT 'CONSOLIDATIONUNIT' OF STRUCTURE <l_adsoval> TO <l_cunitVal>.
ASSIGN COMPONENT 'CONSOLIDATIONGROUP' OF STRUCTURE <l_adsoval> TO <l_congrVal>.
ASSIGN COMPONENT 'PROFITCENTER' OF STRUCTURE <l_adsoval> TO <l_PRcntrVal>.
ASSIGN COMPONENT 'SUBITEM' OF STRUCTURE <l_adsoval> TO <l_SubitVal>.
ASSIGN COMPONENT 'SUBITEMCATEGORY' OF STRUCTURE <l_adsoval> TO <l_SubtyVal>.
gs_dso_data-/bic/zksl = conv f( <l_AmntGCVal>->* ) .
IF <l_CunitElimVal>->* is initial.
gs_dso_data-/bic/zrbunitel = ''.
ELSE.
gs_dso_data-/bic/zrbunitel = <l_CunitElimVal>->*.
ENDIF.
gs_dso_data-/bic/zfsitem = <l_FSItemVal>->*.
gs_dso_data-/bic/zsubit = <l_SubitVal>->*.
gs_dso_data-/bic/zsubty = <l_SubtyVal>->*.
gs_dso_data-/bic/zrbunit = <l_cunitVal>->*.
gs_dso_data-/bic/zrcongr = <l_congrVal>->*.
gs_dso_data-/bic/zprctr = <l_PRcntrVal>->*.
gs_dso_data-/bic/zhsl = <l_AmntLCVal>->*.
APPEND gs_dso_data TO gt_dso_data.
ENDLOOP.
CALL FUNCTION 'RSDRI_DATA_WRAP'
EXPORTING
i_t_data = gt_dso_data
i_unicode_result = rs_c_false
i_compress = rs_c_false
i_result250 = rs_c_true
IMPORTING
e_t_outdata250 = lt_data_250.
CALL FUNCTION 'RSDSO_WRITE_API_RFC'
EXPORTING
i_adsonm = '<your adso>'
i_allow_new_sids = rs_c_true
* I_RFCDATA_UC =
it_rfcdata_250 = lt_data_250
* I_DEBUG = RS_C_FALSE
IMPORTING
e_lines_inserted = gv_numrec
et_msg = gt_log_msgs
* E_UPD_REQ_TSN = DATA(l_req_tsn)
EXCEPTIONS
write_failed = 1
activation_failed = 2
datastore_not_found = 3
OTHERS = 4.
CASE sy-subrc.
WHEN 0.
WRITE: 'Number of records inserted: ', gv_numrec.
WHEN 1.
WRITE: 'ERR! Insert failed...'.
WHEN 2.
WRITE: 'ERR! ADSO not found'.
WHEN OTHERS.
WRITE: 'ERR! Something (what?) went wrong'.
ENDCASE.
NEW-LINE.
NEW-LINE.
LOOP AT gt_log_msgs INTO gs_log_msg.
CALL FUNCTION 'RS_MSG_TEXT'
EXPORTING
* text_type = 'L'
msgid = gs_log_msg-msgid " Message ID
msgno = gs_log_msg-msgno " Message Number
msgv1 = gs_log_msg-msgv1
msgv2 = gs_log_msg-msgv2
msgv3 = gs_log_msg-msgv3
msgv4 = gs_log_msg-msgv4
* dialog = abap_true
TABLES
msgtext = gt_log_msgs2
EXCEPTIONS
message_not_exists = 1
OTHERS = 2.
IF sy-subrc <> 0.
"ERROR
ENDIF.
ENDLOOP.
LOOP AT gt_log_msgs2 INTO gv_log_msg2.
WRITE: / gv_log_msg2.
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
11 | |
10 | |
7 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 |