W Pub: ABAP Prog Propios MIG Up Down

  1. report znadar_filez line-size 1023 no standard page heading.
  2. tables: sscrfields.
  3.  
  4. selection-screen begin of block b01 with frame.
  5. parameters: local_f like rlgrap-filename,
  6.             host_f like rlgrap-filename,
  7.             p_ascii radiobutton group tip default 'X',
  8.             p_binar radiobutton group tip.
  9. selection-screen function key 1.
  10. selection-screen function key 2.
  11. selection-screen function key 3.
  12. selection-screen end of block b01.
  13.  
  14. data: begin of itab occurs 0,
  15.         reg(65534),
  16.       end of itab, titulo(1023).
  17.  
  18. at line-selection.
  19.    perform list_filez.
  20. at user-command.
  21.    if sy-pfkey = 'L100'.
  22.       perform user_input.
  23.    endif.
  24. at selection-screen.
  25.   if sscrfields-ucomm = 'FC01'. perform to_host. endif.
  26.   if sscrfields-ucomm = 'FC02'. perform to_local. endif.
  27.   if sscrfields-ucomm = 'FC03'. perform view_filez. endif.
  28.  
  29. initialization.
  30. include <icon>.
  31.   move '@49@ A Host'  to sscrfields-functxt_01. "ICON_EXPORT
  32.   move '@48@ A Local' to sscrfields-functxt_02. "ICON_IMPORT
  33.   move '@10@ Filez'   to sscrfields-functxt_03. "ICON_IMPORT
  34.  
  35. end-of-selection.
  36. perform get_directory.
  37.  
  38. form view_filez.
  39.   if not host_f is initial.
  40.      leave to list-processing. new-page no-heading no-title.
  41.      perform: read_host, list_filez.
  42.   elseif not local_f is initial.
  43.      leave to list-processing. new-page no-heading no-title.
  44.      perform: read_local, list_filez.
  45.   endif.
  46. endform.
  47.  
  48. form list_filez.
  49. data: posi type i occurs 0 with header line,
  50.       cortar(1), ch type i, cl type i, al(1), ah type i,
  51.       di like itab-reg, si like di.
  52. field-symbols: <h>.
  53.    sy-lsind = sy-lsind - 1.
  54.    set pf-status space.
  55.    read line 1.
  56.    if sy-subrc eq 0.
  57.       if sy-lisel ca 'Xx.|'.
  58.          cortar = 'X'.
  59.          translate sy-lisel using 'X|x|.|'.
  60.          titulo = sy-lisel.
  61.          modify line 1.
  62.          ch = strlen( titulo ). cl = 1.
  63.           do ch times.
  64.             ah = sy-index - 1.
  65.             al = titulo+ah(cl).
  66.             if al ca 'Xx|'. posi = ah. append posi. endif.
  67.          enddo.
  68.       endif.
  69.    else.
  70.      clear cortar.
  71.    endif.
  72.    titulo(1023) = '.'.
  73.    write / titulo input on.
  74.    loop at itab.
  75.      if cortar = 'X'.
  76.         translate itab-reg using ' &not;'.
  77.         clear di.
  78.         ch = 0. write: / ''.
  79.         loop at posi.
  80.            ah = 0.
  81.            ah = posi - ch.
  82.            if ah > 0.
  83.               si = itab-reg.
  84.               si = si+ch(ah). concatenate di si sy-vline into di.
  85.            else. di = sy-vline.
  86.            endif.
  87.            ah = ch = posi.
  88.         endloop.
  89.         ch = strlen( itab-reg ).
  90.         if ch > ah.
  91.            si = itab-reg. translate si using '&not; '.
  92.            ch = strlen( itab-reg ). ah = ch - ah.
  93.            si = si+posi(ah). concatenate di si into di.
  94.         endif.
  95.         translate di using '&not; '.
  96.         write: / di.
  97.      else.
  98.         write: / itab-reg.
  99.      endif.
  100.    endloop.
  101. endform.
  102.  
  103. form to_local.
  104.    perform: read_host, write_local.
  105. endform.
  106.  
  107. form to_host.
  108.    perform: read_local, write_host.
  109. endform.
  110.  
  111. form write_host.
  112.    open dataset host_f for output in text mode.
  113.    if sy-subrc ne 0. message e398(00) with 'Host File Not Found'. endif.
  114.    loop at itab. transfer itab-reg to host_f. endloop.
  115. endform.
  116.  
  117. form write_local.
  118.    call function 'WS_DOWNLOAD'
  119.        exporting
  120.             filename                = local_f
  121.             filetype                = 'ASC'
  122.         tables
  123.             data_tab                = itab
  124.         exceptions
  125.              file_open_error         = 1
  126.              file_write_error        = 2
  127.              invalid_filesize        = 3
  128.              invalid_table_width     = 4
  129.              invalid_type            = 5
  130.              no_batch                = 6
  131.              unknown_error           = 7
  132.              gui_refuse_filetransfer = 8
  133.              others                  = 9.
  134.    if sy-subrc ne 0. message e398(00) with 'Host File Not Found'. endif.
  135. endform.
  136.  
  137. form read_host.
  138.    clear itab. refresh itab.
  139.    if p_ascii = 'X'.
  140.       open dataset host_f in text mode.
  141.    else.
  142.       open dataset host_f in binary mode.
  143.    endif.
  144.    if sy-subrc ne 0. message e398(00) with 'Host File Not Found'. endif.
  145.    do.
  146.      read dataset host_f into itab-reg.
  147.      if sy-subrc ne 0. exit. endif.
  148.      append itab.
  149.    enddo.
  150. endform.
  151.  
  152. form read_local.
  153.    clear itab. refresh itab.
  154.    call function 'WS_UPLOAD'
  155.        exporting
  156.              filename                = local_f
  157.              filetype                = 'ASC'
  158.         tables
  159.              data_tab                = itab
  160.         exceptions
  161.              conversion_error        = 1
  162.              file_open_error         = 2
  163.              file_read_error         = 3
  164.              invalid_table_width     = 4
  165.              invalid_type            = 5
  166.              no_batch                = 6
  167.              unknown_error           = 7
  168.              gui_refuse_filetransfer = 8
  169.              others                  = 9.
  170.  if sy-subrc ne 0. message e398(00) with 'Local File Not Found'. endif.
  171. endform.
  172.  
  173. *--- Plagio de la AL11
  174. data: globaldirectory(75) type c,
  175.       strlen      like sy-fdpos.
  176. data: begin of searchpoints occurs 10,
  177.         dirname(75) type c,            " name of directory.
  178.         sp_name(75) type c,            " name of entry. (may end with *)
  179.         sp_cs(10)   type c, " ContainsString pattern for name.
  180.       end of searchpoints,
  181.       all_gen     value '*',    " generic filename shall select all
  182.       no_cs       value ' '.    " no MUST_ContainString
  183. data: begin of file_list occurs 100,
  184.         dirname(75) type c, " name of directory. (possibly truncated.)
  185.         name(75)    type c, " name of entry. (possibly truncated.)
  186.         type(10)    type c,            " type of entry.
  187.         len(8)      type p,            " length in bytes.
  188.         owner(8)    type c,            " owner of the entry.
  189.         mtime(6)    type p, " last modification date, seconds since 1970
  190.         mode(9)     type c, " like "rwx-r-x--x": protection mode.
  191.         useable(1)  type c,
  192.         subrc(4)    type c,
  193.         errno(3)    type c,
  194.         errmsg(40)  type c,
  195.         mod_date    type d,
  196.         mod_time(8) type c,            " hh:mm:ss
  197.         seen(1)     type c,
  198.         changed(1)  type c,
  199.       end of file_list,
  200.       srt(1)      value 'T'.
  201. data: begin of file,
  202.         dirname(75) type c, " name of directory. (possibly truncated.)
  203.         name(75)    type c, " name of entry. (possibly truncated.)
  204.         type(10)    type c,            " type of entry.
  205.         len(8)      type p,            " length in bytes.
  206.         owner(8)    type c,            " owner of the entry.
  207.         mtime(6)    type p, " last modification date, seconds since 1970
  208.         mode(9)     type c, " like "rwx-r-x--x": protection mode.
  209.         useable(1)  type c,
  210.         subrc(4)    type c,
  211.         errno(3)    type c,
  212.         errmsg(40)  type c,
  213.         mod_date    type d,
  214.         mod_time(8) type c,            " hh:mm:ss
  215.         seen(1)     type c,
  216.         changed(1)  type c,
  217.       end of file,
  218.       sap_no(1)   value ' ',
  219.       sap_yes(1)   value 'X'.
  220. data: h_list_index   type p.  " hided with each data line; otherwise 0
  221.  
  222. form get_directory.
  223.   set pf-status 'L100' of program 'RSWATCH0'.
  224.   set titlebar '100' of program 'RSWATCH0'.
  225.   refresh file_list.
  226.   refresh searchpoints.
  227.   searchpoints-sp_name = all_gen    .
  228.   searchpoints-sp_cs   = no_cs      .
  229.   append searchpoints.
  230.   loop at searchpoints.
  231.     perform fill_file_list using searchpoints-dirname
  232.                                  searchpoints-sp_name
  233.                                  searchpoints-sp_cs.
  234.   endloop.
  235.   srt = 'N'.
  236.   sort file_list by name ascending mtime descending.
  237.   perform show_file_list.
  238. endform.                               "GET_DIRECTORY.
  239.  
  240. form fill_file_list using a_dir_name a_generic_name a_must_cs.
  241.                                        " Routine von M. Mittelstein
  242.  
  243.   data: errcnt(2) type p value 0.
  244.    if a_dir_name is initial. a_dir_name = '/'. endif.
  245.   call 'C_DIR_READ_FINISH'
  246.       id 'ERRNO'  field file_list-errno
  247.       id 'ERRMSG' field file_list-errmsg.
  248.   call 'C_DIR_READ_START' id 'DIR'    field a_dir_name
  249.                           id 'FILE'   field a_generic_name
  250.                           id 'ERRNO'  field file-errno
  251.                           id 'ERRMSG' field file-errmsg.
  252.   if sy-subrc <> 0.
  253.     message e204(s1) with file_list-errmsg file-errmsg.
  254.   endif.
  255.   do.
  256.     clear file.
  257.     call 'C_DIR_READ_NEXT'
  258.       id 'TYPE'   field file-type
  259.       id 'NAME'   field file-name
  260.       id 'LEN'    field file-len
  261.       id 'OWNER'  field file-owner
  262.       id 'MTIME'  field file-mtime
  263.       id 'MODE'   field file-mode
  264.       id 'ERRNO'  field file-errno
  265.       id 'ERRMSG' field file-errmsg.
  266.     file-dirname = a_dir_name.
  267.     move sy-subrc to file-subrc.
  268.     case sy-subrc.
  269.       when 0.
  270.         clear: file-errno, file-errmsg.
  271.         case file-type(1).
  272.           when 'F'.                    " normal file.
  273.             perform filename_useable using file-name file-useable.
  274.           when 'f'.                    " normal file.
  275.             perform filename_useable using file-name file-useable.
  276.           when others. " directory, device, fifo, socket,...
  277.             move sap_no  to file-useable.
  278.         endcase.
  279.         if file-len = 0.
  280.           move sap_no to file-useable.
  281.         endif.
  282.       when 1. exit.
  283.       when others.
  284.         add 1 to errcnt.
  285.         if errcnt > 10. exit. endif.
  286.         if sy-subrc = 5.
  287.           file-type = file-owner = file-mode = '???'.
  288.         endif.
  289.         move sap_no to file-useable.
  290.     endcase.
  291.     perform p6_to_date_time_tz(rstr0400) using file-mtime
  292.                                                file-mod_time
  293.                                                file-mod_date.
  294.     if a_must_cs = no_cs.
  295.       move-corresponding file to file_list.
  296.       append file_list.
  297.     else.
  298.       if file-name cs a_must_cs.
  299.         move-corresponding file to file_list.
  300.         append file_list.
  301.       endif.
  302.     endif.
  303.   enddo.
  304.   call 'C_DIR_READ_FINISH'
  305.       id 'ERRNO'  field file_list-errno
  306.       id 'ERRMSG' field file_list-errmsg.
  307.   if sy-subrc <> 0.
  308.     write: / 'C_DIR_READ_FINISH', 'SUBRC', sy-subrc.
  309.   endif.
  310.   if srt = 'T'.
  311.     sort file_list by mtime descending name ascending.
  312.   else.
  313.     sort file_list by name ascending mtime descending.
  314.   endif.
  315. endform.
  316.  
  317. form show_file_list.
  318.   data: cflag(1) value 'X'.
  319. ******************************************************************CAS***
  320. * Liste der Fehlerprotokolldateien ausgeben.
  321.  
  322.   new-page no-title.
  323.   sy-lsind = 1.
  324.   loop at file_list.
  325.     perform flip_flop(rsora000) using cflag.
  326.     write: / file_list-useable,
  327.              file_list-seen,
  328.              file_list-changed,
  329.              file_list-name(30),
  330.              file_list-len,
  331.              file_list-owner,
  332.              file_list-mod_date dd/mm/yyyy,
  333.              file_list-mod_time.
  334.     h_list_index = sy-tabix.
  335.     hide: h_list_index. " , FILE_LIST-DIRNAME, FILE_LIST-NAME.
  336.   endloop.
  337.   clear: h_list_index, file_list-dirname, file_list-name.
  338.  
  339. endform.
  340.  
  341. form filename_useable using a_name a_useable.
  342.   data l_name(75).
  343.   l_name = a_name.
  344.   if l_name(4) = 'core'.
  345.     a_useable = sap_no.
  346.   else.
  347.     a_useable = 'X'.
  348.   endif.
  349. endform.
  350.  
  351. form user_input.
  352.   data curpage like sy-cpage.
  353.   case sy-pfkey.
  354.     when 'L100'.
  355.       case sy-ucomm.
  356.         when 'DIRL'.
  357.           perform show_dir_list in program rswatch0.
  358.         when 'ATTR'.
  359.           if h_list_index > 0.
  360.             perform show_file_details.
  361.           else.
  362.             message s208(s1). " Cursor befand sich auerhalb der Liste
  363.           endif.
  364.         when 'DISP'.
  365.           if h_list_index > 0.
  366.             read table file_list index h_list_index.
  367.             if file_list-dirname <> globaldirectory.
  368.               perform show_file_contents.
  369.               if file_list-type(1) = 'D' or file_list-type(1) = 'd'.
  370.                 case file_list-name.
  371.                   when '.'.            "stay where ever you are
  372.                   when '..'.           "go up
  373.                   when others.         "go down
  374.                     strlen = strlen( searchpoints-dirname ).
  375.                     if strlen > 1.     "never go higher than root
  376.                       case sy-opsys.
  377.                         when 'VMS'.    "nothing
  378.                         when 'Windows NT'.
  379.                           write '\' to searchpoints-dirname+strlen.
  380.                           strlen = strlen + 1.
  381.                         when others.   "UNIX
  382.                           write '/' to searchpoints-dirname+strlen.
  383.                           strlen = strlen + 1.
  384.                       endcase.
  385.                     endif.
  386.                     write file_list-name to searchpoints-dirname+strlen.
  387.                 endcase.
  388.  
  389.                 perform get_directory. "here we go again
  390.               else.
  391.                 modify current line
  392.                   field value file_list-seen from sap_yes
  393.                               file_list-changed from sap_no.
  394.                 move sap_yes to file_list-seen.
  395.                 move sap_no  to file_list-changed.
  396.                 modify file_list index h_list_index.
  397.               endif.
  398.             endif.
  399.           else.
  400.             message s208(s1). " Cursor befand sich auerhalb der Liste
  401.           endif.
  402.         when 'UPDA'.
  403.           perform update_file_list in program rswatch0.
  404.           curpage = sy-cpage.
  405.           perform show_file_list.
  406.           scroll list index sy-lsind to page curpage.
  407.         when 'NAME'.
  408.           srt = 'N'.
  409.           sort file_list by name ascending mtime descending.
  410.           perform show_file_list.
  411.         when 'TIME'.
  412.           srt = 'T'.
  413.           sort file_list by mtime descending name ascending.
  414.           perform show_file_list.
  415.       endcase.
  416.       clear h_list_index.
  417.     when 'L200'.
  418.       case sy-ucomm.
  419. * ->                                                         L200 + ATTR
  420.         when 'ATTR'.
  421.           perform show_file_details.
  422. * ->                                                         L200 + DIRL
  423.         when 'DIRL'.
  424.           perform show_dir_list in program rswatch0.
  425.       endcase.
  426.   endcase.
  427. endform.
  428.  
  429. form show_file_details.
  430. ******************************************************************CAS***
  431. * Details zu einer Fehlerprotokolldatei
  432.  
  433.   set pf-status 'L300' of program 'RSWATCH0'.
  434.   set titlebar '300'  of program 'RSWATCH0'.
  435.   read table file_list index h_list_index.
  436.   write: / 'Directory......'(019), file_list-dirname,
  437.          / 'Name...........'(001), file_list-name,
  438.          / 'Typ............'(002), file_list-type,
  439.          / 'Lnge..........'(003), file_list-len,
  440.          / 'Erzeuger.......'(004), file_list-owner,
  441.          / 'Letzte nderung'(005), file_list-mod_date dd/mm/yyyy,
  442.                                     file_list-mod_time,
  443.          / 'Mode...........'(006), file_list-mode,
  444.          / 'Verwendbar.....'(007), file_list-useable,
  445.          / 'Fehlernummer...'(008), file_list-errno,
  446.          / 'Fehlermeldung..'(009), file_list-errmsg.
  447. endform.
  448.  
  449. form show_file_contents.
  450.   data: buffer(255) type c,
  451.         path_name(151) type c.
  452.   set pf-status 'L200' of program 'RSWATCH0'.
  453.   set titlebar '200' of program 'RSWATCH0'.
  454.   if file_list-useable = sap_yes.
  455.     path_name        = file_list-dirname.
  456.     strlen = strlen( searchpoints-dirname ).
  457.     if strlen > 1.                     "never go higher than root
  458.       if sy-opsys <> 'VMS'.
  459.         path_name+75(1)  = '/'.
  460.       endif.
  461.     endif.
  462.     path_name+76(75) = file_list-name.
  463.     condense path_name no-gaps.
  464.     open dataset path_name in text mode.
  465.     do.
  466.       read dataset path_name into buffer.
  467.       if sy-subrc <> 0.
  468.         exit.
  469.       else.
  470.         write buffer.
  471.       endif.
  472.     enddo.
  473.     close dataset path_name.
  474.   else.
  475.     if file_list-type(1) = 'D' or file_list-type(1) = 'd'.
  476.     else.
  477.       write: /
  478.        'Der Inhalt dieser Datei kann nicht angezeigt werden.'(018).
  479.     endif.
  480.   endif.
  481.  
  482. endform.