Home > SAP software/management Tips > SAP ABAP/Java developer tips > Automatic nightly client copy triggering
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SAP ABAP/JAVA DEVELOPER TIPS

Automatic nightly client copy triggering


Imre Kabai
05.15.2001
Rating: -2.80- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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 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.



Code

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.


Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
SAP ABAP/Java developer tips
How to do additional dialog processing after SAP COMMIT WORK statement
How to find a piece of SAP ABAP code without debugging
How to read an SAP transaction in an ABAP code
How to provide an SAP R/3 4.5B application server with a Web service interface
How to find owners and transports of deleted ABAP programs
Fixing a common OPEN_FORM and START_FORM error in SAPscript
Select Text fields: Case-insensitive
Is this the quickest way to find a BADI?
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



NetWeaver SAP White Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts