2007 Dec 20 5:44 AM
Hi All,
I need a pattern prog. example of ALV Grid using Classes... What is the methodology??...
Its very helpful if anyone give me the correct way of approach.
Regards,
Sayak
2007 Dec 20 5:59 AM
hi Sayak.,
follow the approach.
To do this, you must:
Create an instance of the ALV grid control and integrate it into a screen.
Select the data to be displayed and pass it together with a description of the fields to the
instance.
Creating an ALV Grid Control
You instantiate an ALV grid control in the same way as other controls:
Declare reference variables for the ALV grid control and the container. In addition, declare an
internal table that you fill with selected data later on:
DATA: grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container
gt_sflight TYPE TABLE OF sflight.
In order to integrate a control into a screen, you can use four different container
controls
Create a standard screen and mark an area for the custom container control in the graphical
Screen Painter (icon identified by letter 'C'). Assign name CCCONTAINER to this area.
In the PBO module of the screen, you must now instantiate the container control and the ALV grid control. By doing this, you create a link between the container control and the screen, using the container created in the Screen Painter. Using parameter parent, you define the container control as the parent of the ALV grid control:
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
CONTAINER_NAME = 'CCCONTAINER'.
CREATE OBJECT GRID1
EXPORTING
I_PARENT = g_custom_container.
ENDIF.
The IF query of reference variable g_custom_container ensures that the
instances are only generated when the PBO is processed for the first time.
Normally, you must use method cl_gui_cfw=>flush to pass the methods called
to the frontend. However, since the Control Framework performs an automatic flush
at the end of the PBO module, this step is not required here.
When you start the program, although the two instances (the container control and the ALV grid control) are generated, they are not visible.
Displaying a List in the ALV Control
Once you have created the ALV grid control and integrated it into a screen using a container
control, you must pass the data and its structure to the ALV grid control:
Fill the internal table with data:
SELECT * FROM sflight INTO TABLE gt_sflight.
Pass the output table and the structure data to the ALV grid control. Again, ensure to call this
method only once after the ALV grid control is created:
CALL METHOD grid->set_table_for_first_display
EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING IT_OUTTAB = gt_sflight.
In this case, the structure data is provided through the Data Dictionary. The ALV grid
control gets the field information from table SFLIGHT and displays all fields of the
table.
*Reward points if useful*
2007 Dec 20 5:48 AM
Hi,
Goto SE38 give BCALV* n press F4 it will display the list of all standard ALV programs.
Refer that.
Regards,
Prashant
2007 Dec 20 5:49 AM
the code is a module pool program having oops alv with event handling
TOP INCLUDE
&----
*& Include MY01TOP Module Pool SAPMY01
*&
&----
PROGRAM sapmy01.
TABLES : vbak,tvls.
ALV Grid Control
DATA : alv_grid TYPE REF TO cl_gui_alv_grid.
Custom Control Name
DATA : custom_control_name TYPE scrfname VALUE 'CONTAINER1'.
Custom Container
DATA : custom_container TYPE REF TO cl_gui_custom_container.
Fieldcatalog Table
DATA : gt_fieldcat TYPE lvc_t_fcat.
Layout Structure
DATA : gt_layout TYPE lvc_s_layo.
Internal Table for Header Sales Order
DATA : itab_header TYPE STANDARD TABLE OF vbak INITIAL SIZE 0.
Internal Table for Item Sales Order
DATA : itab_item TYPE STANDARD TABLE OF vbap INITIAL SIZE 0.
DATA : wa_vbuk TYPE vbuk.
DATA : wa_vbak TYPE vbak.
DATA : vbeln_low TYPE vbak-vbeln,
vbeln_high TYPE vbak-vbeln.
DATA : it_bdcdata_tab TYPE STANDARD TABLE OF bdcdata INITIAL SIZE 0 WITH HEADER LINE.
----
CLASS event_handle DEFINITION
----
*
----
CLASS event_handle DEFINITION.
PUBLIC SECTION.
METHODS : handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
METHODS : handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS. "event_handle DEFINITION
----
CLASS event_handle IMPLEMENTATION
----
*
----
CLASS event_handle IMPLEMENTATION.
METHOD handle_double_click.
PERFORM double_click USING e_row .
ENDMETHOD. "handle_double_click
METHOD handle_data_changed.
PERFORM data_changed USING er_data_changed.
ENDMETHOD. "handle_data_changed
ENDCLASS. "event_handle IMPLEMENTATION
DATA : event_handler TYPE REF TO event_handle.
9001
PROCESS BEFORE OUTPUT.
MODULE status_9001.
*
PROCESS AFTER INPUT.
MODULE user_command_9001.
CHAIN.
FIELD vbeln_low.
FIELD vbeln_high.
module validate.
ENDCHAIN.
9002
PROCESS BEFORE OUTPUT.
MODULE STATUS_9002.
module display_item.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_9002.
9000
PROCESS BEFORE OUTPUT.
MODULE status_9000.
MODULE display_alv.
*
PROCESS AFTER INPUT.
MODULE user_command_9000.
INPUT_OOPSALV
&----
*& Include MY01I01
&----
&----
*& Module USER_COMMAND_9000 INPUT
&----
text
----
MODULE user_command_9000 INPUT.
CASE sy-ucomm.
WHEN 'BACK1'.
LEAVE TO SCREEN 9001.
WHEN 'STOP1'.
LEAVE TO SCREEN 9001.
WHEN 'END1'.
LEAVE PROGRAM.
ENDCASE .
ENDMODULE. " USER_COMMAND_9000 INPUT
&----
*& Module USER_COMMAND_9001 INPUT
&----
text
----
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'STOP'.
LEAVE TO SCREEN 0.
WHEN 'END'.
LEAVE PROGRAM.
ENDCASE .
ENDMODULE. " USER_COMMAND_9001 INPUT
&----
*& Module validate INPUT
&----
text
----
MODULE validate INPUT.
DATA : low(10) TYPE n,
high(10) TYPE n.
low = vbeln_low.
high = vbeln_high.
IF vbeln_low IS NOT INITIAL.
SELECT SINGLE * FROM vbak WHERE vbeln = low.
IF sy-subrc <> 0.
MESSAGE e000(sy) WITH 'Sales Order Number Invalid'.
ENDIF.
ENDIF.
IF vbeln_high IS NOT INITIAL.
SELECT SINGLE * FROM vbak WHERE vbeln = high.
IF sy-subrc <> 0.
MESSAGE e000(sy) WITH 'Sales Order Number Invalid'.
ENDIF.
ENDIF.
ENDMODULE. " validate INPUT
&----
*& Module USER_COMMAND_9002 INPUT
&----
text
----
MODULE user_command_9002 INPUT.
CASE sy-ucomm.
WHEN 'BACK2'.
LEAVE TO SCREEN 9000.
WHEN 'STOP2'.
LEAVE TO SCREEN 9001.
WHEN 'END2'.
LEAVE PROGRAM.
WHEN OTHERS.
LEAVE TO SCREEN 9000.
ENDCASE .
ENDMODULE. " USER_COMMAND_9002 INPUT
OUTPUT SUBROUTINES
&----
*& Include MY01O01
&----
&----
*& Module STATUS_9000 OUTPUT
&----
text
----
MODULE status_9000 OUTPUT.
SET PF-STATUS 'ZSTAT1'.
SET TITLEBAR 'ZTITLE'.
ENDMODULE. " STATUS_9000 OUTPUT
&----
*& Module display_alv OUTPUT
&----
text
----
MODULE display_alv OUTPUT.
IF alv_grid IS INITIAL.
CREATE OBJECT custom_container
EXPORTING
container_name = custom_control_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6
.
CREATE OBJECT alv_grid
EXPORTING
i_parent = custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5
.
CREATE OBJECT event_handler.
SET HANDLER event_handler->handle_double_click FOR alv_grid.
SET HANDLER event_handler->handle_data_changed FOR alv_grid.
ELSE.
CALL METHOD alv_grid->refresh_table_display
EXPORTING
i_soft_refresh = 'X'
EXCEPTIONS
finished = 1
OTHERS = 2.
ENDIF.
PERFORM fill_internaltable.
PERFORM prepare_fieldcatalog.
PERFORM prepare_layout.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAK'
is_layout = gt_layout
CHANGING
it_outtab = itab_header[]
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDMODULE. " display_alv OUTPUT
&----
*& Module STATUS_9001 OUTPUT
&----
text
----
MODULE status_9001 OUTPUT.
SET PF-STATUS 'ZSTAT0'.
SET TITLEBAR 'ZTITLE1'.
ENDMODULE. " STATUS_9001 OUTPUT
&----
*& Module STATUS_9002 OUTPUT
&----
text
----
MODULE status_9002 OUTPUT.
SET PF-STATUS 'ZSTAT3'.
SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_9002 OUTPUT
&----
*& Module display_item OUTPUT
&----
text
----
MODULE display_item OUTPUT.
DATA : lv_fieldcat TYPE slis_t_fieldcat_alv.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = 'VBAP'
CHANGING
ct_fieldcat = lv_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = 'SET_STATUS'
I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME =
IS_LAYOUT =
it_fieldcat = lv_fieldcat
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IR_SALV_LIST_ADAPTER =
IT_EXCEPT_QINFO =
I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = itab_item
EXCEPTIONS
program_error = 1
OTHERS = 2
.
LEAVE TO SCREEN 9000.
ENDMODULE. " display_item OUTPUT
SUBROUTINES
&----
*& Include MY01F01
&----
&----
*& Form fill_internaltable
&----
FORM fill_internaltable .
DATA : low(10) TYPE n,
high(10) TYPE n.
low = vbeln_low.
high = vbeln_high.
SELECT * FROM vbak
INTO TABLE itab_header
WHERE vbeln BETWEEN low AND high .
ENDFORM. " fill_internaltable
&----
*& Form prepare_fieldcatalog
&----
FORM prepare_fieldcatalog .
DATA : ls_fieldcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'VBAK'
CHANGING
ct_fieldcat = gt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
LOOP AT gt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN 'ERNAM'.
ls_fieldcat-no_out = 'X'.
MODIFY gt_fieldcat FROM ls_fieldcat.
WHEN 'VBELN'.
ls_fieldcat-outputlen = '20'.
MODIFY gt_fieldcat FROM ls_fieldcat.
WHEN 'LIFSK'.
ls_fieldcat-edit = 'X'.
MODIFY gt_fieldcat FROM ls_fieldcat.
ENDCASE.
ENDLOOP.
ENDFORM. " prepare_fieldcatalog
&----
*& Form Prepare_layout
&----
FORM prepare_layout .
gt_layout-zebra = 'X'.
gt_layout-grid_title = 'Sales Order'.
ENDFORM. " Prepare_layout
&----
*& Form double_click
&----
text
----
--> p1 text
<-- p2 text
----
FORM double_click USING e_row TYPE lvc_s_row .
DATA : wa_header TYPE vbak.
READ TABLE itab_header INTO wa_header INDEX e_row-index.
SELECT * FROM vbap
INTO TABLE itab_item
WHERE vbeln = wa_header-vbeln.
CALL SCREEN 9002.
ENDFORM. " double_click
&----
*& Form data_changed
&----
text
----
-->P_ER_data_changed text
----
FORM data_changed USING p_er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
DATA : changed_values TYPE lvc_t_modi.
DATA : good_cells TYPE lvc_t_modi.
DATA : wa TYPE LINE OF lvc_t_modi.
changed_values = p_er_data_changed->mt_mod_cells.
LOOP AT changed_values INTO wa.
SELECT SINGLE * FROM tvls WHERE lifsp = wa-value.
IF sy-subrc <> 0.
CONTINUE.
ELSE.
READ TABLE itab_header INTO wa_vbak INDEX 1.
wa_vbak-lifsk = wa-value.
PERFORM bdc_run USING wa_vbak.
ENDIF.
ENDLOOP.
ENDFORM. " data_changed
&----
*& Form bdc_run
&----
text
----
-->P_WA_VBAK text
----
FORM bdc_run USING p_wa_vbak TYPE vbak.
REFRESH : it_bdcdata_tab.
PERFORM bdc_dynpro USING 'SAPMV45A' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VBAK-VBELN'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'VBAK-VBELN'
p_wa_vbak-vbeln.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=T\01'.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=KDE2'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV45A-MABNR(04)'.
PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SICH'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VBAK-LIFSK'.
PERFORM bdc_field USING 'VBAK-LIFSK'
p_wa_vbak-lifsk.
CALL TRANSACTION 'VA02' USING it_bdcdata_tab MODE 'N' UPDATE 'A'.
COMMIT WORK.
ENDFORM. " bdc_run
&----
*& Form bdc_dynpro
&----
text
----
-->PROGRAM text
-->DYNPRO text
----
FORM bdc_dynpro USING program dynpro.
CLEAR it_bdcdata_tab.
it_bdcdata_tab-program = program.
it_bdcdata_tab-dynpro = dynpro.
it_bdcdata_tab-dynbegin = 'X'.
APPEND it_bdcdata_tab.
ENDFORM. "BDC_DYNPRO
----
Insert field *
----
FORM bdc_field USING fnam fval.
CLEAR it_bdcdata_tab.
it_bdcdata_tab-fnam = fnam.
it_bdcdata_tab-fval = fval.
APPEND it_bdcdata_tab.
ENDFORM. "BDC_FIELD
&----
*& Form SET_STATUS
&----
text
----
-->LT_EXTAB text
----
FORM set_status USING lt_extab TYPE any.
SET PF-STATUS 'ZSTAT2'.
ENDFORM. "SET_STATUS
2007 Dec 20 5:53 AM
Hi Sayak,
For ALV Grid you need to use fiedcat.U should fieldcat in declaration part I will give u the sample coding below just have a review over this code you wil get enough idea.
This is the sample program just copy and paste this code.You will get a overview after reviewing this code.
Report ZDEMO_ALVGRID *
*& *
&----
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
&----
REPORT zdemo_alvgrid .
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.
*********************************************************************
Just have a look @ this link it will give you more idea of ALV which is a pdf file.
Thanks,
Sakthi C
*Rewards if useful*
2007 Dec 20 5:58 AM
Hi Sayak Roy,
There are different ways you can use the alv grid class.
It all depends on the class you are using .
If you are using the class cl_gui_alv_grid then you have to create a screen that containing the custom container.
If you are using the class cl_salv_table then don't need to define any custom container for getting the ALV grid.
Here I am copying the Example of both the classes .
Now its all depends upon you which class you prefer to use.
Example 1 : cl_gui_alv_grid
*
o
+ Global data definitions for ALV
ALV Grid instance reference
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .
*
o
+
Name of the custom control added on the screen
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' .
*
o
+
Custom container instance reference
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .
*
o
+
Field catalog table
DATA gt_fieldcat TYPE lvc_t_fcat .
*
o
+
Layout structure
DATA gs_layout TYPE lvc_s_layo .
*
o
+
Internal table holding list data
DATA BEGIN OF gt_list OCCURS 0 .
INCLUDE STRUCTURE SFLIGHT .
*--In further sections, some additional fields will added here
*--for some functionality
DATA END OF gt_list .
DATA :gt_sflight like standard TABLE OF gt_list.
START-OF-SELECTION.
CALL SCREEN '0400'.
&----
*& Module STATUS_0400 OUTPUT
&----
text
-
MODULE STATUS_0400 OUTPUT.
SET PF-STATUS 'ZMNU'.
perform display_alv.
ENDMODULE. " STATUS_0400 OUTPUT
&----
*& Module USER_COMMAND_0400 INPUT
&----
text
-
MODULE USER_COMMAND_0400 INPUT.
CASE SY-UCOMM.
WHEN 'BACK' OR 'EXIT' OR 'RW'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0400 INPUT
&----
*& Form display_alv
&----
text
-
form display_alv.
SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT UP TO 30 ROWS.
IF gr_alvgrid IS INITIAL .
*----Creating custom container instance
CREATE OBJECT gr_ccontainer
EXPORTING
container_name = gc_custom_control_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6 .
IF sy-subrc 0.
--Exception handling
ENDIF.
*----Creating ALV Grid instance
CREATE OBJECT gr_alvgrid
EXPORTING
i_parent = gr_ccontainer
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5 .
IF sy-subrc 0.
*--Exception handling
ENDIF.
*----Preparing field catalog.
PERFORM prepare_field_catalog CHANGING gt_fieldcat .
*----Preparing layout structure
PERFORM prepare_layout CHANGING gs_layout .
*----Here will be additional preparations
*--e.g. initial sorting criteria, initial filtering criteria, excluding
*--functions
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
is_layout = gs_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
CHANGING
it_outtab = gt_sflight[]
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4 .
IF sy-subrc 0.
--Exception handling
ENDIF.
ELSE .
CALL METHOD gr_alvgrid->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2 .
IF sy-subrc 0.
*--Exception handling
ENDIF.
ENDIF .
endform. "display_alv
&----
*& Form prepare_field_catalog
&----
text
-
-->PT_FIELDCATtext
-
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
*---Preparing field catalog manually
*DATA ls_fcat type lvc_s_fcat .
*ls_fcat-fieldname = 'CARRID' .
*ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '3' .
*ls_fcat-coltext = 'Carrier ID' .
*ls_fcat-seltext = 'Carrier ID' .
*ls_fcat-drdn_hndl = '1' .
*APPEND ls_fcat to pt_fieldcat .
*CLEAR ls_fcat .
*ls_fcat-fieldname = 'CONNID' .
*ls_fcat-ref_table = 'SFLIGHT' .
*ls_fcat-ref_table = 'CONNID' .
*ls_fcat-outputlen = '3' .
*ls_fcat-coltext = 'Connection ID' .
*ls_fcat-seltext = 'Connection ID' .
*APPEND ls_fcat to pt_fieldcat .
*---Preparing field catalog semi-automatically
DATA ls_fcat type lvc_s_fcat .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc 0.
*--Exception handling
ENDIF.
LOOP AT pt_fieldcat INTO ls_fcat .
CASE ls_fcat-fieldname .
WHEN 'CARRID' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'Airline Carrier ID' .
ls_fcat-drdn_hndl = '1' .
MODIFY pt_fieldcat FROM ls_fcat .
WHEN 'PAYMENTSUM' .
ls_fcat-no_out = 'X' .
MODIFY pt_fieldcat FROM ls_fcat .
ENDCASE .
ENDLOOP .
ENDFORM . "prepare_field_catalog
&----
*& Form prepare_layout
&----
text
-
-->PS_LAYOUT text
-
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X' .
ps_layout-grid_title = 'Flights' .
ps_layout-smalltitle = 'X' .
ENDFORM. " prepare_layout
Example 2: cl_salv_table
data: gt_outtab type table of sflight.
data: toolbar type ref to cl_salv_functions_list .
data: gr_table type ref to cl_salv_table.
data: lr_aggregations type ref to cl_salv_aggregations.
data: lr_groups type ref to cl_salv_sorts .
select * from sflight into corresponding fields of table gt_outtab.
call method cl_salv_table=>factory
importing
r_salv_table = gr_table
changing
t_table = gt_outtab.
lr_aggregations = gr_table->get_aggregations( ).
toolbar = gr_table->get_functions( ) .
toolbar->set_all(
value = if_salv_c_bool_sap=>true
).
lr_aggregations->clear( ).
lr_groups = gr_table->get_sorts( ) .
lr_groups->clear( ).
try.
lr_groups->add_sort(
columnname = 'CARRID'
position = 8
subtotal = abap_true
sequence = if_salv_c_sort=>sort_up ).
catch cx_salv_not_found cx_salv_data_error cx_salv_existing.
endtry.
try.
lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ).
catch cx_salv_not_found cx_salv_data_error cx_salv_existing.
endtry.
gr_table->display( ).
Reward points, if useful.
Regards,
Manoj Kumar
2007 Dec 20 5:59 AM
hi Sayak.,
follow the approach.
To do this, you must:
Create an instance of the ALV grid control and integrate it into a screen.
Select the data to be displayed and pass it together with a description of the fields to the
instance.
Creating an ALV Grid Control
You instantiate an ALV grid control in the same way as other controls:
Declare reference variables for the ALV grid control and the container. In addition, declare an
internal table that you fill with selected data later on:
DATA: grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container
gt_sflight TYPE TABLE OF sflight.
In order to integrate a control into a screen, you can use four different container
controls
Create a standard screen and mark an area for the custom container control in the graphical
Screen Painter (icon identified by letter 'C'). Assign name CCCONTAINER to this area.
In the PBO module of the screen, you must now instantiate the container control and the ALV grid control. By doing this, you create a link between the container control and the screen, using the container created in the Screen Painter. Using parameter parent, you define the container control as the parent of the ALV grid control:
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
CONTAINER_NAME = 'CCCONTAINER'.
CREATE OBJECT GRID1
EXPORTING
I_PARENT = g_custom_container.
ENDIF.
The IF query of reference variable g_custom_container ensures that the
instances are only generated when the PBO is processed for the first time.
Normally, you must use method cl_gui_cfw=>flush to pass the methods called
to the frontend. However, since the Control Framework performs an automatic flush
at the end of the PBO module, this step is not required here.
When you start the program, although the two instances (the container control and the ALV grid control) are generated, they are not visible.
Displaying a List in the ALV Control
Once you have created the ALV grid control and integrated it into a screen using a container
control, you must pass the data and its structure to the ALV grid control:
Fill the internal table with data:
SELECT * FROM sflight INTO TABLE gt_sflight.
Pass the output table and the structure data to the ALV grid control. Again, ensure to call this
method only once after the ALV grid control is created:
CALL METHOD grid->set_table_for_first_display
EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING IT_OUTTAB = gt_sflight.
In this case, the structure data is provided through the Data Dictionary. The ALV grid
control gets the field information from table SFLIGHT and displays all fields of the
table.
*Reward points if useful*