Friday, October 15, 2010

Dynamically increase/decrease the number of batch/dialog workprocesses from ABAP

REPORT ZURLS.
************************************************************************
* This program dynamically increases/decreases the number of
* dialog/batch workpocesses by 1,2,3 or 4. Before running the program
* two working test (non-productive) operation mode has to be created
* called flex1 and flex2.
* The program does not switch workprocesses, if the workprocess number
* gets too low (min. dia: 2, min. btc.: 1)
* The instance name is hardcoded in this program version!
************************************************************************
TABLES: TPFID.
PARAMETERS:
PLUS_4 RADIOBUTTON GROUP AAA,
PLUS_3 RADIOBUTTON GROUP AAA,
PLUS_2 RADIOBUTTON GROUP AAA,
PLUS_1 RADIOBUTTON GROUP AAA,
MINUS_1 RADIOBUTTON GROUP AAA,
MINUS_2 RADIOBUTTON GROUP AAA,
MINUS_3 RADIOBUTTON GROUP AAA,
MINUS_4 RADIOBUTTON GROUP AAA.
DATA: SWITCH_TO_OPMODE LIKE TPFID-BANAME,
RECENT_OPMODE LIKE TPFID-BANAME.
DATA: MIN_DIA TYPE I VALUE '2',
MIN_BTCH TYPE I VALUE '1',
RECENT_DIA TYPE I,
RECENT_BTCH TYPE I,
TARGET_DIA TYPE I,
TARGET_BTCH TYPE I.
DATA: BEGIN OF REQ_TBL OCCURS 20.
INCLUDE STRUCTURE STHCMLIST.
DATA: END OF REQ_TBL.
DATA: BEGIN OF RSP_TBL OCCURS 50.
INCLUDE STRUCTURE STHCMLIST.
DATA: END OF RSP_TBL.
DATA: SUBRC LIKE SY-SUBRC.

* Find out the active operation
CALL FUNCTION 'RZL_MAKE_STRG_READ_REQ'
EXPORTING
NAME = 'RZL_BANAME'
TYP = 'C'
TABLES
REQ_TBL = REQ_TBL.

CALL FUNCTION 'TH_SEND_ADM_MESS'
EXPORTING
LEVEL = 2
SERVER_NAME = 'instance_name' "e.g. hostname_SID_00
SERVER_TYPES = 0
WAIT_FOR_ANSWER = 1
TRACE = 1
IMPORTING
SUBRC = SUBRC
TABLES
IN_DATA = REQ_TBL
OUT_DATA = RSP_TBL
EXCEPTIONS
SEND_ERROR = 1
OTHERS = 2.

READ TABLE RSP_TBL INDEX 1.
RECENT_OPMODE = RSP_TBL-BUFFER+24.

* Determine the switch_to operation mode
IF RECENT_OPMODE = 'flex1'.
SWITCH_TO_OPMODE = 'flex2'.
ELSE.
SWITCH_TO_OPMODE = 'flex1'.
ENDIF.

* Determine the current workprocess number.
SELECT * FROM TPFID WHERE BANAME = RECENT_OPMODE.
ENDSELECT.
RECENT_DIA = TPFID-WPNODIA.
RECENT_BTCH = TPFID-WPNOBTC.

* Is the switch is possible? (min. dia=2, min. batch=1)
IF PLUS_4 = 'X'. TARGET_DIA = RECENT_DIA + 4. ENDIF.
IF PLUS_3 = 'X'. TARGET_DIA = RECENT_DIA + 3. ENDIF.
IF PLUS_2 = 'X'. TARGET_DIA = RECENT_DIA + 2. ENDIF.
IF PLUS_1 = 'X'. TARGET_DIA = RECENT_DIA + 1. ENDIF.
IF MINUS_1 = 'X'. TARGET_DIA = RECENT_DIA - 1. ENDIF.
IF MINUS_2 = 'X'. TARGET_DIA = RECENT_DIA - 2. ENDIF.
IF MINUS_3 = 'X'. TARGET_DIA = RECENT_DIA - 3. ENDIF.
IF MINUS_4 = 'X'. TARGET_DIA = RECENT_DIA - 4. ENDIF.

TARGET_BTCH = RECENT_DIA + RECENT_BTCH - TARGET_DIA.

IF TARGET_DIA < MIN_DIA.
WRITE: 'ERROR: less then ',MIN_DIA, 'dialog process is not permitted'.
EXIT.
ENDIF.

IF TARGET_BTCH < MIN_BTCH.
WRITE: 'ERROR: less then ',MIN_BTCH, 'batch process is not permitted'.
EXIT.
ENDIF.

* Modify the instance definition
SELECT * FROM TPFID WHERE BANAME = SWITCH_TO_OPMODE.
ENDSELECT.
TPFID-WPNODIA = TARGET_DIA.
TPFID-WPNOBTC = TARGET_BTCH.
MODIFY TPFID.
COMMIT WORK.

* Carry out the actual switch
CALL FUNCTION 'RZL_SWITCH_TO_BA'
EXPORTING
BANAME = SWITCH_TO_OPMODE.

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