‎2007 Aug 10 4:14 PM
Hi,
i am doing the ALV grid display report using oops concept please any one send me the simple alv grid display report code.
Thanks,
Hari.
‎2007 Aug 10 4:18 PM
Hi,
There are lot of example programs in the Package SLIS.
Regards,
Sesh
‎2007 Aug 10 4:18 PM
Hi,
There are lot of example programs in the Package SLIS.
Regards,
Sesh
‎2007 Aug 10 4:28 PM
Hi
Check this for basic concepts of OOPS
Tabstrip
Editable ALV
Tree
http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_usrint.htm
General Tutorial for OOPS
http://www.sapdevelopment.co.uk/reporting/alvhome.htm
http://www.sap-img.com/abap/what-is-alv-programming.htm
http://www.sap-img.com/abap-function.htm
http://www.geocities.com/mpioud/Abap_programs.html
http://www.sapdevelopment.co.uk/reporting/alv/alvtree%5Calvtree_basic.htm
http://esnips.com/doc/ad20dca9-6182-4903-8d8f-96a66dc8590c/ALV.pdf
http://www.sap-img.com/abap-function.htm
Classical ALV:
http://www.geocities.com/mpioud/Abap_programs.html
OOPS ALV:
<b>Reward points for useful Answers</b>
Regards
Anji
‎2007 Aug 10 4:49 PM
hi
good
Search the ABAP Objects forum for my sample reports (beginning with ZUS_SDN). All of them contain at least one example of OO-based event handling. These are simplified reports showing the only the crucial points of event handling.
BCALV_GRID_01
BCALV_GRID_02
BCALV_GRID_03
BCALV_GRID_04
BCALV_GRID_05
BCALV_GRID_06
BCALV_GRID_07
BCALV_GRID_08
BCALV_GRID_09
BCALV_GRID_10
BCALV_GRID_11
BCALV_GRID_AND_POPUP
BCALV_GRID_DEMO
Thanks
mrutyun^
‎2007 Aug 10 5:19 PM
STEPS:
1. Call a screen.
2. Go to the screen layout and add a custom control .
3. Go to attribute and give a name to the custom control (Ex: 'CUSTOM_CONTROL').
4. Give a name to the ok_code ( Ex: ok_code) in the attribute of the screen.
5. Data Declaration section:
I. Data declaration for ALV
a. Declare a object type cl_gui_alv_grid for ALV Grid instance referance
b. Declare a object type cl_gui_custom_container for Custom container instance referance
c. Declare Name of the custom control added to the screen
d. Declare field catalog table of type lvc_t_fcat.
e. Declare layout of type lvc_s_layo.
II. Data declaration for fetching data as input
III. Declare variables for ok_code.
6. Set pf-status and titlebar for the screen.
7. Write PBO. IN PBO do the following:
i. Check whether gr_alvgrid is initial.
a. If yes do the following.
Create instance for custom container (gr_container) by passing the container name.
Create instance for ALV grid by passing the custom control instance reference.
select the material data from database
Build field ctalog
Build layout
Call method set_table_for_first_display for the object gr_alvgrid(alv grid instance reference) with passing layout, input table and field catalog.
b. If NO do the following.
Call method refresh_table_display for the object gr_alvgrid(alv grid instance reference).
ii.
8. Write PAI. IN PAI do the following:
Check the ok_code, if Exit then leave from program.
All the user commands where user do any actions in the screen will be code here . For this purpose check the value of ok_code and according that ok_code, code the functionality for the particular user actions.
REPORT zdemoab.
************************************
*DATA DECLARATION
*************************************
*---Global data deckaration for alv
*--ALV Grid instance referance
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,
*--Name of the custom control added to the screen
gc_custom_control_name TYPE scrfname VALUE 'CUSTOM_CONTROL',
*--Custom container instance referance
gr_container TYPE REF TO cl_gui_custom_container,
*--Field catalog table
gt_fieldcat TYPE lvc_t_fcat,
*--Layout structure
gs_layout TYPE lvc_s_layo.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
*---Input table
TYPES: BEGIN OF t_mara,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
END OF t_mara.
TYPES: t_mara_table TYPE STANDARD TABLE OF t_mara.
DATA: gt_mara TYPE STANDARD TABLE OF t_mara.
************************************
*MAIN
*************************************
CALL SCREEN 101.
*&---------------------------------------------------------------------*
*& Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0101 OUTPUT.
SET PF-STATUS 'STATUS-0101'.
SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module display_alv OUTPUT
*&---------------------------------------------------------------------*
MODULE display_alv OUTPUT.
IF gr_alvgrid IS INITIAL.
*----Create custom container instance
CREATE OBJECT gr_container
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*----Create ALV grid instance
CREATE OBJECT gr_alvgrid
EXPORTING
i_parent = gr_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5 .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* select the material data from database
PERFORM get_input CHANGING gt_mara..
* prepare field catalog
PERFORM prepare_fieldcatalog CHANGING gt_fieldcat.
* prepare layout
PERFORM prepare_layout CHANGING gs_layout.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = gt_mara[]
it_fieldcatalog = gt_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.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDMODULE. " display_alv OUTPUT
*&---------------------------------------------------------------------*
*& Form get_input
*&---------------------------------------------------------------------*
FORM get_input CHANGING gt_mara_table TYPE t_mara_table.
SELECT matnr mtart matkl meins INTO TABLE gt_mara_table
FROM mara UP TO 10 ROWS.
ENDFORM. " get_input
*&---------------------------------------------------------------------*
*& Form prepare_fieldcatalog
*&---------------------------------------------------------------------*
FORM prepare_fieldcatalog CHANGING gt_fieldcat_table TYPE lvc_t_fcat.
DATA: ls_fcat TYPE lvc_s_fcat,
l_col_no TYPE i.
CLEAR: ls_fcat,
l_col_no .
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 18.
ls_fcat-coltext = 'Material No'.
ls_fcat-seltext = 'Material No'.
APPEND ls_fcat TO gt_fieldcat_table.
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MTART'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 4.
ls_fcat-coltext = 'Material type'.
ls_fcat-seltext = 'Material type'.
APPEND ls_fcat TO gt_fieldcat_table.
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MATKL'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 9.
ls_fcat-coltext = 'Material group'.
ls_fcat-seltext = 'Material group'.
APPEND ls_fcat TO gt_fieldcat_table.
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MEINS'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 3.
ls_fcat-coltext = 'Unit'.
ls_fcat-seltext = 'Unit'.
APPEND ls_fcat TO gt_fieldcat_table.
CLEAR: ls_fcat,
l_col_no .
ENDFORM. " prepare_fieldcatalog
*&---------------------------------------------------------------------*
*& Form prepare_layout
*&---------------------------------------------------------------------*
FORM prepare_layout CHANGING p_gs_layout TYPE lvc_s_layo.
p_gs_layout-zebra = 'X'.
p_gs_layout-grid_title = 'Material'.
p_gs_layout-smalltitle = 'X'.
ENDFORM. " prepare_layout
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0101 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
ENDMODULE. " USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
LEAVE PROGRAM.
ENDFORM. " exit_program
‎2007 Aug 10 5:20 PM
DATA: g_container TYPE scrfname VALUE 'CUSTOM CONTROL',
g_custom_container TYPE REF TO cl_gui_custom_container,
g_grid TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
.
DATA: gt_outtab TYPE TABLE OF sflight.
*---------------------------------------------------------------------*
* MAIN *
*---------------------------------------------------------------------*
CALL SCREEN 100 STARTING AT 1 1..
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module pbo OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo OUTPUT.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT g_grid
EXPORTING
i_parent = g_custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5 .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
gs_layout-edit = 'X'.
SELECT * FROM sflight INTO TABLE gt_outtab UP TO 10 ROWS.
*§1.Set status of all cells to editable using the layout structure.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab
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.
*§2.Use SET_READY_FOR_INPUT to allow editing initially.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDIF.
ENDMODULE. " pbo OUTPUT
*&---------------------------------------------------------------------*
*& Module pai INPUT
*&---------------------------------------------------------------------*
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'SWITCH'.
PERFORM switch_edit_mode.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMODULE. " pai INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
LEAVE PROGRAM.
ENDFORM. " exit_program
*&---------------------------------------------------------------------*
*& Form switch_edit_mode
*&---------------------------------------------------------------------*
FORM switch_edit_mode .
*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
IF g_grid->is_ready_for_input( ) EQ 0.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ELSE.
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
ENDFORM. " switch_edit_mode