abap alv multiple header using write

A standard SAP ALV list report will show only one line header, but there will be a requirement someday for you to create a multiple lines header in your ALV list report and in order to do this, you must first set the no_colhead property to “X” in the ALV Layout, this code is to exclude the standard ALV columns and after that we replace the columns text by using WRITE command at the top of page event.

Okay now let’s create a small ALV report that will display multiple lines header.

1. Execute TCODE SE38, and name the program Zmultipleheader

2. Copy and paste this code below.

*&---------------------------------------------------------------------*

*& Report  ZMULTIPLEHEADER

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

 

REPORT  ZMULTIPLEHEADER.

TYPE-POOLS: slis, icon.

 

DATA: ld_fieldcat  TYPE  slis_fieldcat_alv.

DATA: t_alv_fieldcat      TYPE slis_t_fieldcat_alv WITH HEADER LINE,

Alv_Layout TYPE SLIS_LAYOUT_ALV .

DATA : it_fld TYPE slis_t_fieldcat_alv ,

       it_evt TYPE slis_t_event     ,

       wa_fld TYPE slis_fieldcat_alv   ,

       wa_evt TYPE slis_alv_event      ,

       wa_lay TYPE slis_layout_alv     .

 

data:

      BEGIN OF itab OCCURS 0,

        carrid like sflight-carrid,

        connid like sflight-connid,

        planetype like sflight-planetype,

        seatsmax like sflight-seatsmax,

      END OF itab.

 

START-OF-SELECTION.

 

"We are using table sflight to populate the internal

"table

 

SELECT carrid connid planetype seatsmax

       FROM sflight

       INTO TABLE itab.

 

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    IMPORTING

      et_events = it_evt.

 

  READ TABLE it_evt INTO wa_evt

       WITH KEY name = slis_ev_after_line_output .

  wa_evt-form = slis_ev_after_line_output .

  MODIFY it_evt FROM wa_evt INDEX sy-tabix .

 

  READ TABLE it_evt INTO wa_evt

       WITH KEY name = slis_ev_top_of_page .

  wa_evt-form = slis_ev_top_of_page .

  MODIFY it_evt FROM wa_evt INDEX sy-tabix .

 

  CLEAR: ld_fieldcat.

  ld_fieldcat-tabname       = 'ITAB'.

  ld_fieldcat-fieldname     = 'CARRID'.

  ld_fieldcat-ref_tabname   = 'SFLIGHT'.

  ld_fieldcat-outputlen     = '10'.

  APPEND ld_fieldcat TO t_alv_fieldcat.

  CLEAR ld_fieldcat.

 

  CLEAR: ld_fieldcat.

  ld_fieldcat-tabname       = 'ITAB'.

  ld_fieldcat-fieldname     = 'CONNID'.

  ld_fieldcat-ref_tabname   = 'SFLIGHT'.

  ld_fieldcat-outputlen     = '10'.

  APPEND ld_fieldcat TO t_alv_fieldcat.

  CLEAR ld_fieldcat.

 

    CLEAR: ld_fieldcat.

  ld_fieldcat-tabname       = 'ITAB'.

  ld_fieldcat-fieldname     = 'PLANETYPE'.

  ld_fieldcat-ref_tabname   = 'SFLIGHT'.

  ld_fieldcat-outputlen     = '10'.

  APPEND ld_fieldcat TO t_alv_fieldcat.

  CLEAR ld_fieldcat.

 

  CLEAR: ld_fieldcat.

  ld_fieldcat-tabname       = 'ITAB'.

  ld_fieldcat-fieldname     = 'SEATSMAX'.

  ld_fieldcat-ref_tabname   = 'SFLIGHT'.

  ld_fieldcat-outputlen     = '10'.

  APPEND ld_fieldcat TO t_alv_fieldcat.

  CLEAR ld_fieldcat.

 

"This is where we exclude the standard ALV columns

 

ALV_LAYOUT-no_colhead = 'X' .

 

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

      IS_LAYOUT = ALV_LAYOUT

      i_bypassing_buffer = 'X'

      i_callback_program = sy-repid

      it_fieldcat        = t_alv_fieldcat[]

      it_events          it_evt

      i_save             = 'A'

    TABLES

      t_outtab           = ITAB. "internal table

 

  IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

 

 FORM top_of_page .

 

"Uline for creating a horizontal line

 

ULINE AT 1(45) .

 

"Format color for header background

 

FORMAT COLOR 7 .

"This is where we manually create the header text,

"in this example I'm using 2 lines header, if you

"want to have 3 lines header or more, you can just

"add new write command.

 

WRITE: / sy-vline , 02 'CARRID AND CONNID',

23 SY-VLINE, 25 'PLANE & SEATS MAX', 45 SY-VLINE.

 

WRITE: / sy-vline , 02 'CARRID' ,12 sy-vline, 14 'CONNID',

23 SY-VLINE, 25 'PLANE ', 34 SY-VLINE, 36 'SEATS MAX', 45 SY-VLINE.

 

ENDFORM.

 

3. Here’s the multiple header result.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ChampaignWolf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值