Skip to Content
0

No Results in RSA1 Delta load of Function-Module Datasource

Mar 06 at 10:08 PM

24

avatar image

Hello,

I've copied the function module 'RSAX_BIW_GET_DATA_SIMPLE' to get Data from Google Analytics.

The Connection works fine. I've tested the datasource in RSA3 with an initial load and a delta load. Both worked fine.

If I use the datasource in RSA1, the initial load runs perfectly and the packages are filled with data. If I start the delta load, I always get no data. (RSA3 -> works, RSA1 doesnt' work). What is the difference?

I already debugged the function module and in RSA3 and RSA1, I get the correct data from the Google API but it seems that the data packages in RSA1 are not getting created.

Possible error:

- I don't fill the dltdate in the extract structure. I don't see any reason to fill it. Maybe it's necessary?

Thanks for you help

FUNCTION ZRSAX_BIW_GET_DATA_SIMPLE.

*"----------------------------------------------------------------------

*"*"Lokale Schnittstelle:

*"  IMPORTING

*"     VALUE(I_REQUNR) TYPE  SRSC_S_IF_SIMPLE-REQUNR

*"     VALUE(I_DSOURCE) TYPE  SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL

*"     VALUE(I_MAXSIZE) TYPE  SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL

*"     VALUE(I_INITFLAG) TYPE  SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL

*"     VALUE(I_READ_ONLY) TYPE  SRSC_S_IF_SIMPLE-READONLY OPTIONAL

*"     VALUE(I_REMOTE_CALL) TYPE  SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF

*"  TABLES

*"      I_T_SELECT TYPE  SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL

*"      I_T_FIELDS TYPE  SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL

*"      E_T_DATA STRUCTURE  ZWEB_MKTCHAN OPTIONAL

*"      E_T_SOURCE_STRUCTURE_NAME OPTIONAL

*"  EXCEPTIONS

*"      NO_MORE_DATA

*"      ERROR_PASSED_TO_MESS_HANDLER

*"----------------------------------------------------------------------


  STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,

  S_COUNTER_DATAPAKID LIKE SY-TABIX.

  DATA: wa_viewid(20) TYPE c.

  DATA: it_viewid TYPE TABLE OF char20.
DATA: l_s_select TYPE srsc_s_select.
DATA: go_delta_date_start(10) TYPE c,
      go_delta_date_end(10) TYPE c.
data: dltdate TYPE sy-datum.
data: values type table of string.
types: begin of zsd_metrics,
  values like values,
  END OF zsd_metrics.
types: metrics type table of zsd_metrics with non-unique default key.
  data: zdimensions type table of string.
types: begin of zsd_rows,

  dimensions like zdimensions, " kma: table of hinzu

  metrics TYPE metrics,

 end of zsd_rows.



 types: zrows type table of zsd_rows with non-unique default key.



types: begin of zsd_data,

  rows TYPE zrows,

 end of zsd_data.

types: begin of zcolumnheader,

  dimensions like zdimensions,

 end of zcolumnheader.



types: begin of zsd_reports,

  columnheader TYPE zcolumnheader,

  data TYPE zsd_data,

end of zsd_reports.

 types: zreports type table of zsd_reports with non-unique default key.



TYPES: BEGIN OF response,

         reports TYPE zreports,

       END OF response.

data: wa_response type response.

data: lt_rows TYPE zrows,

      wa_reports TYPE zsd_reports,

      "lv_string TYPE string,

      wa_data LIKE LINE OF E_T_DATA.

FIELD-SYMBOLS: <fs_rows> LIKE LINE OF lt_rows.

 DATA: profile    TYPE oa2c_profile,

       target     TYPE string,

       method     TYPE string,

       param_kind TYPE string,

       lt_param   TYPE tihttpnvp,

       ls_param   TYPE ihttpnvp.


   profile = 'Z_GOOGLE_ANALYTICS'.

   target  = `https://analyticsreporting.googleapis.com/v4/reports:batchGet`.

   method  = `POST`.

   param_kind = 'F'.

   data: rlength type i.

   DATA: wf_string2 TYPE string,

          lv_json TYPE string.

   DATA: lo_http_client  TYPE REF TO if_http_client,

         lo_oa2c_client  TYPE REF TO if_oauth2_client,

         l_status_code   TYPE i,

         l_response_data TYPE string,

         lt_fields       TYPE tihttpnvp,

         lx_oa2c         TYPE REF TO cx_oa2c.


   FIELD-SYMBOLS: <ls_field> LIKE LINE OF lt_fields.

  IF I_INITFLAG = SBIWA_C_FLAG_ON.



************************************************************************

* Initialization: check input parameters

*                 buffer input parameters

*                 prepare data selection

************************************************************************

* Check DataSource validity

    CASE I_DSOURCE.

      WHEN 'ZWEB_MKTCHANNEL'.

      WHEN OTHERS.

        IF 1 = 2. MESSAGE E009(R3). ENDIF.

* this is a typical log call. Please write every error message like this

        LOG_WRITE 'E'                  "message type

                  'R3'                 "message class

                  '009'                "message number

                  I_DSOURCE   "message variable 1

                  ' '.                 "message variable 2

        RAISE ERROR_PASSED_TO_MESS_HANDLER.

    ENDCASE.

    APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.



* Fill parameter buffer for data extraction calls

    S_S_IF-REQUNR    = I_REQUNR.

    S_S_IF-DSOURCE = I_DSOURCE.

    S_S_IF-MAXSIZE   = I_MAXSIZE.

* Fill field list table for an optimized select statement

* (in case that there is no 1:1 relation between InfoSource fields

* and database table fields this may be far from beeing trivial)

    APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.



  ELSE.                 "Initialization mode or data extraction ?



************************************************************************

* Data transfer: First Call      OPEN CURSOR + FETCH

*                Following Calls FETCH only

************************************************************************



* First data package -> OPEN CURSOR

    IF S_COUNTER_DATAPAKID = 0.

   LOOP AT s_s_if-t_select INTO l_s_select.

        CASE l_s_select-fieldnm.

          WHEN 'DLTDATE'.

            ls_delta_date_start    = l_s_select-low.

            ls_delta_date_end   = l_s_select-high.


          WHEN 'DATENANSICHT'.

            wa_viewid = l_s_select-low.

            APPEND wa_viewid TO it_viewid.

          ENDCASE.

      ENDLOOP.

      IF ls_delta_date_start = '00000000' OR ls_delta_date_start = ' ' OR ls_delta_date_start IS INITIAL.

        ls_delta_date_start = '20180226'.

      ENDIF.

  ENDIF.

  CONCATENATE ls_delta_date_start(4) '-' ls_delta_date_start+4(2) '-' ls_delta_date_start+6(2) INTO GO_DELTA_DATE_START.

  CONCATENATE ls_delta_date_end(4) '-' ls_delta_date_end+4(2) '-' ls_delta_date_end+6(2) INTO GO_DELTA_DATE_end.

  IF ls_delta_date_start > ls_delta_date_end.

    RAISE NO_MORE_DATA.

  ENDIF.



     LOOP AT it_viewid INTO wa_viewid.

**********************************************************************

* Create HTTP client

**********************************************************************

   CALL METHOD cl_http_client=>create_by_url
     EXPORTING
       url                = target
       ssl_id             = 'ANONYM'
     IMPORTING
       client             = lo_http_client
     EXCEPTIONS
       argument_not_found = 1
       plugin_not_active  = 2
       internal_error     = 3
       OTHERS             = 4.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   lo_http_client->propertytype_logon_popup = 0.


   CALL METHOD lo_http_client->request->set_method
     EXPORTING
       method = method.



   LOOP AT lt_param INTO ls_param.
     CALL METHOD lo_http_client->request->set_form_field
       EXPORTING
         name  = ls_param-name
         value = ls_param-value.
   ENDLOOP.

**********************************************************************

* Set OAuth 2.0 Token

**********************************************************************

   TRY.
       CALL METHOD cl_oauth2_client=>create
         EXPORTING
           i_profile        = profile
         RECEIVING
           ro_oauth2_client = lo_oa2c_client.
     CATCH cx_oa2c INTO lx_oa2c.
       WRITE: `Error calling CREATE.`.
       WRITE: / lx_oa2c->get_text( ).
       RETURN.
   ENDTRY.

 TRY.
       CALL METHOD lo_oa2c_client->set_token 
         EXPORTING
           io_http_client = lo_http_client
           i_param_kind   = param_kind.

     CATCH cx_oa2c INTO lx_oa2c.
       TRY.
           CALL METHOD lo_oa2c_client->execute_refresh_flow.
         CATCH cx_oa2c INTO lx_oa2c.
           WRITE: `Error calling EXECUTE_REFRESH_FLOW.`.
           WRITE: / lx_oa2c->get_text( ).
           RETURN.
       ENDTRY.


       TRY.

           CALL METHOD lo_oa2c_client->set_token

             EXPORTING

               io_http_client = lo_http_client

               i_param_kind   = param_kind.

         CATCH cx_oa2c INTO lx_oa2c.

           WRITE: `Error calling SET_TOKEN.`.

           WRITE: / lx_oa2c->get_text( ).

           RETURN.

       ENDTRY.

   ENDTRY.



   CONCATENATE '{"reportRequests":[{"viewId":"' WA_VIEWID '","dateRanges":[{"startDate":"'

   GO_DELTA_DATE_START '","endDate": "'

   GO_DELTA_DATE_START '"}],"metrics": [{"expression": "ga:transactions"}],'

   '"dimensions": [{"name": "ga:deviceCategory"},{"name": "ga:transactionId"},{"name": "ga:channelGrouping"} ] } ] }' INTO wf_string2.

   lv_json = wf_string2.
    rlength = strlen( wf_string2 ).

   CALL METHOD lo_http_client->request->set_cdata

     EXPORTING
       data   = lv_json
       offset = 0
       length = rlength.

**********************************************************************

* Send / Receive Request

**********************************************************************

     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.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ENDIF.


     CALL METHOD lo_http_client->receive
       EXCEPTIONS
         http_communication_failure = 1
         http_invalid_state         = 2
         http_processing_failed     = 3
       OTHERS                     = 4.

     IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ENDIF.

**********************************************************************
* Display result
**********************************************************************
     CALL METHOD lo_http_client->response->get_status
       IMPORTING
         code = l_status_code.


     IF l_status_code = 200.
       CALL METHOD lo_http_client->response->get_cdata
         RECEIVING
           data = l_response_data.



**********************************************************************

* Close

**********************************************************************

   CALL METHOD lo_http_client->close
     EXCEPTIONS
       http_invalid_state = 1
       OTHERS             = 2.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.


         CALL METHOD /UI2/CL_JSON=>DESERIALIZE
         EXPORTING
          JSON = l_response_data
         CHANGING
          DATA = wa_response.



         READ TABLE WA_RESPONSE-REPORTS INTO wa_reports INDEX 1.
         lt_rows = WA_REPORTS-DATA-ROWS.
         LOOP AT lt_rows ASSIGNING <fs_rows>.
           clear wa_data.
           READ TABLE <fs_rows>-dimensions INTO wa_data-devicecategory INDEX 1.
           READ TABLE <fs_rows>-dimensions INTO wa_data-transactionid INDEX 2.
           READ TABLE <fs_rows>-dimensions INTO wa_data-channelgrouping INDEX 3.
           append wa_data to e_t_data.

         ENDLOOP.

       "ENDIF.

"break-point.

     ELSE.





**********************************************************************

* Close

**********************************************************************

   CALL METHOD lo_http_client->close
     EXCEPTIONS
       http_invalid_state = 1
       OTHERS             = 2.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.



       RAISE ERROR_PASSED_TO_MESS_HANDLER.

     ENDIF.

     CLEAR: wa_response, l_response_data.

      ENDLOOP.

  ls_delta_date_start = ls_delta_date_start + 1.
    S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.

  ENDIF.              "Initialization mode or data extraction ?

ENDFUNCTION.
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers