Application Development and Automation 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: 
Read only

ALV grid display

Former Member
18,419

Hi,

can any one send me a simple program on ALV GRID Display?

Thanks in Advance.

Good answers will be rewared.

Hi,

can any one send me a simple program on ALV GRID Display?

Thanks in Advance.

Good answers will be rewared.

6 REPLIES 6
Read only

ak_upadhyay
Contributor
5,346

Hi,

Try This....



*&---------------------------------------------------------------------*
*& Report  ZTEST_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_ALV.

tables : vbap, ZSTRUCT_ALV.
type-pools: slis.

select-options: vbeln for vbap-vbeln.

data it type table of ZSTRUCT_ALV.

select vbeln posnr from vbap into table it where vbeln in vbeln.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_STRUCTURE_NAME                  = 'ZSTRUCT_ALV'

  TABLES
    T_OUTTAB                          = it
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Reward points if helpful.....

Regards

AK

Read only

Former Member
5,346

Hi i am narrating few things with pseudo code,

hope you can implement the program in the similar fashion..

TO display alv u need to have data in internal table...

fetch the data in to internal table...

this is as follows:

TYPE-POOLS: SLIS.

Types: begin of zstruct,

name type lfa1-name1,

ktokk type lfa1-ktokk,

lifnr type lfa1-lifnr,

end of ztruct.

DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.

DATA: ls_fieldcat LIKE LINE OF lt_fieldcat.

Data: itab type standard table of zstruct.

DATA: wa like line of itab.

start-of-selection.

select lifnr name1 ktokk into corresponding fields of table itab

from lfa1.

  • Now we need to build the field catalog for the internal table *as its a customised strucutre..

  • it is as follows.

LOOP AT lt_fieldcat INTO ls_fieldcat.

CASE ls_fieldcat-fieldname.

WHEN 'NAME1'.

ls_fieldcat-col_pos = 3.

ls_fieldcat-seltext_l = 'NAME'.

ls_fieldcat-seltext_s = 'NAM'.

ls_fieldcat-seltext_m = 'NAME'.

ls_fieldcat-ddictxt = 'M'.

WHEN 'KTOKK'.

ls_fieldcat-col_pos = 1.

ls_fieldcat-seltext_l = 'ACCOUNT GROUP'.

ls_fieldcat-seltext_s = 'AGGRP'.

ls_fieldcat-seltext_m = "ACC GROUP'.

ls_fieldcat-ddictxt = 'M'.

WHEN 'LIFNR'.

ls_fieldcat-seltext_l = 'VENDOR ACCOUNT NUMBER'.

ls_fieldcat-seltext_s = 'VNO'.

ls_fieldcat-seltext_m = 'VEN NO'.

ls_fieldcat-tech = 'X'.

ls_fieldcat-ddictxt = 'M'.

endcase.

MODIFY xt_fieldcat FROM ls_fieldcat

TRANSPORTING col_pos

seltext_l

seltext_s

seltext_m

ddictxt

tech

no_out

fix_column

outputlen.

endloop.

  • Now call the reuse alv grid display fm to display the data with the provided fieldcatalog and data table

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • i_callback_program = g_repid

it_fieldcat = lt_fieldcat

  • i_callback_pf_status_set = g_status_set

  • is_layout = ls_layout

i_save = 'A'

i_default = c_true

TABLES

t_outtab = itab

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.

Hopefully this will help and do reward if needful..

Revert back if any issues with the code..

Good day

Read only

Former Member
0 Likes
5,346

These Link will solve your problems.

1. Please give me general info on ALV.

http://www.sapfans.com/forums/viewtopic.php?t=58286

http://www.sapfans.com/forums/viewtopic.php?t=76490

http://www.sapfans.com/forums/viewtopic.php?t=20591

http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.

2. How do I program double click in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

3. How do I add subtotals (I have problem to add them)...

http://www.sapfans.com/forums/viewtopic.php?t=20386

http://www.sapfans.com/forums/viewtopic.php?t=85191

http://www.sapfans.com/forums/viewtopic.php?t=88401

http://www.sapfans.com/forums/viewtopic.php?t=17335

4. How to add list heading like top-of-page in ABAP lists?

http://www.sapfans.com/forums/viewtopic.php?t=58775

http://www.sapfans.com/forums/viewtopic.php?t=60550

http://www.sapfans.com/forums/viewtopic.php?t=16629

5. How to print page number / total number of pages X/XX in ALV? http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)

6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.

http://www.sapfans.com/forums/viewtopic.php?t=64320

http://www.sapfans.com/forums/viewtopic.php?t=44477

7. How can I set the cell color in ALV? http://www.sapfans.com/forums/viewtopic.php?t=52107

8. How do I print a logo/graphics in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=81149

http://www.sapfans.com/forums/viewtopic.php?t=35498

http://www.sapfans.com/forums/viewtopic.php?t=5013

9. How do I create and use input-enabled fields in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=84933

http://www.sapfans.com/forums/viewtopic.php?t=69878

10. How can I use ALV for reports that are going to be run in background?

http://www.sapfans.com/forums/viewtopic.php?t=83243

http://www.sapfans.com/forums/viewtopic.php?t=19224

11. How can I display an icon in ALV? (Common requirement is traffic light icon).

http://www.sapfans.com/forums/viewtopic.php?t=79424

http://www.sapfans.com/forums/viewtopic.php?t=24512

12. How can I display a checkbox in ALV? http://www.sapfans.com/forums/viewtopic.php?t=88376

http://www.sapfans.com/forums/viewtopic.php?t=40968

http://www.sapfans.com/forums/viewtopic.php?t=6919

Regards,

Mehul Shah.

Read only

Former Member
0 Likes
5,346

These is Standard ALV program: BCALV_GRID_EDIT_DELTA

Check it out.

Regards,

Mehul Shah.

Read only

Former Member
5,346

Hi ,

I attach a sample ALV program with all Events with complete functionality.

report zbnstest. 
************************************************************************ 
* TABLES AND DATA DECLARATION. 
************************************************************************ 
*TABLES: mara,makt.",marc. 
data syrepid like sy-repid. 
data sydatum(10). " LIKE sy-datum. 
data sypagno(3) type n. 
  

* WHEN USING MORE THAN ONE TABLE IN ALV WE NEEED TO DECLARE THE TYPE 
* GROUP (TYPE-POOLS--------->SLIS) 
type-pools : slis. 
  

************************************************************************ 
* INTERNAL TABLE DECLARATION. 
************************************************************************ 
* INTERNAL TABLE TO HOLD THE VALUES FROM THE MARA TABLE 
data: begin of t_mara occurs 0, 
matnr like mara-matnr, 
meins like mara-meins, 
mtart like mara-mtart, 
matkl like mara-matkl, 

end of t_mara. 

* INTERNAL TABLE TO HOLD THE CONTENTS FROM THE EKKO TABLE 
data : begin of t_marc occurs 0, 
matnr like mara-matnr, 
werks like marc-werks, 
minbe like marc-minbe. 
data: end of t_marc. 

* INTERNAL TABLE TO HOLD THE VALUES FROM MAKT TABLE. 
data : begin of t_makt occurs 0, 
matnr like mara-matnr, 
maktx like makt-maktx, 
spras like makt-spras, 
end of t_makt. 

* INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES. 
data: begin of itab1 occurs 0, 
matnr like mara-matnr, 
meins like mara-meins, 
maktx like makt-maktx, 
spras like makt-spras, 
werks like marc-werks, 
minbe like marc-minbe, 
end of itab1. 
  

* THE FOLLOWING DECLARATION IS USED FOR DEFINING THE FIELDCAT 
* AND THE LAYOUT FOR THE ALV. 
* HERE AS slis_t_fieldcat_alv IS A INTERNAL TABLE WITHOUT A HEADER LINE 
* WE EXPLICITELY DEFINE AN INTERNAL TABLE OF THE SAME STRUCTURE AS THAT 
* OF slis_t_fieldcat_alv BUT WITH A HEADER LINE IN THE DEFINITION. 
* THIS IS DONE TO MAKE THE CODE SIMPLER. 
* OTHERWISE WE MAY HAVE TO DEFINE THE STRUCTURE AS IN THE NORMAL SAP 
* PROGRAMS. 
* IN THE FIELDCATALOG TABLE WE ACTUALLY PASS THE FIELDS FROM ONE OR 
* MORE TABLES AND CREATE A STRUCTURE 
* IN THE LAYOUT STRUCTURE WE BASICALLY DEFINE THE FORMATTING OPTIONS 
* LIKE DISPLAY IN THE ZEBRA PATTERN ,THE HOTSPOT OPTIONS ETC. 
data: fieldcatalog type slis_t_fieldcat_alv with header line, 
fieldlayout type slis_layout_alv. 
  

* DECLARING THE EVENTTABLE INTERNL TABLE FOR USING EVENTS LIKE 
* TOP-OF-PAGE ETC. 
data : eventstab type slis_t_event with header line. 

* DECLARING AN INTERNAL TABLE TO HOLD THE DATA FOR THE TOP-OF-PAGE 
data : heading type slis_t_listheader with header line. 
data : heading1 type slis_t_listheader with header line. 
data : heading2 type slis_t_listheader with header line. 
data : heading3 type slis_t_listheader with header line. 
data : heading4 type slis_t_listheader with header line. 
data : heading5 type slis_t_listheader with header line. 
data : heading6 type slis_t_listheader with header line. 
data : heading7 type slis_t_listheader with header line. 
data : heading8 type slis_t_listheader with header line. 
  

* STRUCTURE TO PASS THE COLOR ATTRIBUTES FOR DISPLAY. 
data : colorstruct type slis_coltypes. 
************************************************************************ 
* INITIALIZATION. * 
************************************************************************ 
initialization. 
syrepid = sy-repid. 
sypagno = sy-pagno. 
clear fieldcatalog. 
  

************************************************************************ 
* START-OF-SELECTION. * 
************************************************************************ 
start-of-selection. 
* SUBROUTINE TO POPULATE THE COLORSTRUCT 
perform fill_colorstruct using colorstruct. 
* SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE 
perform populate_fieldcatalog. 
* SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE 
* INTERNAL TABLE. 
perform selectdata_and_sort. 
* SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE. 
perform populate_layout using fieldlayout. 
* SUBROUTINE TO CALL THE FUNCTION MERGE TO ENSURE PROPER DISPLAY. 
perform merge_fieldcatalog. 
* SUBROUTINE TO POPULATE THE EVENTSTAB. 
perform fill_eventstab tables eventstab. 
* SUBROUTINE TO POPULATE THE HEADING TABLES. 
perform fill_headingtable tables heading using 'HEADING'. 
perform fill_headingtable tables heading1 using 'HEADING1'. 
perform fill_headingtable tables heading2 using 'HEADING2'. 
perform fill_headingtable tables heading3 using 'HEADING3'. 
perform fill_headingtable tables heading4 using 'HEADING4'. 
perform fill_headingtable tables heading5 using 'HEADING5'. 
perform fill_headingtable tables heading6 using 'HEADING6'. 
perform fill_headingtable tables heading7 using 'HEADING7'. 
perform fill_headingtable tables heading8 using 'HEADING8'. 

* SUBROUTINE TO DISPLAY THE LIST. 
perform display_alv_list. 
  
  

************************************************************************ 
* FORMS 
************************************************************************ 
* IN THIS SUBROUTINE WE POPULATE THE FIELDCATALOG TABLE WITH THE NAMES 
* OF THE TABLE,FIELDNAME,WHETHER IT IS KEY FIELD OR NOT,HEADING AND 
* COLUMN JUSTIFICATION. 
form populate_fieldcatalog. 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'MATNR' 'X' . 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'MEINS' ' '. 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'MAKTX' ' ' . 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'MTART' ' ' . 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'MATKL' ' ' . 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'SPRAS' ' ' . 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'WERKS' ' ' . 
perform fill_fields_of_fieldcatalog tables fieldcatalog 
using 'ITAB1' 'MINBE' ' ' . 
endform. " POPULATE_FIELDCATALOG 
  

*---------------------------------------------------------------------* 
* FORM FILL_FIELDS_OF_FIELDCATALOG * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
* --> FIELDCATALOG * 
* --> P_TABNAME * 
* --> P_FIELDNAME * 
* --> P_KEY * 
* --> P_KEY * 
*---------------------------------------------------------------------* 
form fill_fields_of_fieldcatalog tables fieldcatalog 
structure fieldcatalog 
using p_tabname 
p_fieldname 
p_key. 
* p_no_out. 
fieldcatalog-tabname = p_tabname. 
fieldcatalog-fieldname = p_fieldname. 
fieldcatalog-key = p_key. 
fieldcatalog-emphasize = '1234'. 
*fieldcatalog-no_out = p_no_out. 
append fieldcatalog. 
endform. " FILL_FIELDSOFFIELDCATALOG 
  

*---------------------------------------------------------------------* 
* FORM POPULATE_LAYOUT * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
* --> FIELDLAYOUT * 
*---------------------------------------------------------------------* 
form populate_layout using fieldlayout type slis_layout_alv. 
fieldlayout-f2code = '&ETA' . 
fieldlayout-zebra = 'X'. 
* FOR THE WINDOW TITLE. 
fieldlayout-window_titlebar = 'ALV with Events'. 

fieldlayout-colwidth_optimize = 'X'. 
fieldlayout-no_vline = ' '. 
*fieldlayout-no_input = 'X'. 
fieldlayout-confirmation_prompt = ''. 
fieldlayout-key_hotspot = 'X'. 
* This removes the column headings if the flag is set to 'X' 
fieldlayout-no_colhead = ' '. 
*fieldlayout-hotspot_fieldname = 'MAKTX'. 
fieldlayout-detail_popup = 'X'. 
* fieldlayout-coltab_fieldname = 'X'. 
endform. " POPULATE_LAYOUT 

*---------------------------------------------------------------------* 
* FORM SELECTDATA_AND_SORT * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form selectdata_and_sort. 
select matnr meins mtart matkl from mara 
into corresponding fields of t_mara 
up to 500 rows . 

select matnr maktx spras from makt 
into corresponding fields of t_makt 
where matnr = t_mara-matnr and 
spras = sy-langu. 

select matnr werks minbe from marc 
into corresponding fields of t_marc 
where matnr = t_mara-matnr. 
append t_marc. 
endselect. 
append t_makt. 
endselect. 
append t_mara. 
endselect. 
perform populate_itab1. 
sort itab1 by matnr. 
endform. " SELECTDATA_AND_SORT 

*---------------------------------------------------------------------* 
* FORM MERGE_FIELDCATALOG * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form merge_fieldcatalog. 
call function 'REUSE_ALV_FIELDCATALOG_MERGE' 
exporting 
i_program_name = syrepid 
i_internal_tabname = 'ITAB1' 
* i_structure_name = 'COLORSTRUCT' 
* I_CLIENT_NEVER_DISPLAY = 'X' 
i_inclname = syrepid 
changing 
ct_fieldcat = fieldcatalog[] 
exceptions 
inconsistent_interface = 1 
program_error = 2 
others = 3. 
endform. " MERGE_FIELDCATALOG 
  

* IN THIS FUNCTION THE MINIMUM PARAMETERS THAT WE NEED TO PASS IS AS 
* FOLLOWS:- 
* i_callback_program --> CALLING PROGRAM NAME 
* i_structure_name --> STRUCTURE NAME. 
* is_layout --> LAYOUT NAME. 
* it_fieldcat ---> BODY OF THE FIELD CATALOGUE INTERNAL TABLE 
form display_alv_list. 
call function 'REUSE_ALV_LIST_DISPLAY' 
exporting 
* I_INTERFACE_CHECK = ' ' 
i_callback_program = syrepid 
* I_CALLBACK_PF_STATUS_SET = ' ' 
* I_CALLBACK_USER_COMMAND = ' ' 
i_structure_name = 'ITAB1' 
is_layout = fieldlayout 
it_fieldcat = fieldcatalog[] 
* IT_EXCLUDING = 
* IT_SPECIAL_GROUPS = 
* IT_SORT = 
* IT_FILTER = 
* IS_SEL_HIDE = 
* I_DEFAULT = 'X' 
* THE FOLLOWING PARAMETER IS SET AS 'A' INORDER TO DISPLAY THE STANDARD 
* TOOL BAR 
i_save = 'A' 
* IS_VARIANT = ' ' 
it_events = eventstab[] 
* IT_EVENT_EXIT = 
* IS_PRINT = 
* I_SCREEN_START_COLUMN = 0 
* I_SCREEN_START_LINE = 0 
* I_SCREEN_END_COLUMN = 0 
* I_SCREEN_END_LINE = 0 
* IMPORTING 
* E_EXIT_CAUSED_BY_CALLER = 
* ES_EXIT_CAUSED_BY_USER = 
tables 
t_outtab = itab1 
exceptions 
program_error = 1 
others = 2. 
endform. " DISPLAY_ALV_LIST 
*&---------------------------------------------------------------------* 
*& Form POPULATE_ITAB1 
*&---------------------------------------------------------------------* 
* text 
*----------------------------------------------------------------------* 
* --> p1 text 
* <-- p2 text 
*----------------------------------------------------------------------* 
form populate_itab1. 
loop at t_mara. 
loop at t_makt where matnr = t_mara-matnr. 
loop at t_marc where matnr = t_mara-matnr. 
move-corresponding t_mara to itab1. 
move-corresponding t_makt to itab1. 
move-corresponding t_marc to itab1. 
append itab1. 
endloop. 
endloop. 
endloop. 
endform. " POPULATE_ITAB1 
*&---------------------------------------------------------------------* 
*& Form FILL_EVENTSTAB 
*&---------------------------------------------------------------------* 
* text 
*----------------------------------------------------------------------* 
* -->P_EVENTSTAB text * 
*----------------------------------------------------------------------* 
form fill_eventstab tables p_eventstab structure eventstab. 
* WHEN THE FOLLOWING FUNCTION IS CALLED THE SYSTEM POPULATES THE 
* INTERNAL TABLE EVENTSTAB WITH A LIST OF EVENTS NAME. 
* AS SHOWN BELOW WHEN USING I_LIST_TYPE = 0 THE FUNCTION RETURNS 14 
* EVENTS NAME. 
call function 'REUSE_ALV_EVENTS_GET' 
exporting 
i_list_type = 0 
importing 
et_events = p_eventstab[] 
exceptions 
list_type_wrong = 1 
others = 2. 

* BY CALLING THE ABOVE FUNCTION WE FIRST POPULATE THE EVENTSTAB WITH 
* THE PREDEFINED EVENTS AND THEN WE MOVE THE FORM NAME AS SHOWN BELOW. 
* WE ASSIGN A FORM NAME TO THE EVENT AS REQUIRED BY THE USER. 
* FORM NAME CAN BE ANYTHING.THE PERFORM STATEMENT FOR THIS FORM 
* IS DYNAMICALY CALLED. 

read table p_eventstab with key name = slis_ev_top_of_page. 
if sy-subrc = 0 . 
move 'TOP_OF_PAGE' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_top_of_coverpage. 
if sy-subrc = 0 . 
move 'TOP_OF_COVERPAGE' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_end_of_coverpage . 
if sy-subrc = 0 . 
move 'END_OF_COVERPAGE' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_foreign_top_of_page. 
if sy-subrc = 0 . 
move 'FOREIGN_TOP_OF_PAGE' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_foreign_end_of_page. 
if sy-subrc = 0 . 
move 'FOREIGN_END_OF_PAGE' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_list_modify. 
if sy-subrc = 0 . 
move 'LIST_MODIFY' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_top_of_list. 
if sy-subrc = 0 . 
move 'TOP_OF_LIST' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_end_of_page. 
if sy-subrc = 0 . 
move 'END_OF_PAGE' to p_eventstab-form. 
append p_eventstab. 
endif. 

read table p_eventstab with key name = slis_ev_end_of_list . 
if sy-subrc = 0 . 
move 'END_OF_LIST' to p_eventstab-form. 
append p_eventstab. 
endif. 
endform. " FILL_EVENTSTAB 
*&---------------------------------------------------------------------* 
*& Form FILL_HEADINGTABLE 
*&---------------------------------------------------------------------* 
* text 
*----------------------------------------------------------------------* 
* -->P_HEADING text * 
*----------------------------------------------------------------------* 
form fill_headingtable tables p_heading structure heading 
using tablename. 
case tablename. 
when 'HEADING'. 
p_heading-typ = 'H'. 
concatenate 
' REPORT NAME:-' syrepid 
' ABB Industry Pte Ltd' into p_heading-info. 
append p_heading. 
write sy-datum using edit mask '__/__/____' to sydatum. 

concatenate 
' DATE:-' sydatum ' USER: ' sy-uname 'PAGE NO:' sypagno 
into p_heading-info. 
append p_heading. 
when 'HEADING1'. 
p_heading-typ = 'H'. 
p_heading-info = 'TOP-OF-COVER-PAGE'. 
append p_heading. 
when 'HEADING2'. 
p_heading-typ = 'H'. 
p_heading-info = 'END-OF-COVER-PAGE'. 
append p_heading. 
when 'HEADING3'. 
p_heading-typ = 'H'. 
p_heading-info = 'FOREIGN-TOP-OF-PAGE'. 
append p_heading. 
when 'HEADING4'. 
p_heading-typ = 'H'. 
p_heading-info = 'FOREIGN-END-OF-PAGE'. 
append p_heading. 
* WHEN 'HEADING5'. 
* P_HEADING-TYP = 'H'. 
* P_HEADING-INFO = 'LIST-MODIFY'. 
* APPEND P_HEADING. 
when 'HEADING6'. 
p_heading-typ = 'H'. 
p_heading-info = 'END-OF-PAGE'. 
append p_heading. 
when 'HEADING7'. 
p_heading-typ = 'H'. 
p_heading-info = 'END-OF-LIST'. 
append p_heading. 
when 'HEADING8'. 
p_heading-typ = 'H'. 
p_heading-info = 'TOP-OF-LIST'. 
append p_heading. 
endcase. 
endform. " FILL_HEADINGTABLE 

*---------------------------------------------------------------------* 
* FORM TOP_OF_PAGE * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form top_of_page. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading[] 
exceptions 
others = 1. 
endform. 
*&---------------------------------------------------------------------* 
*& Form FILL_COLORSTRUCT 
*&---------------------------------------------------------------------* 
* text 
*----------------------------------------------------------------------* 
* -->P_COLORSTRUCT text * 
*----------------------------------------------------------------------* 
form fill_colorstruct using p_colorstruct type slis_coltypes . 
p_colorstruct-heacolfir-col = 6. 
p_colorstruct-heacolfir-int = 1. 
p_colorstruct-heacolfir-inv = 1. 
endform. " FILL_COLORSTRUCT 

*---------------------------------------------------------------------* 
* FORM TOP_OF_COVERPAGE * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form top_of_coverpage. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading1[] 
exceptions 
others = 1. 
endform. 

*---------------------------------------------------------------------* 
* FORM END_OF_COVERPAGE * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form end_of_coverpage. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading2[] 
exceptions 
others = 1. 
endform. 

*---------------------------------------------------------------------* 
* FORM FOREIGN_TOP_OF_PAGE * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form foreign_top_of_page. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading3[] 
exceptions 
others = 1. 

endform. 

*---------------------------------------------------------------------* 
* FORM FOREIGN_END_OF_PAGE * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form foreign_end_of_page. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading4[] 
exceptions 
others = 1. 
endform. 

*---------------------------------------------------------------------* 
* FORM LIST_MODIFY * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
*FORM LIST_MODIFY. 
* CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' 
* EXPORTING 
* IT_LIST_COMMENTARY = HEADING5[] 
* EXCEPTIONS 
* OTHERS = 1. 
*ENDFORM. 

*---------------------------------------------------------------------* 
* FORM END_OF_PAGE * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form end_of_page. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading6[] 
exceptions 
others = 1. 
endform. 

*---------------------------------------------------------------------* 
* FORM END_OF_LIST * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form end_of_list. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading7[] 
exceptions 
others = 1. 
endform. 

*---------------------------------------------------------------------* 
* FORM TOP_OF_LIST * 
*---------------------------------------------------------------------* 
* ........ * 
*---------------------------------------------------------------------* 
form top_of_list. 
call function 'REUSE_ALV_COMMENTARY_WRITE' 
exporting 
it_list_commentary = heading8[] 
exceptions 
others = 1. 
endform. 

*--- End of Program

Regards,

Balakumar .G.

Reward points if helpful.

Read only

Former Member
0 Likes
5,346

Hi,

Have on the following code, you can c the logo also.

THIS IS TO DISPLAY THE HEADER WITH LOGO.

Follow the below step for uploading the image file:

Steps for uploading Logo :-:

1. Goto the transaction OAER

2. Enter the class name as 'PICTURES'

3. Enter the class type as 'OT'

4. Enter the object key as the name of the logo(e.g. tripodsm.gif) you wish to give

5. Execute

6. Then in the new screen select Standard doc. types in bottom window

Click on the Screen icon

Now, it will ask for the file path where you have to upload the logo

7. Now you can use this logo in REUSE_ALV_COMMENTARY_WRITE

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = i_header

i_logo = 'tripodsm.gif'.

TABLES VBAK.

TYPE-POOLS SLIS.

  • Data Declaration

TYPES: BEGIN OF T_VBAK,

VBELN TYPE VBAK-VBELN,

ERDAT TYPE VBAK-ERDAT,

ERNAM TYPE VBAK-ERNAM,

AUDAT TYPE VBAK-AUDAT,

VBTYP TYPE VBAK-VBTYP,

NETWR TYPE VBAK-NETWR,

VKORG TYPE VBAK-VKORG,

VKGRP TYPE VBAK-VKGRP,

LINE_COLOR(4) TYPE C,

END OF T_VBAK.

DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,

WA_VBAK TYPE T_VBAK.

  • ALV Data Declaration

DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

GD_LAYOUT TYPE SLIS_LAYOUT_ALV,

GD_REPID TYPE SY-REPID.

START-OF-SELECTION.

PERFORM DATA_RETRIEVAL.

PERFORM BLD_FLDCAT.

PERFORM BLD_LAYOUT.

PERFORM DISPLAY_ALV_REPORT.

  • Build Field Catalog for ALV Report

FORM BLD_FLDCAT.

FLDCAT-FIELDNAME = 'VBELN'.

FLDCAT-SELTEXT_M = 'Sales Document'.

FLDCAT-COL_POS = 0.

*FLDCAT-EMPHASIZE = 'C411'.

FLDCAT-OUTPUTLEN = 20.

FLDCAT-KEY = 'X'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERDAT'.

FLDCAT-SELTEXT_L = 'Record Date created'.

FLDCAT-COL_POS = 1.

FLDCAT-KEY = 'X'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERNAM'.

FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'AUDAT'.

FLDCAT-SELTEXT_M = 'Document Date'.

FLDCAT-COL_POS = 3.

FLDCAT-EMPHASIZE = 'C110'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'VBTYP'.

FLDCAT-SELTEXT_L = 'SD Document category'.

FLDCAT-COL_POS = 4.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'NETWR'.

FLDCAT-SELTEXT_L = 'Net Value of the SO in Document Currency'.

FLDCAT-COL_POS = 5.

FLDCAT-OUTPUTLEN = 60.

FLDCAT-DO_SUM = 'X'.

FLDCAT-DATATYPE = 'CURR'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'VKORG'.

FLDCAT-SELTEXT_L = 'Sales Organization'.

FLDCAT-COL_POS = 6.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'VKGRP'.

FLDCAT-SELTEXT_M = 'Sales Group'.

FLDCAT-COL_POS = 7.

FLDCAT-EMPHASIZE = 'C801'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

ENDFORM.

  • Build Layout for ALV Grid Report

FORM BLD_LAYOUT.

GD_LAYOUT-NO_INPUT = 'X'.

GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

GD_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.

GD_LAYOUT-CONFIRMATION_PROMPT = 'X'. “ This asks the confirmation before leaving the screen.

ENDFORM.

  • Display report using ALV grid

FORM DISPLAY_ALV_REPORT.

GD_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = GD_REPID

IS_LAYOUT = GD_LAYOUT

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = 'SALES DOCUMENT HEADER'

IT_FIELDCAT = FLDCAT[]

I_SAVE = 'X'

TABLES

T_OUTTAB = IT_VBAK

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.

ENDFORM.

  • Retrieve data from VBAK table and populate itab IT_VBAK

FORM DATA_RETRIEVAL.

DATA LD_COLOR(1) TYPE C.

SELECT VBELN ERDAT ERNAM AUDAT VBTYP NETWR VKORG

UP TO 20 ROWS

FROM VBAK

INTO TABLE IT_VBAK.

LOOP AT IT_VBAK INTO WA_VBAK.

LD_COLOR = LD_COLOR + 1.

IF LD_COLOR = 8.

LD_COLOR = 1.

ENDIF.

CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.

MODIFY IT_VBAK FROM WA_VBAK.

ENDLOOP.

ENDFORM.

FORM TOP_OF_PAGE.

DATA: T_HEADER TYPE SLIS_T_LISTHEADER,

W_HEADER TYPE SLIS_LISTHEADER.

W_HEADER-TYP = 'H'.

W_HEADER-INFO = 'WELCOME HEADER LIST'.

APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.

W_HEADER-KEY = 'REPORT:'.

W_HEADER-INFO = SY-REPID.

APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.

W_HEADER-KEY = 'DATE:'.

CONCATENATE SY-DATUM6(2) ' / ' SY-DATUM4(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.

APPEND W_HEADER TO T_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = T_HEADER

I_LOGO = ‘TRIPODSM.GIF’.

ENDFORM.

Regards,

Chandu