Skip to Content
0
Sep 17, 2007 at 04:46 AM

PRINT button in ALV output without using OOPS

367 Views

Hi Folks,

Can anyone here please let me know how to add a print button in the ALV output without using OOPS.I had added the syntax

set pf-status 'ZAT' and then print in this status but in vain.

Kindly let me know how to do this.

REPORT ZEDITALV .

<b>type-pools:slis,icon.</b>

TABLES:MAKT.

*Declarations for ALV

DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA:itfieldcat1 TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA:itprintparams TYPE slis_print_alv.

DATA:itrepid TYPE sy-repid.

itrepid = sy-repid.

DATA:itevent TYPE slis_t_event.

DATA:itlistheader TYPE slis_t_listheader.

DATA:walistheader LIKE LINE OF itlistheader.

DATA:itlayout TYPE slis_layout_alv.

DATA:top TYPE slis_formname.

DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.

DATA : grid TYPE REF TO cl_gui_alv_grid.

data:begin of imakt occurs 0,

matnr like makt-matnr,

spras like makt-spras,

maktx like makt-maktx,

label1(03) TYPE C,

qty1(03) type c,

label2(03) type c,

qty2(03) type c,

end of imakt.

data:imakt1 like imakt occurs 0 with header line.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:MATNR FOR MAKT-MATNR OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

<b>set pf-status 'ZAT'.</b>

START-OF-SELECTION.

select matnr spras maktx from makt into CORRESPONDING FIELDS OF TABLE IMAKT where spras = sy-langu.

if sy-subrc = 0.

perform alv.

ELSE.

STOP.

ENDIF.

FORM ALV.

DEFINE m_fieldcat.

itfieldcat-fieldname = &1.

itfieldcat-col_pos = &2.

itfieldcat-seltext_l = &3.

itfieldcat-do_sum = &4.

itfieldcat-outputlen = &5.

itfieldcat-edit = &6.

append itfieldcat to itfieldcat.

clear itfieldcat.

END-OF-DEFINITION.

m_fieldcat 'MATNR' '' 'MATERIAL No' '' 18 ''.

m_fieldcat 'SPRAS' '' 'Language' '' 02 ''.

m_fieldcat 'MAKTX' '' 'Description' '' 40 ''.

m_fieldcat 'LABEL1' '' 'LABEL1' '' 12 'X'.

m_fieldcat 'QTY1' '' 'QTY1' '' 12 'X'.

m_fieldcat 'LABEL2' '' 'LABEL2' '' 12 'X'.

m_fieldcat 'QTY2' '' 'QTY2' '' 12 'X'.

itlayout-zebra = 'X'.

itlayout-colwidth_optimize = 'X'.

itlayout-no_subtotals = ' '.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

is_layout = itlayout

i_callback_user_command = 'LIST1'

i_callback_top_of_page = 'TOP'

it_fieldcat = itfieldcat[]

i_save = 'A'

  • is_variant = ITVARIANT

it_events = itevent[]

is_print = ITPRINTPARAMS

it_sort = itsort[]

TABLES

t_outtab = imakt

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.

clear itfieldcat.

ENDFORM.

FORM list1 USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE R_UCOMM.

WHEN 'EXIT'.

STOP.

WHEN '&IC1'.

IF rs_selfield-fieldname = 'QTY1' .

READ TABLE IMAKT INDEX rs_selfield-tabindex.

SET PARAMETER ID 'QTY' FIELD iMAKT-QTY1.

ENDIF.

ENDCASE.

*test

if sy-subrc = 0.

loop at imakt.

move-corresponding imakt to imakt1.

append imakt1.

endloop.

DEFINE k_fieldcat.

itfieldcat1-fieldname = &1.

itfieldcat1-col_pos = &2.

itfieldcat1-seltext_l = &3.

itfieldcat1-outputlen = &4.

append itfieldcat1 to itfieldcat1.

clear itfieldcat.

END-OF-DEFINITION.

k_fieldcat 'MATNR' '' 'MATERIAL No' 18 .

k_fieldcat 'SPRAS' '' 'Language' 02 .

k_fieldcat 'MAKTX' '' 'Description' 40 .

k_fieldcat 'LABEL1' '' 'LABEL1' 12 .

k_fieldcat 'QTY1' '' 'QTY1' 12 .

k_fieldcat 'LABEL2' '' 'LABEL2' 12 .

k_fieldcat 'QTY2' '' 'QTY2' 12 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

is_layout = itlayout

i_callback_user_command = 'LIST2'

i_callback_top_of_page = 'TOP'

it_fieldcat = itfieldcat1[]

i_save = 'A'

  • is_variant = ITVARIANT

it_events = itevent[]

is_print = ITPRINTPARAMS

it_sort = itsort[]

TABLES

t_outtab = imakt1

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.

endif.

clear:itfieldcat1,ITFIELDCAT.

ENDFORM.

FORM list2 USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE R_UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'OTHERS'.

EXIT.

ENDCASE.

ENDFORM.

form top.

data:title(70) type c.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = itevent

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

title = 'TEST'.

walistheader-typ = 'H'.

walistheader-info = title.

APPEND walistheader TO itlistheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = itlistheader

  • I_LOGO = ''.

  • I_END_OF_LIST_GRID =

.

CLEAR itlistheader.

ENDFORM. "TOP

Message was edited by:

Kiran K