Sunday, December 26, 2010
 Two column header is possible using ALV List display(Function module REUSE_ALV_LIST_DISPLAY).  TOP_OF_PAGE event is also used to get required header.

REPORT ztest_alv MESSAGE-ID zz .
*&-----------------------------------------------------------------------------*
*& Declaration     
*&-----------------------------------------------------------------------------* 
TYPE-POOLS: slis.
DATA:
      x_fieldcat  TYPE slis_fieldcat_alv,
      it_fieldcat TYPE slis_t_fieldcat_alv,
      l_layout    TYPE slis_layout_alv,
      x_events    TYPE slis_alv_event,
      it_events   TYPE slis_t_event.

DATA:
      BEGIN OF itab OCCURS 0,
        vbeln LIKE vbak-vbeln,
        posnr LIKE vbap-posnr,
        male TYPE i,
        female TYPE i,
      END OF itab.
*&-----------------------------------------------------------------------------*
*& Start-of-selection     
*&-----------------------------------------------------------------------------*      
START-OF-SELECTION.
SELECT vbeln
       posnr
  FROM vbap
  UP TO 20 ROWS
  INTO TABLE itab.


x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-seltext_l = 'VBELN'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 1.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-seltext_l = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-fieldname = 'MALE'.
x_fieldcat-seltext_l = 'MALE'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 3.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-fieldname = 'FEMALE'.
x_fieldcat-seltext_l = 'FEMALE'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 3.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.

x_events-name = slis_ev_top_of_page.
x_events-form = 'TOP_OF_PAGE'.
APPEND x_events TO it_events.
CLEAR x_events .

l_layout-no_colhead = 'X'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    i_callback_program = sy-repid
    is_layout          = l_layout
    it_fieldcat        = it_fieldcat
    it_events          = it_events
  TABLES
    t_outtab           = itab
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.
IF sy-subrc NE  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
*&---------------------------------------------------------------------*
FORM top_of_page.

*-To display the headers for main list
  FORMAT COLOR COL_HEADING.
  WRITE: / sy-uline(103).
  WRITE: / sy-vline,
  (8) ' ' ,
  sy-vline,
  (8) ' ' ,
  sy-vline,
  (19) 'SEX'(015) CENTERED,
  sy-vline.

  WRITE: / sy-vline,
  (8) 'VBELN'(013) ,
  sy-vline,
  (8) 'POSNR'(014) ,
  sy-vline,
  (8) 'MALE'(016) ,
  sy-vline,
  (8) 'FMALE'(017) ,
  sy-vline.

  FORMAT COLOR OFF.

ENDFORM.                    "TOP_OF_PAGE


0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.