天天看點

ABAP 抓取ALV資料

http://scnblogs.techweb.com.cn/elliott/archives/38.html

types:begin of ty_mb5td,

  matnr            type ekpo-matnr,            “Article

  werks            type ekpo-werks,            “Site

  mb5td_calc_trame type mb5td-mb5td_calc_trame,“Calculated Stock in Transit on Date

  meins            type mara-meins,            “Base Unit of Measure

end of ty_mb5td.

data:t_mb5td  type table of ty_mb5td,

     gw_mb5td type ty_mb5td.

*内表定義的字段要跟ALV structure裡的一緻。

 *&———————————————————————*

*&      Form  GET_DATA

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

form get_data.

data:ls_data type ref to data.

field-symbols: <lt_data> type table,

               <l_data>  type data.

cl_salv_bs_runtime_info=>set(

  display  = abap_false

  metadata = abap_false

  data     = abap_true  ).

submit rm07mtrb_date      ”Tcode MB5TD

  with bukrs    in s_bukrs

  with reswk    eq p_werks

  with pa_budat eq p_budat

  with xtram    eq ”

  and return.

try.

  cl_salv_bs_runtime_info=>get_data_ref(

    importing r_data = ls_data ).

  assign ls_data->* to <lt_data>.

catch cx_salv_bs_sc_runtime_info.

  message ‘Unable to retrieve ALV data’ type ‘E’.

endtry.

cl_salv_bs_runtime_info=>clear_all( ).

loop at <lt_data> assigning <l_data>.

  move-corresponding <l_data> to gw_mb5td.

  append gw_mb5td to t_mb5td.

endloop.

sort t_mb5td.

endform.                    “ GET_DATA

繼續閱讀