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

Import trasports with programs via unix script



 
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: 1636

PostPosted: Fri Jan 22, 2010 5:30 pm    Post subject: Import trasports with programs via unix script Reply with quote

Code:
REPORT ZZBGSCTS MESSAGE-ID Z1.
*----------------------------------------------------------------------*
* Description: Programmet anvendes af abap/4 programmшrer i forbindelse*
*              med transport af programmer. Programmet starter et UNIX *
*              script som importerer en transport til den aktuelle     *
*              SAP maskine fra en anden SAP maskine. .                 *
*                                                                      *
*              Nеr abap/4 programmшren releaser programmet fra udvik-  *
*              lings maskinen, udlжses transporten automatisk af SAP   *
*              til UNIX. For at fе indlжst transporten pе en anden     *
*              maskine f.eks integrationsmaskinen, skal dette program  *
*              startes pе modtagermaskinen, derved kan programmet ogsе *
*              anvendes pе produktionsmakinen.                         *
*                                                                      *
*              Unix script filen returnere sit output pе standard out- *
*              put, som udskrives pе liste og udvalgte data lagres pе  *
*              en logfil.                                              *
*                                                                      *
*              Loggen bliver appended til en og samme logfil, som      *
*              kontrolleres- og tшmmes af driftsafdelingen.            *
*                                                                      *
* Customizing: Programmet forudsжtter at brugeren har adgang til       *
*              log file path og unix script path.                      *
*                                                                      *
* Change of    Du skal blot kontrollere at de anvendte tabeller og evt.*
* release:     includes ikke er жndret. Dette gшres nemmes via ABAP/4  *
*              WORKBENCH.                                              *
*                                                                      *
* Programmer:  Benny G. Sшrensen, BGS Consulting ApS, http://www.bgs.dk*
* Date:        17.10.1998                                              *
*                                                                      *
* Submitting:  Via transaktion SA38 eller via batch jobafvikling.      *
*                                                                      *
* Parametre:   TRKORR : Transportnummer.                               *
*                                                                      *
* Input:       Unix script                                             *
*                                                                      *
* Output:      ZZBGSCTS.LOG (pе importmaskinen)                        *
*                                                                      *
*-------------------------------Corrections----------------------------*
* Date        Userid     Correction                                    *
* 17-09-1998  BGS        Development                                   *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Global constants Must be customized                                  *
*----------------------------------------------------------------------*
DATA:OK                  LIKE SY-SUBRC VALUE 0   "Code for Ok
    ,YES                 TYPE I        VALUE 1   "Boolean = YES
    ,NO                  TYPE I        VALUE 0   "Boolean = No
    ,COMMAND(80)         TYPE C.

*----------------------------------------------------------------------*
* Global variables                                                     *
*----------------------------------------------------------------------*
DATA: RECORD(132)   TYPE C               "Input from UNIX script
     ,OFFSET        TYPE I
     ,QUIT          LIKE NO VALUE 0
     ,RC            LIKE SY-SUBRC
     ,FILENAME(60)  TYPE C
     ,SUFFIX(4)     TYPE C
     ,ELEMENTS      TYPE I
     .
FIELD-SYMBOLS: <F>.

DATA: BEGIN OF TRANSPORTER OCCURS 10      "output to logfile
       ,NUMMER LIKE KO003-TRKORR
     ,END OF TRANSPORTER.

DATA: BEGIN OF LOG_DATA OCCURS 10      "output to logfile
       ,TRKORR LIKE KO003-TRKORR
       ,EXIT_CODE(5) TYPE C
     ,END OF LOG_DATA.

DATA: BEGIN OF TABL OCCURS 0,
        TRKORR LIKE KO003-TRKORR,
        LINE(560),
      END OF TABL.

DATA: BEGIN OF STDOUTPUT OCCURS 0,
        LINE(560),
      END OF STDOUTPUT.

DATA: BEGIN OF OBJHEAD OCCURS 0.
        INCLUDE STRUCTURE SOLI.
DATA: END OF OBJHEAD.

DATA: BEGIN OF OBJECT_HD_CHANGE.
        INCLUDE STRUCTURE SOOD1.
DATA: END OF OBJECT_HD_CHANGE.

DATA: BEGIN OF OBJCONT OCCURS 2.       "contents
        INCLUDE STRUCTURE SOLI.
DATA: END OF OBJCONT.

DATA: BEGIN OF RECEIVERS OCCURS 2.
        INCLUDE STRUCTURE SOOS1.
DATA: END OF RECEIVERS.

DATA: BEGIN OF OBJPARA OCCURS 0.
        INCLUDE STRUCTURE SELC.
DATA: END OF OBJPARA.

DATA: BEGIN OF OBJPARB OCCURS 0.
        INCLUDE STRUCTURE SOOP1.
DATA: END OF OBJPARB.

DATA: BEGIN OF TKORR OCCURS 0.
DATA:   TRKORR LIKE KO003-TRKORR.
DATA: END OF TKORR.
*----------------------------------------------------------------------*
* Tables                                                               *
*----------------------------------------------------------------------*
TABLES: KO003.
*----------------------------------------------------------------------*
* Selection screen                                                     *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK0 WITH FRAME TITLE TEXT-008.
      SELECTION-SCREEN:                      "
        COMMENT 01(72) TEXT-012 .            "
SELECTION-SCREEN END OF BLOCK BLK0.

PARAMETER: SCRIPT(40) TYPE C DEFAULT '/usr/sap/trans/bin/tpimp % % %'
           NO-DISPLAY
          ,LOGG(40)   TYPE C DEFAULT '/usr/sap/trans/zzbgsct.LOG'
           NO-DISPLAY.
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-006.
  SELECTION-SCREEN:                          "Linie-1
    BEGIN OF LINE.                           "
      SELECTION-SCREEN:                      "
        COMMENT 01(20) MANDANT  .            "transport
      PARAMETERS:                            "
        CLIENT  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN END OF LINE.              "
SELECTION-SCREEN END OF BLOCK BLK1.

SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-007.
  SELECTION-SCREEN:                          "Linie-2
    BEGIN OF LINE.                           "
      SELECTION-SCREEN:                      "
        COMMENT 01(20) TEXT-010 .            "transport
      PARAMETERS:                            "
        TRKORR1  LIKE KO003-TRKORR
       ,TRKORR2  LIKE KO003-TRKORR
       ,TRKORR3  LIKE KO003-TRKORR
       ,TRKORR4  LIKE KO003-TRKORR
       ,TRKORR5  LIKE KO003-TRKORR
       .
  SELECTION-SCREEN END OF LINE.              "

  SELECTION-SCREEN:                          "Linie-3
    BEGIN OF LINE.                           "
      SELECTION-SCREEN:                      "
        COMMENT 01(20) TEXT-000 .            "transport
      PARAMETERS:                            "
        TRKORR6  LIKE KO003-TRKORR
       ,TRKORR7  LIKE KO003-TRKORR
       ,TRKORR8  LIKE KO003-TRKORR
       ,TRKORR9  LIKE KO003-TRKORR
       ,TRKORR10 LIKE KO003-TRKORR
       .
  SELECTION-SCREEN END OF LINE.              "

  SELECTION-SCREEN:                          "Linie-4
    BEGIN OF LINE.                           "
      SELECTION-SCREEN:                      "
        COMMENT 01(20) TEXT-000 .            "transport
      PARAMETERS:                            "
        TRKORR11 LIKE KO003-TRKORR
       ,TRKORR12 LIKE KO003-TRKORR
       ,TRKORR13 LIKE KO003-TRKORR
       ,TRKORR14 LIKE KO003-TRKORR
       ,TRKORR15 LIKE KO003-TRKORR
       .
  SELECTION-SCREEN END OF LINE.              "
SELECTION-SCREEN END OF BLOCK BLK2.


* --------------------------------------------------------------------*
* At selection-screen : kontroller inddata                            *
* --------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.

AT SELECTION-SCREEN.
DATA: HMM(20) TYPE C.

  AUTHORITY-CHECK OBJECT 'S_PROGRAM'
    ID 'P_GROUP'  FIELD 'ZZBGSCTS'
    ID 'P_ACTION' DUMMY.
  IF SY-SUBRC NE OK.
    MESSAGE ID 'Z1' TYPE 'E' NUMBER '100'.
  ENDIF.

  GET CURSOR FIELD HMM.

* IF THE USER DID NOT fill any Transport numbers SEND ERROR
  IF TRKORR1  = SPACE AND TRKORR2  = SPACE AND TRKORR3  = SPACE AND
     TRKORR4  = SPACE AND TRKORR5  = SPACE AND TRKORR6  = SPACE AND
     TRKORR7  = SPACE AND TRKORR8  = SPACE AND TRKORR9  = SPACE AND
     TRKORR10 = SPACE AND TRKORR11 = SPACE AND TRKORR12 = SPACE AND
     TRKORR13 = SPACE AND TRKORR14 = SPACE AND TRKORR15 = SPACE .
    MESSAGE ID 'Z1' TYPE 'E' NUMBER '003' WITH TEXT-005.
  ENDIF.

* --------------------------------------------------------------------*
* At LINE-SELECTION: Browse logfil                                    *
* Bemжrk at der findes forskllige LOGFILES og at de er placeret pе    *
* hhv afsender og modtager maskine.                                   *
*                                                                     *
* --------------------------------------------------------------------*
AT LINE-SELECTION.
  SEARCH SY-LISEL FOR 'exit code : '.
  IF SY-SUBRC = OK.
    SEARCH SY-LISEL FOR ':'.
    IF SY-SUBRC = OK.
      ASSIGN SY-LISEL(SY-FDPOS) TO <F>.
      FILENAME = <F>.
      SEARCH FILENAME FOR '...' .
      OFFSET = SY-FDPOS.
      ADD 1 TO OFFSET.
      ASSIGN FILENAME+OFFSET(3) TO <F>.
      SUFFIX = <F>.
      IF SUFFIX = SY-SYSID.
        SUFFIX = 'NONE'.
      ENDIF.

      CALL FUNCTION 'RFC_BROWSE_FILE'
        EXPORTING    FILENAME = FILENAME.
    ENDIF.
  ENDIF.

*----------------------------------------------------------------------*
* EVENT: Initialzation before show of selection-screen                 *
*----------------------------------------------------------------------*
INITIALIZATION.
  MANDANT = TEXT-011.
  REPLACE '&' WITH SY-MANDT INTO MANDANT.
  QUIT = NO.
  AUTHORITY-CHECK OBJECT 'S_PROGRAM'
    ID 'P_GROUP'  FIELD 'ZZBGSCTS'
    ID 'P_ACTION' DUMMY.
  IF SY-SUBRC NE OK.
    MESSAGE ID 'Z1' TYPE 'I' NUMBER '100'.
  ENDIF.

*----------------------------------------------------------------------*
* START-OF-SELECTION, is an event key word started by the REPORT       *
* Statement, is executed before any logical data base table access.    *
*----------------------------------------------------------------------*
START-OF-SELECTION.
   IF TRKORR1  <> SPACE. TKORR-TRKORR = TRKORR1  . APPEND TKORR. ENDIF.
   IF TRKORR2  <> SPACE. TKORR-TRKORR = TRKORR2  . APPEND TKORR. ENDIF.
   IF TRKORR3  <> SPACE. TKORR-TRKORR = TRKORR3  . APPEND TKORR. ENDIF.
   IF TRKORR4  <> SPACE. TKORR-TRKORR = TRKORR4  . APPEND TKORR. ENDIF.
   IF TRKORR5  <> SPACE. TKORR-TRKORR = TRKORR5  . APPEND TKORR. ENDIF.
   IF TRKORR6  <> SPACE. TKORR-TRKORR = TRKORR6  . APPEND TKORR. ENDIF.
   IF TRKORR7  <> SPACE. TKORR-TRKORR = TRKORR7  . APPEND TKORR. ENDIF.
   IF TRKORR8  <> SPACE. TKORR-TRKORR = TRKORR8  . APPEND TKORR. ENDIF.
   IF TRKORR9  <> SPACE. TKORR-TRKORR = TRKORR9  . APPEND TKORR. ENDIF.
   IF TRKORR10 <> SPACE. TKORR-TRKORR = TRKORR10 . APPEND TKORR. ENDIF.
   IF TRKORR11 <> SPACE. TKORR-TRKORR = TRKORR11 . APPEND TKORR. ENDIF.
   IF TRKORR12 <> SPACE. TKORR-TRKORR = TRKORR12 . APPEND TKORR. ENDIF.
   IF TRKORR13 <> SPACE. TKORR-TRKORR = TRKORR13 . APPEND TKORR. ENDIF.
   IF TRKORR14 <> SPACE. TKORR-TRKORR = TRKORR14 . APPEND TKORR. ENDIF.
   IF TRKORR15 <> SPACE. TKORR-TRKORR = TRKORR15 . APPEND TKORR. ENDIF.

   LOOP AT TKORR.
     IF CLIENT = 'X'.
*      command = '/usr/script/sapcp -k& &' .
       COMMAND = SCRIPT.
       REPLACE '&' WITH TKORR-TRKORR INTO COMMAND.
       REPLACE '&' WITH SY-SYSID INTO COMMAND.
       REPLACE '&' WITH SY-MANDT INTO COMMAND.
     ELSE.
       COMMAND = SCRIPT.
       REPLACE '&' WITH TKORR-TRKORR INTO COMMAND.
       REPLACE '&' WITH SY-SYSID INTO COMMAND.
       REPLACE '&' WITH '000' INTO COMMAND.
     ENDIF.

     CLEAR: STDOUTPUT. REFRESH: STDOUTPUT.
     CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND
                   ID 'TAB'     FIELD STDOUTPUT-*SYS*.
     LOOP AT  STDOUTPUT.
       TABL-TRKORR = TKORR-TRKORR.
       TABL-LINE   = STDOUTPUT-LINE.
       APPEND TABL.
     ENDLOOP.

   ENDLOOP.

*----------------------------------------------------------------------*
* END-OF-SELECTION, is an event key word started by the REPORT         *
* Statement, is executed as the last event just before quit            *
*----------------------------------------------------------------------*
END-OF-SELECTION.
  CHECK QUIT = NO.
  PERFORM PRINT_OUTPUT.
  PERFORM LOG_OUTPUT.
  IF SY-BATCH = 'X'.
    PERFORM SEND_MAIL_ADVIS.
  ENDIF.

*----------------------------------------------------------------------*
* PRINT_OUTPUT: Form som udskriver kшrselsloggen, hvis brugeren dobbelt*
* klikker pе en printlinie med logfile, еbnes og displayes denne fil.  *
*----------------------------------------------------------------------*
FORM PRINT_OUTPUT.

   REFRESH LOG_DATA.
   LOOP AT TABL.
     RECORD = TABL-LINE.
     CLEAR LOG_DATA.

     ON CHANGE OF TABL-TRKORR.
       WRITE: / SY-ULINE.
       WRITE: / 'Transport: ', TABL-TRKORR.
     ENDON.

     SEARCH RECORD FOR 'exit code           : '.
     IF SY-SUBRC = OK.
       TRANSLATE RECORD USING '" ' .
       CONDENSE RECORD.
       OFFSET = SY-FDPOS + 12.
       ASSIGN RECORD+OFFSET(20) TO <F>.
       MOVE <F> TO LOG_DATA-EXIT_CODE.
       LOG_DATA-TRKORR = TABL-TRKORR.
       APPEND LOG_DATA.
       IF LOG_DATA-EXIT_CODE = 0.
         WRITE: / RECORD COLOR 5.
       ELSEIF LOG_DATA-EXIT_CODE <= 4.
         WRITE: / RECORD COLOR 3.
       ELSE.
         WRITE: / RECORD COLOR 6.
       ENDIF.
     ELSE.
      WRITE: / RECORD COLOR COL_NORMAL.
     ENDIF.
   ENDLOOP.

ENDFORM.

*----------------------------------------------------------------------*
* LOG_OUTPUT: Form som logger exit codes fra kшrslen samt pеlysninger  *
* om transport dato, tid og user. Logfilen vedligeholdes af driften.   *
*----------------------------------------------------------------------*
FORM LOG_OUTPUT.
   OPEN DATASET LOGG FOR APPENDING IN TEXT MODE.
   IF SY-SUBRC NE OK.
     WRITE: / 'Fejl ved еbning af LOG fil.'(004).
     QUIT = YES.
     STOP.
   ENDIF.

   CLEAR RECORD.
   LOOP AT LOG_DATA.
     ON CHANGE OF LOG_DATA-TRKORR.
       RECORD+00 = SY-DATUM(8).
       RECORD+9  = SY-UZEIT(6).
       RECORD+16 = SY-UNAME(12).
       RECORD+29 = LOG_DATA-TRKORR(10).
     ENDON.
     RECORD+41 = LOG_DATA-EXIT_CODE.
     TRANSFER RECORD TO LOGG.
     CLEAR RECORD.
   ENDLOOP.
  CLOSE DATASET LOGG.

ENDFORM.

*----------------------------------------------------------------------*
* SEND_MAIL_ADVIS: Hvis programmet afvikles batch, sendes mail til     *
* brgeren.                                                             *
*----------------------------------------------------------------------*
FORM SEND_MAIL_ADVIS.
*   Mail Header
    MOVE:  SY-LANGU         TO OBJECT_HD_CHANGE-OBJLA
         ,'ADVIS'           TO OBJECT_HD_CHANGE-OBJNAM
         ,'F'               TO OBJECT_HD_CHANGE-OBJSNS
         ,'Transportadvis:' TO OBJECT_HD_CHANGE-OBJDES
         .
    APPEND OBJHEAD.

*   Mail Contents
    LOOP AT TABL.
      MOVE: TABL-LINE TO OBJCONT-LINE.
      APPEND OBJCONT.
    ENDLOOP.

*   Mail recievers
    MOVE: SY-UNAME TO RECEIVERS-RECNAM
        , 'B'      TO RECEIVERS-RECESC
        , 'X'      TO RECEIVERS-SNDCP
        , 'X'      TO RECEIVERS-FORFB
        , 'X'      TO RECEIVERS-SNDEX
        .
    APPEND RECEIVERS.

*   Send express mail
    CALL FUNCTION 'SO_OBJECT_SEND'
         EXPORTING
              OBJECT_HD_CHANGE           = OBJECT_HD_CHANGE
              OBJECT_TYPE                = 'RAW'
         TABLES
              OBJCONT                    = OBJCONT
              OBJHEAD                    = OBJHEAD
              OBJPARA                    = OBJPARA
              OBJPARB                    = OBJPARB
              RECEIVERS                  = RECEIVERS
         EXCEPTIONS
              OTHERS = 01.
         .

ENDFORM.



*Text elements
*-------------
* I002     Transport findes ikke eller er ikke released.
* I003     Fejl ved еbning af IMPORT log fil.
* I004     Fejl ved еbning af LOG fil.
* I005     Der skal angives mindst йt transportnummer
* I006     Import til klient
* I007     Transport numre
* I010     Transport
* I011     Klient &
* I012     Husk! Transporter skal vжre releaset pе udviklingssystemet.



*Selection texts
*---------------
*STRKORR          Transport nummer.............:
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.