Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

alv

Former Member
0 Kudos

hi all

i have created alv report i set the top-of-page also i want my to-of-page information to display like

title

program name rundate

user name time

tcode

this formate how to do this formate plz hlep me very urgent.

regrads jai.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Jai,

The ALV report that you have created, is it ALV Grid or ALV Classical?

If it is ALV Grid, you can use the FM "ALV_COMMENTRY_WRITE" to display the header portion as you have mentioned.

If it is ALV Classical, you can use WRITE statements to display the header in the EVENT "TOP-OF-PAGE".

<b>Reward points for helpful answers.</b>

Best Regards,

Ram.

4 REPLIES 4

Former Member
0 Kudos

Former Member
0 Kudos

Hi Jai,

Please find a sample ALV report program.

REPORT ZTEST1234 MESSAGE-ID ZZ .

DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID, "First

G_GRID1 TYPE REF TO CL_GUI_ALV_GRID. "Second

DATA: L_VALID TYPE C,

V_FLAG,

V_DATA_CHANGE,

V_ROW TYPE LVC_S_ROW,

V_COLUMN TYPE LVC_S_COL,

V_ROW_NUM TYPE LVC_S_ROID.

DATA: OK_CODE LIKE SY-UCOMM,

SAVE_OK LIKE SY-UCOMM,

G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST', "First Container

G_CONTAINER2 TYPE SCRFNAME VALUE 'TEST1',"Second container

GS_LAYOUT TYPE LVC_S_LAYO.

DATA:BEGIN OF ITAB OCCURS 0,

VBELN LIKE LIKP-VBELN,

POSNR LIKE LIPS-POSNR,

LFDAT like lips-vfdat,

BOX(1),

HANDLE_STYLE TYPE LVC_T_STYL,

END OF ITAB.

----


  • CLASS lcl_event_handler DEFINITION

----


CLASS LCL_EVENT_HANDLER DEFINITION .

PUBLIC SECTION .

METHODS:

**Hot spot Handler

HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,

**Handler to Check the Data Change

HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED

OF CL_GUI_ALV_GRID

IMPORTING ER_DATA_CHANGED

E_ONF4

E_ONF4_BEFORE

E_ONF4_AFTER,

**Double Click Handler

HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW E_COLUMN ES_ROW_NO.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

*Handle Hotspot Click

METHOD HANDLE_HOTSPOT_CLICK .

CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.

V_ROW = E_ROW_ID.

V_COLUMN = E_COLUMN_ID.

V_ROW_NUM = ES_ROW_NO.

MESSAGE I000 WITH V_ROW 'clicked'.

ENDMETHOD. "lcl_event_handler

*Handle Double Click

METHOD HANDLE_DOUBLE_CLICK.

CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.

V_ROW = E_ROW.

V_COLUMN = E_COLUMN.

V_ROW_NUM = ES_ROW_NO.

IF E_COLUMN = 'VBELN'.

SET PARAMETER ID 'VL' FIELD ITAB-VBELN.

CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.

ENDIF.

IF E_COLUMN = 'POSNR'.

MESSAGE I000 WITH 'Click on POSNR row number ' E_ROW.

"with this row num you can get the data

ENDIF.

ENDMETHOD. "handle_double_click

**Handle Data Change

METHOD HANDLE_DATA_CHANGED.

CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY

EXCEPTIONS

FINISHED = 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.

ENDMETHOD. "HANDLE_DATA_CHANGED

ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION

&----


*& Global Definitions

&----


DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1

G_HANDLER TYPE REF TO LCL_EVENT_HANDLER, "handler

G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Container2

*- Fieldcatalog for First and second Report

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

X_FIELDCAT TYPE LVC_S_FCAT,

LS_VARI TYPE DISVARIANT.

*----


  • START-OF_SELECTION

*----


START-OF-SELECTION.

SELECT VBELN

POSNR

FROM LIPS

UP TO 20 ROWS

INTO CORRESPONDING FIELDS OF TABLE ITAB.

END-OF-SELECTION.

IF NOT ITAB[] IS INITIAL.

CALL SCREEN 100.

ELSE.

MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).

ENDIF.

&----


*& Form CREATE_AND_INIT_ALV

&----


  • text

----


FORM CREATE_AND_INIT_ALV .

DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

"First Grid

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER1.

CREATE OBJECT G_GRID

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

"Second Grid

CREATE OBJECT G_CUSTOM_CONTAINER1

EXPORTING CONTAINER_NAME = G_CONTAINER2.

CREATE OBJECT G_GRID1

EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.

  • Set a titlebar for the grid control

CLEAR GS_LAYOUT.

GS_LAYOUT-GRID_TITLE = TEXT-003.

GS_LAYOUT-ZEBRA = SPACE.

GS_LAYOUT-CWIDTH_OPT = 'X'.

GS_LAYOUT-NO_ROWMARK = 'X'.

GS_LAYOUT-BOX_FNAME = 'BOX'.

GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.

CREATE OBJECT G_HANDLER.

SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.

  • SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.

data: ls_outatb like line of itab,

v_index type sy-tabix.

DATA: LS_EDIT TYPE LVC_S_STYL,

LT_EDIT TYPE LVC_T_STYL.

LOOP AT ITAB INTO ls_outatb WHERE POSNR = '000010'.

V_INDEX = SY-TABIX.

LS_EDIT-FIELDNAME = 'VBELN'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

INSERT LINES OF LT_EDIT INTO TABLE ls_outatb-handle_style.

MODIFY ITAB INDEX V_INDEX FROM ls_outatb TRANSPORTING

HANDLE_STYLE.

ENDLOOP.

  • setting focus for created grid control

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS

EXPORTING

CONTROL = G_GRID.

  • Build fieldcat and set editable for date and reason code

  • edit enabled. Assign a handle for the dropdown listbox.

PERFORM BUILD_FIELDCAT.

  • Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.

**Vaiant to save the layout

LS_VARI-REPORT = SY-REPID.

LS_VARI-HANDLE = SPACE.

LS_VARI-LOG_GROUP = SPACE.

LS_VARI-USERNAME = SPACE.

LS_VARI-VARIANT = SPACE.

LS_VARI-TEXT = SPACE.

LS_VARI-DEPENDVARS = SPACE.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.

**Calling the Method for ALV output for First Grid

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

IS_VARIANT = LS_VARI

IS_LAYOUT = GS_LAYOUT

I_SAVE = 'A'

CHANGING

IT_FIELDCATALOG = IT_FIELDCAT

IT_OUTTAB = ITAB[].

**Calling the Method for ALV output for Second Grid

CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY

  • EXPORTING

  • IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

CHANGING

IT_FIELDCATALOG = IT_FIELDCAT

IT_OUTTAB = ITAB[].

  • Set editable cells to ready for input initially

CALL METHOD G_GRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ENDFORM. "CREATE_AND_INIT_ALV

&----


*& Form EXCLUDE_TB_FUNCTIONS

&----


  • text

----


  • -->PT_EXCLUDE text

----


FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.

  • Only allow to change data not to create new entries (exclude

  • generic functions).

DATA LS_EXCLUDE TYPE UI_FUNC.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

&----


*& Form build_fieldcat

&----


  • Fieldcatalog

----


FORM BUILD_FIELDCAT .

DATA: L_POS TYPE I.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).

X_FIELDCAT-FIELDNAME = 'VBELN'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-NO_ZERO = 'X'.

X_FIELDCAT-EDIT = 'X'.

X_FIELDCAT-OUTPUTLEN = '10'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Item'(025).

X_FIELDCAT-FIELDNAME = 'POSNR'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Del Date'(015).

X_FIELDCAT-FIELDNAME = 'LFDAT'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '10'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

ENDFORM. " build_fieldcat

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

**Initializing the grid and calling the fm to Display the O/P

PERFORM CREATE_AND_INIT_ALV.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

<b>***Reward Points if Useful</b>

Regards

Gokul

Former Member
0 Kudos

Hi Jai,

The ALV report that you have created, is it ALV Grid or ALV Classical?

If it is ALV Grid, you can use the FM "ALV_COMMENTRY_WRITE" to display the header portion as you have mentioned.

If it is ALV Classical, you can use WRITE statements to display the header in the EVENT "TOP-OF-PAGE".

<b>Reward points for helpful answers.</b>

Best Regards,

Ram.

Former Member
0 Kudos

hi,

check this example u will get some help:

type-pools slis.

data: begin of i_alv occurs 0,

matnr type mara-matnr,

end of i_alv.

  • Miscellanous Data Declarations

data: fieldcat type slis_t_fieldcat_alv,

events type slis_t_event,

list_top_of_page type slis_t_listheader,

top_of_page type slis_formname value 'TOP_OF_PAGE'.

start-of-selection.

perform initialization.

perform get_data.

perform call_alv.

end-of-selection.

***********************************************************************

  • Form Initialization

***********************************************************************

form initialization.

clear i_alv. refresh i_alv.

perform eventtab_build using events[].

endform.

***********************************************************************

  • Form Get_Data

***********************************************************************

form get_data.

select matnr into table i_alv

from mara up to 100 rows.

endform.

***********************************************************************

  • CALL_ALV

***********************************************************************

form call_alv.

data: variant type disvariant.

data: repid type sy-repid.

repid = sy-repid.

variant-report = sy-repid.

variant-username = sy-uname.

perform build_field_catalog.

perform comment_build using list_top_of_page[].

  • Call ABAP List Viewer (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = fieldcat

i_callback_program = repid

is_variant = variant

it_events = events[]

i_save = 'U'

tables

t_outtab = i_alv.

endform.

***********************************************************************

  • EVENTTAB_BUILD

***********************************************************************

form eventtab_build using events type slis_t_event.

  • Registration of events to happen during list display

data: tmp_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = events.

read table events with key name = slis_ev_top_of_page

into tmp_event.

if sy-subrc = 0.

move top_of_page to tmp_event-form.

append tmp_event to events.

endif.

endform.

***********************************************************************

  • BUILD_FIELD_CATALOG

***********************************************************************

form build_field_catalog.

clear: fieldcat. refresh: fieldcat.

data: tmp_fc type slis_fieldcat_alv.

tmp_fc-reptext_ddic = 'Material'.

tmp_fc-fieldname = 'MATNR'.

tmp_fc-tabname = 'I_ALV'.

tmp_fc-outputlen = 18.

append tmp_fc to fieldcat.

endform.

***********************************************************************

  • COMMENT_BUILD

***********************************************************************

form comment_build using list_top_of_page type

slis_t_listheader.

data: tmp_line type slis_listheader.

clear tmp_line.

tmp_line-typ = 'H'.

tmp_line-info = 'Here is a line of text'.

append tmp_line to list_top_of_page.

clear tmp_line.

tmp_line-typ = 'S'.

tmp_line-key = 'Key1'.

tmp_line-info = 'Here is a value'.

append tmp_line to list_top_of_page.

clear tmp_line.

tmp_line-typ = 'A'.

tmp_line-key = 'Key2'.

tmp_line-info = 'Here is another value'.

append tmp_line to list_top_of_page.

endform.

***********************************************************************

  • TOP_OF_PAGE

***********************************************************************

form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = list_top_of_page.

endform.