Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Kill delayed work processses automatically through batch

Generally we use TCode SM50 to view running processes and delete the long running processes manually. This is an attempt to make this manual process into automated process.


SAP has given a function module 'TH_SERVER_LIST' which gives all the details of the SAP Application Servers on the network.


SAP has given a function module  'TH_SYSTEMWIDE_WPINFO' which gives all the details of work processes on given SAP Application Server.


We can filter the details by which type of work processes shall be stopped based on the time it has taken.


We have to take those process identifications (PID) and SAP Application Server and call the function 'ThWpInfo' to stop the process permanently.


This report could be scheduled so that it runs on its own and stop the long running processes automatically.


It is to be noted that this Program uses unreleased function modules and kernel calls, and so is to be used at your own risk.

Complete source is as follows:


I do hope it helps.


I thank Mr. matthew.billingham for his valuable suggestions and guidance.


REPORT  ZR_KILL_PROCESS.

DATA: itab LIKE STANDARD TABLE OF WPINFO,
      wa
LIKE WPINFO,
      delay_seconds
TYPE i VALUE 900.

DATA: BEGIN OF TY
 
INCLUDE STRUCTURE MSXXLIST_V6.
DATA: END OF TY.

DATA: itab_as LIKE STANDARD TABLE OF TY,
      wa_as
LIKE TY.

CONSTANTS: opcode_wp_stop TYPE x VALUE 2.

CALL FUNCTION 'TH_SERVER_LIST'
TABLES
LIST          
= itab_as
EXCEPTIONS
NO_SERVER_LIST
= 1
OTHERS         = 2.

LOOP AT itab_as INTO wa_as.

  CALL FUNCTION 'TH_WPINFO'
  
EXPORTING
   SRVNAME       
= wa_as-name
  
TABLES
   WPLIST        
= itab
  
EXCEPTIONS
  
OTHERS = 1.

 
LOOP AT ITAB INTO WA.

  
IF WA-WP_TYP = 'DIA' AND WA-WP_STATUS = 'Running' AND WA-WP_ELTIME GT delay_seconds.

    C
ALL 'ThWpInfo'
   
ID 'OPCODE' FIELD opcode_wp_stop
   
ID 'SERVER' FIELD wa_as-name
   
ID 'PID' FIELD wa-wp_pid.

  
ENDIF.
 
ENDLOOP.

ENDLOOP.

9 Comments