‎2006 Nov 21 12:04 PM
Is it possible to display the Master table data in one ALV grid and a child table data, which is related to master table using primary key- foreign key relation, displayed in another ALV grid which is created dynamically based on the record selected by the user (data that correspond to the selected record is to be displayed on this second grid ) on the same screen at the same time ? If yes, please let me know the working logic, function modules or methods and if possible, the source code.
‎2006 Nov 21 12:09 PM
Hi aditya,
For this we can use BLOCK ALV Concept.
(to display two or more internal tables on the same screen)
(It will be shown as LIST and not GRID)
1. This simple program will give u an idea
of block alv.
2. It will print two alv
a) itab = table from t001
b) ptab = table from t000
3. Just copy paste in new program.
REPORT zam_temp54 .
type-pools : slis.
data : alvfc type slis_t_fieldcat_alv.
data : alvly type slis_layout_alv.
data : alvev type slis_t_event .
*----
DATA : BEGIN OF itab OCCURS 0.
include structure t001.
DATA: END OF itab.
DATA : BEGIN OF ptab OCCURS 0.
INCLUDE STRUCTURE t000.
DATA: END OF ptab..
*----
PARAMETERS : a TYPE c.
*----
start-of-selection.
*----
SELECT DATA
SELECT * FROM t001 into table itab.
select * from t000 into table ptab.
*----
INIT BLOCK ALV
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid.
*----
ADD INTERNAL TABLE ITAB
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = ALVFC.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = alvly
it_fieldcat = alvfc
i_tabname = 'ITAB'
it_events = alvev
TABLES
t_outtab = ITAB
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
*----
ADD INTERNAL TABLE PTAB
REFRESH ALVFC[].
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'PTAB'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = ALVFC.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = alvly
it_fieldcat = alvfc
i_tabname = 'PTAB'
it_events = alvev
TABLES
t_outtab = PTAB
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
*----
DISPLAY
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXCEPTIONS
program_error = 1
OTHERS = 2.
regards,
amit m.
‎2006 Nov 21 12:09 PM
Hi aditya,
For this we can use BLOCK ALV Concept.
(to display two or more internal tables on the same screen)
(It will be shown as LIST and not GRID)
1. This simple program will give u an idea
of block alv.
2. It will print two alv
a) itab = table from t001
b) ptab = table from t000
3. Just copy paste in new program.
REPORT zam_temp54 .
type-pools : slis.
data : alvfc type slis_t_fieldcat_alv.
data : alvly type slis_layout_alv.
data : alvev type slis_t_event .
*----
DATA : BEGIN OF itab OCCURS 0.
include structure t001.
DATA: END OF itab.
DATA : BEGIN OF ptab OCCURS 0.
INCLUDE STRUCTURE t000.
DATA: END OF ptab..
*----
PARAMETERS : a TYPE c.
*----
start-of-selection.
*----
SELECT DATA
SELECT * FROM t001 into table itab.
select * from t000 into table ptab.
*----
INIT BLOCK ALV
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid.
*----
ADD INTERNAL TABLE ITAB
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = ALVFC.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = alvly
it_fieldcat = alvfc
i_tabname = 'ITAB'
it_events = alvev
TABLES
t_outtab = ITAB
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
*----
ADD INTERNAL TABLE PTAB
REFRESH ALVFC[].
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'PTAB'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = ALVFC.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = alvly
it_fieldcat = alvfc
i_tabname = 'PTAB'
it_events = alvev
TABLES
t_outtab = PTAB
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
*----
DISPLAY
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXCEPTIONS
program_error = 1
OTHERS = 2.
regards,
amit m.
‎2006 Nov 21 12:16 PM
Hi Aditya,
Welcome to SDN
This is quite possible.
1.create two grids on same screen. say on first grid you display the master data.
2.now you can assign a click event object to this first grid.
3. Now whenever you click on first grid this event will be fired.
4. Here you can get the row number where the user clicked.
5. get the master data on that grid.
6. fetch the data from child table and populate second grid.
hope this helps.
award forum points to helpful answers.
‎2006 Nov 30 11:21 AM
Thanks Sandeep,
I followed the same procedure as suggested by you but with a little modification. I used the object based approach instead of a procedural one. What all I did, I am explaining so that it may be helpful to others also:
(1) I created one custom container and assigned one splitter container into that.
(2) In the two rows of the splitter container, I assigned two grid objects.
(3) Set one user defined class as an event-handler for the hot-spot click event of
CL_GUI_ALV_GRID class, equipped with a method that takes the clicked
row's ID and fetches data from master internal table.
(4) Called subroutines from within the methods to display the child:
(a)CALL METHOD GRID_2->SET_TABLE_FOR_FIRST_DISPLAY for first time
click on any of the rows of master .
(b) For any later click on the rows of master grid :--
CALL METHOD GRID_2->GET_FRONTEND_LAYOUT
(ii) CALL METHOD GRID_2->SET_FRONTEND_LAYOUT
(iii) CALL METHOD GRID_2->REFRESH_TABLE_DISPLAY.
Please check the logic and suggest any improvements you observe in that. In the end, I would like to thank all of you for your support and consideration.
Regards,
Aditya P. Srivastava