SAP Analytics Cloud, SAP S/4HANA

Using SAP Analytics Cloud API Data Export Service from SAP S/4 HANA

In this blog post I will show how we can configure the SAP Analytics Cloud Data Export API to access planning data and integrate it with SAP S/4 HANA On Premise.

I have started to develop the integration for Funds Management component but then I have decided to extend our methods to support other components. See the last chapter with the demo report.

The steps to be covered in this blog post are the technical setup of the integration.

  1. SAP Analytics Cloud Configuration
  2. OAuth2 configuration in SAP S/4 Hana OP
  3. Generic Abap method to read Fact Data of API
  4. Abap report demo

1. SAP Analytics Cloud Configuration

To use the SAP Analytics Cloud Data Export API you require 3 parameters, I refer to these numbers further in the blog post.

1. Token URL

2. OAuth Client ID

3. Secret

In SAP Analytics Cloud navigate to System -> Administration -> App Integration

Here you will see your OAuth Clients and Token URL.

Add a New OAuth Client, when the Data Export API is enabled/released you will see the Data Export Service as an Access Type.

Here is an example of SAP Analytics Cloud app integration:

Figure 1.1

2. Auth2 configuration in SAP S/4 Hana

2.1 Transaction OA2C_CONFIG

In SAP S/4 HANA On Premise, execute transaction OA2C_CONFIG in order to create an OAuth2 profile based on the OAuth2 client ID stored previously in SAP Analytics Cloud.

Figure 2.1 OAuth2.0 Clients

2.2. RFC destination

Depending on your system and if you have a proxy setting, you must define an RFC destination in order to use it during the API access. This RFC destination will be a vehicle to get access information for the API like proxy host and proxy service and also the OAuth Setting.

Here is one example of RFC destination:

Figure 2.2 RFC destination example

3. Read Master data and Fact Data from API Data Export Service

Once the model is built in SAC and the planning data are filled, you are ready to load the planning data in S/4 Hana On Premise by using the API Data Export Service.

But how can we access from SAP S/4 HANA the fact data for this model using ABAP code?

That’s the aim of this blog: helping developer to implement in ABAP this reading mechanism.

Let’s start with an example of a model in SAP Analytics Cloud:

Figure 3.1 Model example

We will use the new methods of the class so called CL_GEN_SAC_ACCESS to read the information of the model. See the note 3241213 valid for OP 2021 release.

You need first to understand which key fields are required to access this API:

  • The SAP Analytics Cloud url that is for example “https://[tenant ID].eu10.hcs.cloud.sap” if you are in Europe.
  • The namespace (default value is “sac”)
  • The authorization profile that we have defined earlier.
  • The authorization configuration that can be equal to the authorization profile or blank.
  • The RFC destination for external server in case you have configured proxy setting

3.1 Read the list of Provider ID (Method F4_HELP_PROVIDERS )

Once the method is called, you will get the provider ID name that is equal to the SAP Analytics Cloud model name.

Here is one configuration example implemented for the Transfer of SAP Analytics Cloud planning to Funds Management Budgeting.

Figure 3.2
CALL METHOD CL_GEN_SAC_ACCESS=>f4_help_providers
EXPORTING
im_sac_url       = g_resulturl
im_oauth_profile = g_oauthprofile
im_oauth_configuration = g_oauthconfiguration
im_rfcdest             = g_rfcdest
im_namespace           = l_namespaceid
IMPORTING
e_providername   = l_providername
e_providerid     = l_providerid
*     et_errors              =
EXCEPTIONS
no_providers           = 1
*     others                 = 2
.

3.2 Read the list of SAP Analytics Cloud fields to be mapped to SAP S/4 HANA fields (Method GET_ALL_FIELDNAMES, CHECK_FIELDNAME and F4_HELP_FIELDNAMES )

Figure 3.3 F4 Help for SAC fields
CALL METHOD CL_GEN_SAC_ACCESS=>f4_help_fieldnames
EXPORTING
im_sac_url       = g_resulturl
im_oauth_profile = g_oauthprofile
im_oauth_configuration = g_oauthconfiguration
im_rfcdest             = g_rfcdest
im_namespace           = u_namespaceid
im_provider      = u_providerid
IMPORTING
e_sacfieldname   = l_sacfieldname
et_errors        = lt_errors
EXCEPTIONS
no_fieldnames    = 1
OTHERS           = 2.
IF sy-subrc <> 0.

3.3 Where to store the field mapping between SAP Analytics Cloud and SAP S/4 Hana

Once you know how to get the provider ID and the list of SAP Analytics Cloud field names, you have to store this mapping information in order to load the fact data for your own S/4 Hana business case.

To enable this feature in an easy way, we have provided two generic tables which create an application and a sub application GENSAC_APPL and GENSAC_SUB_APPL. These tables are editable for customer with custom key fields. These tables are delivered to make the SAC field mapping working with the next table GENSAC_FIELDMAP.

For example, the table will contain the mapping between SAP Analytics Cloud field names used in your model (for example “SAP_ALL_FUND”) and SAP S/4 Hana fieldnames (for example “Fund”)

In Funds Management, the customizing for mapping looks like below:

Figure 3.4 Mapping example

3.4 Read the fact data (Method READ_FACT_DATA )

Here is now the most interesting part which is about the loading of SAP Analytics Cloud data. Note that you can only start this step if you have done the previous steps.

The method “read_fact_data” load the data and return the response that has to be deserialize and export into a reference lo_data.

Then you have to loop on the reference lo_data taking into account the mapping table.

DATA: l_url     TYPE string,
lt_errors TYPE tihttpnvp.

DATA l_response TYPE string.
DATA l_content_type TYPE string.

  DATA: lo_data    TYPE REF TO data,
ls_mapping TYPE ihttpnvp,
lt_mapping TYPE tihttpnvp.

  CALL METHOD cl_gen_sac_access=>read_fact_data
EXPORTING
im_sac_url             = l_result_url
IM_RFCDEST             = l_rfcdest
im_namespace           = i_namespace
im_provider            = i_provider
im_oauth_profile       = l_profile
im_filter_string       = l_filter
im_oauth_configuration = l_Oauth_CONFIGURATION           
IMPORTING
e_content_type         = l_content_type
e_response             = l_response
et_errors              = lt_errors
EXCEPTIONS
OTHERS                 = 1.

  CALL METHOD /ui2/cl_json=>deserialize
EXPORTING
json         = l_response
pretty_name  = /ui2/cl_json=>pretty_mode-user
assoc_arrays = abap_true
CHANGING
data         = lo_data.

  LOOP AT LT_GENSAC_FIELDMAP INTO DATA(ls_sacmapping).

ls_mapping-value = ls_sacmapping-sacfield.
ls_mapping-name = ls_mapping-value. "can also be another field name!
APPEND ls_mapping TO lt_mapping.
ENDLOOP.

ASSIGN lo_data->* TO <data>.
ASSIGN COMPONENT `VALUE` OF STRUCTURE <data> TO <body>.
ASSIGN <body>->* TO <table>.
LOOP AT <table> ASSIGNING <table_line>.

 LOOP AT <table> ASSIGNING <table_line>.

ASSIGN <table_line>->* TO <structure>.
LOOP AT lt_mapping INTO ls_mapping.
UNASSIGN <target_field>.
ASSIGN COMPONENT ls_mapping-value OF STRUCTURE <structure> TO <field>.

READ TABLE LT_GENSAC_FIELDMAP WITH KEY tenantid = i_tenant
providerid = i_provider
namespaceid  = i_namespace
sacfield = ls_mapping-name
INTO ls_sacmapping.

3.5 Handling of SAP Analytics Cloud version

If you work with planning data, you may need to restrict the upload for SAC version “public.Plan”.

Figure 3.5 Value help for SAC version
DATA l_sacversionvalue TYPE string.
  DATA l_sacfieldname TYPE fmsacfieldname.
  l_sacfieldname = 'Version'.
      CALL METHOD CL_GEN_SAC_ACCESS=>f4_help_masterdata_values
        EXPORTING
          im_sac_url       = l_resulturl
          Im_rfcdest       = l_rfcdest 
          im_oauth_profile = l_oauthprofile
          im_namespace     = u_namespace
          im_provider      = u_providerid
          im_sacfieldname  = l_sacfieldname 
        IMPORTING
          e_masterdata_id  = l_sacversionvalue
*         et_errors        =
        EXCEPTIONS
          no_masterdata    = 1
          OTHERS           = 2.
      IF sy-subrc <> 0.

3.6 Filtering option to limit the size of the upload

In Funds Management business case, is it common to upload planning data in several runs using a criterion like the Fund. To do so, the method “ENHANCE_FILTER_OPTION” has be called before the method “READ_FACT_DATA”.

DATA l_filter TYPE string.

  DATA(l_vnfld) = 'Version'.
  IF i_sacversn IS NOT INITIAL.
    l_filter = l_filter && `{VERSION_FIELD} eq '{VERSION_VALUE}'`.
    REPLACE `{VERSION_FIELD}` IN l_filter WITH l_vnfld. "SAC Field name for the version, to be taken from customizing!
    REPLACE `{VERSION_VALUE}` IN l_filter WITH i_sacversn.
  ELSE.
*    l_url = l_url && `?$select=Account`. "does not work!!! Internal server error!
  ENDIF.

  DATA l_T_FIELD_SELECTION TYPE bubas_t_field_selection.
  DATA l_s_field_selection TYPE bubas_s_field_selection.
  DATA l_f_range_for_filter TYPE rsdsselopt.
  DATA l_t_range_for_filter TYPE bubas_t_selopt.
  DATA g_t_rfund TYPE FMBS_T_RFUND.

  IF i_s_fm01-fikrs IS NOT INITIAL.
    l_s_field_selection-fieldname = 'FINANCIALMANAGEMENTAREA'.
    l_f_range_for_filter-sign = 'I'.
    l_f_range_for_filter-option = 'EQ'.
    l_f_range_for_filter-low = i_s_fm01-fikrs.
    APPEND  l_f_range_for_filter TO  l_t_range_for_filter.
    CLEAR  l_f_range_for_filter.
    APPEND LINES OF l_t_range_for_filter TO l_s_field_selection-t_selopt.
    APPEND l_s_field_selection TO l_t_field_selection.
    CLEAR l_s_field_selection.
  ENDIF.

  FREE l_t_range_for_filter.
  l_s_field_selection-fieldname = 'FUND'.
  LOOP AT  g_t_rfund ASSIGNING FIELD-SYMBOL(<l_f_rfund>).
    MOVE-CORRESPONDING <l_f_rfund> TO l_f_range_for_filter.
    APPEND  l_f_range_for_filter TO l_t_range_for_filter.
    CLEAR  l_f_range_for_filter.
  ENDLOOP.
  APPEND LINES OF l_t_range_for_filter TO l_s_field_selection-t_selopt.
  APPEND l_s_field_selection TO l_t_field_selection.
  CLEAR l_s_field_selection.

  CALL METHOD CL_GEN_SAC_ACCESS=>enhance_filter_option
    EXPORTING
      im_tenantid                  = i_tenant
      im_namespaceid               = i_namespace
      im_providerid                = i_provider
      im_t_standard_select_options = l_T_FIELD_SELECTION
    CHANGING
      c_filter_query_option        = l_filter
    EXCEPTIONS
      OTHERS                       = 1.

  IF sy-subrc NE 0.

Then you will call the method “READ_FACT_DATA” with the importing parameter “im_filter_string” equal here to “l_filter”.

3.7 Handling the date from SAP Analytics Cloud

Note that it is not obvious to get a proper time dimension from SAP Analytics Cloud. In the SAP Analytics Cloud model, you define the date and the corresponding granularity like for example the year:

Figure 3.6 Granularity per year

During the mapping in SAP S/4 Hana, you have to define the field date to an SAP S/4 Hana fieldname represented the fiscal year.

If the granularity is set to month like below, you will have to define with a different data type for SAP S/4 Hana fieldname.

Figure 3.7: Month / Year granularity

In SAP S/4 HANA, you will then define a mapping with a field like SACYEARMONTH define with type CHAR06.

Figure 3.8

4. ABAP report example: RFGEN_SAC_RETRACTOR_DEMO

The report is delivered via the note 3256990 and will guide you on how to use the different methods for your own business:

Once you have saved the connection and authorization setting in chapter 1 and 2, you are able to execute the report.

You have to enter the url like [TenantID].eu10.hcs.cloud.sap for Europe and the RFC destination.

Figure 4: demo program
Rating: 0 / 5 (0 votes)