ITPub博客

首页 > Linux操作系统 > Linux操作系统 > BW筆記之MDX讀取cube數據

BW筆記之MDX讀取cube數據

Linux操作系统 作者:517424787 时间:2015-10-18 17:11:36 0 删除 编辑
用程式讀取cube數據:
1.clear MDX table
  SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L4S31 { font-style. italic; color: #808080; } .L4S52 { color: #0000FF; } FORM clear_mdx_table.
  CLEAR:g_datasetid,g_start_cell,g_end_cell.
  CLEAR:g_return,g_mndtry_prptys,g_option_prptys_vals,
        g_axis_info,g_axis_dimensions,g_cell_data,g_command_text.
  CLEAR: g_return[],g_mndtry_prptys[],g_option_prptys_vals[],
         g_axis_info[],g_axis_dimensions[],g_cell_data[],g_command_text[].
ENDFORM.                    "CLEAR_MDX_TABLE
2.prepare MDX String
  SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L4S31 { font-style. italic; color: #808080; } .L4S32 { color: #3399FF; } .L4S33 { color: #4DA619; } .L4S52 { color: #0000FF; } FORM prepare_mdx_string1 USING l_plant.
  DATA: l_str(40)   TYPE c.

  CLEAR: g_command_text,g_command_text[].
  APPEND ' SELECT NON EMPTY' TO g_command_text.
*  APPEND '  {[Measures].[0VALSTCKQTY]}' TO g_command_text.
  APPEND '  {[Measures].[0VALSTCKQTY],[Measures].[0VALSTCKVAL] }' TO g_command_text.
  APPEND '   ON COLUMNS,' TO g_command_text.
  APPEND ' NON EMPTY' TO g_command_text.
  APPEND '  [0PLANT].[LEVEL01].MEMBERS ' TO g_command_text .
  APPEND '  * [0STOR_LOC].[LEVEL01].MEMBERS ' TO g_command_text.
  APPEND '  * [ZMATERIAL].[LEVEL01].MEMBERS ON ROWS' TO g_command_text.
  APPEND ' FROM [$ZIC_C05U]' TO g_command_text.
  APPEND ' WHERE' TO g_command_text.
  CLEAR l_str.
  CONCATENATE '([0PLANT].'  '['  l_plant   '],'   INTO l_str.
  APPEND l_str TO g_command_text.
  IF p_ssyid_matnr <> ''.
    CLEAR l_str.
    CONCATENATE '[ZMATERIAL].'  '['  p_ssyid_matnr   '],'   INTO l_str.
    APPEND l_str TO g_command_text.
  ENDIF.
  CLEAR l_str.
  CONCATENATE '[0CALDAY].' '[' p_date ']'  ')' INTO l_str.
  APPEND l_str TO g_command_text.

ENDFORM.                    "Prepare_mdx_string2
 
3. Read Cube
  SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L4S31 { font-style. italic; color: #808080; } .L4S33 { color: #4DA619; } .L4S52 { color: #0000FF; } FORM read_cube.
  CALL FUNCTION 'BAPI_MDDATASET_CREATE_OBJECT'
    IMPORTING
      return       = g_return
      datasetid    = g_datasetid
    TABLES
      command_text = g_command_text.
  IF NOT g_return IS INITIAL.
    WRITE:/ g_return-messageEXIT.
  ENDIF.

  CALL FUNCTION 'BAPI_MDDATASET_GET_AXIS_DATA'
    EXPORTING
      datasetid          = g_datasetid
      axis               = '001'
    IMPORTING
      return             = g_return
    TABLES
      mndtry_prptys      = g_mndtry_prptys
      option_prptys_vals = g_option_prptys_vals.
  IF NOT g_return IS INITIAL.
    WRITE:/ g_return-messageEXIT.
  ENDIF.

  CALL FUNCTION 'BAPI_MDDATASET_GET_AXIS_INFO'
    EXPORTING
      datasetid       = g_datasetid
    IMPORTING
      return          = g_return
    TABLES
      axis_info       = g_axis_info
      axis_dimensions = g_axis_dimensions.
  IF NOT g_return IS INITIAL.
    WRITE:/ g_return-messageEXIT.
  ENDIF.

  CALL FUNCTION 'BAPI_MDDATASET_GET_CELL_DATA'
    EXPORTING
      datasetid  = g_datasetid
      start_cell = g_start_cell
      end_cell   = g_end_cell
    IMPORTING
      return     = g_return
    TABLES
      cell_data  = g_cell_data.
  IF NOT g_return IS INITIAL.
    WRITE:/ g_return-messageEXIT.
  ENDIF.

  CALL FUNCTION 'BAPI_MDDATASET_DELETE_OBJECT'
    EXPORTING
      datasetid = g_datasetid
    IMPORTING
      return    = g_return.
  IF NOT g_return IS INITIAL.
    WRITE:/ g_return-messageEXIT.
  ENDIF.

ENDFORM.                    "read_cube
4.insert data into inner table
  SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L4S31 { font-style. italic; color: #808080; } .L4S32 { color: #3399FF; } .L4S33 { color: #4DA619; } .L4S52 { color: #0000FF; } FORM fill_tab_storage.
  DATA: l_rows(6TYPE n,
        l_columns(6TYPE n.
  DATA: de TYPE i.
  DATA: l_mem_unam(255TYPE c,
        l_dim(40)  TYPE c.
  DATA: l_cell_ordinal LIKE bapi6111cd-cell_ordinal.
  DATA: l_tabix LIKE sy-tabix.

  CLEAR:it02,it02[].

  LOOP AT g_mndtry_prptys .
    it02-tuple_ordinal = g_mndtry_prptys-tuple_ordinal.
    APPEND it02.
  ENDLOOP.

  DELETE ADJACENT DUPLICATES FROM it02.

  READ TABLE it02 INDEX 1.
  l_cell_ordinal = it02-tuple_ordinal .

  LOOP AT it02.
    CLEAR it_inv_stor.
    it_inv_stor-cdate = p_date.
    DO 3 TIMES .
      READ TABLE g_mndtry_prptys WITH KEY tuple_ordinal = it02-tuple_ordinal
                                        BINARY SEARCH.
      l_tabix = sy-tabix.
      PERFORM get_objectname USING g_mndtry_prptys-dim_key CHANGING l_dim .
      PERFORM split_string USING g_mndtry_prptys-mem_unam CHANGING l_mem_unam .

      IF l_dim = '[0PLANT]' .
        it_inv_stor-plant = l_mem_unam .
        READ TABLE it_com_plant INTO wa_com_plant  WITH KEY plant =  it_inv_stor-plant.
        it_inv_stor-comp = wa_com_plant-comp_code.
*        PERFORM get_compcode USING it_inv_stor-plant CHANGING it_inv_stor-comp.
      ENDIF.


      IF l_dim = '[0STOR_LOC]' .
        it_inv_stor-lgort = l_mem_unam+4(18).
      ENDIF.

      IF l_dim = '[ZMATERIAL]' .
        it_inv_stor-ssyid = l_mem_unam(2).
        it_inv_stor-matnr = l_mem_unam+2(18).
        IF it_inv_stor-ssyid = '!+' .
          SELECT SINGLE soursystem /bic/zmaterial
                 INTO (it_inv_stor-ssyid,it_inv_stor-matnr)
          FROM /bic/szmaterial
          WHERE sid = it_inv_stor-matnr .
        ENDIF.

      ENDIF.


      DELETE g_mndtry_prptys INDEX l_tabix.
    ENDDO.

    READ TABLE g_cell_data WITH KEY cell_ordinal = l_cell_ordinal
                                        BINARY SEARCH.
    DELETE g_cell_data INDEX sy-tabix.
    it_inv_stor-menge = g_cell_data-value.
    it_inv_stor-meins = g_cell_data-unit .

    l_cell_ordinal = l_cell_ordinal + 1.

    READ TABLE g_cell_data WITH KEY cell_ordinal = l_cell_ordinal
                                        BINARY SEARCH.
    DELETE g_cell_data INDEX sy-tabix.
    it_inv_stor-dmbtr = g_cell_data-value.
    it_inv_stor-waers = g_cell_data-currency.


    l_cell_ordinal = l_cell_ordinal + 1.

    IF it_inv_stor-menge <> 0 OR it_inv_stor-dmbtr <> 0 .
      IF it_inv_stor-dmbtr <> 0 .
        PERFORM limit_decimal CHANGING it_inv_stor-waers  it_inv_stor-dmbtr .
      ENDIF.
      IF it_inv_stor-meins <> '' .
        PERFORM conver_uom  CHANGING it_inv_stor-meins.
      ENDIF.

      PERFORM get_profit_center USING it_inv_stor-matnr it_inv_stor-plant
         CHANGING  it_inv_stor-carea  it_inv_stor-prcte .
      APPEND it_inv_stor.
    ENDIF.

  ENDLOOP.
ENDFORM.    

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16354317/viewspace-1814804/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-03-30

  • 博文量
    22
  • 访问量
    26493