01-30-2008 5:23 AM
Hello Experts,
I haverequirement like below,
I have a report ouyput , with correct customer and incorrect customers,
now i m printing the correct customer first in the ALV format by using FM 'REUSE_ALV_LIST_DISPLAY'.
So after this ineed to write incorrect customer list also..
can u give me how i can write in one ALV List display..
Thanks,
Suresh
01-30-2008 5:25 AM
then u need to use block display use FM 'REUSE_ALV _ BLOCK _ DISPLAY'
go through this report which ll give you detail idea about the blocked alv
TYPE-POOLS:slis.
DATA:x_layout TYPE slis_layout_alv,
t_field TYPE slis_t_fieldcat_alv,
*--field catalog
x_fldcat LIKE LINE OF t_field,
*--to hold all the events
t_events TYPE slis_t_event,
x_events TYPE slis_alv_event,
t_sort TYPE slis_t_sortinfo_alv,
x_sort LIKE LINE OF t_sort ,
*--Print Layout
x_print_layout TYPE slis_print_alv.
*----Macro to add field catalog.
*field "text "length "tech "COL_POS "DATATYPE "DDIC_OUTPUTLEN
DEFINE add_catalog.
clear x_fldcat.
x_fldcat-fieldname = &1.
x_fldcat-seltext_m = &2.
x_fldcat-outputlen = &3.
x_fldcat-tech = &4.
x_fldcat-col_pos = &5.
x_fldcat-no_zero = 'X'.
x_fldcat-ddictxt = 'M'.
x_fldcat-datatype = &6.
x_fldcat-ddic_outputlen = &7.
if &6 = 'N'.
x_fldcat-lzero = 'X'.
endif.
*--build field catalog
append x_fldcat to t_field.
END-OF-DEFINITION.
data declerations.
data: v_repid like sy-repid.
data: begin of itab occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
meins like mara-meins,
end of itab.
data: begin of jtab occurs 0,
matnr like makt-matnr,
maktx like makt-maktx,
end of jtab.
select matnr ernam meins
up to 20 rows
from mara
into table itab.
select matnr maktx
up to 20 rows
from makt
into table jtab.
v_repid = sy-repid.
*DISPLAY alv
Initialize Block
call function 'REUSE_ALV_BLOCK_LIST_INIT'
exporting
i_callback_program = v_repid.
*Block 1:
*INITIALIZE
refresh t_field. clear t_field.
refresh t_events.
*field "text "length "tech "COL_POS "DATATYPE "DDIC_OUTPUTLEN
add_catalog:
'MATNR' 'Material' '18' '' '1' 'C' '18',
'ERNAM' 'Created By' '12' '' '2' 'C' '12',
'MEINS' 'Unit' '5' '' '3' 'C' '3'.
*--build table for events.
x_events-form = 'TOP_OF_LIST1'.
x_events-name = slis_ev_top_of_list.
append x_events to t_events.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = x_layout
it_fieldcat = t_field
i_tabname = 'ITAB'
it_events = t_events
it_sort = t_sort
tables
t_outtab = itab
exceptions
program_error = 1
maximum_of_appends_reached = 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.
*--BLOCK 2(SUMMARY REPORT)
*INITIALIZE
refresh t_field. clear t_field.
refresh t_events.
*field "text "length "tech "COL_POS "DATATYPE "DDIC_OUTPUTLEN
add_catalog:
'MATNR' 'Material' '20' '' '1' 'C' '18',
'MAKTX' 'Description' '40' '' '2' 'C' '40'.
*--build table for events.
x_events-form = 'TOP_OF_LIST2'.
x_events-name = slis_ev_top_of_list.
append x_events to t_events.
Append table block.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = x_layout
it_fieldcat = t_field
i_tabname = 'JTAB'
it_events = t_events
tables
t_outtab = jtab
exceptions
program_error = 1
maximum_of_appends_reached = 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.
*--CALL FM TO DISPLAY THE BLOCK REPORT.
call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
exporting
is_print = x_print_layout
exceptions
program_error = 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.
form top_of_list1.
skip 1.
write: 10 'List 1',
/5 '----
'.
skip 1.
format reset.
endform.
form top_of_list2.
skip 1.
write: 10 'List 2',
/5 '----
'.
skip 1.
format reset.
endform.
thanks
Madhavi
01-30-2008 5:27 AM
hi,
can u have any sample code for that ..
if so plz help.
thanks,
Suresh
01-30-2008 5:27 AM
Hi
To display one ALV list after another ALV list on the same screen, you cannot use REUSE_ALV_LIST_DISPLAY.
For your requiorement, you need to use Blocked ALV. For blocked ALV, see the sample code below and change ur code accordingly,
Block ALV means more than one list in one screen.
Means u can have many list in one screen at a time.
Like this,
TYPE-POOLS : slis.
TABLES : mara,
makt.
SELECT-OPTIONS : mat FOR mara-matnr.
DATA : BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
matkl LIKE mara-matkl,
mtart LIKE mara-mtart,
END OF itab.
DATA : BEGIN OF itab1 OCCURS 0,
mtart LIKE mara-mtart,
count TYPE i,
END OF itab1.
DATA : BEGIN OF itab1_col OCCURS 0,
mtart LIKE mara-mtart,
count TYPE i,
END OF itab1_col.
DATA : t_fcat1 TYPE slis_t_fieldcat_alv,
t_fcat2 TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
t_eve TYPE slis_t_event,
wa_eve TYPE slis_alv_event,
t_layout TYPE slis_layout_alv.
DATA : v_repid LIKE sy-repid,
t_mat LIKE mara-matnr.
DEFINE create_fcat.
clear wa_fcat.
wa_fcat-fieldname = &1.
wa_fcat-seltext_l = &2.
wa_fcat-outputlen = &3.
append wa_fcat to t_fcat1.
END-OF-DEFINITION.
START-OF-SELECTION.
PERFORM get_data.
PERFORM dis_data.
&----
*& Form get_data
&----
text
-
FORM get_data.
SELECT amatnr bmaktx amtart amatkl INTO CORRESPONDING FIELDS OF TABLE itab
FROM mara AS a INNER JOIN makt AS b ON
amatnr = bmatnr
WHERE a~matnr IN mat.
LOOP AT itab.
itab1-mtart = itab-mtart.
itab1-count = 1.
APPEND itab1.
ENDLOOP.
SORT itab1 BY mtart.
LOOP AT itab1.
MOVE-CORRESPONDING itab1 TO itab1_col.
COLLECT itab1_col.
ENDLOOP.
ENDFORM. "get_data
&----
*& Form dis_data
&----
text
-
FORM dis_data.
v_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = v_repid.
REFRESH t_fcat1.
CLEAR t_fcat1.
REFRESH t_eve.
wa_eve-name = 'TOP_OF_PAGE'.
wa_eve-form = 'TOP_OF_PAGE1'.
APPEND wa_eve TO t_eve.
create_fcat:
'MATNR' 'Material' '10',
'MAKTX' 'Material Description' '40',
'MTART' 'Type' '10',
'MATKL' 'Group' '10'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = t_layout
it_fieldcat = t_fcat1
i_tabname = 'ITAB'
it_events = t_eve
TABLES
t_outtab = itab.
REFRESH t_fcat1.
CLEAR t_fcat1.
REFRESH t_eve.
wa_eve-name = 'TOP_OF_PAGE'.
wa_eve-form = 'TOP_OF_PAGE2'.
APPEND wa_eve TO t_eve.
create_fcat:
'MTART' 'Type' '10',
'COUNT' 'Total' '5'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = t_layout
it_fieldcat = t_fcat1
i_tabname = 'ITAB1_COL'
it_events = t_eve
TABLES
t_outtab = itab1_col.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
ENDFORM. "dis_data
&----
*& Form top_of_page1
&----
text
-
FORM top_of_page1.
FORMAT COLOR COL_POSITIVE.
WRITE:/ 'First Block'.
FORMAT COLOR OFF.
ENDFORM. "top_of_page
&----
*& Form top_of_page2
&----
text
-
FORM top_of_page2.
FORMAT COLOR COL_NEGATIVE.
WRITE /5 'Second Block'.
FORMAT COLOR OFF.
ENDFORM. "top_of_page
In hierarchical ALV hierarchy will create,
Like This,
TYPE-POOLS : slis.
TABLES : mseg.
DATA : BEGIN OF itab_head OCCURS 0,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
END OF itab_head.
DATA : BEGIN OF itab_item OCCURS 0,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
mblnr LIKE mseg-mblnr,
menge LIKE mseg-menge,
END OF itab_item.
DATA : t_fcat TYPE slis_t_fieldcat_alv,
key_info TYPE slis_keyinfo_alv,
t_eve TYPE slis_t_event,
gt_subtot TYPE slis_t_sortinfo_alv,
subtot LIKE LINE OF gt_subtot,
t_listhead TYPE slis_t_listheader,
st_line TYPE slis_listheader.
DATA : t_mtdoc LIKE mseg-mblnr.
SELECT-OPTIONS : mat FOR mseg-matnr.
INITIALIZATION.
PERFORM build_cat USING t_fcat.
PERFORM build_eve.
START-OF-SELECTION.
PERFORM get_data.
PERFORM dis_data.
&----
*& Form build_cat
&----
text
-
-->TEMP_FCAT text
-
FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.
DATA : wa_fcat TYPE slis_fieldcat_alv.
wa_fcat-tabname = 'ITAB_HEAD'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'Material'.
APPEND wa_fcat TO temp_fcat.
CLEAR wa_fcat.
wa_fcat-tabname = 'ITAB_HEAD'.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-seltext_m = 'Plant'.
APPEND wa_fcat TO temp_fcat.
CLEAR wa_fcat.
wa_fcat-tabname = 'ITAB_ITEM'.
wa_fcat-fieldname = 'MBLNR'.
wa_fcat-seltext_m = 'Material Doc.'.
APPEND wa_fcat TO temp_fcat.
CLEAR wa_fcat.
wa_fcat-tabname = 'ITAB_ITEM'.
wa_fcat-fieldname = 'MENGE'.
wa_fcat-seltext_m = 'Quantity'.
wa_fcat-do_sum = 'Y'.
APPEND wa_fcat TO temp_fcat.
CLEAR wa_fcat.
subtot-spos = 1.
subtot-fieldname = 'MATNR'.
subtot-tabname = 'ITAB_HEAD'.
subtot-up = 'X'.
subtot-group = 'X'.
subtot-subtot = 'X'.
subtot-expa = 'X'.
APPEND subtot TO gt_subtot.
ENDFORM. "build_cat
&----
*& Form build_eve
&----
text
-
FORM build_eve.
DATA : wa_eve TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = t_eve
EXCEPTIONS
LIST_TYPE_WRONG = 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.
READ TABLE t_eve INTO wa_eve WITH KEY name = 'TOP_OF_PAGE'.
IF sy-subrc = 0.
wa_eve-form = 'TOP_OF_PAGE'.
MODIFY t_eve FROM wa_eve INDEX sy-tabix.
ENDIF.
ENDFORM. "build_eve
&----
*& Form get_data
&----
text
-
FORM get_data.
SELECT matnr werks mblnr menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab_item
WHERE matnr IN mat.
ENDFORM. "get_data
&----
*& Form dis_data
&----
text
-
FORM dis_data.
key_info-header01 = 'MATNR'.
key_info-item01 = 'MATNR'.
key_info-header02 = 'WERKS'.
key_info-item02 = 'WERKS'.
REFRESH itab_head.
LOOP AT itab_item.
ON CHANGE OF itab_item-matnr OR itab_item-werks.
MOVE-CORRESPONDING itab_item TO itab_head.
APPEND itab_head.
ENDON.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = 'ZHEIRALV_PRDS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = t_fcat
it_sort = gt_subtot
it_events = t_eve[]
i_tabname_header = 'ITAB_HEAD'
i_tabname_item = 'ITAB_ITEM'
is_keyinfo = key_info
TABLES
t_outtab_header = itab_head
t_outtab_item = itab_item
EXCEPTIONS
PROGRAM_ERROR = 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.
ENDFORM. "dis_data
&----
*& Form top_of_page
&----
text
-
FORM top_of_page.
CLEAR st_line.
st_line-typ = 'H'.
st_line-info = 'Dhwani Shah'.
APPEND st_line TO t_listhead.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_listhead
I_LOGO =
I_END_OF_LIST_GRID =
I_ALV_FORM =
.
ENDFORM. "top_of_page
reward if useful.
Shakir
01-30-2008 5:34 AM
Hi,
Usually in an ALV report, the data present in one internal table will be displayed. If we want to display more than ALV LIST in the same report when we execute our program, then U can use this REUSE_ALV_BLOCK_LIST_DISPLAY.
If u want to display 2 ALV LIST when u execute ur report, then u need to populate 2 internal tables and build fieldcatalog's for these 2 internal table. Then pass this fieldcat and internal table to 2 separate REUSE_ALV_BLOCK_LIST_APPEND function modules.
U have to use the following 2 other FM before using this FM.
1)<b> 'REUSE_ALV_BLOCK_LIST_INIT'</b>
2) <b>'REUSE_ALV_BLOCK_LIST_APPEND'</b>
and then
3)<b> 'REUSE_ALV_BLOCK_LIST_DISPLAY'</b>
See the complete code given below...
Building ALV Block:
report zalv_block.
type-pools: slis.
types: begin of g_ty_s_test,
layo_no_vert_lines type char1,
end of g_ty_s_test.
data: int_tab type table of zprod,
fs type zprod,
int_tab1 type table of zprod,
fs1 type zprod.
data : alvfc type slis_t_fieldcat_alv,
alvwc type slis_fieldcat_alv.
data : alvly type slis_layout_alv.
data : alvev type slis_t_event.
*data: gt_outtab type g_ty_t_outtab with header line,
data: gs_test type g_ty_s_test.
select * from zprod into table int_tab.
select * from zprod into table int_tab1 up to 5 rows.
gs_test-layo_no_vert_lines = 'X'.
alvly-no_vline = gs_test-layo_no_vert_lines.
call function 'REUSE_ALV_BLOCK_LIST_INIT'
exporting
i_callback_program = sy-repid.
clear alvwc.
alvwc-fieldname = 'PNO'.
append alvwc to alvfc.
clear alvwc.
alvwc-fieldname = 'PNAME'.
append alvwc to alvfc.
clear alvwc.
alvwc-fieldname = 'QTY'.
append alvwc to alvfc.
clear alvwc.
alvwc-fieldname = 'RATE1'.
append alvwc to alvfc.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = alvly
it_fieldcat = alvfc
i_tabname = 'INT_TAB'
it_events = alvev
tables
t_outtab = int_tab
exceptions
program_error = 1
maximum_of_appends_reached = 2
others = 3.
clear alvfc.
clear alvfc[].
clear alvwc.
alvwc-fieldname = 'PNO'.
append alvwc to alvfc.
clear alvwc.
alvwc-fieldname = 'PNAME'.
append alvwc to alvfc.
clear alvwc.
alvwc-fieldname = 'QTY'.
append alvwc to alvfc.
clear alvwc.
alvwc-fieldname = 'RATE1'.
append alvwc to alvfc.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = alvly
it_fieldcat = alvfc
i_tabname = 'INT_TAB1'
it_events = alvev
tables
t_outtab = int_tab1
exceptions
program_error = 1
maximum_of_appends_reached = 2
others = 3.
<b>***DISPLAY*****</b>
call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
exceptions
program_error = 1
others = 2.
Also Check the following link for ALV Block List
http://www.sap-basis-abap.com/abap/sample-program-on-block-lists.htm
<b>REWARD IF USEFUL </b>
regards,
sunil kairam.