Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SPAN

Unknown macro: { font-family}

.L1S31

Unknown macro: { font-style}

.L1S32

Unknown macro: { color}

.L1S33

Unknown macro: { color}

.L1S52

Unknown macro: { color}

*&---------------------------------------------------------------------*
*& Report  ZPROG_DELETE
*&
*&---------------------------------------------------------------------*
*& This Program reads the excel file containing all the obsolete
*& programs and adds them to a transport request.
*& The co-files and data files for this transport request are
*& downloaded and kept secure as a back up for the deleted programs.
*& The programs are deleted and are added to a single transport req.
*&---------------------------------------------------------------------*

report  zprog_delete.
*&---------------------------------------------------------------------*
*& Declaration part : Declaration of variables  and tables
*&---------------------------------------------------------------------*

tables: tadir.
type-pools: sabc, stms, trwbo.

data: folder type string,
      retval like table of ddshretval with header line,
      fldvalue like help_info-fldvalue,
      transdir type text255,
      filename(255),
      trfile(20) type c,
      datatab type table of text8192 with header line,
      len type i,
      flen type i,
      t_string type string.

data : gt_file type alsmex_tabline occurs 0 with header line.

data: begin of it_progname occurs 0,
      progname(40) type c,
      end of it_progname.

data: wa_progname like it_progname.

data: flag_success type flag.
data: flag_delete type flag.

data: begin of t_data occurs 0.
        include structure bdcdata.
data: end of t_data.
data : w_message(255),

       begin of t_output occurs 0,
       sel(4)         type c,
       findchar(40)   type c,
       propchar(40)   type c,
       object         like tadir-obj_name,
       author         like tadir-author,
       count          type i,
       lines(150)     type c,
       end of t_output.
data: tt_system type table of tmscsys with header line,
      es_selected_request type trwbo_request_header,
      es_selected_task type trwbo_request_header,
      iv_organizer_type type trwbo_calling_organizer,
      is_selection type trwbo_selection.

data: title type string.

data: lt_e072 type tr_objects,
      lt_e071 like e071 occurs 0 with header line,
      l_num(6) type n,
      lv_request type trwbo_request_header.

data: auth_filename type authb-filename,
      gui_filename type string.

*&----------------------------------------------------------------------
*& Selection screen to choose the following
*&     File Name-- Excel sheet containing the name of obsolete programs
*&     Transport request1-- Transport request for Download
*&     Transport Request2-- Transport request for Delete
*&     Folder Name-- Folder for download of files.
*&     Seperator -- by default '\'
*&----------------------------------------------------------------------

selection-screen begin of block b1 with frame title text-001.
parameter p_file type rlgrap-filename.
parameter p_trans type e071-trkorr.
parameter p_trans1 type e071-trkorr.
parameter: p_folder(255) type c lower case, p_sepr obligatory.
selection-screen end of block b1.

*&---------------------------------------------------------------------*
*& Initialization of the various variables.
*&---------------------------------------------------------------------*

initialization.

  if sy-opsys = 'Windows NT'.
    p_sepr = '\'.
  else.
    p_sepr = '/'.
  endif.

at selection-screen on value-request for p_file.
  perform browse_excel_file.

at selection-screen on value-request for p_trans.

  iv_organizer_type = 'W'. is_selection-reqstatus = 'R'.

  call function 'TR_PRESENT_REQUESTS_SEL_POPUP'
    exporting
      iv_organizer_type   = iv_organizer_type
      is_selection        = is_selection
    importing
      es_selected_request = es_selected_request
      es_selected_task    = es_selected_task.
  p_trans = es_selected_request-trkorr.

at selection-screen on value-request for p_folder.

  title = 'Select target folder'(005).
  call method cl_gui_frontend_services=>directory_browse
    exporting
      window_title    = title
    changing
      selected_folder = folder
    exceptions
      cntl_error      = 1
      error_no_gui    = 2
      others          = 3.

  call function 'CONTROL_FLUSH'
    exceptions
      cntl_system_error = 1
      cntl_error        = 2
      others            = 3.

  p_folder = folder.

start-of-selection.

*&---------------------------------------------------------------------*
*& Function :    ALSM_EXCEL_TO_INTERNAL_TABLE
*&---------------------------------------------------------------------*
*& Description:  Take the Excel file as input and feeding the entries in
*&               in internal table.
*&---------------------------------------------------------------------*

  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 31
      i_end_row               = 60000
    tables
      intern                  = gt_file
    exceptions
      inconsistent_parameters = 1
      upload_ole              = 2
      others                  = 3.
  if sy-subrc <> 0.
    message i001(mo) with 'File Open Error'.
  endif.

  if gt_file[] is not initial.
    loop at gt_file.
      wa_progname = gt_file-value.
      append wa_progname to it_progname.
      clear wa_progname.

    endloop.
  endif.

*&---------------------------------------------------------------------*
*& Calling Perform to Add the objects in the transport request.
*&---------------------------------------------------------------------*

  perform add_object_in_tr using p_trans t_output-object.

*&---------------------------------------------------------------------*
*& Form:         browse_excel_file
*&---------------------------------------------------------------------*
*& Description:  Reads the excel file
*----------------------------------------------------------------------*
form browse_excel_file.

  call function 'F4_FILENAME'
    exporting
      program_name  = sy-repid
      dynpro_number = sy-dynnr
      field_name    = 'PATH'
    importing
      file_name     = p_file.

  if sy-subrc <> 0.

  endif.
endform.

*&---------------------------------------------------------------------*
*&  Form:          Add_object_in_tr.
*&---------------------------------------------------------------------*
*   Description:  Add objects in a transport request
*----------------------------------------------------------------------*
form add_object_in_tr using    p_tr type any
                               p_output_object type any.

  clear flag_success.
  loop at it_progname.
    p_output_object = it_progname-progname.
    refresh lt_e071.
    clear : lt_e071, lv_request.
    l_num = l_num + 1.
    lt_e071-trkorr = p_tr.
    lt_e071-as4pos = l_num.
    lt_e071-pgmid = 'R3TR'.
    lt_e071-object = 'PROG'.
    lt_e071-obj_name = p_output_object.

    append lt_e071.

    call function 'TR_REQUEST_CHOICE'
      exporting
        iv_suppress_dialog   = 'X'
        iv_request           = p_tr
        it_e071              = lt_e071[]
        iv_lock_objects      = 'X'
      importing
        es_request           = lv_request
      exceptions
        invalid_request      = 1
        invalid_request_type = 2
        user_not_owner       = 3
        no_objects_appended  = 4
        enqueue_error        = 5
        cancelled_by_user    = 6
        recursive_call       = 7
        others               = 8.
    if sy-subrc <> 0.

      t_string = t_string.
      concatenate t_string ' ' p_output_object ',' into t_string.
      flag_success = 'X'.

    endif.

  endloop.

  if flag_success = 'X'.
    write: 'Objects not added to the request are:'.
    write  t_string.
    write /.
    write 'Request not released.'.
  else.
    perform release_transport.
  endif.
endform.

*&---------------------------------------------------------------------*
*&  Form:           Release_transport.
*&---------------------------------------------------------------------*
*   Description:    Release transport.
*----------------------------------------------------------------------*
form release_transport.

  call function 'TR_RELEASE_REQUEST'
    exporting
      iv_trkorr                  = p_trans
    exceptions
      cts_initialization_failure = 1
      enqueue_failed             = 2
      no_authorization           = 3
      invalid_request            = 4
      request_already_released   = 5
      repeat_too_early           = 6
      error_in_export_methods    = 7
      object_check_error         = 8
      docu_missing               = 9
      db_access_error            = 10
      action_aborted_by_user     = 11
      export_failed              = 12
      others                     = 13.

  case sy-subrc.
    when 0.
    when 1. w_message = 'cts_initialization_failure'.
    when 2. w_message = 'enqueue_failed'.
    when 3. w_message = 'no_authorization'.
    when 4. w_message = 'invalid_request'.
    when 5. w_message = 'request_already_released'.
    when 6. w_message = 'repeat_too_early'.
    when 7. w_message = 'error_in_export_methods'.
    when 8. w_message = 'object_check_error'.
    when 9. w_message = 'docu_missing'.
    when 10. w_message = 'db_access_error'.
    when 11. w_message = 'action_aborted_by_user'.
    when 12. w_message = 'export_failed'.

  endcase.
*
  if sy-subrc <> 0.
    message i001(mo) with w_message.
  else.
    perform download_transport.
    perform delete_program.
  endif.

endform.
*&---------------------------------------------------------------------*
*& Form:  Download_Transport.
*&---------------------------------------------------------------------*
*  Description:     download the co-files and data-files for the
*                   transport req
*----------------------------------------------------------------------*
form download_transport.

  folder = p_folder.
  concatenate p_trans+3(7) '.' p_trans(3) into trfile.

  call function 'RSPO_R_SAPGPARAM'
    exporting
      name   = 'DIR_TRANS'
    importing
      value  = transdir
    exceptions
      error  = 0
      others = 0.

  perform copy_file using 'cofiles' trfile.
  trfile(1) = 'R'.
  perform copy_file using 'data' trfile.
  trfile(1) = 'D'.
  perform copy_file using 'data' trfile.
endform.                    "download_transport
*---------------------------------------------------------------------*
* FORM: copy_file *
*---------------------------------------------------------------------*
*  Description: -> SUBDIR   -> FNAME *
*---------------------------------------------------------------------*
form copy_file using subdir fname.

  concatenate transdir subdir fname
    into filename
    separated by p_sepr.

  refresh datatab.
  clear flen.

  auth_filename = filename.
  call function 'AUTHORITY_CHECK_DATASET'
    exporting
      activity         = sabc_act_read
      filename         = auth_filename
    exceptions
      no_authority     = 1
      activity_unknown = 2
      others           = 3.

  if sy-subrc <> 0.
    format color col_negative.
    write: / 'Read access denied. File'(001),
              filename.
    format color off. exit.
  endif.

  open dataset filename for input in binary mode.

  if sy-subrc ne 0.
    format color col_total.
    write: / 'File open error'(010), filename.
    format color off. exit.
  endif.

  do.
    clear len.
    read dataset filename into datatab length len.
    flen = flen + len.
    if len > 0. append datatab. endif.
    if sy-subrc ne 0.
      exit.
    endif.
  enddo.
  close dataset filename.
  concatenate p_folder '\' fname into gui_filename.

  call method cl_gui_frontend_services=>gui_download
    exporting
      bin_filesize            = flen
      filename                = gui_filename
      filetype                = 'BIN'
    changing
      data_tab                = datatab[]
    exceptions
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      others                  = 24.

  if sy-subrc = 0.
    write: / 'File'(002), filename, 'downloaded. Length'(003), flen.

  else.
    format color col_negative.
    write: / 'File download error. Filename:'(004), filename.
    format color off.
  endif.
endform.
*&---------------------------------------------------------------------*
*& Form:         Delete_program.
*&---------------------------------------------------------------------*
* Description:   Delete the programs and adds to a transport req.
*----------------------------------------------------------------------*
form delete_program.
  clear flag_delete.
  loop at it_progname.

    call function 'RS_DELETE_PROGRAM'
      exporting
        corrnumber                 = p_trans1
        program                    = it_progname-progname
        suppress_checks            = ' '
        suppress_commit            = ' '
        suppress_popup             = 'X'
        mass_delete_call           = 'X'
        with_cua                   = 'X'
        with_documentation         = 'X'
        with_dynpro                = 'X'
        with_includes              = 'X'
        with_textpool              = 'X'
        with_variants              = 'X'
        force_delete_used_includes = ' '
      exceptions
        enqueue_lock               = 1
        object_not_found           = 2
        permission_failure         = 3
        reject_deletion            = 4
        others                     = 5.

    case sy-subrc.
      when 0.
      when 1. w_message = 'enqueue_lock'.
      when 2. w_message = 'object_not_found'.
      when 3. w_message = 'permission_failure'.
      when 4. w_message = 'reject_deletion'.

    endcase.
*
    if sy-subrc <> 0.
      message i001(mo) with w_message.

    else.

      flag_delete = 'X'.

    endif.
  endloop.

  if flag_delete = 'X'.
    message i003(z_message) with 'Objects deleted successfully and'
    'added to transport req no.' p_trans1.

  endif.

endform.

  • No labels