ABAP/BC/Выгрузка транспортных запросов

Материал из Викиучебника — открытых книг для открытого мира
Перейти к навигации Перейти к поиску
  1  REPORT ZBC_DOWNLOAD_REQ.
  2  PARAMETERS:
  3    p_reqest TYPE trkorr OBLIGATORY,
  4    p_folder(255) TYPE c LOWER CASE, p_sepr OBLIGATORY.
  5 
  6  DATA:
  7    folder TYPE string,
  8    retval LIKE TABLE OF ddshretval WITH HEADER LINE,
  9    fldvalue LIKE help_info-fldvalue,
 10    transdir TYPE text255,
 11    filename(255),
 12    trfile(20) TYPE c,
 13    datatab TYPE TABLE OF text8192 WITH HEADER LINE,
 14    len TYPE i,
 15    flen TYPE i.
 16 
 17  TYPE-POOLS: sabc, stms, trwbo.
 18 
 19  INITIALIZATION.
 20    CONCATENATE sy-sysid 'K*' INTO p_reqest.
 21 
 22    IF sy-opsys = 'Windows NT'.
 23      p_sepr = '\'.
 24    ELSE.
 25      p_sepr = '/'.
 26    ENDIF.
 27 
 28 
 29  AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_reqest.
 30    DATA:
 31      tt_system TYPE TABLE OF tmscsys WITH HEADER LINE,
 32      es_selected_request TYPE trwbo_request_header,
 33      es_selected_task TYPE trwbo_request_header,
 34      iv_organizer_type TYPE trwbo_calling_organizer,
 35      is_selection TYPE trwbo_selection.
 36 
 37    iv_organizer_type = 'W'. is_selection-reqstatus = 'R'.
 38    CALL FUNCTION 'TR_PRESENT_REQUESTS_SEL_POPUP'
 39      EXPORTING
 40        iv_organizer_type   = iv_organizer_type
 41        is_selection        = is_selection
 42      IMPORTING
 43        es_selected_request = es_selected_request
 44        es_selected_task    = es_selected_task.
 45    p_reqest = es_selected_request-trkorr.
 46 
 47  AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder.
 48    DATA: title TYPE string.
 49 
 50    title = 'Select target folder'(005).
 51    CALL METHOD cl_gui_frontend_services=>directory_browse
 52      EXPORTING
 53        window_title    = title
 54      CHANGING
 55        selected_folder = folder
 56      EXCEPTIONS
 57        cntl_error      = 1
 58        error_no_gui    = 2
 59        OTHERS          = 3.
 60 
 61    CALL FUNCTION 'CONTROL_FLUSH'
 62      EXCEPTIONS
 63        cntl_system_error = 1
 64        cntl_error        = 2
 65        OTHERS            = 3.
 66 
 67    p_folder = folder.
 68 
 69  AT SELECTION-SCREEN ON p_reqest.
 70    DATA: request_info TYPE stms_wbo_request,
 71          request_infos TYPE stms_wbo_requests.
 72 
 73    REFRESH request_infos.
 74    CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST'
 75      EXPORTING
 76        iv_request                 = p_reqest
 77        iv_header_only             = 'X'
 78      IMPORTING
 79        et_request_infos           = request_infos
 80      EXCEPTIONS
 81        read_config_failed         = 1
 82        table_of_requests_is_empty = 2
 83        system_not_available       = 3
 84        OTHERS                     = 4.
 85 
 86    IF sy-subrc <> 0.
 87      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
 88              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 89    ENDIF.
 90    CLEAR request_info.
 91    READ TABLE request_infos INTO request_info INDEX 1.
 92    IF sy-subrc NE 0
 93    OR request_info-e070-trkorr IS INITIAL.
 94      MESSAGE e398(00) WITH 'Request'(006)
 95 p_reqest 'not found'(007).
 96    ELSEIF request_info-e070-trstatus NE 'R'.
 97      MESSAGE e398(00)
 98      WITH 'You must release request'(008)
 99           request_info-e070-trkorr
100           'before downloading'(009).
101    ENDIF.
102 
103  START-OF-SELECTION.
104    folder = p_folder.
105    CONCATENATE p_reqest+3(7) '.' p_reqest(3) INTO trfile.
106 
107    CALL FUNCTION 'RSPO_R_SAPGPARAM'
108      EXPORTING
109        name   = 'DIR_TRANS'
110      IMPORTING
111        value  = transdir
112      EXCEPTIONS
113        error  = 0
114        OTHERS = 0.
115 
116    PERFORM copy_file USING 'cofiles' trfile.
117    trfile(1) = 'R'.
118    PERFORM copy_file USING 'data' trfile.
119    trfile(1) = 'D'.
120    PERFORM copy_file USING 'data' trfile.
121  FORM copy_file USING subdir fname.
122    DATA:
123      auth_filename TYPE authb-filename,
124      gui_filename TYPE string.
125 
126    CONCATENATE transdir subdir fname
127      INTO filename
128      SEPARATED BY p_sepr.
129 
130    REFRESH datatab.
131    CLEAR flen.
132 
133    auth_filename = filename.
134    CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
135      EXPORTING
136        activity         = sabc_act_read
137        filename         = auth_filename
138      EXCEPTIONS
139        no_authority     = 1
140        activity_unknown = 2
141        OTHERS           = 3.
142 
143    IF sy-subrc <> 0.
144      FORMAT COLOR COL_NEGATIVE.
145      WRITE: / 'Read access denied. File'(001),
146                filename.
147      FORMAT COLOR OFF. EXIT.
148    ENDIF.
149 
150    OPEN DATASET filename FOR INPUT IN BINARY MODE.
151 
152    IF sy-subrc NE 0.
153      FORMAT COLOR COL_TOTAL.
154      WRITE: / 'File open error'(010), filename.
155      FORMAT COLOR OFF. EXIT.
156    ENDIF.
157 
158    DO.
159      CLEAR len.
160      READ DATASET filename INTO datatab LENGTH len.
161      flen = flen + len.
162      IF len > 0.
163        APPEND datatab.
164      ENDIF.
165      IF sy-subrc NE 0.
166        EXIT.
167      ENDIF.
168    ENDDO.
169    CLOSE DATASET filename.
170    CONCATENATE p_folder '\' fname INTO gui_filename.
171 
172    CALL METHOD cl_gui_frontend_services=>gui_download
173      EXPORTING
174        bin_filesize            = flen
175        filename                = gui_filename
176        filetype                = 'BIN'
177      CHANGING
178        data_tab                = datatab[]
179      EXCEPTIONS
180        file_write_error        = 1
181        no_batch                = 2
182        gui_refuse_filetransfer = 3
183        invalid_type            = 4
184        no_authority            = 5
185        unknown_error           = 6
186        header_not_allowed      = 7
187        separator_not_allowed   = 8
188        filesize_not_allowed    = 9
189        header_too_long         = 10
190        dp_error_create         = 11
191        dp_error_send           = 12
192        dp_error_write          = 13
193        unknown_dp_error        = 14
194        access_denied           = 15
195        dp_out_of_memory        = 16
196        disk_full               = 17
197        dp_timeout              = 18
198        file_not_found          = 19
199        dataprovider_exception  = 20
200        control_flush_error     = 21
201        OTHERS                  = 24.
202 
203    IF sy-subrc = 0.
204      WRITE: / 'File'(002), filename,
205 'downloaded. Length'(003), flen.
206    ELSE.
207      FORMAT COLOR COL_NEGATIVE.
208      WRITE: / 'File download error. Filename:'(004), filename.
209      FORMAT COLOR OFF.
210    ENDIF.
211  ENDFORM. "copy_file