InfoProvider lesen (ABAP)

Aus MattWiki
Version vom 11. Oktober 2017, 16:07 Uhr von Matt (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „Beispiel für den Einsatz von FIELD-SYMBOLS in Form eins Programms, welches ein beliebiges DSO liest und dieses in Form einer Tabelle zurück gibt. <syntaxhig…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Beispiel für den Einsatz von FIELD-SYMBOLS in Form eins Programms, welches ein beliebiges DSO liest und dieses in Form einer Tabelle zurück gibt.

FUNCTION zreaddso.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"----------------------------------------------------------------------

  FIELD-SYMBOLS:
                 <lt_data> TYPE ANY TABLE,
                 <ls_data> TYPE any.

  DATA:
        lr_data1 TYPE REF TO data,
        lr_rsd_dta TYPE REF TO cl_rsd_dta,
        lr_work_area TYPE REF TO cl_rsplfu_work_area,
        lr_wa_data TYPE REF TO data,
        lt_dta_iobj TYPE rsd_t_dta_iobj,
        ls_dta_iobj TYPE rsd_s_dta_iobj,
        lt_sel TYPE rsplf_t_charsel,                " Selektionstabelle
        ls_sel TYPE rsplf_s_charsel,
        lt_sfc TYPE rsdri_th_sfc,                   " Benötigte Merkmale
        ls_sfc TYPE rsdri_s_sfc,
        lt_sfk TYPE rsdri_th_sfk,                   " Benötigte Kennzahlen
        ls_sfk TYPE rsdri_s_sfk,
        l_first_call TYPE rs_bool,
        l_end_of_data TYPE rs_bool,
        lt_iobj TYPE rsplf_th_iobj,
        lt_iobj_sel TYPE rsplf_th_iobj,
        ls_iobj TYPE rsplf_s_iobjnm,
        c_infoprov TYPE rsinfoprov VALUE 'ZNWVKDAT'.


  " Ermittlung der InfoObjekte des InfoCubes
  CALL METHOD cl_rsd_dta=>factory
    EXPORTING
      i_infoprov = c_infoprov
    RECEIVING
      r_r_dta    = lr_rsd_dta.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  " Ermittlung der InfoObjekte des Zielcubes
  CALL METHOD lr_rsd_dta->dta_get_info
    EXPORTING
      i_objvers    = rs_c_objvers-active
    IMPORTING
      e_t_dta_iobj = lt_dta_iobj.
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.


  " InfoObjekte in Merkmals-/Kennzahldefinition
  LOOP AT lt_dta_iobj INTO ls_dta_iobj.
    IF ls_dta_iobj-iobjtp = 'KYF'.
      CLEAR ls_sfk.
      ls_sfk-kyfnm = ls_dta_iobj-iobjnm.
      ls_sfk-kyfalias = ls_dta_iobj-iobjnm.
      ls_sfk-aggr = 'SUM'.
      INSERT ls_sfk INTO TABLE lt_sfk.
    ELSEIF ls_dta_iobj-iobjnm <> '0RECORMODE'.

      CLEAR ls_sfc.
      ls_sfc-chanm = ls_dta_iobj-iobjnm.
      ls_sfc-chaalias = ls_dta_iobj-iobjnm.
      ls_sfc-orderby = 0.
      INSERT ls_sfc INTO TABLE lt_sfc.

      ls_iobj-iobjnm = ls_dta_iobj-iobjnm.
      COLLECT ls_iobj INTO lt_iobj_sel.
    ENDIF.

    ls_iobj-iobjnm = ls_dta_iobj-iobjnm.
    COLLECT ls_iobj INTO lt_iobj.
  ENDLOOP.

  " WorkArea für Struktur des ZielCubes erstellen
  CALL METHOD cl_rsplfu_work_area=>instance_get
    EXPORTING
      i_infoprov  = c_infoprov
      i_th_iobj   = lt_iobj
    RECEIVING
      r_work_area = lr_work_area.

  CALL METHOD lr_work_area->work_area_create
    RECEIVING
      r_r_wa = lr_wa_data.

  ASSIGN lr_wa_data->* TO <ls_data>.
  CREATE DATA lr_data1 LIKE TABLE OF <ls_data>.
  ASSIGN lr_data1->* TO <lt_data>.

  CALL FUNCTION 'RSDRI_INFOPROV_READ'
    EXPORTING
      i_infoprov             = c_infoprov
      i_th_sfc               = lt_sfc
      i_th_sfk               = lt_sfk
      i_t_range              = lt_sel
      i_rollup_only          = rs_c_true
      i_packagesize          = -1                     " -1 für unbegrenzt
    IMPORTING
      e_t_data               = <lt_data>
      e_end_of_data          = l_end_of_data
    CHANGING
      c_first_call           = l_first_call
    EXCEPTIONS
      illegal_input          = 1
      illegal_input_sfc      = 2
      illegal_input_sfk      = 3
      illegal_input_range    = 4
      illegal_input_tablesel = 5
      no_authorization       = 6
      illegal_download       = 7
      illegal_tablename      = 8
      OTHERS                 = 13.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.


ENDFUNCTION.