04-30-2008 6:08 AM
Hi Team,
Can any one give me a small example about the oops ALV like how to build the container and assign a grid to the container inorder to display.
Thank you,
04-30-2008 7:20 AM
hi,
create a layout which conatin one custom control in se51 assign a name to it.
example
*Name of the custom control added on the screen
DATA GC_CUSTOM_CONTROL_NAME TYPE SCRFNAME VALUE 'CC_ALV' . (here the cc_alv is the name assigned to the custom control)
Custom container instance reference
DATA GR_CCONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER .
ALV Grid instance reference
DATA GR_ALVGRID TYPE REF TO CL_GUI_ALV_GRID .
Field catalog table
DATA GT_FIELDCAT TYPE LVC_T_FCAT .
Layout structure
DATA GS_LAYOUT TYPE LVC_S_LAYO .
declare the fields
declare the internal table and work area
&----
*
*& Module STATUS_0001 OUTPUT
&----
text
----
create an object for the custom container
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
.
create an object for grid
CREATE OBJECT GR_ALVGRID
EXPORTING
I_PARENT = GR_CCONTAINER.
select query
PERFORM FIELD_CATALOG.
PERFORM GRID_DISPLAY.
ENDMODULE.
form fieldcat.
.....................
.......................
form grid_display.
CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = pass the internal table name IT_FIELDCATALOG = GT_FIELDCAT
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
OTHERS = 4
.
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.
reward if useful
thanks and regards
04-30-2008 6:22 AM
04-30-2008 7:20 AM
hi,
create a layout which conatin one custom control in se51 assign a name to it.
example
*Name of the custom control added on the screen
DATA GC_CUSTOM_CONTROL_NAME TYPE SCRFNAME VALUE 'CC_ALV' . (here the cc_alv is the name assigned to the custom control)
Custom container instance reference
DATA GR_CCONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER .
ALV Grid instance reference
DATA GR_ALVGRID TYPE REF TO CL_GUI_ALV_GRID .
Field catalog table
DATA GT_FIELDCAT TYPE LVC_T_FCAT .
Layout structure
DATA GS_LAYOUT TYPE LVC_S_LAYO .
declare the fields
declare the internal table and work area
&----
*
*& Module STATUS_0001 OUTPUT
&----
text
----
create an object for the custom container
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
.
create an object for grid
CREATE OBJECT GR_ALVGRID
EXPORTING
I_PARENT = GR_CCONTAINER.
select query
PERFORM FIELD_CATALOG.
PERFORM GRID_DISPLAY.
ENDMODULE.
form fieldcat.
.....................
.......................
form grid_display.
CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = pass the internal table name IT_FIELDCATALOG = GT_FIELDCAT
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
OTHERS = 4
.
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.
reward if useful
thanks and regards
04-30-2008 7:22 AM
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
http://help.sap.com/saphelp_nw2004s/helpdata/en/5e/88d440e14f8431e10000000a1550b0/frameset.htm
http://sgstocks.tripod.com/alvgrid_control.htm
http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://esnips.com/doc/b708766f-a934-42a1-8064-c4de75b48fc4/Sample-Program-of-alv-using-oops.ppt
http://esnips.com/doc/2d953590-e8c5-490c-a607-d1ab7cf517d7/ALV.pdf
Best Regards,
Vibha
Please mark all the helpful answers
04-30-2008 7:37 AM
Hi,
pls find the following program of ALV using oops.
data declarations
data : itab type standard table of mara,"Output Internal table
i_fieldcat type standard table of lvc_s_fcat,"Field catalog
wa type mara,
w_variant type disvariant,
o_docking type ref to cl_gui_docking_container,
"Docking Container
o_grid type ref to cl_gui_alv_grid."Grid
select * from mara into table itab up to 100 rows.
call screen 9000.
&----
*& Module STATUS_9000 OUTPUT
&----
text
----
module status_9000 output.
if o_docking is initial.
set pf-status 'ZSTATUS'.
set titlebar 'ZTITLE'.
create the docking container
create object o_docking
exporting
ratio = '95'
.
if sy-subrc eq 0.
creating the grid
create object o_grid
exporting
i_parent = o_docking
.
endif.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'MARA'
changing
ct_fieldcat = i_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
w_variant-report = sy-repid.
display the output
call method o_grid->set_table_for_first_display
exporting
is_variant = w_variant
i_save = 'A'
changing
it_outtab = itab
it_fieldcatalog = i_fieldcat
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
if sy-subrc 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.
endmodule. " STATUS_9000 OUTPUT
&----
*& Module USER_COMMAND_9000 INPUT
&----
text
----
module user_command_9000 input.
data lv_ucomm type sy-ucomm.
lv_ucomm = sy-ucomm.
case lv_ucomm.
when 'CANCEl' or 'EXIT'.
perform free_objects.
leave program.
when 'BACK'.
perform free_objects.
set screen '0'.
leave screen.
endcase.
endmodule. " USER_COMMAND_9000 INPUT
&----
*& Form free_objects
&----
text
----
--> p1 text
<-- p2 text
----
form free_objects .
call method o_grid->free
exceptions
cntl_error = 1
cntl_system_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.
call method o_docking->free
exceptions
cntl_error = 1
cntl_system_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.
endform. " free_objects
Regards,
Raja.