‎2008 Mar 15 10:51 AM
Hi,
When user chooses say X then the first data table with its fieldcatalog should be output and when he chooses Y then second data table with its fieldcatalog should be output.
I m transfering my output data table and fieldcatalog to global parameters: <DATA> and it_fieldcatalog, where <DATA> is the fieldsymbol of type table and it_fieldcatalog is of type lvc_t_fcat and then calling the following:
CREATE OBJECT g_container
EXPORTING
container_name = 'C_CONTAINER'.
CREATE OBJECT g_grid
EXPORTING
i_parent = g_container.
CALL METHOD g_grid->set_table_for_first_display
CHANGING
it_outtab = <DATA> it_fieldcatalog = it_fieldcatalog
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.
The problem i m facing is that when i user chooses X then the first output table's data is displayed in the ALV but when he chooses Y the same data is shown instead of second table's data.
Why the current data is not displayed though respective table and fieldcatalog tables match.
PLZ HELP!
‎2008 Mar 15 9:34 PM
Hello Annie
There must be something wrong with the refreshing of the ALV list output. The error is in the coding not shown.
Below you see sample report ZUS_SDN_ALV_SINGLE_SWITCH_DISP which shows a possible solution to your problem:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALV_SINGLE_SWITCH_DISP
*&
*&---------------------------------------------------------------------*
*& Thread: ALV data
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="783560"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_alv_single_switch_disp.
DATA:
gd_okcode TYPE ui_func,
*
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gd_tabname TYPE tabname,
gdo_data TYPE REF TO data,
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_knvv TYPE STANDARD TABLE OF knvv.
FIELD-SYMBOLS:
<gt_outtab> TYPE table.
PARAMETERS:
p_xknb1 RADIOBUTTON GROUP radi DEFAULT 'X',
p_xknvv RADIOBUTTON GROUP radi.
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1 UP TO 100 ROWS
WHERE bukrs = '1000'.
SELECT * FROM knvv INTO TABLE gt_knvv UP TO 100 ROWS
FOR ALL ENTRIES IN gt_knb1
WHERE kunnr = gt_knb1-kunnr.
PERFORM init_controls.
PERFORM set_output_data.
* Build fieldcatalog
PERFORM build_fieldcatalog.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
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.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
* Display data
CALL METHOD go_grid->set_table_for_first_display
CHANGING
it_outtab = <gt_outtab>
it_fieldcatalog = gt_fcat
EXCEPTIONS
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.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'TOGGLE'.
IF ( p_xknb1 = 'X' ).
p_xknb1 = ' '.
p_xknvv = 'X'.
ELSE.
p_xknb1 = 'X'.
p_xknvv = ' '.
ENDIF.
PERFORM set_output_data.
PERFORM build_fieldcatalog.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
REFRESH: gt_fcat. " !!! otherwise columns are appended
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = gd_tabname
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_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. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
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
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
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.
ENDFORM. " INIT_CONTROLS
*&---------------------------------------------------------------------*
*& Form SET_OUTPUT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_output_data .
* define local data
DATA: lo_typedescr TYPE REF TO cl_abap_typedescr,
lo_tabledescr TYPE REF TO cl_abap_tabledescr,
lo_strucdescr TYPE REF TO cl_abap_structdescr,
ld_relname TYPE string.
CLEAR: gdo_data,
gd_tabname.
UNASSIGN <gt_outtab>.
IF ( p_xknb1 = 'X' ).
GET REFERENCE OF gt_knb1 INTO gdo_data.
ELSE.
GET REFERENCE OF gt_knvv INTO gdo_data.
ENDIF.
ASSIGN gdo_data->* TO <gt_outtab>.
" Determine structure of output list dynamically
CALL METHOD cl_abap_typedescr=>describe_by_data_ref
EXPORTING
p_data_ref = gdo_data
RECEIVING
p_descr_ref = lo_typedescr
EXCEPTIONS
reference_is_initial = 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.
lo_tabledescr ?= lo_typedescr.
lo_strucdescr ?= lo_tabledescr->get_table_line_type( ).
ld_relname = lo_strucdescr->get_relative_name( ).
gd_tabname = ld_relname.
ENDFORM. " SET_OUTPUT_DATA
Regards
Uwe
‎2008 Mar 17 6:15 AM
Hi Uwe,
Thanks a lot for the help.
Ur code is really helpful.
Now, after creating docking container and sisplaying data on it, what i can see is
1.) Radiobutton X -- Data displayed on screen 100
2.)Radiobutton Y -- Screen 100 divided by two. On one screen above (step 1) data and on the other part step 2 data.
Also for step 1 i've created fieldcatalog by FM LVC_FIELDCATALOG_MERGE and transfering the fieldcatalog to global variable.
For step 2 i've created fieldcatalog by passing individual parameter and appending it to the internal table and then transfering this fieldcatalog to global variable.
Also in screen 100 is blank, and i 've not created any custom container.
My query is though i can see data for step 2 but why the previous data is also displayed.
PLZ HELP!
‎2008 Mar 17 6:31 AM
Hello Annie
Based on your description I see two problems:
(1) You create the docking container a second time when you choose the other radiobutton
As you can see from my coding all the control instantiation is done prior to displaying the screen. In the screen logic I simply do the display of the ALV list output (method SET_TABLE_FOR_FIRST_DISPLAY).
You could use the same logic with a custom container on the screen. Just take care that there is no duplicated instantiation.
(2) You append the fieldcatalog for the second table to the fieldcatalog for the first table.
Looking at my example then the line structure of the output itab would look like this:
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1 AS knb1.
INCLUDE TYPE knvv AS knvv. " not possible -> syntax error (explanation see below)
INCLUDE TYPE knvv AS knvv RENAMING WITH SUFFIX _knvv.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA: gt_outtab TYPE ty_t_outtab.
Actually, this coding will not work because the second structure (KNVV) contains same field names like KNB1. Thus, it would be necessary to rename the fieldnames.
If you want to display two completely different tables then you need to independent and separate fieldcatalogs.
Regards
Uwe
‎2008 Mar 17 5:18 AM
Hi Annie,
Little addition in your code as below would help.
IF sy_ucomm EQ 'BACK'.
CALL METHOD lr_grid_file->refresh_table_display.
Refreshing the grid display for further selections.
ELSE.
CALL METHOD lr_grid_file->set_table_for_first_display
EXPORTING
is_layout = lv_layout
CHANGING
it_outtab = lt_file_list
it_fieldcatalog = lt_fieldcat.
ENDIF.
Hope this works ,
Regds,
Gaurav
‎2008 Mar 17 7:01 AM
Hi,
If flag = 'Y'
perform for_1_report usinf fcat, events and al
else
perform for_1_report usinf fcat, events and al
endif