Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV LIST DISPLAY (Combining two function module)

Former Member
0 Likes
819

Hi All,

I have a problem with using function module 'REUSE_ALV_LIST_DISPLAY'. i have two different structures to be used to display output based on condition for each. instead of using the function module twice how can i use single function module for both the structures. i have used as below other parameters in the function modules are same only the structure is different.here 'gt_vendor_cc' and 'gt_vendor' are my two structures.please suggest.

IF NOT p_bukrs IS INITIAL.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = g_repid

IT_FIELDCAT = lt_fcat

I_SAVE = 'A'

IS_VARIANT = ls_vari

IT_EVENTS = lt_evts

TABLES

T_OUTTAB = gt_vendor_cc.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ELSE.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = g_repid

IT_FIELDCAT = lt_fcat

I_SAVE = 'A'

IS_VARIANT = ls_vari

IT_EVENTS = lt_evts

TABLES

T_OUTTAB = gt_vendor .

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

6 REPLIES 6
Read only

Former Member
0 Likes
794

Hi,

Make use FM REUSE_ALV_BLOCK_LIST_APPEND'

.

See example Program .

BALVBT01.

Regards,

Balakumar.G

Reward Points if helpful.

Read only

dhruv_shah3
Active Contributor
0 Likes
794

Hi,

You can use Block ALV for solving your purpose.

Examples for this type of Reports...



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: 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.

Also,



report zfieldcatalog .

type-pools: slis.

data : w_fcat1 type slis_fieldcat_alv,
w_fcat2 type slis_fieldcat_alv,
w_fcat3 type slis_fieldcat_alv,
w_events type slis_alv_event,
flayout type slis_layout_alv.

data : t_fcat1 type slis_t_fieldcat_alv,
t_fcat2 type slis_t_fieldcat_alv,
t_fcat3 type slis_t_fieldcat_alv,
t_kna1 type kna1 occurs 1,
t_vbak type vbak occurs 1,
t_vbap type vbap occurs 1,

t_events1 type slis_t_event,
t_events2 type slis_t_event,
t_events3 type slis_t_event.

w_events-name ='TOP-OF-PAGE'.
w_events-form ='TOP1'.
append w_events to t_events1.

w_events-name ='TOP-OF-PAGE'.
w_events-form = 'TOP2'.
append w_events to t_events2.

w_events-name = 'TOP-OF-PAGE'.
w_events-form = 'TOP3'.
append w_events to t_events3.

select * from kna1 into table t_kna1 up to 5 rows.
select * from vbak into table t_vbak up to 5 rows.
select * from vbap into table t_vbap up to 5 rows.

perform top1.
perform top2.
perform top3.
perform get_data.

call function 'REUSE_ALV_BLOCK_LIST_INIT'
exporting
i_callback_program = sy-repid

    * I_CALLBACK_PF_STATUS_SET = ' '
    * I_CALLBACK_USER_COMMAND = ' '
    * IT_EXCLUDING =

.

call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = flayout
it_fieldcat = t_fcat1
i_tabname = 't_kna1'
it_events = t_events1

    * IT_SORT =
    * I_TEXT = ' '

tables
t_outtab = t_kna1

    * 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 function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = flayout
it_fieldcat = t_fcat2
i_tabname = 't_vbak'
it_events = t_events2

    * IT_SORT =
    * I_TEXT = ' '

tables
t_outtab = t_vbak

    * 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 function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = flayout
it_fieldcat = t_fcat3
i_tabname = 't_vbap'
it_events = t_events3

    * IT_SORT =
    * I_TEXT = ' '

tables
t_outtab = t_vbap.

    * 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 function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
*exporting

    * I_INTERFACE_CHECK = ' '
    * IS_PRINT =
    * I_SCREEN_START_COLUMN = 0
    * I_SCREEN_START_LINE = 0
    * I_SCREEN_END_COLUMN = 0
    * I_SCREEN_END_LINE = 0
    * IMPORTING
    * E_EXIT_CAUSED_BY_CALLER =
    * ES_EXIT_CAUSED_BY_USER =
    * 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 top1
&--------------------------------------------------------------------

    * text

---------------------------------------------------------------------
form top1.
write: / 'customer information list'.
endform. "top1

&--------------------------------------------------------------------
*& Form top2
&--------------------------------------------------------------------

    * text

---------------------------------------------------------------------
form top2.
write:/ 'sales order information list'.
endform. "top2

&--------------------------------------------------------------------
*& Form top3
&--------------------------------------------------------------------

    * text

---------------------------------------------------------------------
form top3.
write:/ 'sales item list'.
endform. "top3

&--------------------------------------------------------------------
*& Form get_data
&--------------------------------------------------------------------

    * text

---------------------------------------------------------------------
form get_data.

w_fcat1-col_pos = 1.
w_fcat1-fieldname = 'kunnr'.
w_fcat1-seltext_m = 'customer number'.
w_fcat1-tabname = 't_kna1'.
append w_fcat1 to t_fcat1.

w_fcat1-col_pos = 2.
w_fcat1-fieldname = 'name1'.
w_fcat1-seltext_m = 'customer name'.
w_fcat1-tabname = 't_kna1'.
append w_fcat1 to t_fcat1.

w_fcat1-col_pos = 3.
w_fcat1-fieldname = 'land1'.
w_fcat1-seltext_m = 'country'.
w_fcat1-tabname = 't_kna1'.
append w_fcat1 to t_fcat1.

w_fcat2-col_pos = 1.
w_fcat2-fieldname = 'vbeln'.
w_fcat2-seltext_m = 'order number'.
w_fcat2-tabname = 't_vbak'.
append w_fcat2 to t_fcat2.

w_fcat2-col_pos = 2.
w_fcat2-fieldname = 'erdat'.
w_fcat2-seltext_m = 'order date'.
w_fcat2-tabname = 't_vbak'.
append w_fcat2 to t_fcat2.

w_fcat2-col_pos = 3.
w_fcat2-fieldname = 'netwr'.
w_fcat2-seltext_m = 'order value'.
w_fcat2-tabname = 't_vbak'.
append w_fcat2 to t_fcat2.

w_fcat3-col_pos = 1.
w_fcat3-fieldname = 'posnr'.
w_fcat3-seltext_m = 'order item '.
w_fcat3-tabname = 't_vbap'.
append w_fcat3 to t_fcat3.

w_fcat3-col_pos = 2.
w_fcat3-fieldname = 'arktx'.
w_fcat3-seltext_m = 'item description'.
w_fcat3-tabname = 't_vbap'.
append w_fcat3 to t_fcat3.

w_fcat3-col_pos = 3.
w_fcat3-fieldname = 'werks'.
w_fcat3-seltext_m = 'plant'.
w_fcat3-tabname = 't_vbap'.
append w_fcat3 to t_fcat3.

endform. "get_data

[;

See the example program - BALVBT01

[;

[;

HTH

Regards,

Dhruv Shah

Read only

Former Member
0 Likes
794

Hi Abinash,

Just call the ALV twice itself as you have coded.Y u want to change it.This is the most straight forward way of doing their requirement.

Thanks Arjun

Read only

Former Member
0 Likes
794

Hi,

call the function module only once and place all the data in one internal table, while creating the catalog check the condition.


  IF NOT p_mat IS INITIAL.
    perform write_fcat using 'MATNR' 'ITAB' 'VBAP' c_n 'Material' c_n c_n.
    perform write_fcat using 'KUNNR' 'ITAB' 'VBAP' c_n 'Sold-To' c_n c_n.
    perform write_fcat using 'NAME1' 'ITAB' 'KNA1' c_n 'Desc' c_n c_n.
  ELSEIF NOT p_cst IS INITIAL.
    perform write_fcat using 'KUNNR' 'ITAB' 'VBAP' c_n 'Sold-To' c_n c_n.
    perform write_fcat using 'NAME1' 'ITAB' 'KNA1' c_n 'Desc' c_n c_n.
    perform write_fcat using 'MATNR' 'ITAB' 'VBAP' c_n 'Material' c_n c_n.
  ENDIF.

rgds,

bharat.

Read only

Former Member
0 Likes
794

Hai.

check this.

http://www.saptechnical.com/index.html

REPORT z_alv_list_block.

TYPE-POOLS: slis. " ALV Global types

SELECTION-SCREEN :

SKIP,

BEGIN OF LINE,

COMMENT 5(27) v_1 FOR FIELD p_max.

PARAMETERS p_max(2) TYPE n DEFAULT '02' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

DATA:

  • 1st Table

BEGIN OF gt_kna1 OCCURS 0, " Data displayed

kunnr LIKE kna1-kunnr, " Customer number

ernam LIKE kna1-ernam, " Name of Person who Created

erdat LIKE kna1-erdat, " Creation date

name1 LIKE kna1-name1, " Name 1

END OF gt_kna1,

  • 2nd Table

BEGIN OF gt_mara OCCURS 0,

ernam LIKE mara-ernam, " Name of Person who Created

matnr LIKE mara-matnr, " Material number

ersda LIKE mara-e rsda, " Creation date

brgew LIKE mara-brgew, " Gross weight

END OF gt_mara,

  • 3rd Table

BEGIN OF gt_vbak OCCURS 0,

vkorg LIKE vbak-vkorg, " Sales organization

kunnr LIKE vbak-kunnr, " Sold-to party

vbeln LIKE vbak-vbeln, " Sales document

netwr LIKE vbak-netwr, " Net Value of the Sales Order

waerk LIKE vbak-waerk, " SD document currency

END OF gt_vbak.

----


INITIALIZATION.

v_1 = 'Maximum of records to read'.

----


START-OF-SELECTION.

  • Read data

SELECT * FROM kna1

UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_kna1.

SELECT * FROM mara

UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_mara.

SELECT * FROM vbak

UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_vbak.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = sy-cprog

i_callback_user_command = 'USER_COMMAND'.

PERFORM list_append TABLES gt_kna1

USING '1'

'GT_KNA1'.

PERFORM list_append TABLES gt_mara

USING '2'

'GT_MARA'.

PERFORM list_append TABLES gt_vbak

USING '3'

'GT_VBAK'.

PERFORM f_list_display.

----


  • FORM USER_COMMAND *

----


FORM user_command USING i_ucomm LIKE sy-ucomm

is_selfield TYPE slis_selfield. "#EC CALLED

CASE i_ucomm.

WHEN '&IC1'. " Pick

CASE is_selfield-tabname.

WHEN 'GT_MARA'.

WHEN 'GT_KNA1'.

WHEN 'GT_VBAK'.

READ TABLE gt_vbak INDEX is_selfield-tabindex.

IF sy-subrc EQ 0.

  • Sales order number

SET PARAMETER ID 'AUN' FIELD gt_vbak-vbeln.

  • Display Sales Order

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

ENDIF.

ENDCASE.

ENDCASE.

ENDFORM. " USER_COMMAND

----


< /div>

  • Form list_append

----


FORM list_append TABLES ut_table

USING u_no TYPE char1

u_tabname TYPE slis_tabname.

  • Macro definition

DEFINE m_fieldcat.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = &2.

append ls_fieldcat to lt_fieldcat.

END-OF-DEFINITION.

DEFINE m_sort.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

append ls_sort to lt_sort.

END-OF-DEFINITION.

DATA :

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog

ls_sort TYPE slis_sortinfo_alv,

lt_sort TYPE slis_t_sortinfo_alv. " Sort table

DATA:

lt_events TYPE slis_t_event,

ls_event TYPE slis_alv_event,

ls_layout TYPE slis_layout_alv.

ls_layout-group_change_edit = 'X'.

ls_layout-colwidth_optimize = 'X'.

ls_layout-zebra = 'X'.

ls_layout-detail_popup = 'X'.

ls_layout-get_selinfos = 'X'.

ls_layout-max_linesize = '200'.

CASE u_no.

WHEN '1'.

  • Build field catalog and sort table

m_fieldcat 'KUNNR' 'KNA1'.

m_fieldcat 'ERNAM' 'KNA1'.

m_fieldcat 'ERDAT' 'KNA1'.

m_fieldcat 'NAME1' 'KNA1'.

m_sort 'KUNNR'.

WHEN '2'.

m_fieldcat 'MATNR' 'MARA'.

m_fieldcat 'ERNAM' 'MARA'.

m_fieldcat 'ERSDA' 'MARA'.

m_fieldcat 'BRGEW' 'MARA'.

m_sort 'MATNR'.

WHEN '3'.

m_fieldcat 'VBELN' 'VBAK'.

m_fieldcat 'VKORG' 'VBAK'.

m_fieldcat 'KUNNR' 'VBAK'.

m_fieldcat 'NETWR' 'VBAK'.

m_fieldcat 'WAERK' 'VBAK'.

m_sort 'VBELN'.

ENDCASE.

IF u_no CA '13'.

MOVE 'TOP_OF_PAGE' TO ls_event-name.

CONCATENATE 'TOP_OF_PAGE' u_no INTO ls_event-form.

APPEND ls_event TO lt_events.

ELSE.

MOVE 'TOP_OF_LIST' TO ls_event-name.

CONCATENATE 'TOP_OF_LIST' u_no INTO ls_event-form.

APPEND ls_event TO lt_events.

ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

it_fieldcat = lt_fieldcat

is_layout = ls_layout

i_tabname = u_tabname

it_events = lt_events

it_sort = lt_sort

  • i_text =

TABLES

t_outtab = ut_table

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.

ENDFORM. " LIST_APPEND

----


  • Form f_list_display

----


FORM f_list_display.

DATA ls_print TYPE slis_print_alv.

ls_print-no_print_selinfos = 'X'. " Display no selection infos

ls_print-no_print_listinfos = 'X'. " Display no listinfos

ls_print-reserve_lines = 2. " Lines reserved for end of page

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

EXPORTING

i_interface_check = ' '

is_print = ls_print

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. " F_LIST_DISPLAY

----


  • FORM top_of_page1 *

----


FORM top_of_page1. "#EC CALLED

PERFORM top_of_page.

ENDFORM.

----


  • FORM top_of_page3 *

----


FORM top_of_page3. "#EC CALLED

PERFORM top_of_page.

ENDFORM.

----


  • FORM top_of_page *

----


FORM top_of_page.

ULINE.

WRITE : sy-uname, sy-title(56) CENTERED, sy-datum.

ULINE.

ENDFORM.

----


  • FORM top_of_list2 *

----


FORM top_of_list2. "#EC CALLED

WRITE 'TOP OF LIST2'.

ENDFORM.

                            • END OF PROGRAM Z_ALV_LIST_BLOCK ***********************

regards.

sowjanya.b

Read only

Former Member
0 Likes
794

Hi,

If the structure of the gt_vendor_cc and gt_vendor are same, define another table with the same structure (Eg: gt_final).

Now check the code below,

IF NOT p_bukrs IS INITIAL.

gt_final[ ] = gt_vendor_cc[ ].

else.

gt_final[ ] = gt_vendor[ ].

endif.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = g_repid

IT_FIELDCAT = lt_fcat

I_SAVE = 'A'

IS_VARIANT = ls_vari

IT_EVENTS = lt_evts

TABLES

T_OUTTAB = gt_final[].