SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Master client copy trigger



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Transport and Upgrade | Транспорт и Обновления
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Nov 17, 2007 6:57 pm    Post subject: Master client copy trigger Reply with quote

Master client copy trigger - if no user activity or scheduled jobs

Code:

REPORT YMASTCP .

* This program raise an event START_MCP to start an automatic
* master client copy if there are no users in the system and
* there is no sceduled background job for the time when the client
* copy is running. The time period can be changed (syuzeit), and all
* the background jobs starting with @ are avoided. During this time
* the users get a system message in case of login attempt.
* The event should be specified in CCMS and a event driven client
* copy should be scheduled by SCC0.

TABLES: UINFO, TBTCO.

DATA: SYUZEIT TYPE T, SYDATUM TYPE D, LIN TYPE N, OPCODE TYPE X VALUE 2,
      FLAG, STCR.

DATA: BEGIN OF ITAB OCCURS 10,
   JOBNAME LIKE TBTCO-JOBNAME,
   SDLSTRTDT LIKE TBTCO-SDLSTRTDT,
   SDLSTRTTM LIKE TBTCO-SDLSTRTTM,
   EVENTID LIKE TBTCO-EVENTID,
END OF ITAB.

DATA: BEGIN OF BDC_TAB OCCURS 5.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.

DATA: BEGIN OF DATUM,
   1(2),
   2 VALUE '.',
   3(2),
   4 VALUE '.',
   5(4),
END OF DATUM.

DATA: BEGIN OF TIME,
   1(2),
   2 VALUE ':',
   3(2),
   4 VALUE ':',
   5(2),
END OF TIME.

DATA: BEGIN OF USR_TABL OCCURS 10.
        INCLUDE STRUCTURE UINFO.
DATA: END OF USR_TABL.

* Count date and time for system message

SYDATUM = SY-DATUM.
SYUZEIT = SY-UZEIT + 7200.             "MAX 12 hours overflow!!!!!
IF SY-UZEIT > SYUZEIT. SYDATUM = SY-DATUM + 1.ENDIF.
DATUM-5 = SYDATUM. DATUM-3 = SYDATUM+4(2). DATUM-1 = SYDATUM+6(2).
TIME-1 = SYUZEIT. TIME-3 = SYUZEIT+2(2). TIME-5 = SYUZEIT(2).

WRITE: / SY-DATUM, SY-UZEIT.
WRITE: / DATUM, TIME.

* Check active users

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

DESCRIBE TABLE USR_TABL LINES LIN.
IF LIN > 0.
  SKIP.
  WRITE: / LIN, 'ACTIVE USER IS IN THE SYSTEM'.
  SKIP.
  LOOP AT USR_TABL.
    WRITE: /2 USR_TABL-MANDT, 15 USR_TABL-BNAME.
  ENDLOOP.
  SKIP.
  WRITE: / 'MASTER CLIENT COPY ABORTED!!!'.
  EXIT.
ENDIF.

* Are there scheduled jobs ?

IF SYDATUM = SY-DATUM.
  SELECT * FROM TBTCO WHERE STATUS = 'S' AND SDLSTRTTM <> '        '
  AND  SDLSTRTTM > SY-UZEIT AND SDLSTRTTM < SYUZEIT
  AND  SDLSTRTDT = SYDATUM.
    MOVE-CORRESPONDING TBTCO TO ITAB.
    APPEND ITAB.
  ENDSELECT.
ELSE.
  SELECT * FROM TBTCO WHERE STATUS = 'S' AND SDLSTRTTM <> '        '
  AND ( ( ( SDLSTRTDT = SY-DATUM ) AND ( SDLSTRTTM > SYUZEIT ) ) OR
        ( ( SDLSTRTDT = SYDATUM )  AND ( SDLSTRTTM < SYUZEIT ) ) ).
    MOVE-CORRESPONDING TBTCO TO ITAB.
    APPEND ITAB.
  ENDSELECT.
ENDIF.

DESCRIBE TABLE ITAB LINES LIN.
IF LIN > 0.
  LOOP AT  ITAB.
    STCR = ITAB-JOBNAME.
    IF STCR <> '@'.
      FLAG = 'R'.
      WRITE: / ITAB.
    ENDIF.
  ENDLOOP.
  IF FLAG = 'R'.
    SKIP.
    WRITE: / 'MASTER CLIENT COPY ABORTED!!!'.
    EXIT.
  ENDIF.
ENDIF.

* Enter system message: Do not work in client 21!!!

BDC_TAB-PROGRAM = 'SAPMSSY0'.
BDC_TAB-DYNPRO = '0120'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-FNAM = 'BDC_OKCODE'.
BDC_TAB-FVAL = '/5'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-PROGRAM = 'SAPMSEM1'.
BDC_TAB-DYNPRO = '4400'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-FNAM = 'EMLINE1'.
BDC_TAB-FVAL = 'DO NOT LOG IN TO CLIENT 21!!!!'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-FNAM = 'EMLINE2'.
BDC_TAB-FVAL = 'OTHERWISE YOU MIGHT DAMAGE CLIENT 21 and 999!!!!'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-FNAM = 'TEMSG-DATDEL'.
BDC_TAB-FVAL = DATUM.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-FNAM = 'TEMSG-TIMDEL'.
BDC_TAB-FVAL = TIME.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-PROGRAM = 'SAPMSYST'.
BDC_TAB-DYNPRO = '0040'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

BDC_TAB-FNAM = 'BDC_OKCODE'.
BDC_TAB-FVAL = '/3'.
APPEND BDC_TAB.
CLEAR BDC_TAB.

CALL TRANSACTION 'SM02' USING BDC_TAB MODE 'N'.

CALL FUNCTION 'BP_EVENT_RAISE'
     EXPORTING
          EVENTID = 'START_MCP'.

SKIP.
WRITE: / 'EVENT: START_MCP RAISED'.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Transport and Upgrade | Транспорт и Обновления All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.