REPORT ZTREXPI200 LINE-SIZE 255 LINE-COUNT 65. *======================================================================* * Titre : Planification et ordonnancement des jobs * * Programme : ZTREXPI200 * * Description : Injection de jobs à partir des fichiers * * Planification et ordonnancement * *======================================================================* * Date Création : 23.12.2002 * Auteur : Abdel SIDHOM * * www.saptechno.com * *======================================================================* ************************************************************************ * DECLARATION des DONNEES * ************************************************************************ TABLES : TRDIR, " Table système TRDIR. USR02, " Données de connexion BTCUEV, " événements util. p. traitement à l'arrière-plan, TBTCO, " Table de l'état des jobs BTCCTL, " Table de contrôle pour traitement à l'arrière-plan TFACD. " Déf. du cal. d'entreprise * Structures des steps des jobs -> Pour planifier DATA : BEGIN OF WS_FILE, JOB(32), "Nom du job USER TYPE SY-UNAME, "User TYPE(1), "P(Programme) ou S(Script) PROG(100), "Programme ou Script PARAM(100), "Variante ou parametre EXTPGM_SYSTEM LIKE TBTCSTEP-XPGTGTSYS, END OF WS_FILE. * Table texte des critères d'ordonnacement des jobs -> pour libérer DATA : BEGIN OF WT_ORD_FILE_TXT OCCURS 0, JOB(32), "Nom du job TARGETSYSTEM(40), TYPE(2), SDLSTRTDT(8), " like TBTCJOB-LASTSTRTDT, SDLSTRTTM(6), PRDMONTHS(2), PRDWEEKS(2), PRDDAYS(3), PRDHOURS(2), PRDMINS(2), CALENDAR_ID LIKE TBTCJOB-CALENDARID, BTC_PROCESS_ALWAYS(1), BTC_DONT_PROCESS_ON_HOLIDAY(1), BTC_PROCESS_BEFORE_HOLIDAY(1), BTC_PROCESS_AFTER_HOLIDAY(1), EVENT_ID LIKE TBTCJOB-EVENTID, EVENT_PARAM LIKE TBTCJOB-EVENTPARM, EVENT_PERIODIC LIKE BTCH0000-CHAR1, END OF WT_ORD_FILE_TXT. * Table des critères d'ordonnacement des jobs -> pour libérer DATA : BEGIN OF WS_ORD_FILE, JOB(32), "Nom du job TARGETSYSTEM LIKE BTCTGTSRVR-SRVNAME, TYPE(2), SDLSTRTDT LIKE TBTCJOB-LASTSTRTDT, SDLSTRTTM LIKE TBTCJOB-LASTSTRTTM, PRDMONTHS LIKE TBTCJOB-PRDMONTHS, PRDWEEKS LIKE TBTCJOB-PRDWEEKS, PRDDAYS LIKE TBTCJOB-PRDDAYS, PRDHOURS LIKE TBTCJOB-PRDHOURS, PRDMINS LIKE TBTCJOB-PRDMINS, CALENDAR_ID LIKE TBTCJOB-CALENDARID, BTC_PROCESS_ALWAYS(1), BTC_DONT_PROCESS_ON_HOLIDAY(1), BTC_PROCESS_BEFORE_HOLIDAY(1), BTC_PROCESS_AFTER_HOLIDAY(1), EVENT_ID LIKE TBTCJOB-EVENTID, EVENT_PARAM LIKE TBTCJOB-EVENTPARM, EVENT_PERIODIC LIKE BTCH0000-CHAR1, END OF WS_ORD_FILE. DATA : BEGIN OF WT_TBTCO OCCURS 0, JOBNAME LIKE TBTCO-JOBNAME, JOBCOUNT LIKE TBTCO-JOBCOUNT, STATUS LIKE TBTCO-STATUS, END OF WT_TBTCO. DATA : BEGIN OF WT_SERVER OCCURS 0, BTCSERVER LIKE BTCCTL-BTCSERVER, BTCSYSTEM LIKE BTCCTL-BTCSYSTEM, END OF WT_SERVER. DATA : BEGIN OF WT_CALENDAR OCCURS 0, IDENT LIKE TFACD-IDENT, END OF WT_CALENDAR. DATA : WT_FILE LIKE WS_FILE OCCURS 0 WITH HEADER LINE. DATA : WT_ORD_FILE LIKE WS_ORD_FILE OCCURS 0 WITH HEADER LINE. DATA : WT_BTCUEV LIKE BTCUEV OCCURS 0 WITH HEADER LINE. DATA : W_JOBCOUNT LIKE TBTCJOB-JOBCOUNT, W_ERRORS TYPE I, W_STEP(2) TYPE N, W_SUBRC LIKE SY-SUBRC, W_REPORT TYPE RALDB_REPO, W_VARIANT TYPE RALDB_VARI, W_JOB(32), W_PROGRAMME LIKE SY-REPID, W_VARIANTE LIKE RALDB-VARIANT, W_SCRIPT LIKE TBTCSTEP-PROGRAM, W_PARAMETRE LIKE TBTCSTEP-PARAMETER, WL_JOB_WAS_RELEASED, W_CAL_OPTION TYPE I, W_STARTDATE_RESTRICTION LIKE TBTCJOB-PRDBEHAV, W_CPT_DEL_JOBS TYPE I. * Options du calendrier DATA: BTC_DONT_PROCESS_ON_HOLIDAY LIKE BTCH0000-CHAR1 VALUE 'D', BTC_PROCESS_BEFORE_HOLIDAY LIKE BTCH0000-CHAR1 VALUE 'B', BTC_PROCESS_AFTER_HOLIDAY LIKE BTCH0000-CHAR1 VALUE 'A', BTC_PROCESS_ALWAYS LIKE BTCH0000-CHAR1 VALUE ' '. ************************************************************************ * ECRAN DE SELECTION * ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1. PARAMETERS: P_FILE TYPE LOCALFILE DEFAULT 'D:\JOBS.TXT' OBLIGATORY, P_ORFILE TYPE LOCALFILE DEFAULT 'D:\ORDO.TXT' OBLIGATORY, P_ENTET AS CHECKBOX DEFAULT 'X', P_REEL AS CHECKBOX, P_LANGU LIKE SY-LANGU DEFAULT 'FR'. SELECTION-SCREEN SKIP. PARAMETERS P_PLAN RADIOBUTTON GROUP GRP1. PARAMETERS P_PL_LIB RADIOBUTTON GROUP GRP1. SELECTION-SCREEN END OF BLOCK BL1. ************************************************************************ * EVENNEMENTS * ************************************************************************ AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. CALL FUNCTION 'F4_FILENAME' IMPORTING FILE_NAME = P_FILE. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_ORFILE. CALL FUNCTION 'F4_FILENAME' IMPORTING FILE_NAME = P_ORFILE. ************************************************************************ * CORPS DU PROGRAMME * ************************************************************************ START-OF-SELECTION. * Lecture des fichiers PERFORM READ_FILE. * Initialisation PERFORM INIT. * Contrôle des données PERFORM CONTROL_DATA. IF W_ERRORS = 0 . WRITE : /5 'Fichiers OK' COLOR 5. ELSE. WRITE : /5 'Veuillez vérifier votre fichier --> Aucun job créé' COLOR 6. ENDIF. SKIP. * Création des jobs IF P_REEL = 'X' AND W_ERRORS = 0. IF P_PLAN = 'X'. WRITE : /5 'Planification uniquement' COLOR 5. ELSE. WRITE : /5 'Planification et ordonnancement' COLOR 5. ENDIF. SKIP. PERFORM CREATE_JOBS. ENDIF. ************************************************************************ * DEFINITION DES ROUTINES ************************************************************************ *&---------------------------------------------------------------------* *& Form READ_FILE *&---------------------------------------------------------------------* FORM READ_FILE. * Chargement du fichier CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = P_FILE FILETYPE = 'DAT' TABLES DATA_TAB = WT_FILE EXCEPTIONS INVALID_FILESIZE = 1 INVALID_TABLE_WIDTH = 2 INVALID_TYPE = 3 NO_BATCH = 4 UNKNOWN_ERROR = 5 GUI_REFUSE_FILETRANSFER = 6 OTHERS = 7. IF SY-SUBRC <> 0. WRITE : /5 'Téléchargement JOB KO' COLOR 6. STOP. ENDIF. IF P_ENTET = 'X'. DELETE WT_FILE INDEX 1. WRITE : /5 'Entête fichier JOB supprimée' COLOR 5. ENDIF. DELETE WT_FILE WHERE JOB = SPACE. IF P_PL_LIB = 'X'. * Chargement du fichier d'ordonnancement CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = P_ORFILE FILETYPE = 'DAT' TABLES DATA_TAB = WT_ORD_FILE_TXT EXCEPTIONS INVALID_FILESIZE = 1 INVALID_TABLE_WIDTH = 2 INVALID_TYPE = 3 NO_BATCH = 4 UNKNOWN_ERROR = 5 GUI_REFUSE_FILETRANSFER = 6 OTHERS = 7. IF SY-SUBRC <> 0. WRITE : /5 'Téléchargement fichier ORDO KO' COLOR 6. STOP. ELSE. LOOP AT WT_ORD_FILE_TXT. MOVE-CORRESPONDING WT_ORD_FILE_TXT TO WT_ORD_FILE. APPEND WT_ORD_FILE. ENDLOOP. ENDIF. IF P_ENTET = 'X'. DELETE WT_ORD_FILE INDEX 1. WRITE : /5 'Entête fichier ORDO supprimée' COLOR 5. ENDIF. DELETE WT_ORD_FILE WHERE JOB = SPACE. SORT WT_ORD_FILE BY JOB. DELETE ADJACENT DUPLICATES FROM WT_ORD_FILE COMPARING JOB. IF SY-SUBRC = 0. WRITE : /5 'Le fichier ORDO contient des doublons' COLOR 6. STOP. ENDIF. ENDIF. SKIP. ENDFORM. " READ_FILE *&---------------------------------------------------------------------* *& Form CONTROL_DATA *&---------------------------------------------------------------------* FORM CONTROL_DATA. LOOP AT WT_FILE INTO WS_FILE. IF WS_FILE-JOB NE W_JOB. CLEAR W_STEP. ENDIF. ADD 1 TO W_STEP. IF WS_FILE-USER = SPACE. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB,' Step',W_STEP, ' --> User vide'. ELSE. SELECT SINGLE BNAME INTO USR02-BNAME FROM USR02 WHERE BNAME = WS_FILE-USER. IF SY-SUBRC NE 0. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB,' Step',W_STEP, ' --> User inexistant :', WS_FILE-USER COLOR 6. ENDIF. ENDIF. IF WS_FILE-TYPE IS INITIAL. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB,' Step',W_STEP, ' --> Type vide'. ELSEIF WS_FILE-TYPE NE 'P' AND WS_FILE-TYPE NE 'S'. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB,' Step',W_STEP, ' --> Type incorrect (P ou S ):',WS_FILE-TYPE COLOR 6. ENDIF. IF WS_FILE-PROG = SPACE. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB,' Step',W_STEP, ' --> Step vide'. ENDIF. IF WS_FILE-TYPE = 'P'. SELECT SINGLE * FROM TRDIR WHERE NAME = WS_FILE-PROG. IF SY-SUBRC <> 0. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB, ' Step',W_STEP, ' --> Programme inexistant:',WS_FILE-PROG COLOR 6. ELSEIF WS_FILE-PARAM NE SPACE. * Contrôle de la variante SHIFT WS_FILE-PROG LEFT DELETING LEADING SPACE. SHIFT WS_FILE-PARAM LEFT DELETING LEADING SPACE. MOVE WS_FILE-PROG TO W_REPORT. MOVE WS_FILE-PARAM TO W_VARIANT. CALL FUNCTION 'RS_VARIANT_EXISTS' EXPORTING REPORT = W_REPORT VARIANT = W_VARIANT IMPORTING R_C = W_SUBRC EXCEPTIONS NOT_AUTHORIZED = 1 NO_REPORT = 2 REPORT_NOT_EXISTENT = 3 REPORT_NOT_SUPPLIED = 4 OTHERS = 5. IF SY-SUBRC <> 0 OR W_SUBRC <> 0. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB, ' Step',W_STEP, ' --> Variante incorrecte :',WS_FILE-PROG(30) COLOR 6, WS_FILE-PARAM COLOR 6. ENDIF. ENDIF. ENDIF. * Vérification des scripts IF WS_FILE-TYPE = 'S'. OPEN DATASET WS_FILE-PROG FOR INPUT IN TEXT MODE. IF SY-SUBRC = 0. CLOSE DATASET WS_FILE-PROG. * Contrôle machine cible IF WS_FILE-EXTPGM_SYSTEM IS INITIAL. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB, ' Step',W_STEP, ' --> Machine cible non définie' . ELSE. READ TABLE WT_SERVER WITH KEY BTCSYSTEM = WS_FILE-EXTPGM_SYSTEM. IF SY-SUBRC <> 0. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB, ' Step',W_STEP, ' --> Machine cible introuvable',WS_FILE-EXTPGM_SYSTEM COLOR 6. ENDIF. ENDIF. ELSE. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB, ' Step',W_STEP, ' --> Script inexistant :',WS_FILE-PROG COLOR 6. ENDIF. ENDIF. W_JOB = WS_FILE-JOB. * Contrôle des critère d'ordo. si on veut liberer des jobs AT END OF JOB. IF P_PL_LIB = 'X'. * verifie si l'enr. d'ordo. existe ? READ TABLE WT_ORD_FILE WITH KEY JOB = WS_FILE-JOB INTO WS_ORD_FILE BINARY SEARCH. IF SY-SUBRC = 0. PERFORM CONTROL_ORDO. ELSE. WRITE : /5 WS_FILE-JOB, '*Enregistrement ordo. non trouvé'. W_ERRORS = W_ERRORS + 1. ENDIF. ENDIF. " IF P_PL_LIB = 'X' ENDAT. ENDLOOP. SKIP. ENDFORM. " CONTROL_DATA *&---------------------------------------------------------------------* *& Form CREATE_JOBS *&---------------------------------------------------------------------* FORM CREATE_JOBS. CLEAR : WL_JOB_WAS_RELEASED, WS_FILE, W_CPT_DEL_JOBS. LOOP AT WT_FILE INTO WS_FILE. ADD 1 TO W_STEP. CLEAR : W_PROGRAMME, W_VARIANTE, W_SCRIPT, W_PARAMETRE. CASE WS_FILE-TYPE. WHEN 'P'. MOVE : WS_FILE-PROG TO W_PROGRAMME, WS_FILE-PARAM TO W_VARIANTE. WHEN 'S'. MOVE : WS_FILE-PROG TO W_SCRIPT, WS_FILE-PARAM TO W_PARAMETRE. ENDCASE. AT NEW JOB. * Deleter le job (de status PLANIFIE ou LIBERE) avant de recréer PERFORM DELET_JOB. W_STEP = 1. PERFORM OPEN_JOB. ENDAT. * Planifier (créer de(s) step(s)) PERFORM SUBMIT_JOB. AT END OF JOB. * Cas Planifier uniquement CASE P_PLAN. WHEN 'X'. PERFORM CLOSE_JOB. * Cas Planifier & libérer WHEN OTHERS. PERFORM RELEASE_AND_CLOSE_JOB. ENDCASE. ENDAT. ENDLOOP. ENDFORM. " CREATE_JOBS *&---------------------------------------------------------------------* *& Form control_ordo *&---------------------------------------------------------------------* FORM CONTROL_ORDO. * controle la machine cible IF NOT WS_ORD_FILE-TARGETSYSTEM IS INITIAL. READ TABLE WT_SERVER WITH KEY BTCSERVER = WS_ORD_FILE-TARGETSYSTEM BINARY SEARCH. IF SY-SUBRC <> 0. ADD 1 TO W_ERRORS. WRITE : /5 WS_FILE-JOB, '*Serveur cible introuvable',WS_ORD_FILE-TARGETSYSTEM COLOR 6. ENDIF. ENDIF. * liberer les jobs en fonction de leur type CASE WS_ORD_FILE-TYPE. WHEN 'EV'. " type lancement après l'evt IF WS_ORD_FILE-EVENT_ID IS INITIAL. WRITE : /5 WS_ORD_FILE-JOB, '*Evénement non renseigné:'. W_ERRORS = W_ERRORS + 1. ELSE. READ TABLE WT_BTCUEV WITH KEY EVENTID = WS_ORD_FILE-EVENT_ID BINARY SEARCH. IF SY-SUBRC <> 0. WRITE : /5 WS_ORD_FILE-JOB, '*Evénement inexistant', WS_ORD_FILE-EVENT_ID COLOR 6. W_ERRORS = W_ERRORS + 1. ENDIF. ENDIF. WHEN 'DH'. "type lancement Date, heure IF WS_ORD_FILE-SDLSTRTDT IS INITIAL OR WS_ORD_FILE-SDLSTRTTM IS INITIAL. WRITE : /5 WS_ORD_FILE-JOB, '*Date ou heure non renseignée'. W_ERRORS = W_ERRORS + 1. ELSE. * Controle des données concernant délimitaion IF NOT WS_ORD_FILE-CALENDAR_ID IS INITIAL. * Calendrier id existe ? READ TABLE WT_CALENDAR WITH KEY IDENT = WS_ORD_FILE-CALENDAR_ID BINARY SEARCH. IF SY-SUBRC <> 0. WRITE : /5 WS_ORD_FILE-JOB, '*Calendrier id inexistant', WS_ORD_FILE-CALENDAR_ID COLOR 6. W_ERRORS = W_ERRORS + 1. ENDIF. * Verifie si l'option de calendrier est exclusive CLEAR : W_CAL_OPTION. IF NOT WS_ORD_FILE-BTC_PROCESS_ALWAYS IS INITIAL. W_CAL_OPTION = W_CAL_OPTION + 1. ENDIF. IF NOT WS_ORD_FILE-BTC_DONT_PROCESS_ON_HOLIDAY IS INITIAL. W_CAL_OPTION = W_CAL_OPTION + 1. ENDIF. IF NOT WS_ORD_FILE-BTC_PROCESS_BEFORE_HOLIDAY IS INITIAL. W_CAL_OPTION = W_CAL_OPTION + 1. ENDIF. IF NOT WS_ORD_FILE-BTC_PROCESS_AFTER_HOLIDAY IS INITIAL. W_CAL_OPTION = W_CAL_OPTION + 1. ENDIF. IF W_CAL_OPTION IS INITIAL. WRITE : /5 WS_ORD_FILE-JOB, '*Option calendrier non renseignée'. W_ERRORS = W_ERRORS + 1. ELSEIF W_CAL_OPTION > 1. WRITE : /5 WS_ORD_FILE-JOB, '*Option calendrier inexclusive'. W_ERRORS = W_ERRORS + 1. ENDIF. ELSE. " si le calendrier id n'est pas renseigné * Si une option de calendrier est renseigné * lorsque calendrier id non renseigé -> message erreur IF NOT WS_ORD_FILE-BTC_PROCESS_ALWAYS IS INITIAL OR NOT WS_ORD_FILE-BTC_DONT_PROCESS_ON_HOLIDAY IS INITIAL OR NOT WS_ORD_FILE-BTC_PROCESS_BEFORE_HOLIDAY IS INITIAL OR NOT WS_ORD_FILE-BTC_PROCESS_AFTER_HOLIDAY IS INITIAL. WRITE : /5 WS_ORD_FILE-JOB, '*Calendrier id non reseigné'. W_ERRORS = W_ERRORS + 1. ENDIF. ENDIF. * Verifie la valeur de date CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY' EXPORTING DATE = WS_ORD_FILE-SDLSTRTDT EXCEPTIONS PLAUSIBILITY_CHECK_FAILED = 1 OTHERS = 2. IF SY-SUBRC <> 0. WRITE : /5 WS_ORD_FILE-JOB, '*Date incorrecte', WS_ORD_FILE-SDLSTRTDT COLOR 6. W_ERRORS = W_ERRORS + 1. ELSE. * Test si la date est bien dans le futur IF WS_ORD_FILE-SDLSTRTDT < SY-DATUM. WRITE : /5 WS_ORD_FILE-JOB, '*Date passée', WS_ORD_FILE-SDLSTRTDT COLOR 6. W_ERRORS = W_ERRORS + 1. ELSEIF WS_ORD_FILE-SDLSTRTDT = SY-DATUM AND WS_ORD_FILE-SDLSTRTTM < SY-UZEIT. WRITE : /5 WS_ORD_FILE-JOB, '*Heure passée', WS_ORD_FILE-SDLSTRTTM COLOR 6. W_ERRORS = W_ERRORS + 1. ENDIF. ENDIF. * VERIFIE LA VALEUR DE L'HEURE CALL FUNCTION 'TIME_CHECK_PLAUSIBILITY' EXPORTING TIME = WS_ORD_FILE-SDLSTRTTM EXCEPTIONS PLAUSIBILITY_CHECK_FAILED = 1 OTHERS = 2. IF SY-SUBRC <> 0. WRITE : /5 WS_ORD_FILE-JOB, '*Heure incorrecte', WS_ORD_FILE-SDLSTRTTM COLOR 6. W_ERRORS = W_ERRORS + 1. ENDIF. ENDIF. WHEN ''. WRITE : /5 WS_ORD_FILE-JOB, '*Type ordo. non reseigné'. W_ERRORS = W_ERRORS + 1. WHEN OTHERS. WRITE : /5 WS_ORD_FILE-JOB, '*Type ordo. non valide', WS_ORD_FILE-TYPE COLOR 6. W_ERRORS = W_ERRORS + 1. ENDCASE. ENDFORM. " control_ordo *&---------------------------------------------------------------------* *& Form init *&---------------------------------------------------------------------* FORM INIT. IF P_PL_LIB = 'X'. * Lire la table BTCUEV et stock les données dans wt_BTCUEV SELECT EVENTID INTO TABLE WT_BTCUEV FROM BTCUEV. SORT WT_BTCUEV. ENDIF. * Chargement de tous les anciens jobs planifié et libérés SELECT JOBNAME JOBCOUNT STATUS INTO CORRESPONDING FIELDS OF TABLE WT_TBTCO FROM TBTCO FOR ALL ENTRIES IN WT_FILE WHERE STATUS = 'S' OR STATUS = 'P' "P: Planifié, S:libéré AND JOBNAME = WT_FILE-JOB. * lire la table de serveurs des systeme cible SELECT BTCSERVER BTCSYSTEM INTO TABLE WT_SERVER FROM BTCCTL. SORT WT_SERVER BY BTCSERVER. * Lire la table de calendrier SELECT IDENT INTO TABLE WT_CALENDAR FROM TFACD. SORT WT_CALENDAR BY IDENT. ENDFORM. " init *&---------------------------------------------------------------------* *& Form delet_job *&---------------------------------------------------------------------* * Suppression des anciens jobs *----------------------------------------------------------------------* FORM DELET_JOB. FORMAT COLOR 1 INTENSIFIED OFF . CLEAR W_CPT_DEL_JOBS. LOOP AT WT_TBTCO WHERE JOBNAME = WS_FILE-JOB. CALL FUNCTION 'BP_JOB_DELETE' EXPORTING JOBCOUNT = WT_TBTCO-JOBCOUNT JOBNAME = WT_TBTCO-JOBNAME EXCEPTIONS CANT_DELETE_EVENT_ENTRY = 1 CANT_DELETE_JOB = 2 CANT_DELETE_JOBLOG = 3 CANT_DELETE_STEPS = 4 CANT_DELETE_TIME_ENTRY = 5 CANT_DERELEASE_SUCCESSOR = 6 CANT_ENQ_PREDECESSOR = 7 CANT_ENQ_SUCCESSOR = 8 CANT_ENQ_TBTCO_ENTRY = 9 CANT_UPDATE_PREDECESSOR = 10 CANT_UPDATE_SUCCESSOR = 11 COMMIT_FAILED = 12 JOBCOUNT_MISSING = 13 JOBNAME_MISSING = 14 JOB_DOES_NOT_EXIST = 15 JOB_IS_ALREADY_RUNNING = 16 NO_DELETE_AUTHORITY = 17 OTHERS = 18. IF SY-SUBRC <> 0. WRITE : /5 WS_FILE-JOB, 'JOB_DELETE --> KO', WT_TBTCO-JOBCOUNT COLOR 6. ELSE. W_CPT_DEL_JOBS = W_CPT_DEL_JOBS + 1. WRITE : /5 WS_FILE-JOB,'JOB_DELETE --> OK',WT_TBTCO-JOBCOUNT . ENDIF. ENDLOOP. WRITE : /5 WS_FILE-JOB,'Jobs supprimés ',W_CPT_DEL_JOBS . FORMAT RESET. ENDFORM. " delet_job *&---------------------------------------------------------------------* *& Form release_and_close_job *&---------------------------------------------------------------------* * Release & close jobs *----------------------------------------------------------------------* FORM RELEASE_AND_CLOSE_JOB. CLEAR : WT_ORD_FILE, WS_ORD_FILE-JOB. * Cherche l'enr. de critère d'ordo. READ TABLE WT_ORD_FILE WITH KEY JOB = WS_FILE-JOB INTO WS_ORD_FILE BINARY SEARCH. * Définition de l'option du calendrier CLEAR : W_STARTDATE_RESTRICTION. IF NOT WS_ORD_FILE-BTC_DONT_PROCESS_ON_HOLIDAY IS INITIAL. W_STARTDATE_RESTRICTION = BTC_DONT_PROCESS_ON_HOLIDAY. ENDIF. IF NOT WS_ORD_FILE-BTC_PROCESS_BEFORE_HOLIDAY IS INITIAL. W_STARTDATE_RESTRICTION = BTC_PROCESS_BEFORE_HOLIDAY. ENDIF. IF NOT WS_ORD_FILE-BTC_PROCESS_AFTER_HOLIDAY IS INITIAL. W_STARTDATE_RESTRICTION = BTC_PROCESS_AFTER_HOLIDAY. ENDIF. IF NOT WS_ORD_FILE-BTC_PROCESS_ALWAYS IS INITIAL. W_STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYS. ENDIF. IF WS_ORD_FILE-TYPE = 'EV'. CALL FUNCTION 'JOB_CLOSE' EXPORTING EVENT_ID = WS_ORD_FILE-EVENT_ID EVENT_PARAM = WS_ORD_FILE-EVENT_PARAM EVENT_PERIODIC = WS_ORD_FILE-EVENT_PERIODIC JOBCOUNT = W_JOBCOUNT JOBNAME = WS_FILE-JOB TARGETSERVER = WS_ORD_FILE-TARGETSYSTEM IMPORTING JOB_WAS_RELEASED = WL_JOB_WAS_RELEASED EXCEPTIONS CANT_START_IMMEDIATE = 1 INVALID_STARTDATE = 2 JOBNAME_MISSING = 3 JOB_CLOSE_FAILED = 4 JOB_NOSTEPS = 5 JOB_NOTEX = 6 LOCK_FAILED = 7 OTHERS = 8. IF SY-SUBRC <> 0. WRITE : /5 WS_FILE-JOB, 'Erreur JOB_CLOSE :', SY-SUBRC COLOR 6. ELSE. WRITE : /5 WS_FILE-JOB, 'JOB_CLOSE --> OK'. ENDIF. ELSE. CALL FUNCTION 'JOB_CLOSE' EXPORTING JOBNAME = WS_FILE-JOB JOBCOUNT = W_JOBCOUNT SDLSTRTDT = WS_ORD_FILE-SDLSTRTDT SDLSTRTTM = WS_ORD_FILE-SDLSTRTTM CALENDAR_ID = WS_ORD_FILE-CALENDAR_ID PRDDAYS = WS_ORD_FILE-PRDDAYS PRDHOURS = WS_ORD_FILE-PRDHOURS PRDMINS = WS_ORD_FILE-PRDMINS PRDMONTHS = WS_ORD_FILE-PRDMONTHS PRDWEEKS = WS_ORD_FILE-PRDWEEKS STARTDATE_RESTRICTION = W_STARTDATE_RESTRICTION TARGETSERVER = WS_ORD_FILE-TARGETSYSTEM IMPORTING JOB_WAS_RELEASED = WL_JOB_WAS_RELEASED EXCEPTIONS CANT_START_IMMEDIATE = 1 INVALID_STARTDATE = 2 JOBNAME_MISSING = 3 JOB_CLOSE_FAILED = 4 JOB_NOSTEPS = 5 JOB_NOTEX = 6 LOCK_FAILED = 7 OTHERS = 8. IF SY-SUBRC <> 0. WRITE : /5 WS_FILE-JOB, 'Erreur JOB_CLOSE :', SY-SUBRC COLOR 6. ELSE. WRITE : /5 WS_FILE-JOB, 'JOB_CLOSE --> OK'. ENDIF. ENDIF. SKIP. ENDFORM. " release_and_close_job *&---------------------------------------------------------------------* *& Form close_job *&---------------------------------------------------------------------* * close job *----------------------------------------------------------------------* FORM CLOSE_JOB. CALL FUNCTION 'JOB_CLOSE' EXPORTING JOBCOUNT = W_JOBCOUNT JOBNAME = WS_FILE-JOB EXCEPTIONS CANT_START_IMMEDIATE = 1 INVALID_STARTDATE = 2 JOBNAME_MISSING = 3 JOB_CLOSE_FAILED = 4 JOB_NOSTEPS = 5 JOB_NOTEX = 6 LOCK_FAILED = 7 OTHERS = 8. IF SY-SUBRC <> 0. WRITE : /5 WS_FILE-JOB, 'Erreur JOB_CLOSE :', SY-SUBRC COLOR 6. ELSE. WRITE : /5 WS_FILE-JOB, 'JOB_CLOSE --> OK'. ENDIF. SKIP. ENDFORM. " close_job *&---------------------------------------------------------------------* *& Form open_job *&---------------------------------------------------------------------* * Open job *----------------------------------------------------------------------* FORM OPEN_JOB. CLEAR W_JOBCOUNT. CALL FUNCTION 'JOB_OPEN' EXPORTING JOBNAME = WS_FILE-JOB IMPORTING JOBCOUNT = W_JOBCOUNT EXCEPTIONS CANT_CREATE_JOB = 1 INVALID_JOB_DATA = 2 JOBNAME_MISSING = 3 OTHERS = 4. FORMAT COLOR 1 INTENSIFIED OFF . IF SY-SUBRC <> 0. WRITE : /5 WS_FILE-JOB, 'Erreur JOB_OPEN :', SY-SUBRC COLOR 6. ELSE. WRITE : /5 WS_FILE-JOB, 'JOB_OPEN --> OK'. ENDIF. FORMAT RESET. ENDFORM. " open_job *&---------------------------------------------------------------------* *& Form submit_job *&---------------------------------------------------------------------* * Planifier des job *----------------------------------------------------------------------* FORM SUBMIT_JOB. CALL FUNCTION 'JOB_SUBMIT' EXPORTING AUTHCKNAM = WS_FILE-USER EXTPGM_NAME = W_SCRIPT EXTPGM_PARAM = W_PARAMETRE * EXTPGM_SET_TRACE_ON = ' ' * EXTPGM_STDERR_IN_JOBLOG = 'X' * EXTPGM_STDOUT_IN_JOBLOG = 'X' EXTPGM_SYSTEM = WS_FILE-EXTPGM_SYSTEM * EXTPGM_RFCDEST = ' ' * EXTPGM_WAIT_FOR_TERMINATION = 'X' JOBCOUNT = W_JOBCOUNT JOBNAME = WS_FILE-JOB LANGUAGE = P_LANGU * PRIPARAMS = ' ' REPORT = W_PROGRAMME VARIANT = W_VARIANTE EXCEPTIONS BAD_PRIPARAMS = 1 BAD_XPGFLAGS = 2 INVALID_JOBDATA = 3 JOBNAME_MISSING = 4 JOB_NOTEX = 5 JOB_SUBMIT_FAILED = 6 LOCK_FAILED = 7 PROGRAM_MISSING = 8 PROG_ABAP_AND_EXTPG_SET = 9 OTHERS = 10. IF SY-SUBRC <> 0. WRITE : /7 'Step :',W_STEP,'-Erreur JOB_SUBMIT :', SY-SUBRC COLOR 6. ELSE. WRITE : /7 'Step : ',W_STEP,'--> OK'. ENDIF. ENDFORM. " submit_job