Simple ALV with custom table

  REPORT  ZTESTFORGG_OOALV_NO_CONTAINER.
tables sflight.
data: begin of test,
      f1(10) type C,
      f2(10) type C,
    end of test.
data: it_out like standard table of test,
      wa_out like line of it_out.
data: f_cat type lvc_t_fcat,
      wa_f_cat type lvc_s_fcat.
data: it_sflight type standard table of sflight.
start-of-selection.
select from sflight into table it_sflight up to 100 rows.
wa_out-f1 = 'gaivn'.
wa_out-f2 = 'test'.
append wa_out to it_out.
wa_out-f1 = 'gaivn2'.
wa_out-f2 = 'test2'.
append wa_out to it_out.
  wa_f_cat-FIELDNAME = 'F1'.
  wa_f_cat-SCRTEXT_L = 'Type'.
  wa_f_cat-SCRTEXT_M = 'Type'.
  wa_f_cat-SCRTEXT_S = 'Type'.
  append wa_f_cat to f_cat.
  wa_f_cat-FIELDNAME = 'F2'.
  wa_f_cat-SCRTEXT_L = 'Message'.
  wa_f_cat-SCRTEXT_M = 'Message'.
  wa_f_cat-SCRTEXT_S = 'Message'.
  append wa_f_cat to f_cat.

data: l_alv type ref to cl_gui_alv_grid.
create object l_alv
exporting
  i_parent = cl_gui_container=>screen0.
call method l_alv->set_table_for_first_display
exporting
  i_structure_name = 'test'
changing
  it_fieldcatalog = f_cat
  it_outtab = it_out.
write: ''.

结尾的write很重要,没有的话不会显示。

原文地址:https://www.cnblogs.com/yanluckly/p/1783738.html