Automatic nightly client copy triggering

Automatic nightly client copy triggering

Automatic nightly client copy triggering
By Imre Kabai

This tip is published with the permission of Imre Kabai.

This program raise an event START_MCP to start an automatic master client copy if there are no users in the system and

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

there is no scheduled 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.


REPORT YMASTCP .
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'.

To view this tip, or others like it, surf on over to Imre Kabai's website.

Did you like this tip? Hate it? Send us an email to let us know your thoughts.

This was first published in May 2001

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.