‎2013 Oct 23 2:58 PM
Hi Guys, Question is: Can I display two results in the same ALV output? I have been trying with no success. One internal table have data from SAP and the other is a reults table coming from an inbound interface. The structures are not the same. I am not exprienced with ALV, so if that is not possible, how can I make this? Two ALVs? Examples would be hihly appreciated. Thank you, F
‎2013 Oct 24 8:10 AM
Hello,
It is possible to display more than 1 ALV on screen. You have to use classes and objects.
Is that what you need?
Please note that you can have several data from several tables but in this example am displaying the same data in the four quadrant.
REPORT zalv_classe.
************************************************************************
* DICTIONARY TYPES DEFINITION
************************************************************************
TYPE-POOLS: slis.
************************************************************************
************************************************************************
* TYPES
************************************************************************
TYPES : BEGIN OF ty_vbap_vbak,
"VBAP
vbeln TYPE vbeln_va, "Document de vente
posnr TYPE posnr_va, "Poste de document de vente
matnr TYPE matnr, "Numéro d'article
matkl TYPE matkl, "Groupe de marchandises
arktx TYPE arktx, "Désignation du poste d'une commande client
zieme TYPE dzieme, "Unité de quantité cible
netpr TYPE netpr, "Prix net
"VBAK
erdat TYPE erdat, "Date de création de l'enregistrement
ernam TYPE ernam, "Nom de l'utilisateur qui a créé l'objet
auart TYPE auart, "Type de document de vente
vbtyp TYPE vbtyp, "Type de document commercial
END OF ty_vbap_vbak.
************************************************************************
************************************************************************
* TABLES
************************************************************************
************************************************************************
************************************************************************
* INTERNALS TABLES
************************************************************************
DATA : gt_vbap_vbak TYPE STANDARD TABLE OF ty_vbap_vbak,
gt_fieldcat TYPE slis_t_fieldcat_alv.
************************************************************************
************************************************************************
* STRUCTURES
************************************************************************
DATA : gs_vbap_vbak TYPE ty_vbap_vbak,
gs_layout TYPE slis_layout_alv.
************************************************************************
************************************************************************
* VARIABLES
************************************************************************
DATA : g_save(1) TYPE c.
************************************************************************
************************************************************************
* CONSTANTS
************************************************************************
CONSTANTS : c_x(1) TYPE c VALUE 'X',
c_structure_name TYPE dd02l-tabname VALUE 'Z_S_ALV_NORMAL',
c_col_x TYPE sap_bool VALUE 'X'.
************************************************************************
************************************************************************
* CLASSE, INTERFACE et INSTANCE
************************************************************************
DATA : gr_table TYPE REF TO cl_salv_table,
gr_table1 TYPE REF TO cl_salv_table,
gr_table2 TYPE REF TO cl_salv_table,
gr_table3 TYPE REF TO cl_salv_table,
o_container TYPE REF TO cl_gui_custom_container,
o_splitter TYPE REF TO cl_gui_splitter_container,
o_grid TYPE REF TO cl_gui_container,
o_grid1 TYPE REF TO cl_gui_container,
o_grid2 TYPE REF TO cl_gui_container,
o_grid3 TYPE REF TO cl_gui_container,
gr_function TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_display TYPE REF TO cl_salv_display_settings,
g_title TYPE lvc_title.
************************************************************************
************************************************************************
* SELECTION SCREEN
************************************************************************
************************************************************************
************************************************************************
START-OF-SELECTION.
************************************************************************
"Récupération des données
PERFORM f_get_data.
************************************************************************
************************************************************************
END-OF-SELECTION.
************************************************************************
"Traitement des données
PERFORM f_process_data.
"Affichage des données en format ALV
PERFORM f_display_alv.
************************************************************************
*&---------------------------------------------------------------------*
FORM f_get_data .
*----------------------------------------------------------------------*
SELECT vbap~vbeln
vbap~posnr
vbap~matnr
vbap~matkl
vbap~arktx
vbap~zieme
vbap~netpr
vbak~erdat
vbak~ernam
vbak~auart
vbak~vbtyp
FROM vbap
INNER JOIN vbak
ON vbap~vbeln EQ vbak~vbeln
INTO TABLE gt_vbap_vbak.
IF sy-subrc EQ 0.
SORT gt_vbap_vbak BY vbeln posnr.
ENDIF.
ENDFORM. " f_get_data
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
FORM f_process_data .
*----------------------------------------------------------------------*
ENDFORM. " f_process_data
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
FORM f_display_alv .
*----------------------------------------------------------------------*
"Affichage en format ALV
CALL SCREEN 9000.
ENDFORM. " f_display_alv
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'MENU'.
SET TITLEBAR 'GRAND_TITRE'.
CREATE OBJECT o_container
EXPORTING container_name = 'CONTAINER'.
CREATE OBJECT o_splitter
EXPORTING parent = o_container
rows = 2
columns = 2.
CALL METHOD o_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = o_grid.
CALL METHOD o_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = o_grid1.
CALL METHOD o_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = o_grid2.
CALL METHOD o_splitter->get_container
EXPORTING
row = 2
column = 2
RECEIVING
container = o_grid3.
cl_salv_table=>factory(
EXPORTING
r_container = o_grid
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = gt_vbap_vbak
).
cl_salv_table=>factory(
EXPORTING
r_container = o_grid1
IMPORTING
r_salv_table = gr_table1
CHANGING
t_table = gt_vbap_vbak
).
cl_salv_table=>factory(
EXPORTING
r_container = o_grid2
IMPORTING
r_salv_table = gr_table2
CHANGING
t_table = gt_vbap_vbak
).
cl_salv_table=>factory(
EXPORTING
r_container = o_grid3
IMPORTING
r_salv_table = gr_table3
CHANGING
t_table = gt_vbap_vbak
).
gr_function = gr_table->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title1' TO g_title.
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table->display.
gr_function = gr_table1->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table1->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title2' TO g_title.
gr_display = gr_table1->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table1->display.
gr_function = gr_table2->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table2->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title3' TO g_title.
gr_display = gr_table2->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table2->display.
gr_function = gr_table3->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table3->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title4' TO g_title.
gr_display = gr_table3->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table3->display.
ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm.
* WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
WHEN '&F03' OR '&F12' OR '&F15'.
LEAVE TO SCREEN 0 .
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
Thanks and Kind Regards,
Yovish.
‎2013 Oct 23 3:03 PM
Hi Fafa,
It's not possible but you can display two alv's on the same screen using split container.
Check this discussion:
http://scn.sap.com/message/392805#392805
Regards,
Vladimir
‎2013 Oct 23 3:47 PM
Hi Vladimir,
sorry to contradict you, but it is possible.
When you use class CL_SALV_TABLE for this purpose there is method
SET_DATA to provide new content to your alv
to give you an example:
...snip...
DATA: itab1 type sometable,
itab2 type sometable.
DATA: gr_alv type ref to CL_SALV_TABLE.
DATA: gr_functions TYPE REF TO cl_salv_functions.
DATA: gr_colums TYPE REF TO cl_salv_columns_table.
...
... populate itab1 and itab2...
...
CL_SALV_TABLE=>factory( "getting the alv handle
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table = itab1
).
* you may want to set your own PF_STATUS to control user-command
gr_alv->set_screen_status( report = my_repid
pfstatus = my_status
set_functions = 1 ).
* let's you set the available functions in alv
gr_functions = r_alv->get_functions_base( ).
gr_functions->set_all( abap_true ).
gr_colums = r_alv->get_columns( ).
* here you can tune the field-catalog to your needs
PERFORM set_colums.
CALL METHOD gr_alv->display.
now you want to display the contents of your 2nd table
gr_alv->set_data( t_table = itab2 ).
Well of course, if itab2 has a different structure, you had better set your fieldcatalog new as well.
Have fun with trying.
Best regards - Jörg
‎2013 Oct 23 4:05 PM
Hi Jörg, Yes, itab has a different structure. What do you mean by " setting your fieldcatalog new as well " ? I did not understand that. Could you please exemplify? I am not used to ALVs ... Thank you.
‎2013 Oct 23 5:27 PM
Hi Fafa,
when you use the class cl_salv_table and you have locally defined itab-structures, then you can use the column-object to specify ech columns settings.
You will have to call set_columns with different settings after setting the new table content.
On the other hand, when you're only dealing with ddic defined structuresyou actually don't have to do anything, unless you want to have it really nice.
now my example code for the field-catalog settings is like follows:
form set_columns.
data: lt_columns type salv_t_column_ref.
data: ls_column type salv_s_column_ref.
data: lv_colpos type i.
data: lv_short type scrtext_s.
data: lv_med type scrtext_m.
data: lv_long type scrtext_l.
data: lo_aggreg type ref to cl_salv_aggregations.
data: lo_sorts type ref to cl_salv_sorts.
try.
lo_sorts = io_alv->get_sorts( 1 ).
catch cx_salv_not_found.
endtry.
* enable sorting
lo_sorts->set_group_active( ).
* and aggregations likewise
lo_aggreg = io_alv->get_aggregations( ).
* retrieve the columns object
lo_colums = io_alv->get_columns( ).
* get the objects for all columns in this table
lt_columns = lo_colums->get( ).
* now for each column, you can set the desired attributes
loop at lt_columns into ls_column.
* you should know which column you're actually dealing with thus
case ls_column-columnname.
when 'xxxx'. "choose your column-names here to give the correct settings
lo_colums->set_column_position( columnname = ls_column-columnname
position = lv_colpos ).
ls_column-r_column->set_optimized( abap_true ).
lv_short = lv_med = lv_long = 'some title'.
ls_column-r_column->set_short_text( lv_short ).
ls_column-r_column->set_medium_text( lv_med ).
ls_column-r_column->set_long_text( lv_long ).
ls_column-r_column->set_tooltip( lv_long ).
* you might want to enable aggregation for this column
lo_aggreg->add_aggregation( columnname = ls_column-columnname aggregation = 1 ).
* or you might want to hide a column
ls_column-r_column->set_visible( abap_false ).
when others.
endcase.
endloop.
endform.
´Try and adjust to your needs.
Regards - Jörg
‎2013 Oct 23 10:24 PM
Hi Fafa,
Simple option is use Block display alv for your requirement.
Use below FM in same sequence as mentioned.
1. Initialize CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
2. Pass first internal table for output call function 'REUSE_ALV_BLOCK_LIST_APPEND'
3 You can pass another internal table using same FM as in point 2.
4. After you have appended all internal tables use CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY' for displaying output.
Regards,
Koustubh
‎2013 Oct 24 6:19 AM
Hello Mr.Seller,
You can use the following details.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = v_repid.
**First block
v_tabname = 'IT_LAST'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog1
i_tabname = v_tabname
it_events = GT_EVENTS
TABLES
t_outtab = it_last.
**Second block
v_tabname = 'IT_TRANSPORT2'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog2
i_tabname = v_tabname
it_events = GT_EVENTS
TABLES
t_outtab = it_transport2.
v_tabname = 'IT_FINAL'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog2
i_tabname = v_tabname
it_events = GT_EVENTS
TABLES
t_outtab = it_final.
**Display
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
‎2013 Oct 24 8:10 AM
Hello,
It is possible to display more than 1 ALV on screen. You have to use classes and objects.
Is that what you need?
Please note that you can have several data from several tables but in this example am displaying the same data in the four quadrant.
REPORT zalv_classe.
************************************************************************
* DICTIONARY TYPES DEFINITION
************************************************************************
TYPE-POOLS: slis.
************************************************************************
************************************************************************
* TYPES
************************************************************************
TYPES : BEGIN OF ty_vbap_vbak,
"VBAP
vbeln TYPE vbeln_va, "Document de vente
posnr TYPE posnr_va, "Poste de document de vente
matnr TYPE matnr, "Numéro d'article
matkl TYPE matkl, "Groupe de marchandises
arktx TYPE arktx, "Désignation du poste d'une commande client
zieme TYPE dzieme, "Unité de quantité cible
netpr TYPE netpr, "Prix net
"VBAK
erdat TYPE erdat, "Date de création de l'enregistrement
ernam TYPE ernam, "Nom de l'utilisateur qui a créé l'objet
auart TYPE auart, "Type de document de vente
vbtyp TYPE vbtyp, "Type de document commercial
END OF ty_vbap_vbak.
************************************************************************
************************************************************************
* TABLES
************************************************************************
************************************************************************
************************************************************************
* INTERNALS TABLES
************************************************************************
DATA : gt_vbap_vbak TYPE STANDARD TABLE OF ty_vbap_vbak,
gt_fieldcat TYPE slis_t_fieldcat_alv.
************************************************************************
************************************************************************
* STRUCTURES
************************************************************************
DATA : gs_vbap_vbak TYPE ty_vbap_vbak,
gs_layout TYPE slis_layout_alv.
************************************************************************
************************************************************************
* VARIABLES
************************************************************************
DATA : g_save(1) TYPE c.
************************************************************************
************************************************************************
* CONSTANTS
************************************************************************
CONSTANTS : c_x(1) TYPE c VALUE 'X',
c_structure_name TYPE dd02l-tabname VALUE 'Z_S_ALV_NORMAL',
c_col_x TYPE sap_bool VALUE 'X'.
************************************************************************
************************************************************************
* CLASSE, INTERFACE et INSTANCE
************************************************************************
DATA : gr_table TYPE REF TO cl_salv_table,
gr_table1 TYPE REF TO cl_salv_table,
gr_table2 TYPE REF TO cl_salv_table,
gr_table3 TYPE REF TO cl_salv_table,
o_container TYPE REF TO cl_gui_custom_container,
o_splitter TYPE REF TO cl_gui_splitter_container,
o_grid TYPE REF TO cl_gui_container,
o_grid1 TYPE REF TO cl_gui_container,
o_grid2 TYPE REF TO cl_gui_container,
o_grid3 TYPE REF TO cl_gui_container,
gr_function TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_display TYPE REF TO cl_salv_display_settings,
g_title TYPE lvc_title.
************************************************************************
************************************************************************
* SELECTION SCREEN
************************************************************************
************************************************************************
************************************************************************
START-OF-SELECTION.
************************************************************************
"Récupération des données
PERFORM f_get_data.
************************************************************************
************************************************************************
END-OF-SELECTION.
************************************************************************
"Traitement des données
PERFORM f_process_data.
"Affichage des données en format ALV
PERFORM f_display_alv.
************************************************************************
*&---------------------------------------------------------------------*
FORM f_get_data .
*----------------------------------------------------------------------*
SELECT vbap~vbeln
vbap~posnr
vbap~matnr
vbap~matkl
vbap~arktx
vbap~zieme
vbap~netpr
vbak~erdat
vbak~ernam
vbak~auart
vbak~vbtyp
FROM vbap
INNER JOIN vbak
ON vbap~vbeln EQ vbak~vbeln
INTO TABLE gt_vbap_vbak.
IF sy-subrc EQ 0.
SORT gt_vbap_vbak BY vbeln posnr.
ENDIF.
ENDFORM. " f_get_data
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
FORM f_process_data .
*----------------------------------------------------------------------*
ENDFORM. " f_process_data
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
FORM f_display_alv .
*----------------------------------------------------------------------*
"Affichage en format ALV
CALL SCREEN 9000.
ENDFORM. " f_display_alv
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'MENU'.
SET TITLEBAR 'GRAND_TITRE'.
CREATE OBJECT o_container
EXPORTING container_name = 'CONTAINER'.
CREATE OBJECT o_splitter
EXPORTING parent = o_container
rows = 2
columns = 2.
CALL METHOD o_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = o_grid.
CALL METHOD o_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = o_grid1.
CALL METHOD o_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = o_grid2.
CALL METHOD o_splitter->get_container
EXPORTING
row = 2
column = 2
RECEIVING
container = o_grid3.
cl_salv_table=>factory(
EXPORTING
r_container = o_grid
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = gt_vbap_vbak
).
cl_salv_table=>factory(
EXPORTING
r_container = o_grid1
IMPORTING
r_salv_table = gr_table1
CHANGING
t_table = gt_vbap_vbak
).
cl_salv_table=>factory(
EXPORTING
r_container = o_grid2
IMPORTING
r_salv_table = gr_table2
CHANGING
t_table = gt_vbap_vbak
).
cl_salv_table=>factory(
EXPORTING
r_container = o_grid3
IMPORTING
r_salv_table = gr_table3
CHANGING
t_table = gt_vbap_vbak
).
gr_function = gr_table->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title1' TO g_title.
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table->display.
gr_function = gr_table1->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table1->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title2' TO g_title.
gr_display = gr_table1->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table1->display.
gr_function = gr_table2->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table2->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title3' TO g_title.
gr_display = gr_table2->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table2->display.
gr_function = gr_table3->get_functions( ).
gr_function->set_all( abap_true ).
gr_columns = gr_table3->get_columns( ).
gr_columns->set_optimize( c_col_x ).
"Titre
MOVE 'Title4' TO g_title.
gr_display = gr_table3->get_display_settings( ).
gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
gr_display->set_list_header( g_title ).
CALL METHOD gr_table3->display.
ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm.
* WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
WHEN '&F03' OR '&F12' OR '&F15'.
LEAVE TO SCREEN 0 .
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
Thanks and Kind Regards,
Yovish.
‎2013 Oct 24 10:30 AM
Hi,
You can have two alv on the same screen. Using splitter, split the container into two and place a grid in both the containers.Display the alv of different structure in the containers.
Regards,
Jeffin