REPORT ZTREXPI100 LINE-SIZE 255 LINE-COUNT 65. *======================================================================* * Titre : Injecteur de jobs * * Programme : ZTREXPI100 * * Description : Injection de jobs à partir d'un fichier * * texte avec séparateurs tabulations * *======================================================================* * Date Création : 23.12.2002 * Auteur : Abdel SIDHOM * * www.saptechno.com * *======================================================================* ************************************************************************ * DECLARATION des DONNEES * ************************************************************************ TABLES : TRDIR,USR02. 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 END OF WS_FILE. DATA : WT_FILE LIKE WS_FILE 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. ************************************************************************ * ECRAN DE SELECTION * ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1. PARAMETERS: P_FILE TYPE LOCALFILE DEFAULT 'D:\JOBS.TXT', P_ENTET AS CHECKBOX DEFAULT 'X', P_REEL AS CHECKBOX, P_LANGU LIKE SY-LANGU DEFAULT 'FR', P_SYST LIKE TBTCSTEP-XPGTGTSYS DEFAULT SY-HOST. "machine cible 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. ************************************************************************ * CORPS DU PROGRAMME * ************************************************************************ START-OF-SELECTION. PERFORM READ_FILE. PERFORM CONTROL_DATA. IF W_ERRORS = 0 . WRITE : /5 'Fichier OK' COLOR 5. ELSE. WRITE : /5 'Veuillez vérifier votre fichier --> Aucun job créé' COLOR 6. ENDIF. IF P_REEL = 'X' AND W_ERRORS = 0. 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 KO'. STOP. ELSE. WRITE : /5 'Téléchargement OK' COLOR 5. ENDIF. SKIP. IF P_ENTET = 'X'. DELETE WT_FILE INDEX 1. WRITE : /5 'Entête fichier supprimée' COLOR 5. SKIP. ENDIF. ENDFORM. " READ_FILE *&---------------------------------------------------------------------* *& Form CONTROL_DATA *&---------------------------------------------------------------------* FORM CONTROL_DATA. DELETE WT_FILE WHERE JOB = SPACE. LOOP AT WT_FILE. IF WT_FILE-JOB NE W_JOB. CLEAR W_STEP. ENDIF. ADD 1 TO W_STEP. IF WT_FILE-USER = SPACE. ADD 1 TO W_ERRORS. WRITE : /5 'Job :', WT_FILE-JOB,' Step',W_STEP, ' --> User vide :'. ELSE. SELECT SINGLE BNAME INTO USR02-BNAME FROM USR02 WHERE BNAME = WT_FILE-USER. IF SY-SUBRC NE 0. ADD 1 TO W_ERRORS. WRITE : /5 'Job :', WT_FILE-JOB,' Step',W_STEP, ' --> User inexistant :', WT_FILE-USER. ENDIF. ENDIF. IF WT_FILE-TYPE NE 'P' AND WT_FILE-TYPE NE 'S'. ADD 1 TO W_ERRORS. WRITE : /5 'Job :', WT_FILE-JOB,' Step',W_STEP, ' --> Type incorrect (P ou S ):',WT_FILE-TYPE. ENDIF. IF WT_FILE-PROG = SPACE. ADD 1 TO W_ERRORS. WRITE : /5 'Job :', WT_FILE-JOB,' Step',W_STEP, ' --> Step vide'. ENDIF. IF WT_FILE-TYPE = 'P'. SELECT SINGLE * FROM TRDIR WHERE NAME = WT_FILE-PROG. IF SY-SUBRC <> 0. ADD 1 TO W_ERRORS. WRITE : /5 'Job :', WT_FILE-JOB, ' Step',W_STEP, ' --> Programme inexistant:',WT_FILE-PROG. ELSEIF WT_FILE-PARAM NE SPACE. * Contôle de la variante SHIFT WT_FILE-PROG LEFT DELETING LEADING SPACE. SHIFT WT_FILE-PARAM LEFT DELETING LEADING SPACE. MOVE WT_FILE-PROG TO W_REPORT. MOVE WT_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 'Job :', WT_FILE-JOB, ' Step',W_STEP, ' --> Variante incorrecte :',WT_FILE-PROG(30), WT_FILE-PARAM. ENDIF. ENDIF. ENDIF. * Vérification des scripts IF WT_FILE-TYPE = 'S'. OPEN DATASET WT_FILE-PROG FOR INPUT IN TEXT MODE. IF SY-SUBRC = 0. CLOSE DATASET WT_FILE-PROG. ELSE. ADD 1 TO W_ERRORS. WRITE : /5 'Job :', WT_FILE-JOB, ' Step',W_STEP, ' --> Script incorrect :',WT_FILE-PROG. ENDIF. ENDIF. W_JOB = WT_FILE-JOB. ENDLOOP. SKIP. ENDFORM. " CONTROL_DATA *&---------------------------------------------------------------------* *& Form CREATE_JOBS *&---------------------------------------------------------------------* FORM CREATE_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. SKIP. W_STEP = 1. 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. ENDAT. 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 = P_SYST * 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. AT END OF 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. ENDAT. ENDLOOP. ENDFORM. " CREATE_JOBS