Application Development 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: 

Button in alv grid cell using REUSE_ALV_GRID_DISPLAY

Former Member
0 Kudos

Hi all,

I want to make the contents of 2 columns of my alv grid as push button with values as text on it. I am not using classes or methods but alv grid fm. On clicking the button one dialog box has to pop up which gives edit option for the values in that coloumn, my question is how to introduce button in alv grid cell? if i can use t_fieldcatalog-icon, then please give me the complete steps for that.

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

this may helps u

u need to copy stadard screen elemetn to MARATAB1(at PF -STATUS)

You should copy the 'STANDARD' GUI status from program <b>SAPLSLVC_FULLSCREEN</b>

type this one in SE41 program name is:<b>SAPLSLVC_FULLSCREEN</b>

status : <b>STANDARD_FULLSCREEN</b>

and copy it ...

----


  • Type-pool

----


type-pools slis.

----


  • Tables

----


tables: mara,sscrfields.

----


  • Selection screen

----


select-options: s_matnr for mara-matnr.

PARAMETERS: p_email TYPE somlreci1-receiver.

TYPES: BEGIN OF t_charmara,

matnr(18) TYPE c, " Material Number

ernam(12) TYPE c, " Person Credited

aenam(12) TYPE c, " Person Changed Object

pstat(15) TYPE c, " Maintenance Status

END OF t_charmara.

----


  • Data Declarations

----


data: rt_extab type slis_t_extab, " Table of inactive function

  • codes

wa_charmara TYPE t_charmara, " work area of mara Table

fs_fieldcat type slis_t_fieldcat_alv,

" Field catalog with field

  • descriptions

t_fieldcat like line of fs_fieldcat,

" Table of Field catalog

r_ucomm like sy-ucomm, " User Command

rs_selfield TYPE slis_selfield. " cursor position ALV

data: filedlayout type slis_layout_alv,

heading type slis_t_listheader with header line,

t_event type slis_t_event.

data: fs_event like line of t_event.

data: fs_sort type slis_sortinfo_alv,

t_sort type slis_t_sortinfo_alv.

data: w_char(200) type c,

w_matnr type mara-matnr.

  • fs_sort-fieldname = 'MATNR'.

  • fs_sort-up = 'X'.

  • fs_sort-group = '*'.

  • append fs_sort to t_sort.

  • clear fS_sort.

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

w_cnt TYPE i,

w_sent_all(1) TYPE c,

w_doc_data LIKE sodocchgi1,

gd_error TYPE sy-subrc,

gd_reciever TYPE sy-subrc.

----


  • Internal Tables

----


data: begin of it_mara occurs 0,

matnr like mara-matnr, " Material Number

ernam like mara-ernam, " Person Credited

aenam like mara-aenam, " Person Changed Object

pstat like mara-pstat, " Maintenance Status

end of it_mara.

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

*at selection-screen on field event

AT SELECTION-SCREEN on s_matnr.

PERFORM f0100_VALIDATE_MATERIAL_NUMBER.

start-of-selection.

  • retrive Data from the data base table Mara

perform retrive_data_from_mara.

end-of-selection.

*Field catalog with field descriptions

perform fieldcat.

*perform top_of_page.

PERFORM EVENT_LIST.

*ALV Grid Display

perform alv_display.

  • Creating one Push button ENTER

perform maratab1 USING RT_EXTAB.

&----


*& Form f0100_VALIDATE_MATERIAL_NUMBER

&----


  • text

----


  • There are no interface parameters to be passed to this subroutine

----


FORM F0100_VALIDATE_MATERIAL_NUMBER .

select matnr " Material Number

from mara

up to 1 rows

into mara-matnr

where matnr in s_matnr.

endselect.

IF sy-subrc NE 0.

clear sscrfields-ucomm.

MESSAGE e000 WITH 'Enter valid Material number'(003).

ENDIF. " IF sy-subrc NE 0

ENDFORM. " f0100_VALIDATE_MATERIAL_NUMBER

&----


*& Form retrive_data_from_mara

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM retrive_data_from_mara .

select matnr " Material Number

ernam " Person Credited

aenam " Person Changed Object

pstat " Maintenance Status

from mara

into table It_mara

where matnr in s_matnr.

IF sy-subrc NE 0.

MESSAGE i001 WITH 'Records are not found'.

exit.

stop.

ENDIF. " IF sy-subrc NE 0

ENDFORM. " retrive_data_from_mara

&----


*& Form fieldcat

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM fieldcat .

*field catalog for MATNR

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'MATNR'.

t_fieldcat-col_pos = 1.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for ERNAM

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'ERNAM'.

t_fieldcat-col_pos = 2.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for AENAM

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'AENAM'.

t_fieldcat-col_pos = 3.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for PSTAT

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'PSTAT'.

t_fieldcat-col_pos = 4.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

ENDFORM. " fieldcat

&----


*& Form EVENT_LIST

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM EVENT_LIST .

fs_event-name ='TOP_OF_PAGE'.

fs_event-form = 'TOP_PAGE'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

fs_event-name ='END_OF_PAGE'.

fs_event-form = 'END_PAGE'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

fs_event-name ='END_OF_LIST'.

fs_event-form = 'LIST_END'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

ENDFORM. " EVENT_LIST

&----


*& Form alv_display

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM alv_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_PF_STATUS_SET = 'MARATAB1'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

IT_FIELDCAT = FS_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = T_SORT

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = T_EVENT

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IR_SALV_LIST_ADAPTER =

  • IT_EXCEPT_QINFO =

  • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = IT_MARA[]

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

form TOP_PAGE.

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = 'Created by : Vijay Pawar'.

append wa_listheader to tbl_listheader.

wa_listheader-typ = 'S'.

concatenate ' Date ' sy-datum into

wa_listheader-info separated by space.

append wa_listheader to tbl_listheader.

wa_listheader-typ = 'S'.

concatenate ' From ' s_matnr-low ' To ' s_matnr-high into

wa_listheader-info separated by space.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " form TOP_PAGE.

form END_PAGE.

STATICS W_PAGE TYPE I .

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = W_PAGE.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

add 1 to w_page.

endform. " form END_PAGE.

form list_end.

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = '......................................Last Page'

.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " form list_end.

&----


*& Form maratab1

&----


  • text

----


  • -->P_RT_EXTAB text

----


FORM maratab1 USING P_RT_EXTAB.

SET PF-STATUS 'MARATAB1' EXCLUDING rt_extab.

ENDFORM. " maratab1

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

case r_ucomm.

when 'ENTER'.

perform bulid_xls_data_table.

PERFORM send_file_as_email_attachment

tables it_message

it_attach

using p_email "'vijay.pawar@yash.com'

'Example .xls documnet attachment'

'XLS'

'filename'

' '

' '

' '

changing gd_error

gd_reciever.

perform populate_email_message_body.

PERFORM initiate_mail_execute_program.

endcase. " case r_ucomm.

endform. " FORM user_command

  • perform populate_email_message_body.

*

  • PERFORM initiate_mail_execute_program.

  • CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'

  • EXPORTING

  • DATA_FILENAME = 'MARA.XLS'

  • DATA_PATH_FLAG = 'W'

    • DATA_ENVIRONMENT =

  • DATA_TABLE = ITAB[]

    • MACRO_FILENAME =

    • MACRO_PATH_FLAG = 'E'

    • MACRO_ENVIRONMENT =

  • WAIT = 'X'

    • DELETE_FILE = 'X'

  • EXCEPTIONS

  • NO_BATCH = 1

  • EXCEL_NOT_INSTALLED = 2

  • INTERNAL_ERROR = 3

  • CANCELLED = 4

  • DOWNLOAD_ERROR = 5

  • NO_AUTHORITY = 6

  • FILE_NOT_DELETED = 7

  • OTHERS = 8

  • .

  • IF SY-SUBRC <> 0.

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

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

  • ENDIF.

  • leave to list-processing.

  • endcase.

&----


*& Form bulid_xls_data_table

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM bulid_xls_data_table .

  • CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode

  • con_tab TYPE x VALUE '09'. "OK for non Unicode

*If you have Unicode check active in program attributes thnen you will

*need to declare constants as follows

*class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

con_cret type c value cl_abap_char_utilities=>CR_LF.

CONCATENATE 'matnr' 'ernam' 'aenam' 'pstat'

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

LOOP AT It_mara INTO wa_charmara.

CONCATENATE wa_charmara-matnr wa_charmara-ernam

wa_charmara-aenam wa_charmara-pstat

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

ENDLOOP. " LOOP AT it_mara INTO...

ENDFORM. " bulid_xls_data_table

&----


*& Form send_file_as_email_attachment

&----


  • Send email

----


  • -->P_IT_MESSAGE text

  • -->P_IT_ATTACH text

  • -->P_P_EMAIL text

  • -->P_0387 text

  • -->P_0388 text

  • -->P_0389 text

  • -->P_0390 text

  • -->P_0391 text

  • -->P_0392 text

  • <--P_GD_ERROR text

  • <--P_GD_RECIEVER text

----


FORM send_file_as_email_attachment tables pit_message

pit_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam ,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

ld_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = pit_attach[].

  • Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_receivers

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

ENDFORM. " send_file_as_email_attachment

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


FORM initiate_mail_execute_program.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

&----


*& Form POPULATE_EMAIL_MESSAGE_BODY

&----


  • Populate message body text

----


form populate_email_message_body.

REFRESH it_message.

it_message = 'Please find attached a list test mara records'.

APPEND it_message.

endform. "form populate_email_message_bod

rewards if it helps u

6 REPLIES 6

Former Member
0 Kudos

hi ,

U can have button on application toolbar.

You just have to use the new pf status in your report program.

You should copy the 'STANDARD' GUI status from program SAPLKKBL using transaction SE90 >Programming SubObjects> Gui Status.

Execute this transaction to get to next screen. select status using checkbox. click on GUI Status --> Copy.

Enter your Z program name and the name you what for this status - you can keep it as 'STANDARD' to be simple.

Then you can edit the new status to add or delete buttons. This will also bring in the standard SAP ALV functionality.

Have a look at below code for using the new status.

TYPE-POOLS: slis.

DATA: i_qmel LIKE qmel OCCURS 0.

data v_repid type repid.

SELECT * FROM qmel INTO TABLE i_qmel.

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = v_repid

I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

i_structure_name = 'QMEL'

TABLES

t_outtab = i_qmel

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 set_pf_status using rt_extab type slis_t_extab.

set pf-status 'TEST'.

endform.

FORM user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

data lv_ucomm type sy-ucomm.

lv_ucomm

= sy-ucomm.

CASE lv_ucomm.

WHEN 'BUTTON'. "Double Click line Item

**Write ur functinality here

endcase.

endform.

Also have a look at below links.

http://www.sap-basis-abap.com/abap/add-button-to-alv-toolbar-with-reuse-alv-list-display.htm

rgds

Deepak

Former Member
0 Kudos

this may helps u

u need to copy stadard screen elemetn to MARATAB1(at PF -STATUS)

You should copy the 'STANDARD' GUI status from program <b>SAPLSLVC_FULLSCREEN</b>

type this one in SE41 program name is:<b>SAPLSLVC_FULLSCREEN</b>

status : <b>STANDARD_FULLSCREEN</b>

and copy it ...

----


  • Type-pool

----


type-pools slis.

----


  • Tables

----


tables: mara,sscrfields.

----


  • Selection screen

----


select-options: s_matnr for mara-matnr.

PARAMETERS: p_email TYPE somlreci1-receiver.

TYPES: BEGIN OF t_charmara,

matnr(18) TYPE c, " Material Number

ernam(12) TYPE c, " Person Credited

aenam(12) TYPE c, " Person Changed Object

pstat(15) TYPE c, " Maintenance Status

END OF t_charmara.

----


  • Data Declarations

----


data: rt_extab type slis_t_extab, " Table of inactive function

  • codes

wa_charmara TYPE t_charmara, " work area of mara Table

fs_fieldcat type slis_t_fieldcat_alv,

" Field catalog with field

  • descriptions

t_fieldcat like line of fs_fieldcat,

" Table of Field catalog

r_ucomm like sy-ucomm, " User Command

rs_selfield TYPE slis_selfield. " cursor position ALV

data: filedlayout type slis_layout_alv,

heading type slis_t_listheader with header line,

t_event type slis_t_event.

data: fs_event like line of t_event.

data: fs_sort type slis_sortinfo_alv,

t_sort type slis_t_sortinfo_alv.

data: w_char(200) type c,

w_matnr type mara-matnr.

  • fs_sort-fieldname = 'MATNR'.

  • fs_sort-up = 'X'.

  • fs_sort-group = '*'.

  • append fs_sort to t_sort.

  • clear fS_sort.

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

w_cnt TYPE i,

w_sent_all(1) TYPE c,

w_doc_data LIKE sodocchgi1,

gd_error TYPE sy-subrc,

gd_reciever TYPE sy-subrc.

----


  • Internal Tables

----


data: begin of it_mara occurs 0,

matnr like mara-matnr, " Material Number

ernam like mara-ernam, " Person Credited

aenam like mara-aenam, " Person Changed Object

pstat like mara-pstat, " Maintenance Status

end of it_mara.

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

*at selection-screen on field event

AT SELECTION-SCREEN on s_matnr.

PERFORM f0100_VALIDATE_MATERIAL_NUMBER.

start-of-selection.

  • retrive Data from the data base table Mara

perform retrive_data_from_mara.

end-of-selection.

*Field catalog with field descriptions

perform fieldcat.

*perform top_of_page.

PERFORM EVENT_LIST.

*ALV Grid Display

perform alv_display.

  • Creating one Push button ENTER

perform maratab1 USING RT_EXTAB.

&----


*& Form f0100_VALIDATE_MATERIAL_NUMBER

&----


  • text

----


  • There are no interface parameters to be passed to this subroutine

----


FORM F0100_VALIDATE_MATERIAL_NUMBER .

select matnr " Material Number

from mara

up to 1 rows

into mara-matnr

where matnr in s_matnr.

endselect.

IF sy-subrc NE 0.

clear sscrfields-ucomm.

MESSAGE e000 WITH 'Enter valid Material number'(003).

ENDIF. " IF sy-subrc NE 0

ENDFORM. " f0100_VALIDATE_MATERIAL_NUMBER

&----


*& Form retrive_data_from_mara

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM retrive_data_from_mara .

select matnr " Material Number

ernam " Person Credited

aenam " Person Changed Object

pstat " Maintenance Status

from mara

into table It_mara

where matnr in s_matnr.

IF sy-subrc NE 0.

MESSAGE i001 WITH 'Records are not found'.

exit.

stop.

ENDIF. " IF sy-subrc NE 0

ENDFORM. " retrive_data_from_mara

&----


*& Form fieldcat

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM fieldcat .

*field catalog for MATNR

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'MATNR'.

t_fieldcat-col_pos = 1.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for ERNAM

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'ERNAM'.

t_fieldcat-col_pos = 2.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for AENAM

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'AENAM'.

t_fieldcat-col_pos = 3.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for PSTAT

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'PSTAT'.

t_fieldcat-col_pos = 4.

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

ENDFORM. " fieldcat

&----


*& Form EVENT_LIST

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM EVENT_LIST .

fs_event-name ='TOP_OF_PAGE'.

fs_event-form = 'TOP_PAGE'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

fs_event-name ='END_OF_PAGE'.

fs_event-form = 'END_PAGE'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

fs_event-name ='END_OF_LIST'.

fs_event-form = 'LIST_END'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

ENDFORM. " EVENT_LIST

&----


*& Form alv_display

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM alv_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_PF_STATUS_SET = 'MARATAB1'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

IT_FIELDCAT = FS_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = T_SORT

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = T_EVENT

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IR_SALV_LIST_ADAPTER =

  • IT_EXCEPT_QINFO =

  • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = IT_MARA[]

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

form TOP_PAGE.

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = 'Created by : Vijay Pawar'.

append wa_listheader to tbl_listheader.

wa_listheader-typ = 'S'.

concatenate ' Date ' sy-datum into

wa_listheader-info separated by space.

append wa_listheader to tbl_listheader.

wa_listheader-typ = 'S'.

concatenate ' From ' s_matnr-low ' To ' s_matnr-high into

wa_listheader-info separated by space.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " form TOP_PAGE.

form END_PAGE.

STATICS W_PAGE TYPE I .

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = W_PAGE.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

add 1 to w_page.

endform. " form END_PAGE.

form list_end.

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = '......................................Last Page'

.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " form list_end.

&----


*& Form maratab1

&----


  • text

----


  • -->P_RT_EXTAB text

----


FORM maratab1 USING P_RT_EXTAB.

SET PF-STATUS 'MARATAB1' EXCLUDING rt_extab.

ENDFORM. " maratab1

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

case r_ucomm.

when 'ENTER'.

perform bulid_xls_data_table.

PERFORM send_file_as_email_attachment

tables it_message

it_attach

using p_email "'vijay.pawar@yash.com'

'Example .xls documnet attachment'

'XLS'

'filename'

' '

' '

' '

changing gd_error

gd_reciever.

perform populate_email_message_body.

PERFORM initiate_mail_execute_program.

endcase. " case r_ucomm.

endform. " FORM user_command

  • perform populate_email_message_body.

*

  • PERFORM initiate_mail_execute_program.

  • CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'

  • EXPORTING

  • DATA_FILENAME = 'MARA.XLS'

  • DATA_PATH_FLAG = 'W'

    • DATA_ENVIRONMENT =

  • DATA_TABLE = ITAB[]

    • MACRO_FILENAME =

    • MACRO_PATH_FLAG = 'E'

    • MACRO_ENVIRONMENT =

  • WAIT = 'X'

    • DELETE_FILE = 'X'

  • EXCEPTIONS

  • NO_BATCH = 1

  • EXCEL_NOT_INSTALLED = 2

  • INTERNAL_ERROR = 3

  • CANCELLED = 4

  • DOWNLOAD_ERROR = 5

  • NO_AUTHORITY = 6

  • FILE_NOT_DELETED = 7

  • OTHERS = 8

  • .

  • IF SY-SUBRC <> 0.

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

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

  • ENDIF.

  • leave to list-processing.

  • endcase.

&----


*& Form bulid_xls_data_table

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM bulid_xls_data_table .

  • CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode

  • con_tab TYPE x VALUE '09'. "OK for non Unicode

*If you have Unicode check active in program attributes thnen you will

*need to declare constants as follows

*class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

con_cret type c value cl_abap_char_utilities=>CR_LF.

CONCATENATE 'matnr' 'ernam' 'aenam' 'pstat'

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

LOOP AT It_mara INTO wa_charmara.

CONCATENATE wa_charmara-matnr wa_charmara-ernam

wa_charmara-aenam wa_charmara-pstat

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

ENDLOOP. " LOOP AT it_mara INTO...

ENDFORM. " bulid_xls_data_table

&----


*& Form send_file_as_email_attachment

&----


  • Send email

----


  • -->P_IT_MESSAGE text

  • -->P_IT_ATTACH text

  • -->P_P_EMAIL text

  • -->P_0387 text

  • -->P_0388 text

  • -->P_0389 text

  • -->P_0390 text

  • -->P_0391 text

  • -->P_0392 text

  • <--P_GD_ERROR text

  • <--P_GD_RECIEVER text

----


FORM send_file_as_email_attachment tables pit_message

pit_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam ,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

ld_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = pit_attach[].

  • Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_receivers

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

ENDFORM. " send_file_as_email_attachment

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


FORM initiate_mail_execute_program.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

&----


*& Form POPULATE_EMAIL_MESSAGE_BODY

&----


  • Populate message body text

----


form populate_email_message_body.

REFRESH it_message.

it_message = 'Please find attached a list test mara records'.

APPEND it_message.

endform. "form populate_email_message_bod

rewards if it helps u

Former Member
0 Kudos

Hi,

Check the following link:

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_pfstatus.htm

Hope this helps.

Reward if helpful.

Regards,

Sipra

0 Kudos

I want these buttons in my alv grid itself, not in application toolbar.

0 Kudos

yes it is displayed in the ALV grid only

Former Member
0 Kudos

hi,

data : gd_repid like sy-repid.

gd_repid = sy-repid.

Call function module reuse_alv_grid_display.

exporting.

programme = gd_repid.

top-of-page = 'TOP_OF_PAGE'.

set_pf_status = 'SET_PF_STATUS'.

importing.

t_outtab = itab.

exceptions.

form set_pf_status using rt_extab type slis_t_extab.

set pf-status 'NEW'.

endform.

doubleclick on new it will give a new window there we can include push buttons.

Reward with points if helpful.