Friday, October 15, 2010

This ABAP rings the bell on any chosen pc, that has a sapgui connected to SAP

REPORT SAPLGRAP.
************************************************************************
* This program seds an audio alert to a specific user's frontend
* server. The program needs a pre-registered rfc program listening on
* every pc. The rfcexec can be started from the windows automatic
* startup like this:
* rfcexec -a100.100.100.100.rfcexec -ggatewayhostname -xsapgwXX
* ^ ^
* IP of the pc IP of the gateway host
************************************************************************

* Get the terminal, that belongs to the user
start-of-selection.
data: user value 'IMRE'.
DATA: OPCODE TYPE X VALUE 2.
DATA: BEGIN OF USR_TABL OCCURS 10.
INCLUDE STRUCTURE UINFO.
DATA: END OF USR_TABL.

CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE
ID 'TAB' FIELD USR_TABL-*SYS*.

* Get the corresponding IP address
data: arp_command(30) value '/usr/sbin/arp',
BEGIN OF TABL OCCURS 0,
LINE(200),
END OF TABL,
ip_address(100).

read table usr_tabl with key bname = 'IMRE'.
if sy-subrc <> 0. write: 'There is no such a user logged in'.
exit.endif.
arp_command+14 = usr_tabl-term.
CALL 'SYSTEM' ID 'COMMAND' FIELD arp_command
ID 'TAB' FIELD TABL-*SYS*.
read table tabl index 1.
shift tabl right up to ')'.
shift tabl right deleting trailing ')'.
shift tabl left up to '('.
shift tabl left deleting leading '('.

* Get the systems that has been registered on the gateway.
data: begin of connected_systems occurs 10.
include structure GWY_SYSTEm.
data: end of connected_systems.

call function 'GWY_READ_CONNECTED_SYSTEMS'
exporting
gwhost = 'optima'
gwserv = 'sapgw00'
tables
CONNECTED_SYSTEMS = CONNECTED_SYSTEMS.

* Get the registrated entry for the user's ip.
data: host_string(40).

loop at CONNECTED_SYSTEMS.
if CONNECTED_SYSTEMS-ADDR1 = tabl and
CONNECTED_SYSTEMS-SYSTYPE = 'REGISTER_TP'.
host_string = CONNECTED_SYSTEMS-tpname.
exit.
endif.
endloop.
if host_string is initial. write: 'No registered RFC server'.
exit.endif.

* Create a new destination in RFCDES
tables: rfcdes.

rfcdes-rfcdest = 'ZTTTT'.
rfcdes-rfctype = 'T'.
rfcdes-rfcoptions = 'H=%%RFCSERVER%%,N='.
rfcdes-rfcoptions+19 = host_string.
rfcdes-rfcoptions+59 = ','.
condense rfcdes-rfcoptions NO-GAPS.
modify rfcdes.
if sy-subrc <> 0. write: 'Unsuccessfull modification'.
exit. endif.
commit work.

* Call the alert with the new destination
DATA : BEGIN OF RET OCCURS 10,
TEXT(80),
END OF RET .
data: command(256) value
'sndrec32.exe /play /close c:/winnt/ringin.wav'.
CALL FUNCTION 'RFC_REMOTE_EXEC' DESTINATION 'ZTTTT'
EXPORTING
COMMAND = COMMAND
TABLES
PIPEDATA = RET.

* Delete the rfc destination
clear rfcdes.
select single * from rfcdes where rfcdest = 'ZTTTT'.
delete rfcdes.
if sy-subrc <> 0. write: 'Unsuccessfull delete'.
exit. endif.
commit work.

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites