宏的方式显示ALV

Posted HARU_ちゃん

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了宏的方式显示ALV相关的知识,希望对你有一定的参考价值。

*&---------------------------------------------------------------------*
*& Report  Y_TEST_JAMES_ALV_FOR_JUN
*&
*&---------------------------------------------------------------------*
*& Creator: JAMES ZONG
*& This report IS FOR TEST
*&---------------------------------------------------------------------*

REPORT Y_TEST_JAMES_ALV_FOR_JUN.

DATA: BEGIN OF gs_alv,
        new_flag TYPE c. "Indicator for New lines
    INCLUDE STRUCTURE SETLINET.
DATA: END OF gs_alv.
DATA: gt_alv LIKE TABLE OF gs_alv."All lines


*& ------  ALV related DATA Definition ------
TYPE-POOLS: VRM,SLIS,TRUXS.  " USED TO LISTBOX

DATA: gt_field    LIKE TABLE OF lvc_s_fcat WITH HEADER LINE, "ALV fields
      gs_layout   TYPE lvc_s_layo,                           "ALV layout
      gw_events   TYPE slis_alv_event,

      gw_sort_lvc TYPE lvc_s_sort,
      gt_sort_lvc TYPE lvc_t_sort,

      gt_event    TYPE slis_t_event,                         "ALV-event
      gs_event    LIKE LINE OF gt_event.

DATA:LR_GRID TYPE REF TO cl_gui_alv_grid. " ALV OBJECT

DATA:
  LT_ITAB1 TYPE TABLE OF SETLINET.
*& ------  ALV related DATA Definition ------

* Macro definition of ALV

DEFINE alv.
  gt_field-fieldname = &1.
  gt_field-coltext   = &2.
  gt_field-outputlen = &3.
  gt_field-no_zero   = &4.
  gt_field-ref_table = &5.
  gt_field-ref_field = &6.
  gt_field-edit      = &7.
  gt_field-checkbox  = &8.

  APPEND gt_field.
  CLEAR gt_field.

END-OF-DEFINITION.

*&---------------------------------------------------------------------*
*&  SELECTION SCREEN
*&---------------------------------------------------------------------*
PARAMETERS: p_cont TYPE SETLINET-SETCLASS OBLIGATORY.

SELECTION-SCREEN BEGIN OF BLOCK b13 WITH FRAME TITLE TEXT-t00.
SELECTION-SCREEN COMMENT /1(75) TEXT-t01.
SELECTION-SCREEN COMMENT /1(75) TEXT-t02.
SELECTION-SCREEN COMMENT /1(75) TEXT-t03.
SELECTION-SCREEN COMMENT /1(75) TEXT-t04.
SELECTION-SCREEN COMMENT /1(75) TEXT-t05.
SELECTION-SCREEN COMMENT /1(75) TEXT-t06.
*SELECTION-SCREEN COMMENT /1(75) text-955.
*SELECTION-SCREEN COMMENT /1(75) text-956.
*SELECTION-SCREEN COMMENT /1(75) text-957.
*SELECTION-SCREEN COMMENT /1(75) text-958.
*SELECTION-SCREEN COMMENT /1(75) text-000.
*SELECTION-SCREEN COMMENT /1(75) text-959.
SELECTION-SCREEN END OF BLOCK b13.


" Get entries from ZYJJ_VEHICLE

SELECT * FROM SETLINET INTO CORRESPONDING FIELDS OF TABLE gt_alv
  WHERE SETCLASS = p_cont.

" DISPLAY ALV

  gs_layout-cwidth_opt = \'X\'.
  gs_layout-zebra = \'X\'.

  alv \'SETCLASS\' \'Display a\' 10 \'\' \'\' \'\' \'\' \'\'.
  alv \'SUBCLASS\' \'Display b\' 10 \'\' \'\' \'\' \'\' \'\'.
  alv \'SETNAME\' \'Display c\' 10 \'\' \'\' \'\' \'\' \'\'.
  alv \'LANGU\' \'Display d\' 10 \'\' \'\' \'\' \'\' \'\'.
  alv \'LINEID\' \'Display f\' 16 \'\' \'\' \'\' \'\' \'\'.

  CALL FUNCTION \'REUSE_ALV_GRID_DISPLAY_LVC\'
    EXPORTING
      i_callback_program      = sy-repid
      is_layout_lvc           = gs_layout
      it_fieldcat_lvc         = gt_field[]
      i_grid_title            = \'\'
      i_callback_user_command = \'USER_COMMAND\'
      "i_callback_pf_status_set = \'SET_PF_STATUS\'
      i_save                  = \'A\'
*     it_events               = gt_event
    TABLES
      t_outtab                = gt_alv
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

 之前用了fm 的方式去显示ALV, 接着用了OO 的方式也去实现了一下。今天用宏的方式来实现一下.

用宏的方式的好处:

解放了出力显示字段的制约,也就是说ALV出力显示的字段可以用自己来决定,比如可以随意的去改变字段的显示位置,长度,文本,等等等一些字段单位的属性。

 

 必须配合 【FM】CALL FUNCTION \'REUSE_ALV_GRID_DISPLAY_LVC\'进行使用

 

以上是关于宏的方式显示ALV的主要内容,如果未能解决你的问题,请参考以下文章

[代码]如何在ALV头中显示Logo图片-[REUSE_ALV_GRID_DISPLAY]

一百一十一SAP的OO-ALV之五,显示ALV表格

sap alv显示问题

abap开发中,在屏幕上怎样显示alv

sap alv字段当满足条件变灰

ABAP ALV控件的使用