09-25-2008 9:52 AM
can someone tell me what i have forget in this coding, I alwaya get a dump when I run the program.
DATA: r_row TYPE REF TO cl_gui_alv_grid,
lt_selected_rows TYPE lvc_t_row.
CALL METHOD r_row->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.
09-25-2008 10:06 AM
Hello Muhammet
Before you collect the selected rows you need to create your grid instance, e.g.:
DATA: go_grid TYPE REF TO cl_gui_alv_grid.
...
CREATE OBJECT go_grid
IMPORTING
...
.
...
" Now you can retrieve the selected rows, e.g.:
DATA: lt_rows TYPE lvc_t_row,
ls_row TYPE lvc_s_row.
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = lt_rows.
For a sample report have a look at thread
Regards
Uwe
09-25-2008 9:58 AM
Hi,
You havent instantiated the object..
Do this way...
DATA: r_row TYPE REF TO cl_gui_alv_grid,
lt_selected_rows TYPE lvc_t_row.
CREATE OBJECT r_row. " Creating the object for the class CL_GUI_ALV_GRID
" or Use PATTERN to create object for you.
CALL METHOD r_row->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.
Hope this would solve your issue.
Good luck
Narin
09-25-2008 10:00 AM
I had try this befor I post the problem but when I use
CREATE OBJECT r_row.
I get a syntax error "i_parent is needed" but I am not sure which actual parameter I have use for i_parent.
09-25-2008 10:05 AM
The constructor (CREATE OBJECT) requires an importing parameter of i_parent. In this case it is the name of the custom container. See program BCALV_GRID_01 module pbo:
data: custom_container type ref to cl_gui_custom_container,
grid1 type ref to cl_gui_alv_grid.
...
if custom_container is initial.
* create a custom container control for our ALV Control
create object custom_container
exporting
container_name = mycontainer
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
* create an instance of alv control
create object grid1
exporting i_parent = custom_container.
r_row doesn't seem to me a good name for an instance of an alv grid, by the way.
matt
09-25-2008 10:05 AM
Hi,
The parent parameter refers to the container instance.
CREATE OBJECT go_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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*----Creating ALV Grid instance
CREATE OBJECT go_alvgrid
EXPORTING
i_parent = go_ccontainer
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.
Thanks,
KD
09-25-2008 10:14 AM
Hi,
You need to create an object for the container and then the GRID as GRID is present in the container.
You have to tell the container that so and so grid is to be specified. so first create Container Instance and
then GRID instance..
Please check the below example..
TYPE-POOLS: z1152.
*"Table declarations...................................................
TABLES:
spfli.
*"Selection screen elements............................................
SELECT-OPTIONS:
s_carrid FOR spfli-carrid, " Airline code
s_connid FOR spfli-connid. " Flight connection number
*"--------------------------------------------------------------------*
* Internal table to hold spfli details *
*"--------------------------------------------------------------------*
DATA:
t_spfli TYPE
STANDARD TABLE
OF z1152_spfli,
wa_spfli LIKE LINE OF t_spfli. " Workarea for spfli details
*"--------------------------------------------------------------------*
* Internal table to hold field catalog details *
*"--------------------------------------------------------------------*
DATA:
t_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
DATA:
w_grid TYPE REF TO
cl_gui_alv_grid, " Grid reference
w_container TYPE REF TO
cl_gui_custom_container, " Container reference
w_layout TYPE lvc_s_layo, " Layout structure
w_cont_name TYPE
scrfname VALUE 'CC_ALV'. " Container name
*Calling screen
CALL SCREEN 1152.
*---------------------------------------------------------------------*
* Module status_1152 OUTPUT
*---------------------------------------------------------------------*
* This module is used to set the GUI Status
*---------------------------------------------------------------------*
MODULE status_1152 OUTPUT.
SET PF-STATUS 'ALV_GUI'.
ENDMODULE. " status_1152 OUTPUT
*---------------------------------------------------------------------*
* Module display_alv OUTPUT
*---------------------------------------------------------------------*
* This module is used to display ALV
*---------------------------------------------------------------------*
MODULE display_alv OUTPUT.
PERFORM get_spfli_details.
PERFORM container_reference.
PERFORM grid_reference.
PERFORM prepare_field_catalog.
PERFORM prepare_grid_layout.
PERFORM display_alv.
ENDMODULE. " display_alv OUTPUT
*---------------------------------------------------------------------*
* Module USER_COMMAND_1152 INPUT
*---------------------------------------------------------------------*
* This module is used to act upon user interaction in the output
*---------------------------------------------------------------------*
MODULE user_command_1152 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE.
ENDCASE. " CASE SY-UCOMM
ENDMODULE. " USER_COMMAND_1152 INPUT
*---------------------------------------------------------------------*
* Form container_reference
*---------------------------------------------------------------------*
* This subroutine is used to create instance for container class
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
FORM container_reference .
*Creating custom container reference
CREATE OBJECT w_container " Container Instance
EXPORTING
* PARENT =
container_name = w_cont_name " Container name
* STYLE =
* LIFETIME = lifetime_default
* REPID =
* DYNNR =
* NO_AUTODEF_PROGID_DYNNR =
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 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " container_reference
*---------------------------------------------------------------------*
* Form grid_reference
*---------------------------------------------------------------------*
* This subroutine is used to create instance for container class
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
FORM grid_reference .
CREATE OBJECT w_grid " Grid instance
EXPORTING
* I_SHELLSTYLE = 0
* I_LIFETIME =
i_parent = w_container " Specifying the parent for Grid and that is Container
* I_APPL_EVENTS = space
* I_PARENTDBG =
* I_APPLOGPARENT =
* I_GRAPHICSPARENT =
* I_NAME =
* I_FCAT_COMPLETE = SPACE
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 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " grid_reference
*&---------------------------------------------------------------------*
*& Form prepare_field_catalog
*&---------------------------------------------------------------------*
* This subroutine is used to define the field catalog
*----------------------------------------------------------------------*
* No interface parameters
*----------------------------------------------------------------------*
FORM prepare_field_catalog .
CLEAR:
wa_fcat,
t_fcat[].
wa_fcat-fieldname = 'CARRID'.
wa_fcat-ref_table = 'SPFLI'.
wa_fcat-ref_field = 'CARRID'.
wa_fcat-coltext = 'Airline Code'.
wa_fcat-seltext = 'Airline Code'.
APPEND wa_fcat TO t_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'CONNID'.
wa_fcat-ref_table = 'SPFLI'.
wa_fcat-ref_field = 'CONNID'.
wa_fcat-coltext = 'Connection ID'.
wa_fcat-seltext = 'Connection ID'.
APPEND wa_fcat TO t_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'CITYFROM'.
wa_fcat-ref_table = 'SPFLI'.
wa_fcat-ref_field = 'CITYFROM'.
wa_fcat-coltext = 'City from'.
wa_fcat-seltext = 'City from'.
APPEND wa_fcat TO t_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'CITYTO'.
wa_fcat-ref_table = 'SPFLI'.
wa_fcat-ref_field = 'CITYTO'.
wa_fcat-coltext = 'City to'.
wa_fcat-seltext = 'City to'.
APPEND wa_fcat TO t_fcat.
ENDFORM. " prepare_field_catalog
*---------------------------------------------------------------------*
* Form prepare_grid_layout
*---------------------------------------------------------------------*
* This subroutine is used to define the layout for the grid
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
FORM prepare_grid_layout .
w_layout-zebra = 'X'.
w_layout-grid_title = 'SPFLI Details'.
* w_layout-edit_mode = 'X'.
ENDFORM. " prepare_grid_layout
*---------------------------------------------------------------------*
* Form display_alv
*---------------------------------------------------------------------*
* This subroutine is used to display ALV
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
FORM display_alv .
w_grid->set_table_for_first_display(
EXPORTING
* I_BUFFER_ACTIVE = 'X'
* I_BYPASSING_BUFFER = I_BYPASSING_BUFFER
* I_CONSISTENCY_CHECK = I_CONSISTENCY_CHECK
* I_STRUCTURE_NAME = I_STRUCTURE_NAME
* IS_VARIANT = IS_VARIANT
* I_SAVE = I_SAVE
* I_DEFAULT = 'X'
is_layout = w_layout
* IS_PRINT = IS_PRINT
* IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS
* IT_TOOLBAR_EXCLUDING = IT_TOOLBAR_EXCLUDING
* IT_HYPERLINK = IT_HYPERLINK
* IT_ALV_GRAPHICS = IT_ALV_GRAPHICS
* IT_EXCEPT_QINFO = IT_EXCEPT_QINFO
* IR_SALV_ADAPTER = IR_SALV_ADAPTER
CHANGING
it_outtab = t_spfli
it_fieldcatalog = t_fcat
* IT_SORT = IT_SORT
* IT_FILTER = IT_FILTER
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " display_alv
*---------------------------------------------------------------------*
* Form get_spfli_details
*---------------------------------------------------------------------*
* This subroutine is used to get the spfli details
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
FORM get_spfli_details .
SELECT carrid
connid
cityfrom
cityto
FROM spfli
INTO TABLE t_spfli
WHERE carrid IN s_carrid
AND connid IN s_connid.
SORT t_spfli BY carrid connid.
ENDFORM. " get_spfli_details
Hope this would solve your issue.
Good luck
Narin
09-25-2008 10:06 AM
Hello Muhammet
Before you collect the selected rows you need to create your grid instance, e.g.:
DATA: go_grid TYPE REF TO cl_gui_alv_grid.
...
CREATE OBJECT go_grid
IMPORTING
...
.
...
" Now you can retrieve the selected rows, e.g.:
DATA: lt_rows TYPE lvc_t_row,
ls_row TYPE lvc_s_row.
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = lt_rows.
For a sample report have a look at thread
Regards
Uwe
09-25-2008 10:12 AM
now my coding looks like
DATA: r_row TYPE REF TO cl_gui_alv_grid,
lt_selected_rows TYPE lvc_t_row.
CREATE OBJECT r_row
EXPORTING
i_parent = g_custom_container1.
CALL METHOD r_row->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.
i am not sure if it works because i don't really know in which module i have to use it. i hav included it pai module of my dynrpo but i think this is wrong.
i think the coding is ok as i don't get a syntax error, but where i have to include it to get the row when i select a line of my alv.
09-25-2008 10:14 AM
Hello Muhammet
Have a look at the thread I mentioned before. There you will see when and where you should create the grid instance and where it makes sense to collect selected rows.
Regards
Uwe
09-25-2008 10:26 AM
I think I have problem to explain my case
I have included my coding in PAI of my dynrpo. But if I debug and select a row of my alc, pai is not executed, so I think that pai for my coding is not the wright place. I think I heard something like to register an event that the system know when I select a row.
I am sorry if I am not able to explain my problem , but I thank you for all your help.
09-25-2008 10:33 AM
I think it helps when I post my whole coding.
PAI module on user command:
PERFORM get_data.
CALL METHOD grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZSERIALNO'
is_layout = gs_layout
CHANGING
it_outtab = lt_displayold
it_fieldcatalog = lt_fct
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
DATA: r_row TYPE REF TO cl_gui_alv_grid,
lt_selected_rows TYPE lvc_t_row.
CREATE OBJECT r_row
EXPORTING
i_parent = g_custom_container1.
CALL METHOD r_row->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.
endmodule.
I also have the coding for my alv in the PBO module.
IF g_custom_container1 IS INITIAL.
CREATE OBJECT g_custom_container1
EXPORTING
container_name = 'CCCONTAINER1'.
CREATE OBJECT grid
EXPORTING
i_parent = g_custom_container1.
CALL METHOD grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZSERIALNO'
is_layout = gs_layout
CHANGING
it_outtab = lt_displayold
it_fieldcatalog = lt_fct
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDIF.
Does this help more?
09-25-2008 11:29 AM
ok i solve the problem, ther was a small mistake in my coding.
the old coding was:
DATA: r_grid TYPE REF TO cl_gui_alv_grid,
lt_selected_rows TYPE lvc_t_row.
*
CREATE OBJECT r_row
EXPORTING
i_parent = g_custom_container1.
*
CALL METHOD r_row->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.
i used r_row but this was wrong, i have to use grid, so now it run with
CALL METHOD grid->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.
if you see in my whole coding, i use grid to display my alv. and it works in my pai modul.
09-25-2008 11:38 AM
Hi Muhammet,
You would paste the code very earlier.. So that the problem would get solved very earlier...
Thats the best practice..
Good luck
Narin
09-25-2008 11:41 AM
Ok i will memorize it for the next time
Thank you all, all answers were very helpful.