如何将查询结果显示在选择屏幕上的代码

 *&---------------------------------------------------------------------*
*& Generates the ALV on the Selection Screen itself
*&
*&---------------------------------------------------------------------*
REPORT  zalv_on_sel_screen.
*
*----------------------------------------------------------------------*
*  Local class for report
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
  PUBLIC SECTION.
    DATA: t_data   TYPE STANDARD TABLE OF sflight,  " Output dat
          r_carrid TYPE RANGE OF sflight-carrid.    " Select Option
    METHODS:
      get_data,
      generate_output.
ENDCLASS.                    "lcl_report DEFINITION

DATA: lo_report TYPE REF TO lcl_report.
DATA: w_carrid TYPE sflight-carrid.

** Selection Screen
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
SELECT-OPTIONS: s_carrid FOR w_carrid.
SELECTION-SCREEN: END   OF BLOCK blk1.

** Initialization
INITIALIZATION.
  aaa = 'Selection Criteria'.
* object for the report
  CREATE OBJECT lo_report.
* generate output
  lo_report->generate_output( ).
** Start of Selection
START-OF-SELECTION.
* Get data
  lo_report->r_carrid = s_carrid[].
  lo_report->get_data( ).
*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
  METHOD get_data.
    SELECT * FROM sflight
           INTO  TABLE me->t_data
           WHERE carrid IN s_carrid.
    IF sy-dbcnt IS INITIAL.
      MESSAGE s398(00) WITH 'No data selected'.
    ENDIF.
    EXPORT data = me->t_data TO MEMORY ID sy-cprog.
  ENDMETHOD.                    "get_data

  METHOD generate_output.
    DATA: lo_dock TYPE REF TO cl_gui_docking_container,
          lo_cont TYPE REF TO cl_gui_container,
          lt_fcat             type lvc_t_fcat,
          gr_grid_d1001        type ref to cl_gui_alv_grid.
    IMPORT data = me->t_data FROM MEMORY ID sy-cprog.
    FREE MEMORY ID sy-cprog.
    CHECK me->t_data IS NOT INITIAL.
    CHECK lo_dock IS INITIAL.
    CREATE OBJECT lo_dock
      EXPORTING
        repid     = sy-cprog
        dynnr     = sy-dynnr
        ratio     = 80
        side      = cl_gui_docking_container=>dock_at_bottom
        name      = 'DOCK_CONT'.
    IF sy-subrc <> 0.
      MESSAGE 'Error in the Docking control' TYPE 'S'.
    ENDIF.
    CHECK gr_grid_d1001 IS INITIAL.
    lo_cont ?= lo_dock.
    create object gr_grid_d1001
                  exporting i_parent = lo_cont.

  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      i_buffer_active              = space
      i_structure_name             = 'SFLIGHT'
      i_client_never_display       = 'X'
      i_bypassing_buffer           = space
    changing
      ct_fieldcat                  = lt_fcat
    exceptions
      inconsistent_interface       = 1
      program_error                = 2
      others                       = 3.

    call method gr_grid_d1001->set_table_for_first_display
      exporting
        i_buffer_active     = space
        i_bypassing_buffer  = space
      changing
        it_outtab           = me->t_data
        it_fieldcatalog     = lt_fcat.
  ENDMETHOD.                    "generate_output
  ENDCLASS.                    "lcl_report IMPLEMENTATION

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值