04-17-2006 10:55 AM
hai
blow the function modules can u send the some code examples
Reuse_alv_list_display
Reuse_alv_fieldcatalog_merge
Reuse_alv_events_get
Reuse_alv_commentary_write
Reuse_alv_grid_display
04-17-2006 10:58 AM
Hi
You should see the demo programs, so in SE38 see all programs whose name begin with BALV* or BCALV*
Max
04-17-2006 10:58 AM
Go to se38, give
bcalv in the program name. and press f4.
YOu can find lots of them.
Regards,
Ravi
04-17-2006 10:58 AM
Hi Franklin,
You can check the std programs under the development package SLIS. Goto se80 and display SLIS development package you can find a lot of SAP programs giving you details of the usage.
Hope this helps.
Cheers
VJ
04-17-2006 11:01 AM
Hi Franklin
here is everything about ALV
Its excellent just go through its
I hope you will get what you want
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://www.sappoint.com/ppt/alv.ppt
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_basic.htm
Basic ALV programs
Thanks
04-17-2006 11:02 AM
Hi,
Take a look at this site.
http://www.geocities.com/mpioud/Abap_programs.html
Quite a few examples.
regards,
Ravi
Note : Please mark all the helpful answers
04-17-2006 11:02 AM
Hi,
check this forum..
check package SLIS from SE80.
check the links..
http://www.geocities.com/mpioud/Abap_programs.html
http://www.sapdevelopment.co.uk/reporting/alvhome.htm
Regards
vijay
04-17-2006 11:05 AM
hi,
here is a link
http://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/an easy reference for alv grid control.pdf
and the code which might help you.
REPORT ZKINTEST_ALV .
type-pools:slis.
data : it_fieldcat type slis_t_fieldcat_alv,
it_fieldcat1 type slis_t_fieldcat_alv.
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
end of itab.
data: begin of itab1 occurs 0,
vbeln like likp-vbeln,
posnr like lips-posnr,
vgbel like lips-vgbel,
vgpos like lips-vgpos,
end of itab1.
data: it_lips like itab1 occurs 0 with header line.
select vbeln posnr up to 1000 rows
from vbap
into table itab.
if sy-subrc = 0.
sort itab by vbeln .
select vbeln posnr vgbel vgpos into table
itab1 from lips for all entries in itab where vgbel = itab-vbeln
and vgpos = itab-posnr.
endif.
data: x_fieldcat type
slis_fieldcat_alv.
x_fieldcat-fieldname = '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-tabname = 'ITAB'.
x_fieldcat-col_pos = 1.append x_fieldcat to it_fieldcat.
clear x_fieldcat.
perform alv_grid_display.
*&---------------------------------------------------------------------*
*& Form
*&-----------------------------------------------------------------
**
*------------------------------------------------------------------
** -->P_EXTAB
*-------------------------------------------------------------------
form popup using p_extab type slis_t_extab.
set pf-status 'POPUP'.
endform.
*&-----------------------------------------------------------------
**& Form
*&---------------------------------------------------
*-------------------------------------------------------------------
** -->R_UCOMM text* -->RS_SELFIELD
*-------------------------------------------------------------------
form handle_user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when 'BACK' or 'CANC' or 'EXIT'.
leave to screen 0.
when '&IC1'.
set parameter id 'AUN' field rs_selfield-value.
call transaction 'VA03' and skip first screen.
when 'BUTTON'.
loop at it_fieldcat into x_fieldcat.
if x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-no_out = 'X'.
modify it_fieldcat from x_fieldcat transporting no_out.
endif.
endloop.
rs_selfield-exit = 'X'.
perform alv_grid_display.
endcase.
endform.
"HANDLE_USER_COMMAND
*&---------------------------------------------------------------------*
*& **text*---------------------------------------------------------
** --> p1 text
* <--
*-------------------------------------------------------------------
form alv_grid_display .
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'POPUP'
i_callback_user_command = 'HANDLE_USER_COMMAND'
i_callback_top_of_page = 'TOP-OF-PAGE'
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
others = 2.
if
sy-subrc = 0.
endif.
endform. " alv_grid_display
FORM TOP-OF-PAGE.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info+10(15) = ' SY-REPID'.
*wa_header-info+21(10) = text-001.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
endform.
regards,
Kinshuk
PS reward points if you find this useful
04-17-2006 11:07 AM
Hi,
check this sample..
REPORT Z_TEST_ALV_EVENTS .
type-pools: slis.
data: x_fieldcat type slis_fieldcat_Alv,
it_fieldcat type slis_t_fieldcat_alv,
x_events type slis_alv_event,
it_events type SLIS_T_EVENT.
data: v_lines type i.
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
end of itab.
select vbeln
posnr
from vbap
up to 100 rows
into table itab.
x_events-name = 'END_OF_LIST'.
x_events-form = 'END_OF_LIST'.
append x_events to it_events.
clear x_events.
x_events-name = 'TOP_OF_PAGE'.
x_events-form = 'TOP_OF_PAGE'.
append x_events to it_events.
clear x_events.
"if you use FM..
* call function 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
* IMPORTING
* ET_EVENTS = IT_EVENTS
* EXCEPTIONS
* LIST_TYPE_WRONG = 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.
*
* read table it_events into x_events with key name = 'TOP_OF_PAGE'.
* if sy-subrc = 0.
* x_events-form = 'TOP_OF_PAGE'.
* modify it_events from x_events index sy-tabix transporting form .
* endif.
*
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
describe table itab lines v_lines.
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_PF_STATUS_SET = 'STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELDCAT
IT_EVENTS = IT_EVENTS
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.
endif.
FORM TOP_OF_PAGE.
DATA: LS_LINE TYPE SLIS_LISTHEADER,
E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
* Listenüberschrift: Typ H
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
* LS_LINE-KEY: not used for this type
LS_LINE-INFO = 'Summary'.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
* Kopfinfo: Typ S
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'Test'.
LS_LINE-INFO = ''.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
LS_LINE-KEY = 'ASIA'.
LS_LINE-INFO = 'test'.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
* Aktionsinfo: Typ A
CLEAR LS_LINE.
LS_LINE-TYP = 'A'.
* LS_LINE-KEY: not used for this type
LS_LINE-INFO = TEXT-105.
APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = E04_LT_TOP_OF_PAGE
I_LOGO = 'ENJOYSAP_LOGO'.
ENDFORM.
FORM END_OF_LIST.
write 😕 'No of Records ', v_lines.
ENDFORM.
Regards
vijay
04-17-2006 11:08 AM
04-17-2006 11:09 AM
Check the below example programs by SAP.
BCALV_GRID_01,02...10
Cheers,
Abdul Hakim
04-17-2006 11:14 AM
hi
good
Reuse_alv_list_display->data definition
tables:
marav. "Table MARA and table MAKT
----
Data to be displayed in ALV
Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.
----
Other data needed
field to store report name
data i_repid like sy-repid.
field to check table length
data i_lines like sy-tabix.
----
Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
----
select-options:
s_matnr for marav-matnr matchcode object MAT1.
----
start-of-selection.
read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
----
*
Now, we start with ALV
*
----
*
*
To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
The fieldcatalouge can be generated by FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
report source, including this report.
The only problem one might have is that the report and table names
need to be in capital letters. (I had it )
*
*
----
Store report name
i_repid = sy-repid.
Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
I_PROGRAM_NAME is the program which calls this function
*
I_INTERNAL_TABNAME is the name of the internal table which you want
to display in ALV
*
I_INCLNAME is the ABAP-source where the internal table is defined
(DATA....)
CT_FIELDCAT contains the Fieldcatalouge that we need later for
ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
----
*
And now, we are ready to display our list
Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
I_CALLBACK_PROGRAM is the program which calls this function
*
IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
now the data definition needed for display
*
I_SAVE allows the user to save his own layouts
*
T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
-
Reuse_alv_fieldcatalog_merge->
*data definition
tables:
marav. "Table MARA and table MAKT
----
Data to be displayed in ALV
Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.
----
Other data needed
field to store report name
data i_repid like sy-repid.
field to check table length
data i_lines like sy-tabix.
----
Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
----
select-options:
s_matnr for marav-matnr matchcode object MAT1.
----
start-of-selection.
read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
----
*
Now, we start with ALV
*
----
*
*
To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
The fieldcatalouge can be generated by FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
report source, including this report.
The only problem one might have is that the report and table names
need to be in capital letters. (I had it )
*
*
----
Store report name
i_repid = sy-repid.
Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
I_PROGRAM_NAME is the program which calls this function
*
I_INTERNAL_TABNAME is the name of the internal table which you want
to display in ALV
*
I_INCLNAME is the ABAP-source where the internal table is defined
(DATA....)
CT_FIELDCAT contains the Fieldcatalouge that we need later for
ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
----
*
And now, we are ready to display our list
Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
I_CALLBACK_PROGRAM is the program which calls this function
*
IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
now the data definition needed for display
*
I_SAVE allows the user to save his own layouts
*
T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
-
Reuse_alv_events_get->
http://www.sappoint.com/ppt/alv.ppt
-
Reuse_alv_commentary_write->
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = heading.
-
Reuse_alv_grid_display->
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = repname
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
i_callback_top_of_page = 'TOP_OF_PAGE'
i_structure_name = 'TI_ACRED'
is_layout = layout
it_fieldcat = fieldtab
i_default = 'X'
i_save = g_save
is_variant = g_variant
it_events = events[]
TABLES
t_outtab = ti_acred
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.
Thanks
Mrutyun
11-28-2007 7:00 AM
Hi
<b>Reuse_alv_list_display</b>
type-pools: slis.
data: fieldcat type slis_t_fieldcat_alv,
fieldcat_ln like line of fieldcat,
fs_layout type slis_layout_alv,
t_layoout like standard table
of fs_layout.
data: begin of fs_spfli,
carrid type spfli-carrid,
connid type spfli-connid,
countryfr type spfli-countryfr,
cityfrom type spfli-cityfrom,
airpfrom type spfli-airpfrom,
countryto type spfli-countryto,
cityto type spfli-cityto,
airpto type spfli-airpto,
fltime type spfli-fltime,
deptime type spfli-deptime,
arrtime type spfli-arrtime,
distance type spfli-distance,
distid type spfli-distid,
fltype type spfli-fltype,
period type spfli-period,
checkbox,
color(3),
end of fs_spfli.
data:
begin of fs_table,
carrid type spfli-carrid,
connid type spfli-connid,
end of fs_table.
data: begin of fs_sflight,
check,
color(3).
include type sflight.
data:end of fs_sflight.
data:
begin of fs_table1,
carrid type sflight-carrid,
connid type sflight-connid,
fldate type sflight-fldate,
end of fs_table1.
data:
t_spfli like standard table
of fs_spfli.
data:
t_table like standard table
of fs_table.
data:
t_table1 like standard table
of fs_table1.
data:
t_sflight like standard table
of fs_sflight.
data:
t_sbook like standard table
of sbook.
data t_layout type slis_layout_alv.
select *
into corresponding fields of table t_spfli
from spfli.
perform start_list_viewer.
perform get_spfli_details.
*&--------------------------------------------------------------------*
*& Form SUB1
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
form sub1 using rt_extab type slis_t_extab.
data: flight type slis_extab.
flight-fcode = 'SFLIGHT'.
append flight to rt_extab.
set pf-status 'SFLIGHT'. " EXCLUDING RT_EXTAB.
endform. "SUB1
*&---------------------------------------------------------------------*
*& Form START_LIST_VIEWER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form start_list_viewer .
data: pgm like sy-repid.
pgm = sy-repid.
fs_layout-box_fieldname = 'CHECKBOX'.
fs_layout-info_fieldname = 'COLOR'.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = pgm
i_callback_pf_status_set = 'SUB1'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'SPFLI'
is_layout = fs_layout
tables
t_outtab = t_spfli
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. " START_LIST_VIEWER
********Process Call Back Events (Begin)***************************
form user_command using ucomm like sy-ucomm
selfield type slis_selfield.
case ucomm.
when 'SFLIGHT'.
selfield-refresh = 'X'.
perform get_spfli_details.
select *
from sflight
into corresponding fields of table t_sflight
for all entries in t_table
where carrid eq t_table-carrid
and connid eq t_table-connid.
perform display_sflight.
when 'SBOOK'.
selfield-refresh = 'X'.
perform get_sflight_details.
select *
from sbook
into corresponding fields of table t_sbook
for all entries in t_table1
where carrid eq t_table1-carrid
and connid eq t_table1-connid
and fldate eq t_table1-fldate.
perform display_sbook.
endcase.
endform. "USER_COMMAND
*&--------------------------------------------------------------------*
*& Form SUB2
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
form sub2 using rt_extab type slis_t_extab.
data: flight type slis_extab.
flight-fcode = 'SBOOK'.
append flight to rt_extab.
set pf-status 'SBOOK'. " EXCLUDING RT_EXTAB.
endform. "SUB2
*&---------------------------------------------------------------------*
*& Form DISPLAY_SFLIGHT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_sflight .
data: pgm like sy-repid.
pgm = sy-repid.
clear t_layout.
fs_layout-box_fieldname = 'CHECK'.
fs_layout-info_fieldname = 'COLOR'.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = pgm
i_callback_pf_status_set = 'SUB2'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'SFLIGHT'
is_layout = fs_layout
tables
t_outtab = t_sflight
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. " DISPLAY_SFLIGHT
*&---------------------------------------------------------------------*
*& Form GET_SPFLI_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_spfli_details .
loop at t_spfli into fs_spfli.
if fs_spfli-checkbox = 'X'.
fs_spfli-color = 'C51'.
fs_spfli-checkbox = '1'.
fs_table-carrid = fs_spfli-carrid.
fs_table-connid = fs_spfli-connid.
append fs_table to t_table.
modify t_spfli from fs_spfli.
endif.
endloop.
endform. " GET_SFLIGHT_DETAILS
*&---------------------------------------------------------------------*
*& Form GET_SFLIGHT_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_sflight_details .
loop at t_sflight into fs_sflight.
if fs_sflight-check = 'X'.
fs_sflight-color = 'C71'.
fs_sflight-check = '1'.
fs_table1-carrid = fs_sflight-carrid.
fs_table1-connid = fs_sflight-connid.
fs_table1-fldate = fs_sflight-fldate.
append fs_table1 to t_table1.
modify t_sflight from fs_sflight.
endif.
endloop.
endform. " GET_SFLIGHT_DETAILS
*&---------------------------------------------------------------------*
*& Form DISPLAY_SBOOK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_sbook .
data: pgm like sy-repid.
pgm = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = pgm
i_structure_name = 'SBOOK'
tables
t_outtab = t_sbook
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. " DISPLAY_SBOOK
<b> Reuse_alv_fieldcatalog_merge</b>
*data definition
tables:
marav. "Table MARA and table MAKT
*---------------------------------------------------------------------*
* Data to be displayed in ALV
* Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
* matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.
*---------------------------------------------------------------------*
* Other data needed
* field to store report name
data i_repid like sy-repid.
* field to check table length
data i_lines like sy-tabix.
*---------------------------------------------------------------------*
* Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
*---------------------------------------------------------------------*
select-options:
s_matnr for marav-matnr matchcode object MAT1.
*---------------------------------------------------------------------*
start-of-selection.
* read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
* Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
* Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
*---------------------------------------------------------------------*
*
* Now, we start with ALV
*
*---------------------------------------------------------------------*
*
*
* To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
* The fieldcatalouge can be generated by FUNCTION
* 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
* report source, including this report.
* The only problem one might have is that the report and table names
* need to be in capital letters. (I had it 😞 )
*
*
*---------------------------------------------------------------------*
* Store report name
i_repid = sy-repid.
* Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
* I_PROGRAM_NAME is the program which calls this function
*
* I_INTERNAL_TABNAME is the name of the internal table which you want
* to display in ALV
*
* I_INCLNAME is the ABAP-source where the internal table is defined
* (DATA....)
* CT_FIELDCAT contains the Fieldcatalouge that we need later for
* ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
*---------------------------------------------------------------------*
*
* And now, we are ready to display our list
* Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
* I_CALLBACK_PROGRAM is the program which calls this function
*
* IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
* now the data definition needed for display
*
* I_SAVE allows the user to save his own layouts
*
* T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
<b> Reuse_alv_events_get</b>
By using this function module called 'REUSE_ALV_EVENTS_GET' where u get all the events like PF_STATUS_SET, TOP_OF_LIST, END_OF_PAGE,END_OF_LIST etc populated into an internal table So u can read this internal table and call the appropriate form to print the content at the end of the list. Below is the sample code for ur reference.
FORM build_events USING flag
CHANGING pa_events TYPE slis_t_event.
*Get all possible events
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = pa_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
* Specify events used in selection screen
READ TABLE pa_events WITH KEY name = slis_ev_top_of_page
INTO ls_events.
IF sy-subrc = 0.
IF flag = 1.
ls_events-form = 'TOP_OF_PAGE1'.
ELSEIF flag = 2.
ls_events-form = 'TOP_OF_PAGE2'.
ELSE.
ls_events-form = 'TOP_OF_PAGE3'.
ENDIF.
MODIFY pa_events FROM ls_events INDEX sy-tabix.
CLEAR ls_events.
ENDIF.
ENDFORM. "build_events
*&---------------------------------------------------------------------*
*& Form top_of_page1
*&---------------------------------------------------------------------*
FORM top_of_page1.
WRITE: 'Last Year'.
ENDFORM. "TOP_OF_PAGE1
*&---------------------------------------------------------------------*
*& Form top_of_page2
*&---------------------------------------------------------------------*
FORM top_of_page2.
WRITE: 'Budget'.
ENDFORM. "TOP_OF_PAGE2
*&---------------------------------------------------------------------*
*& Form top_of_page3
*&---------------------------------------------------------------------*
FORM top_of_page3.
WRITE: 'This year'.
ENDFORM. "TOP_OF_PAGE3
<b>Reuse_alv_commentary_write </b>
*&---------------------------------------------------------------------*
*& Report ZALV *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
Report ZALV .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
* gd_layout-zebra = 'X'.
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* 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
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_ekko
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. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
endform. " DATA_RETRIEVAL
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform.
*------------------------------------------------------------------*
* FORM USER_COMMAND *
*------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* Check function code
CASE r_ucomm.
WHEN '&IC1'.
* Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'EBELN'.
* Read data table, using index of row user clicked on
READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
* Set parameter ID for transaction screen field
SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
* Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_EVENTS
*&---------------------------------------------------------------------*
* Build events table
*----------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*&---------------------------------------------------------------------*
*& Form BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
* Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*& Form END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*&---------------------------------------------------------------------*
*& Form END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
<b>Reuse_alv_grid_display</b>
*&---------------------------------------------------------------------*
*& Report ZALVTEST *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZALVTEST.
TABLES: mara, makt.
TYPE-POOLS: slis.
TYPES: BEGIN OF tab,
matnr TYPE matnr,
matkl TYPE matkl,
maktx TYPE maktx,
END OF tab.
DATA: itab TYPE TABLE OF tab,
wa LIKE LINE OF itab.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material No'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATKL'.
fieldcatalog-seltext_m = 'Group'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MAKTX'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* 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
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
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.
endif.
endform. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
SELECT F~matnr F~matkl P~maktx
INTO table itab
FROM mara AS F INNER JOIN makt AS P
ON F~matnr = P~matnr.
endform. " DATA_RETRIEVAL
Regards
Pavan