SAP Server Filesystem Utils ZCL_BACKEND_SERVICES

Nützliche Abap Codes und Code Fragmente

SAP Server Filesystem Utils ZCL_BACKEND_SERVICES

Postby Tron » Mon Apr 27, 2020 4:34 am

001.png
001.png (11.23 KiB) Viewed 131 times


002.png
002.png (25.74 KiB) Viewed 131 times


000.png
000.png (69.17 KiB) Viewed 132 times

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. class ZCL_GUI_BACKEND_SERVICES definition
  2.   public
  3.   final
  4.   create public .
  5.  
  6. public section.
  7.   type-pools ABAP .
  8.   type-pools CNDP .
  9.   type-pools SABC .
  10.  
  11.   class-methods FILE_EXIST
  12.     importing
  13.       value(FILE) type STRING
  14.     returning
  15.       value(RESULT) type ABAP_BOOL
  16.     exceptions
  17.       WRONG_PARAMETER
  18.       NO_AUTHORITY
  19.       SOURCE_NOT_EXISTS .
  20.   class-methods FILE_GET_SIZE
  21.     importing
  22.       value(FILE) type STRING
  23.     returning
  24.       value(FILE_SIZE) type INT4
  25.     exceptions
  26.       WRONG_PARAMETER
  27.       NO_AUTHORITY .
  28.   class-methods CHECK_AUTHORITY
  29.     importing
  30.       value(I_FILE) type STRING
  31.       value(ACTIVITY) type CHAR20
  32.     returning
  33.       value(RC) type SYST-SUBRC
  34.     exceptions
  35.       NO_PERMISSION .
  36.   class-methods GET_FILE_SEPARATOR
  37.     returning
  38.       value(SEP) type CHAR01 .
  39.   class-methods FILE_READ_BIN
  40.     importing
  41.       !FILE type STRING
  42.     exporting
  43.       !FILESIZE type I
  44.     returning
  45.       value(DATA) type SOLIX_TAB
  46.     exceptions
  47.       NO_PERMISSION
  48.       OPEN_FAILED
  49.       READ_ERROR
  50.       PATH_ERROR .
  51.   class-methods FILE_WRITE_BIN
  52.     importing
  53.       !DATA type SOLIX_TAB
  54.       !FILE type STRING
  55.       !I_FILE_OVERWRITE type ABAP_BOOL default ' '
  56.       !I_FILE_SIZE type I default 0
  57.     exceptions
  58.       NO_PERMISSION
  59.       OPEN_FAILED
  60.       AP_FILE_EXISTS
  61.       CLOSE_FAILED
  62.       WRITE_FAILED .
  63.   class-methods FILE_DELETE
  64.     importing
  65.       !FILE type STRING
  66.     exceptions
  67.       NO_PERMISSION
  68.       FAILURE .
  69.   class-methods DIRECTORY_LIST
  70.     importing
  71.       value(I_PATH) type STRING
  72.       !I_MASK type STRING default '*'
  73.     returning
  74.       value(DIRLIST) type ZCSTT_EPSFILI
  75.     exceptions
  76.       WRONG_PARAMETER
  77.       INVALID_EPS_SUBDIR
  78.       SAPGPARAM_FAILED
  79.       BUILD_DIRECTORY_FAILED
  80.       NO_AUTHORIZATION
  81.       READ_DIRECTORY_FAILED
  82.       TOO_MANY_READ_ERRORS
  83.       EMPTY_DIRECTORY_LIST .
  84.   class-methods SPLIT_FILENAME
  85.     importing
  86.       !FILE type STRING
  87.     exporting
  88.       !PATH type STRING
  89.       !FILE_WITH_EXT type STRING .
  90.   class-methods FILE_APPEND_TEXT
  91.     importing
  92.       value(I_FILE) type STRING optional
  93.       value(I_LANGU) type SY-LANGU default SY-LANGU
  94.     exporting
  95.       !E_ERROR_TAB type BAPIRET2_TAB
  96.     changing
  97.       !I_TEXTDATA_TAB type STANDARD TABLE
  98.     exceptions
  99.       NO_PERMISSION
  100.       OPEN_FAILED .
  101.   class-methods FILE_WRITE_TEXT
  102.     importing
  103.       value(I_FILE) type STRING optional
  104.       value(I_FILE_OVERWRITE) type XFELD optional
  105.       value(I_LANGU) type SY-LANGU default SY-LANGU
  106.     exporting
  107.       !E_ERROR_TAB type BAPIRET2_TAB
  108.     changing
  109.       !I_TEXTDATA_TAB type STANDARD TABLE
  110.     exceptions
  111.       NO_PERMISSION
  112.       OPEN_FAILED
  113.       AP_FILE_EXISTS .
  114.   class-methods DIRECTORY_GET_ALIAS_PATH
  115.     importing
  116.       value(I_ALIAS) type C
  117.     returning
  118.       value(O_PATH) type STRING
  119.     exceptions
  120.       NOT_FOUND .
  121.   class-methods FILE_COPY
  122.     importing
  123.       !I_SOURCE type STRING
  124.       !I_DEST type STRING
  125.     exceptions
  126.       SOURCE_NOT_EXISTS
  127.       NO_PERMISSION
  128.       OPEN_FAILED
  129.       AP_FILE_EXISTS
  130.       CLOSE_FAILED
  131.       WRITE_FAILED
  132.       READ_ERROR
  133.       PATH_ERROR .
  134.   class-methods FILE_MOVE
  135.     importing
  136.       !I_SOURCE type STRING
  137.       !I_DEST type STRING
  138.     exceptions
  139.       SOURCE_NOT_EXISTS
  140.       NO_PERMISSION
  141.       OPEN_FAILED
  142.       AP_FILE_EXISTS
  143.       CLOSE_FAILED
  144.       WRITE_FAILED
  145.       READ_ERROR
  146.       PATH_ERROR .
  147.   class-methods FILE_READ_TEXT
  148.     importing
  149.       !I_FILE type STRING
  150.       value(I_SEP) type CHAR01 optional
  151.     changing
  152.       !I_TEXTDATA_TAB type STANDARD TABLE
  153.     exceptions
  154.       ERROR_OPENING_FILE .
  155.   class-methods CHECK_AUTHORITY_SYSCMD
  156.     exceptions
  157.       NOT_ALLOWED
  158.       NO_OS_COMMANDS_ALLOWED .
  159. protected section.
  160. private section.
  161.  
  162.   constants LG_MAX_LEN type I value  255 ##NO_TEXT.
  163.  
  164.  
  165.  
  166. CLASS ZCL_GUI_BACKEND_SERVICES IMPLEMENTATION.
  167.  
  168.  
  169. * <SIGNATURE>---------------------------------------------------------------------------------------+
  170. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>CHECK_AUTHORITY
  171. * +-------------------------------------------------------------------------------------------------+
  172. * | [--->] I_FILE                         TYPE        STRING
  173. * | [--->] ACTIVITY                       TYPE        CHAR20
  174. * | [<-()] RC                             TYPE        SYST-SUBRC
  175. * | [EXC!] NO_PERMISSION
  176. * +--------------------------------------------------------------------------------------</SIGNATURE>
  177.   METHOD CHECK_AUTHORITY.
  178. * CONSTANTS:
  179. *  SABC_ACT_READ(4)               VALUE 'READ',
  180. *  SABC_ACT_WRITE(5)              VALUE 'WRITE',
  181. *  SABC_ACT_READ_WITH_FILTER(16)  VALUE 'READ_WITH_FILTER',
  182. *  SABC_ACT_WRITE_WITH_FILTER(17) VALUE 'WRITE_WITH_FILTER',
  183. *  SABC_ACT_DELETE(6)             VALUE 'DELETE',
  184. *  SABC_ACT_INIT(4)               VALUE 'INIT',
  185. *  SABC_ACT_ACCEPT(6)             VALUE 'ACCEPT',
  186. *  SABC_ACT_CALL(4)               VALUE 'CALL'.
  187.  
  188. data l_file type AUTHB-FILENAME.
  189. l_file = i_file.
  190. * check the authority for file
  191.     CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
  192.       EXPORTING
  193. *       PROGRAM          =
  194.         activity         = activity
  195.         filename         = l_file
  196.       EXCEPTIONS
  197.         no_authority     = 1
  198.         activity_unknown = 2
  199.         OTHERS           = 3.
  200.     rc = sy-subrc.
  201.  
  202.  
  203. * <SIGNATURE>---------------------------------------------------------------------------------------+
  204. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>CHECK_AUTHORITY_SYSCMD
  205. * +-------------------------------------------------------------------------------------------------+
  206. * | [EXC!] NOT_ALLOWED
  207. * | [EXC!] NO_OS_COMMANDS_ALLOWED
  208. * +--------------------------------------------------------------------------------------</SIGNATURE>
  209.   method CHECK_AUTHORITY_SYSCMD.
  210. *data: TCODE type TSTC-TCODE,
  211. *      USER(6),
  212. *      CMD(254), "Max length = 254 Bytes
  213. *      CMD_NR TYPE I,
  214. *      CMD_LINE TYPE I,
  215. *
  216. *      RESULT(255) OCCURS 100 WITH HEADER LINE, "No max length
  217. *
  218. *      BEGIN OF LIST OCCURS 100,
  219. *        NR TYPE I,
  220. *        LINE(255),
  221. *      END OF LIST,
  222.  
  223. data      rdisp_call_system.
  224. data      USER(6).
  225.  
  226. *      HOME(60),
  227. *      opsysgroup like opsystem-filesys,
  228. *      CD_PATH(60),
  229. *      lCD_PATH(60).
  230.  
  231. * Authority check
  232.   DATA AUTHRC TYPE I.
  233.   CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
  234.        EXPORTING
  235.             TCODE  = 'SM69'
  236.        EXCEPTIONS
  237.             OK     = 0
  238.             NOT_OK = 2
  239.             OTHERS = 3.
  240.   AUTHRC = SY-SUBRC.
  241.   IF AUTHRC = 0.
  242.     CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
  243.          EXPORTING
  244.               TCODE  = 'SM49'
  245.          EXCEPTIONS
  246.               OK     = 0
  247.               NOT_OK = 2
  248.               OTHERS = 3.
  249.     AUTHRC = SY-SUBRC.
  250.   ENDIF.
  251.   IF AUTHRC = 0.
  252.     AUTHORITY-CHECK OBJECT 'S_RZL_ADM'
  253.             ID 'ACTVT' FIELD '01'.
  254.     AUTHRC = SY-SUBRC.
  255.   ENDIF.
  256.   IF AUTHRC = 0.
  257.     AUTHORITY-CHECK OBJECT 'S_LOG_COM'
  258.       ID 'COMMAND'    FIELD 'RSBDCOS0'
  259.       ID 'OPSYSTEM'   FIELD SY-OPSYS
  260.       ID 'HOST'       FIELD SY-HOST.
  261.     AUTHRC = SY-SUBRC.
  262.   ENDIF.
  263.   IF AUTHRC NE 0.
  264.     raise not_allowed.
  265.   ENDIF.
  266.  
  267. * Are OS Commands allowed?
  268.   CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'rdisp/call_system' "#ec notext
  269.                      ID 'VALUE' FIELD rdisp_call_system.
  270.  
  271.   IF rdisp_call_system NE '1'.
  272.     raise NO_OS_COMMANDS_ALLOWED.
  273.   ENDIF.
  274.  
  275. *data  RESULT(255) OCCURS 100 WITH HEADER LINE. "No max length
  276. *
  277. *"data  RESULT type  TABLE OF char255 WITH HEADER LINE.
  278. *
  279. *data CMD(254). "Max length = 254 Bytes
  280. *
  281. *cmd = 'ls'.
  282. *
  283. *
  284. *
  285. *"data result type table of char255.
  286. ** Execute command
  287. *  REFRESH RESULT.
  288. *  CALL 'SYSTEM' ID 'COMMAND' FIELD CMD
  289. *                ID 'TAB'     FIELD RESULT-*SYS*.
  290.  
  291.  
  292.  
  293.  
  294. * <SIGNATURE>---------------------------------------------------------------------------------------+
  295. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>DIRECTORY_GET_ALIAS_PATH
  296. * +-------------------------------------------------------------------------------------------------+
  297. * | [--->] I_ALIAS                        TYPE        C
  298. * | [<-()] O_PATH                         TYPE        STRING
  299. * | [EXC!] NOT_FOUND
  300. * +--------------------------------------------------------------------------------------</SIGNATURE>
  301.   METHOD DIRECTORY_GET_ALIAS_PATH.
  302.  
  303.     DATA dir_trans TYPE text255.
  304.     DATA l_alias TYPE text255.
  305.  
  306. * Get Path on server from alias
  307.  
  308.     l_alias = i_alias.
  309.  
  310.     CALL FUNCTION 'RSPO_R_SAPGPARAM'
  311.       EXPORTING
  312.         name   = l_alias
  313.       IMPORTING
  314.         value  = dir_trans
  315.       EXCEPTIONS
  316.         error  = 1
  317.         OTHERS = 2.
  318.  
  319.     IF sy-subrc <> 0.
  320.       SELECT SINGLE dirname FROM user_dir INTO dir_trans WHERE aliass EQ l_alias.
  321.     IF sy-subrc <> 0.
  322.       raise not_found.
  323.     ENDIF.
  324.  
  325.       o_path = dir_trans.
  326.     ELSE.
  327.       o_path = dir_trans.
  328.     ENDIF.
  329.  
  330.  
  331.  
  332. * <SIGNATURE>---------------------------------------------------------------------------------------+
  333. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>DIRECTORY_LIST
  334. * +-------------------------------------------------------------------------------------------------+
  335. * | [--->] I_PATH                         TYPE        STRING
  336. * | [--->] I_MASK                         TYPE        STRING (default ='*')
  337. * | [<-()] DIRLIST                        TYPE        ZCSTT_EPSFILI
  338. * | [EXC!] WRONG_PARAMETER
  339. * | [EXC!] INVALID_EPS_SUBDIR
  340. * | [EXC!] SAPGPARAM_FAILED
  341. * | [EXC!] BUILD_DIRECTORY_FAILED
  342. * | [EXC!] NO_AUTHORIZATION
  343. * | [EXC!] READ_DIRECTORY_FAILED
  344. * | [EXC!] TOO_MANY_READ_ERRORS
  345. * | [EXC!] EMPTY_DIRECTORY_LIST
  346. * +--------------------------------------------------------------------------------------</SIGNATURE>
  347.   METHOD directory_list.
  348.     DATA l_dir TYPE epsf-epsdirnam.
  349.     DATA l_filemask TYPE epsf-epsfilnam.
  350.  
  351. * check parameter, wild characters not allowed
  352.     IF i_path IS INITIAL OR i_path CA '*<>|"'.
  353.       RAISE wrong_parameter.
  354.       EXIT.
  355.     ENDIF.
  356.  
  357.     l_dir = i_path.
  358.     l_filemask = i_mask.
  359.  
  360.     CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
  361.       EXPORTING
  362.         dir_name               = l_dir
  363.         file_mask              = l_filemask
  364.       TABLES
  365.         dir_list               = dirlist
  366.       EXCEPTIONS
  367.         invalid_eps_subdir     = 1
  368.         sapgparam_failed       = 2
  369.         build_directory_failed = 3
  370.         no_authorization       = 4
  371.         read_directory_failed  = 5
  372.         too_many_read_errors   = 6
  373.         empty_directory_list   = 7
  374.         OTHERS                 = 8.
  375.  
  376.     CASE sy-subrc.
  377.       WHEN 1. RAISE invalid_eps_subdir.
  378.       WHEN 2. RAISE sapgparam_failed.
  379.       WHEN 3. RAISE build_directory_failed.
  380.       WHEN 4. RAISE no_authorization.
  381.       WHEN 5. RAISE read_directory_failed.
  382.       WHEN 6. RAISE too_many_read_errors.
  383.       WHEN 7. RAISE empty_directory_list.
  384.       WHEN OTHERS.
  385.     ENDCASE.
  386.  
  387.  
  388.  
  389. * <SIGNATURE>---------------------------------------------------------------------------------------+
  390. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_APPEND_TEXT
  391. * +-------------------------------------------------------------------------------------------------+
  392. * | [--->] I_FILE                         TYPE        STRING(optional)
  393. * | [--->] I_LANGU                        TYPE        SY-LANGU (default =SY-LANGU)
  394. * | [<---] E_ERROR_TAB                    TYPE        BAPIRET2_TAB
  395. * | [<-->] I_TEXTDATA_TAB                 TYPE        STANDARD TABLE
  396. * | [EXC!] NO_PERMISSION
  397. * | [EXC!] OPEN_FAILED
  398. * +--------------------------------------------------------------------------------------</SIGNATURE>
  399.   METHOD FILE_APPEND_TEXT.
  400.  
  401. * local data -----------------------------------------------------------
  402.     DATA l_filename TYPE  authb-filename.
  403.     DATA ls_ret TYPE bapiret2.
  404.     FIELD-SYMBOLS <t> TYPE any.
  405.  
  406.  
  407. * function body --------------------------------------------------------
  408. * init
  409.     l_filename = i_file.
  410.  
  411. * check the authority for file
  412.     CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
  413.       EXPORTING
  414.         activity         = sabc_act_write
  415. * Authority Check allows right now only 60 Character
  416.         filename         = l_filename(60)
  417.       EXCEPTIONS
  418.         no_authority     = 1
  419.         activity_unknown = 2
  420.         OTHERS           = 3.
  421.     IF sy-subrc <> 0.
  422.       RAISE no_permission.
  423.     ENDIF.
  424.  
  425.     SET LOCALE LANGUAGE i_langu.
  426.  
  427. * open dataset for writing
  428.     OPEN DATASET i_file WITH WINDOWS LINEFEED FOR APPENDING IN TEXT MODE
  429.                  ENCODING NON-UNICODE.
  430.     IF NOT sy-subrc IS INITIAL.
  431.       RAISE open_failed.
  432.     ELSE.
  433.  
  434.  
  435.       LOOP AT i_textdata_tab ASSIGNING <t>.
  436.         TRY.
  437.  
  438. *       write data in file
  439.             TRANSFER <t> TO i_file.
  440.  
  441. *       conversion erortable does not exist
  442.           CATCH cx_sy_codepage_converter_init cx_sy_conversion_codepage.
  443.  
  444.             CLEAR ls_ret.
  445. *         MESSAGE S003(EHSBM_LS).
  446. *         Fehler bei der Konvertierung der sprachabhängigen Daten
  447.             ls_ret-type = 'W'.
  448.             ls_ret-id   = 'EHSBM_LS'.
  449.             ls_ret-number = 003.
  450.             APPEND ls_ret TO e_error_tab.
  451.  
  452.             CLEAR ls_ret.
  453. *         MESSAGE S137(C$) with I_TEXTDATA_TAB.
  454.             ls_ret-type = 'W'.
  455.             ls_ret-id   = 'C$'.
  456.             ls_ret-number = 137.
  457.             ls_ret-message_v1 = <t>.
  458.             APPEND ls_ret TO e_error_tab.
  459.  
  460.         ENDTRY.
  461.  
  462.       ENDLOOP.
  463.  
  464.     ENDIF.
  465.  
  466. * close the dataset
  467.     CLOSE DATASET i_file.
  468.  
  469.     SET LOCALE LANGUAGE space.
  470.  
  471.  
  472.  
  473. * <SIGNATURE>---------------------------------------------------------------------------------------+
  474. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_COPY
  475. * +-------------------------------------------------------------------------------------------------+
  476. * | [--->] I_SOURCE                       TYPE        STRING
  477. * | [--->] I_DEST                         TYPE        STRING
  478. * | [EXC!] SOURCE_NOT_EXISTS
  479. * | [EXC!] NO_PERMISSION
  480. * | [EXC!] OPEN_FAILED
  481. * | [EXC!] AP_FILE_EXISTS
  482. * | [EXC!] CLOSE_FAILED
  483. * | [EXC!] WRITE_FAILED
  484. * | [EXC!] READ_ERROR
  485. * | [EXC!] PATH_ERROR
  486. * +--------------------------------------------------------------------------------------</SIGNATURE>
  487.   METHOD file_copy.
  488.  
  489.     DATA l_exist(1).
  490.     DATA l_filesize TYPE i.
  491.     DATA t_data TYPE solix_tab.
  492.  
  493.     l_exist =   zcl_gui_backend_services=>file_exist( i_source ).
  494.  
  495.     IF l_exist IS INITIAL.
  496.       RAISE source_not_exists.
  497.     ENDIF.
  498.  
  499.     CALL METHOD zcl_gui_backend_services=>file_read_bin
  500.       EXPORTING
  501.         file          = i_source
  502.       IMPORTING
  503.         filesize      = l_filesize
  504.       RECEIVING
  505.         data          = t_data
  506.       EXCEPTIONS
  507.         no_permission = 1
  508.         open_failed   = 2
  509.         read_error    = 3
  510.         path_error    = 4
  511.         OTHERS        = 5.
  512.  
  513.     CASE sy-subrc.
  514.       WHEN 1. RAISE no_permission.
  515.       WHEN 2. RAISE open_failed.
  516.       WHEN 3. RAISE read_error.
  517.       WHEN 4. RAISE path_error.
  518.       WHEN OTHERS.
  519.         EXIT.
  520.     ENDCASE.
  521.  
  522.  
  523.     CALL METHOD zcl_gui_backend_services=>file_write_bin
  524.       EXPORTING
  525.         data             = t_data
  526.         file             = i_dest
  527.         i_file_overwrite = 'X'
  528.         i_file_size      = l_filesize
  529.       EXCEPTIONS
  530.         no_permission    = 1
  531.         open_failed      = 2
  532.         ap_file_exists   = 3
  533.         close_failed     = 4
  534.         write_failed     = 5
  535.         OTHERS           = 6.
  536.     CASE sy-subrc.
  537.       WHEN 1. RAISE no_permission.
  538.       WHEN 2. RAISE open_failed.
  539.       WHEN 3. RAISE ap_file_exists.
  540.       WHEN 4. RAISE close_failed .
  541.       WHEN 5. RAISE write_failed.
  542.       WHEN OTHERS.
  543.         EXIT.
  544.     ENDCASE.
  545.  
  546.  
  547.  
  548.  
  549. * <SIGNATURE>---------------------------------------------------------------------------------------+
  550. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_DELETE
  551. * +-------------------------------------------------------------------------------------------------+
  552. * | [--->] FILE                           TYPE        STRING
  553. * | [EXC!] NO_PERMISSION
  554. * | [EXC!] FAILURE
  555. * +--------------------------------------------------------------------------------------</SIGNATURE>
  556.   METHOD file_delete.
  557.  
  558.     DATA rc TYPE sy-subrc.
  559.     "DATA i_file TYPE rcgiedial-iefile.
  560.  
  561.     rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'DELETE' ).
  562.     IF rc <> 0.
  563.       RAISE no_permission.
  564.     ENDIF.
  565.  
  566.     "i_file = file.
  567.     DELETE DATASET file.
  568.     IF rc <> 0.
  569.       RAISE failure.
  570.     ENDIF.
  571.  
  572.  
  573.  
  574. * <SIGNATURE>---------------------------------------------------------------------------------------+
  575. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_EXIST
  576. * +-------------------------------------------------------------------------------------------------+
  577. * | [--->] FILE                           TYPE        STRING
  578. * | [<-()] RESULT                         TYPE        ABAP_BOOL
  579. * | [EXC!] WRONG_PARAMETER
  580. * | [EXC!] NO_AUTHORITY
  581. * | [EXC!] SOURCE_NOT_EXISTS
  582. * +--------------------------------------------------------------------------------------</SIGNATURE>
  583.   METHOD file_exist.
  584.     DATA rc TYPE i.
  585.     DATA l_file TYPE rlgrap-filename.
  586.     DATA l_dir TYPE epsf-epsdirnam.
  587.     DATA l_filemask TYPE epsf-epsfilnam.
  588.     DATA:it_dirlist TYPE STANDARD TABLE OF epsfili.
  589.     DATA long_filename TYPE dbmsgora-filename.
  590.     DATA pure_filename TYPE sdbah-actid.
  591.     DATA pure_extension TYPE sdbad-funct.
  592.     DATA full_file TYPE dbmsgora-filename.
  593.  
  594. * check parameter, wild characters not allowed
  595.     IF file IS INITIAL OR file CA '*<>|"'.
  596.       RAISE wrong_parameter.
  597.       EXIT.
  598.     ENDIF.
  599.  
  600.     rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'READ' ).
  601.  
  602.     IF rc <> 0.
  603.       RAISE no_authority.
  604.     ENDIF.
  605.  
  606. *    long_filename = file.
  607. *    CALL FUNCTION 'SPLIT_FILENAME'
  608. *      EXPORTING
  609. *        long_filename  = long_filename
  610. *      IMPORTING
  611. *        pure_filename  = pure_filename
  612. *        pure_extension = pure_extension.
  613. *
  614. *    CONCATENATE pure_filename '.' pure_extension INTO full_file.
  615. *
  616. *    l_dir = file.
  617. *    REPLACE ALL OCCURRENCES OF full_file IN l_dir WITH ''.
  618. *    l_filemask = full_file.
  619.  
  620.     DATA l_dir_s TYPE string.
  621.     DATA l_filemask_s TYPE string.
  622.  
  623.     CALL METHOD zcl_gui_backend_services=>split_filename
  624.       EXPORTING
  625.         file          = file
  626.       IMPORTING
  627.         path          = l_dir_s
  628.         file_with_ext = l_filemask_s.
  629.  
  630.     l_dir = l_dir_s.
  631.     l_filemask = l_filemask_s.
  632.  
  633.     CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
  634.       EXPORTING
  635.         dir_name               = l_dir
  636.         file_mask              = l_filemask
  637.       TABLES
  638.         dir_list               = it_dirlist[]
  639.       EXCEPTIONS
  640.         invalid_eps_subdir     = 1
  641.         sapgparam_failed       = 2
  642.         build_directory_failed = 3
  643.         no_authorization       = 4
  644.         read_directory_failed  = 5
  645.         too_many_read_errors   = 6
  646.         empty_directory_list   = 7
  647.         OTHERS                 = 8.
  648.     IF sy-subrc <> 0.
  649.       result = abap_false.
  650.       EXIT.
  651.     ENDIF.
  652.  
  653.     IF it_dirlist[] IS INITIAL.
  654.       result = abap_false.
  655.       EXIT.
  656.     ENDIF.
  657.  
  658.     READ TABLE it_dirlist TRANSPORTING NO FIELDS WITH KEY name = l_filemask.
  659.     IF sy-subrc = 0.
  660.       result = abap_true.
  661.     ELSE.
  662.       result = abap_false.
  663.     ENDIF.
  664.  
  665.  
  666.  
  667. * <SIGNATURE>---------------------------------------------------------------------------------------+
  668. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_GET_SIZE
  669. * +-------------------------------------------------------------------------------------------------+
  670. * | [--->] FILE                           TYPE        STRING
  671. * | [<-()] FILE_SIZE                      TYPE        INT4
  672. * | [EXC!] WRONG_PARAMETER
  673. * | [EXC!] NO_AUTHORITY
  674. * +--------------------------------------------------------------------------------------</SIGNATURE>
  675.   METHOD file_get_size.
  676.     DATA rc TYPE i.
  677.     DATA l_file TYPE rlgrap-filename.
  678.     DATA l_dir TYPE epsf-epsdirnam.
  679.     DATA l_filemask TYPE epsf-epsfilnam.
  680.     DATA:it_dirlist TYPE STANDARD TABLE OF epsfili.
  681.     DATA:ls_dirlist TYPE epsfili.
  682.     DATA long_filename TYPE dbmsgora-filename.
  683.     DATA pure_filename TYPE sdbah-actid.
  684.     DATA pure_extension TYPE sdbad-funct.
  685.     DATA full_file TYPE dbmsgora-filename.
  686.  
  687. * check parameter, wild characters not allowed
  688.     IF file IS INITIAL OR file CA '*<>|"'.
  689.       RAISE wrong_parameter.
  690.       EXIT.
  691.     ENDIF.
  692.  
  693.     rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'READ' ).
  694.  
  695.     IF rc <> 0.
  696.       RAISE no_authority.
  697.     ENDIF.
  698.  
  699.     DATA l_dir_s TYPE string.
  700.     DATA l_filemask_s TYPE string.
  701.  
  702.     CALL METHOD zcl_gui_backend_services=>split_filename
  703.       EXPORTING
  704.         file          = file
  705.       IMPORTING
  706.         path          = l_dir_s
  707.         file_with_ext = l_filemask_s.
  708.  
  709.     l_dir = l_dir_s.
  710.     l_filemask = l_filemask_s.
  711.  
  712.     CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
  713.       EXPORTING
  714.         dir_name               = l_dir
  715.         file_mask              = l_filemask
  716.       TABLES
  717.         dir_list               = it_dirlist[]
  718.       EXCEPTIONS
  719.         invalid_eps_subdir     = 1
  720.         sapgparam_failed       = 2
  721.         build_directory_failed = 3
  722.         no_authorization       = 4
  723.         read_directory_failed  = 5
  724.         too_many_read_errors   = 6
  725.         empty_directory_list   = 7
  726.         OTHERS                 = 8.
  727.     IF sy-subrc <> 0.
  728.       EXIT.
  729.     ENDIF.
  730.  
  731.  
  732.     READ TABLE it_dirlist INTO ls_dirlist WITH KEY name = l_filemask.
  733.     IF sy-subrc = 0.
  734.       file_size = ls_dirlist-size.
  735.     ENDIF.
  736.  
  737.  
  738.  
  739. * <SIGNATURE>---------------------------------------------------------------------------------------+
  740. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_MOVE
  741. * +-------------------------------------------------------------------------------------------------+
  742. * | [--->] I_SOURCE                       TYPE        STRING
  743. * | [--->] I_DEST                         TYPE        STRING
  744. * | [EXC!] SOURCE_NOT_EXISTS
  745. * | [EXC!] NO_PERMISSION
  746. * | [EXC!] OPEN_FAILED
  747. * | [EXC!] AP_FILE_EXISTS
  748. * | [EXC!] CLOSE_FAILED
  749. * | [EXC!] WRITE_FAILED
  750. * | [EXC!] READ_ERROR
  751. * | [EXC!] PATH_ERROR
  752. * +--------------------------------------------------------------------------------------</SIGNATURE>
  753.   METHOD file_move.
  754.  
  755.     DATA l_exist(1).
  756.     DATA l_filesize TYPE i.
  757.     DATA t_data TYPE solix_tab.
  758.     DATA l_ok(1).
  759.  
  760.     l_exist =   zcl_gui_backend_services=>file_exist( i_source ).
  761.  
  762.     IF l_exist IS INITIAL.
  763.       RAISE source_not_exists.
  764.     ENDIF.
  765.  
  766.     CALL METHOD zcl_gui_backend_services=>file_read_bin
  767.       EXPORTING
  768.         file          = i_source
  769.       IMPORTING
  770.         filesize      = l_filesize
  771.       RECEIVING
  772.         data          = t_data
  773.       EXCEPTIONS
  774.         no_permission = 1
  775.         open_failed   = 2
  776.         read_error    = 3
  777.         path_error    = 4
  778.         OTHERS        = 5.
  779.  
  780.     CASE sy-subrc.
  781.       WHEN 1. RAISE no_permission.
  782.       WHEN 2. RAISE open_failed.
  783.       WHEN 3. RAISE read_error.
  784.       WHEN 4. RAISE path_error.
  785.       WHEN OTHERS.
  786.         EXIT.
  787.     ENDCASE.
  788.  
  789.  
  790.     CALL METHOD zcl_gui_backend_services=>file_write_bin
  791.       EXPORTING
  792.         data             = t_data
  793.         file             = i_dest
  794.         i_file_overwrite = 'X'
  795.         i_file_size      = l_filesize
  796.       EXCEPTIONS
  797.         no_permission    = 1
  798.         open_failed      = 2
  799.         ap_file_exists   = 3
  800.         close_failed     = 4
  801.         write_failed     = 5
  802.         OTHERS           = 6.
  803.     CASE sy-subrc.
  804.       WHEN 1. RAISE no_permission.
  805.       WHEN 2. RAISE open_failed.
  806.       WHEN 3. RAISE ap_file_exists.
  807.       WHEN 4. RAISE close_failed .
  808.       WHEN 5. RAISE write_failed.
  809.       WHEN OTHERS.
  810.         EXIT.
  811.     ENDCASE.
  812.  
  813.     CALL METHOD zcl_gui_backend_services=>file_delete
  814.       EXPORTING
  815.         file          = i_source
  816.       EXCEPTIONS
  817.         no_permission = 1
  818.         OTHERS        = 2.
  819.  
  820.  
  821.  
  822.  
  823. * <SIGNATURE>---------------------------------------------------------------------------------------+
  824. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_READ_BIN
  825. * +-------------------------------------------------------------------------------------------------+
  826. * | [--->] FILE                           TYPE        STRING
  827. * | [<---] FILESIZE                       TYPE        I
  828. * | [<-()] DATA                           TYPE        SOLIX_TAB
  829. * | [EXC!] NO_PERMISSION
  830. * | [EXC!] OPEN_FAILED
  831. * | [EXC!] READ_ERROR
  832. * | [EXC!] PATH_ERROR
  833. * +--------------------------------------------------------------------------------------</SIGNATURE>
  834.   METHOD file_read_bin.
  835.  
  836. * lokal data -----------------------------------------------------------
  837.     DATA l_len LIKE sy-tabix.
  838.     DATA l_subrc LIKE sy-subrc.
  839.     DATA i_file TYPE char200.
  840.     DATA rc TYPE sy-subrc.
  841.     DATA ls_data TYPE solix.
  842.     DATA e_file_size TYPE char200.
  843.     DATA e_lines TYPE  i.
  844.  
  845.     rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'READ' ).
  846.  
  847.     IF rc <> 0.
  848.       RAISE no_permission.
  849.     ENDIF.
  850.  
  851.     REFRESH data.
  852.  
  853. ** read the raw-file from the appl.server
  854.     CLEAR l_subrc.
  855.     CATCH SYSTEM-EXCEPTIONS open_dataset_no_authority = 1
  856.                             dataset_too_many_files = 2
  857.                             OTHERS = 4.
  858.  
  859.       i_file = file.
  860.       OPEN DATASET i_file FOR INPUT IN BINARY MODE.
  861.       l_subrc = sy-subrc.
  862.     ENDCATCH.
  863.     IF sy-subrc <> 0 OR
  864.         l_subrc <> 0.
  865.       RAISE open_failed.
  866.     ENDIF.
  867.  
  868.     CATCH SYSTEM-EXCEPTIONS dataset_read_error = 11
  869.                             OTHERS = 12.
  870.       DO.
  871.         CLEAR l_len.
  872.         CLEAR ls_data.
  873.         READ DATASET i_file INTO ls_data LENGTH l_len.
  874.         IF sy-subrc <> 0.
  875.           IF l_len > 0.
  876.             e_file_size = e_file_size + l_len.
  877.             APPEND ls_data TO data.
  878.           ENDIF.
  879.           EXIT.
  880.         ENDIF.
  881.         e_file_size = e_file_size + l_len.
  882.         APPEND ls_data TO data.
  883.       ENDDO.
  884.     ENDCATCH.
  885.     IF sy-subrc > 10.
  886.       RAISE read_error.
  887.     ENDIF.
  888.  
  889.     DESCRIBE TABLE data LINES e_lines.
  890.     filesize =  e_file_size.
  891.     CATCH SYSTEM-EXCEPTIONS dataset_cant_close = 1
  892.                             OTHERS = 4.
  893.       CLOSE DATASET i_file.
  894.     ENDCATCH.
  895.     IF NOT sy-subrc IS INITIAL.
  896. *  but there wasn't any error at the reading of the data
  897.     ENDIF.
  898.  
  899.  
  900.  
  901.  
  902. * <SIGNATURE>---------------------------------------------------------------------------------------+
  903. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_READ_TEXT
  904. * +-------------------------------------------------------------------------------------------------+
  905. * | [--->] I_FILE                         TYPE        STRING
  906. * | [--->] I_SEP                          TYPE        CHAR01(optional)
  907. * | [<-->] I_TEXTDATA_TAB                 TYPE        STANDARD TABLE
  908. * | [EXC!] ERROR_OPENING_FILE
  909. * +--------------------------------------------------------------------------------------</SIGNATURE>
  910.   METHOD file_read_text.
  911.  
  912.     DATA l_line TYPE string.
  913.     DATA t_split TYPE tab512.
  914.  
  915.     DATA lt TYPE TABLE OF tab512.
  916.     DATA ls TYPE tab512.
  917.     DATA l_idx TYPE i.
  918.  
  919.       <ls>        TYPE tab512,
  920.       <dyn_rec>   TYPE any,
  921.       <dyn_field> TYPE any.
  922.  
  923. *------------------------------------------------------------------------------*
  924. *      read the file from the application server
  925. *------------------------------------------------------------------------------*
  926.     REFRESH i_textdata_tab.
  927.     OPEN DATASET i_file WITH WINDOWS LINEFEED FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  928.     IF sy-subrc NE 0.
  929.       RAISE error_opening_file.
  930.     ELSE.
  931.       WHILE ( sy-subrc EQ 0 ).
  932.         READ DATASET i_file INTO l_line.
  933.         IF NOT l_line IS INITIAL.
  934.           IF i_sep IS INITIAL.
  935.             APPEND l_line TO i_textdata_tab.
  936.           ELSE.
  937.  
  938.             SPLIT l_line AT i_sep INTO TABLE lt.
  939.             APPEND INITIAL LINE TO i_textdata_tab.
  940.             READ TABLE i_textdata_tab ASSIGNING <dyn_rec> INDEX sy-tabix.
  941.  
  942.             LOOP AT lt INTO ls.
  943.               l_idx = sy-tabix.
  944.               ASSIGN COMPONENT l_idx OF STRUCTURE <dyn_rec> TO <dyn_field>.
  945.               <dyn_field> = ls-wa.
  946.             ENDLOOP.
  947.  
  948.           ENDIF.
  949.  
  950.         ENDIF.
  951.  
  952.         CLEAR l_line.
  953.       ENDWHILE.
  954.     ENDIF.
  955.     CLOSE DATASET i_file.
  956.  
  957.  
  958.  
  959. * <SIGNATURE>---------------------------------------------------------------------------------------+
  960. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_WRITE_BIN
  961. * +-------------------------------------------------------------------------------------------------+
  962. * | [--->] DATA                           TYPE        SOLIX_TAB
  963. * | [--->] FILE                           TYPE        STRING
  964. * | [--->] I_FILE_OVERWRITE               TYPE        ABAP_BOOL (default =' ')
  965. * | [--->] I_FILE_SIZE                    TYPE        I (default =0)
  966. * | [EXC!] NO_PERMISSION
  967. * | [EXC!] OPEN_FAILED
  968. * | [EXC!] AP_FILE_EXISTS
  969. * | [EXC!] CLOSE_FAILED
  970. * | [EXC!] WRITE_FAILED
  971. * +--------------------------------------------------------------------------------------</SIGNATURE>
  972.   METHOD file_write_bin.
  973.  
  974.     DATA l_len TYPE i.
  975.     DATA l_all_lines_len TYPE i.
  976.     DATA l_diff_len TYPE i.
  977.     DATA l_subrc LIKE sy-subrc.
  978.  
  979.     DATA rc TYPE sy-subrc.
  980.     DATA ls_data TYPE solix.
  981.     DATA e_file_size TYPE char200.
  982.     DATA i_lines TYPE  i.
  983.     DATA i_file TYPE char200.
  984.  
  985.  
  986.     rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'WRITE' ).
  987.     IF rc <> 0.
  988.       RAISE no_permission.
  989.     ENDIF.
  990.     rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'DELETE' ).
  991.     IF rc <> 0.
  992.       RAISE no_permission.
  993.     ENDIF.
  994.  
  995.     i_file = file.
  996.  
  997. * check if file exists if we arn't allowed to overwrite file
  998.     IF i_file_overwrite = ' '. " apap_FALSE'.
  999.  
  1000.       CLEAR l_subrc.
  1001.       CATCH SYSTEM-EXCEPTIONS open_dataset_no_authority = 1
  1002.                               dataset_too_many_files = 2
  1003.                               OTHERS = 4.
  1004.         OPEN DATASET i_file FOR INPUT IN BINARY MODE.
  1005.         l_subrc = sy-subrc.
  1006.       ENDCATCH.
  1007.       IF l_subrc <> 0.
  1008. *     nothing
  1009.       ELSE.
  1010.         CATCH SYSTEM-EXCEPTIONS OTHERS = 4.
  1011.           CLOSE DATASET i_file.
  1012.         ENDCATCH.
  1013.         RAISE ap_file_exists.
  1014.       ENDIF.
  1015.       CATCH SYSTEM-EXCEPTIONS OTHERS = 4.
  1016.         CLOSE DATASET i_file.
  1017.       ENDCATCH.
  1018.  
  1019.     ENDIF.
  1020.  
  1021.     i_lines = lines( data ).
  1022. * open dataset for writing
  1023.     OPEN DATASET i_file FOR OUTPUT IN BINARY MODE.
  1024.     IF NOT sy-subrc IS INITIAL.
  1025.       RAISE open_failed.
  1026.     ELSE.
  1027.  
  1028.       l_len = lg_max_len.
  1029.       LOOP AT data INTO ls_data.
  1030. *     last line is shorter perhaps
  1031.         IF sy-tabix = i_lines.
  1032.           l_all_lines_len = lg_max_len * ( i_lines - 1 ).
  1033.           l_diff_len = i_file_size - l_all_lines_len.
  1034.           l_len = l_diff_len.
  1035.         ENDIF.
  1036. *     write data in file
  1037.         CATCH SYSTEM-EXCEPTIONS dataset_write_error = 1
  1038.                                 OTHERS = 4.
  1039.           TRANSFER ls_data TO i_file LENGTH l_len.
  1040.         ENDCATCH.
  1041.  
  1042.         IF NOT sy-subrc IS INITIAL.
  1043.           RAISE write_failed.
  1044.         ENDIF.
  1045.  
  1046.       ENDLOOP.
  1047.     ENDIF.
  1048.  
  1049. * close the dataset
  1050.  
  1051.     CATCH SYSTEM-EXCEPTIONS dataset_cant_close = 1
  1052.                             OTHERS = 4.
  1053.       CLOSE DATASET i_file.
  1054.     ENDCATCH.
  1055.  
  1056.     IF NOT sy-subrc IS INITIAL.
  1057.       RAISE close_failed.
  1058.     ENDIF.
  1059.  
  1060.  
  1061.  
  1062. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1063. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_WRITE_TEXT
  1064. * +-------------------------------------------------------------------------------------------------+
  1065. * | [--->] I_FILE                         TYPE        STRING(optional)
  1066. * | [--->] I_FILE_OVERWRITE               TYPE        XFELD(optional)
  1067. * | [--->] I_LANGU                        TYPE        SY-LANGU (default =SY-LANGU)
  1068. * | [<---] E_ERROR_TAB                    TYPE        BAPIRET2_TAB
  1069. * | [<-->] I_TEXTDATA_TAB                 TYPE        STANDARD TABLE
  1070. * | [EXC!] NO_PERMISSION
  1071. * | [EXC!] OPEN_FAILED
  1072. * | [EXC!] AP_FILE_EXISTS
  1073. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1074.   METHOD file_write_text.
  1075.  
  1076. * local data -----------------------------------------------------------
  1077.     DATA l_filename TYPE  authb-filename.
  1078.     DATA ls_ret TYPE bapiret2.
  1079.     FIELD-SYMBOLS <t> TYPE any.
  1080.  
  1081.  
  1082. * function body --------------------------------------------------------
  1083. * init
  1084.     l_filename = i_file.
  1085.  
  1086. * check the authority for file
  1087.     CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
  1088.       EXPORTING
  1089.         activity         = sabc_act_write
  1090. * Authority Check allows right now only 60 Character
  1091.         filename         = l_filename(60)
  1092.       EXCEPTIONS
  1093.         no_authority     = 1
  1094.         activity_unknown = 2
  1095.         OTHERS           = 3.
  1096.     IF sy-subrc <> 0.
  1097.       RAISE no_permission.
  1098.     ENDIF.
  1099.  
  1100. * check if file exists if we arn't allowed to overwrite file
  1101.     IF i_file_overwrite IS INITIAL.
  1102.       OPEN DATASET i_file FOR INPUT IN TEXT MODE
  1103.                    ENCODING NON-UNICODE.
  1104.       IF sy-subrc IS INITIAL.
  1105.         CLOSE DATASET i_file.
  1106.         RAISE ap_file_exists.
  1107.       ENDIF.
  1108.       CLOSE DATASET i_file.
  1109.     ENDIF.
  1110.  
  1111.     SET LOCALE LANGUAGE i_langu.
  1112.  
  1113. * open dataset for writing
  1114.     OPEN DATASET i_file WITH WINDOWS LINEFEED FOR OUTPUT IN TEXT MODE
  1115.                  ENCODING NON-UNICODE.
  1116.     IF NOT sy-subrc IS INITIAL.
  1117.       RAISE open_failed.
  1118.     ELSE.
  1119.  
  1120.  
  1121.       LOOP AT i_textdata_tab ASSIGNING <t>.
  1122.         TRY.
  1123.  
  1124. *       write data in file
  1125.             TRANSFER <t> TO i_file.
  1126.  
  1127. *       conversion erortable does not exist
  1128.           CATCH cx_sy_codepage_converter_init cx_sy_conversion_codepage.
  1129.  
  1130.             CLEAR ls_ret.
  1131. *         MESSAGE S003(EHSBM_LS).
  1132. *         Fehler bei der Konvertierung der sprachabhängigen Daten
  1133.             ls_ret-type = 'W'.
  1134.             ls_ret-id   = 'EHSBM_LS'.
  1135.             ls_ret-number = 003.
  1136.             APPEND ls_ret TO e_error_tab.
  1137.  
  1138.             CLEAR ls_ret.
  1139. *         MESSAGE S137(C$) with I_TEXTDATA_TAB.
  1140.             ls_ret-type = 'W'.
  1141.             ls_ret-id   = 'C$'.
  1142.             ls_ret-number = 137.
  1143.             ls_ret-message_v1 = <t>.
  1144.             APPEND ls_ret TO e_error_tab.
  1145.  
  1146.         ENDTRY.
  1147.  
  1148.       ENDLOOP.
  1149.  
  1150.     ENDIF.
  1151.  
  1152. * close the dataset
  1153.     CLOSE DATASET i_file.
  1154.  
  1155.     SET LOCALE LANGUAGE space.
  1156.  
  1157.  
  1158.  
  1159. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1160. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>GET_FILE_SEPARATOR
  1161. * +-------------------------------------------------------------------------------------------------+
  1162. * | [<-()] SEP                            TYPE        CHAR01
  1163. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1164.   METHOD get_file_separator.
  1165. *
  1166. ** Ermittle Trenner
  1167. *    IF sy-opsys CS 'WINDOWS'.
  1168. ** Windows NT/2000
  1169. *      sep = '\'.
  1170. *    ELSE.
  1171. ** UNIX
  1172. *      sep = '/'.
  1173. *    ENDIF.
  1174.  
  1175. data l_VALUE TYPE  TEXT255.
  1176. CALL FUNCTION 'RSPO_R_SAPGPARAM'
  1177.   EXPORTING
  1178.     name          = 'DIR_SEP'
  1179.  IMPORTING
  1180.     VALUE         = l_VALUE
  1181.  EXCEPTIONS
  1182.    ERROR         = 1
  1183.    OTHERS        = 2
  1184.           .
  1185. IF sy-subrc <> 0.
  1186. * Implement suitable error handling here
  1187.  
  1188. sep = l_value.
  1189.  
  1190.  
  1191.  
  1192. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1193. * | Static Public Method ZCL_GUI_BACKEND_SERVICES=>SPLIT_FILENAME
  1194. * +-------------------------------------------------------------------------------------------------+
  1195. * | [--->] FILE                           TYPE        STRING
  1196. * | [<---] PATH                           TYPE        STRING
  1197. * | [<---] FILE_WITH_EXT                  TYPE        STRING
  1198. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1199.   METHOD split_filename.
  1200.  
  1201.     DATA long_filename TYPE dbmsgora-filename.
  1202.     DATA pure_filename TYPE sdbah-actid.
  1203.     DATA pure_extension TYPE sdbad-funct.
  1204.     DATA full_file TYPE dbmsgora-filename.
  1205.  
  1206.     long_filename = file.
  1207.     path = file.
  1208.  
  1209.     CALL FUNCTION 'SPLIT_FILENAME'
  1210.       EXPORTING
  1211.         long_filename  = long_filename
  1212.       IMPORTING
  1213.         pure_filename  = pure_filename
  1214.         pure_extension = pure_extension.
  1215.  
  1216.     CONCATENATE pure_filename '.' pure_extension INTO full_file.
  1217.  
  1218.     file_with_ext = full_file.
  1219.  
  1220.     REPLACE ALL OCCURRENCES OF full_file IN path WITH ''.
  1221.  
  1222.  
  1223.  
GeSHi ©
Attachments
ZBC_BACKEND_SERVICE.zip
(12.64 KiB) Downloaded 9 times
Tron
.....
.....
 
Posts: 1098
Joined: Sat Aug 04, 2007 10:21 pm

2: SAP Server Filesystem Utils ZCL_BACKEND_SERVICES

Postby Tron » Mon Apr 27, 2020 4:47 am

Add Dynpro 100 plus OK_CODE
003.png
003.png (49.83 KiB) Viewed 128 times

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report ZBC_BACKEND_SERVICE
  3. *&---------------------------------------------------------------------*
  4. *&
  5. *&---------------------------------------------------------------------*
  6. REPORT ZBC_BACKEND_SERVICE.
  7.  
  8.  
  9.  
  10. * Tabellen der Varianten
  11. * ltdx
  12. * Ltdxd
  13. * Ltdxs
  14.  
  15. INCLUDE <icon>.
  16. TYPE-POOLS slis .
  17.  
  18. CONSTANTS c_structure TYPE dd02l-tabname VALUE 'ZBC_BACKEND_SERVICE_ALV'.
  19. TYPES ty_data TYPE zbc_backend_service_alv.
  20. FIELD-SYMBOLS <p> TYPE zbc_backend_service_alv.
  21.  
  22. * ALV Datenquelle
  23. *DATA: BEGIN OF it_data OCCURS 0.
  24. *        INCLUDE STRUCTURE epsfili.
  25. *DATA: stflg   TYPE xfeld.
  26. *"as4text TYPE e07t-as4text.
  27. *DATA END OF it_data.
  28. DATA it_data TYPE TABLE OF ty_data WITH HEADER LINE.
  29.  
  30. * Grid Parameter
  31. DATA: ok_code      LIKE sy-ucomm,
  32.       lo_split     TYPE REF TO cl_gui_splitter_container,
  33.       lo_container TYPE REF TO cl_gui_container,
  34.       grid1        TYPE REF TO cl_gui_alv_grid,
  35.       is_variant   TYPE disvariant.
  36.  
  37. *--- Field catalog table
  38. DATA gt_fieldcat TYPE lvc_t_fcat WITH HEADER LINE.
  39. *--- Layout structure
  40. DATA gs_layout TYPE lvc_s_layo .
  41.  
  42. * LT_EXCLUDE => Tabelle zum Ausschliessen von Funktionen innerhalb
  43. * der Toolbar des ALV-Grid
  44. DATA: lt_exclude TYPE ui_functions,
  45.       ls_exclude TYPE ui_func.
  46.  
  47.  
  48.  
  49. *---------------------------------------------------------------------*
  50. *       CLASS lcl_event_handler DEFINITION
  51. *---------------------------------------------------------------------*
  52. *
  53. *---------------------------------------------------------------------*
  54. CLASS lcl_event_handler DEFINITION .
  55.   PUBLIC SECTION .
  56.     METHODS:
  57. *--To add new functional buttons to the ALV toolbar
  58.       handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
  59.         IMPORTING e_object e_interactive ,
  60.  
  61. *--To implement user commands
  62.       handle_user_command
  63.                     FOR EVENT user_command OF cl_gui_alv_grid
  64.         IMPORTING e_ucomm ,
  65.  
  66.  
  67.  
  68. *--To be triggered before user commands
  69.       handle_before_user_command
  70.                     FOR EVENT before_user_command OF cl_gui_alv_grid
  71.         IMPORTING e_ucomm.
  72.  
  73. *--Double-click control
  74. *handle_double_click
  75. *FOR EVENT double_click OF cl_gui_alv_grid
  76. *IMPORTING e_row e_column es_row_no.
  77.  
  78.   PRIVATE SECTION.
  79. ENDCLASS.                    "lcl_event_handler DEFINITION
  80.  
  81.  
  82.  
  83. *---------------------------------------------------------------------*
  84. *       CLASS lcl_event_handler IMPLEMENTATION
  85. *---------------------------------------------------------------------*
  86. *
  87. *---------------------------------------------------------------------*
  88. CLASS lcl_event_handler IMPLEMENTATION .
  89.  
  90. *--Handle Toolbar
  91.   METHOD handle_toolbar.
  92.     PERFORM handle_toolbar USING e_object e_interactive .
  93.   ENDMETHOD .                    "handle_toolbar
  94.  
  95. *--Handle User Command
  96.   METHOD handle_user_command .
  97.     PERFORM handle_user_command USING e_ucomm .
  98.   ENDMETHOD.                    "handle_user_command
  99.  
  100. *--Handle Before User Command JG
  101.   METHOD handle_before_user_command .
  102.     PERFORM handle_before_user_command USING e_ucomm .
  103.   ENDMETHOD .                    "handle_before_user_command
  104.  
  105.  
  106. ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
  107.  
  108. DATA gr_event_handler TYPE REF TO lcl_event_handler .
  109.  
  110.  
  111. * Eingabe und Auswertung ---------------------------------------------*
  112.  
  113.  
  114.   PARAMETERS: pfilmsk TYPE epsf-epsfilnam DEFAULT '*.*',
  115.               p_dir   TYPE epsf-epsfilnam DEFAULT 'DIR_MOVESGPDATA',
  116.               pc_verz TYPE epsf-epsdirnam DEFAULT 'C:\tmp\sapdata\'.
  117.  
  118.  
  119.   PERFORM get_data.
  120.  
  121.   CALL SCREEN 100.
  122.  
  123.   EXIT.
  124.  
  125.   DATA:
  126.     l_report   TYPE raldb_repo,
  127.     l_variante TYPE raldb_vari,
  128.     BEGIN OF t_info OCCURS 0,
  129.       typ(1),
  130.       null(1),
  131.       line(120),
  132.     END OF t_info.
  133.  
  134. ** Lade Variante sy-uname
  135.   l_report   = sy-repid.
  136.   l_variante = sy-uname.
  137.  
  138.  
  139.   CALL FUNCTION 'RS_COVERPAGE_SELECTIONS'
  140.     EXPORTING
  141.       report  = l_report
  142.       variant = l_variante
  143.     TABLES
  144.       infotab = t_info
  145.     EXCEPTIONS
  146.       OTHERS  = 3.
  147.  
  148. *---------------------------------------------------------------------*
  149. *       MODULE PBO OUTPUT                                             *
  150. *---------------------------------------------------------------------*
  151. MODULE pbo OUTPUT.
  152.  
  153.   IF lo_split IS INITIAL.
  154.  
  155.  
  156.     CREATE OBJECT lo_split
  157.       EXPORTING
  158.         parent                  = cl_gui_container=>screen0
  159.         rows                    = 1
  160.         columns                 = 1
  161.         no_autodef_progid_dynnr = 'X'.
  162.  
  163.     lo_split->set_border( 'X' ).
  164.  
  165. *    lo_split->set_column_width(  EXPORTING id                = 1
  166. *                                           width             = 20 ).
  167. *    lo_split->set_column_width(  EXPORTING id                = 2
  168. *                                           width             = 40 ).
  169.  
  170. * Left:   List of reports
  171.     lo_container = lo_split->get_container( row       = 1
  172.                                             column    = 1 ).
  173.  
  174.  
  175.     CREATE OBJECT grid1
  176.       EXPORTING
  177.         i_parent = lo_container.
  178.  
  179. *--Creating an instance for the event handler
  180.     CREATE OBJECT gr_event_handler .
  181.  
  182. *----Preparing field catalog.
  183.     PERFORM prepare_field_catalog TABLES gt_fieldcat[] .
  184. *----Preparing layout structure
  185.     PERFORM prepare_layout CHANGING gs_layout .
  186. *----Preparing Disable Toolbar Buttons
  187.     PERFORM change_buttons .
  188.  
  189.     is_variant-report = sy-repid.
  190.     is_variant-variant = '/GLOB_DEF'.
  191.  
  192.     CALL METHOD grid1->set_table_for_first_display
  193.       EXPORTING
  194.         is_variant           = is_variant
  195.         i_save               = 'A'
  196.         is_layout            = gs_layout
  197.         it_toolbar_excluding = lt_exclude
  198.       CHANGING
  199.         it_outtab            = it_data[]
  200.         it_fieldcatalog      = gt_fieldcat[].
  201.  
  202.  
  203. *--Registering handler methods to handle ALV Grid events JG
  204.  
  205. *   SET HANDLER gr_event_handler->handle_double_click FOR grid1 .
  206.     SET HANDLER gr_event_handler->handle_toolbar FOR grid1.
  207.     SET HANDLER gr_event_handler->handle_user_command FOR grid1.
  208.     SET HANDLER gr_event_handler->handle_before_user_command
  209.         FOR grid1 .
  210.  
  211. * Die Toolbar des Grids muss noch auf interactive
  212. * geschaltet werden. Dadurch werden die
  213. * definierten Buttons angezeigt und die
  214. * oben im PERFORM change_buttons ausgeschalteten
  215. * Buttons heraus genommen werden
  216.  
  217.     CALL METHOD grid1->set_toolbar_interactive.
  218.  
  219. * Der GRID1 wird noch refreshed
  220.     CALL METHOD grid1->refresh_table_display.
  221.  
  222.   ENDIF.
  223.  
  224.   SET PF-STATUS 'MAIN100'.
  225.   SET TITLEBAR 'AUSW' WITH text-001.
  226.  
  227. ENDMODULE.                    "PBO OUTPUT
  228. *---------------------------------------------------------------------*
  229. *       MODULE PAI INPUT                                              *
  230. *---------------------------------------------------------------------*
  231. MODULE pai INPUT.
  232. *   to react on oi_custom_events:
  233.   CALL METHOD cl_gui_cfw=>dispatch.
  234.   CASE ok_code.
  235.     WHEN 'EXIT'.
  236.       PERFORM exit_program.
  237.     WHEN OTHERS.
  238. *     do nothing
  239.   CLEAR ok_code.
  240. ENDMODULE.                    "PAI INPUT
  241. *---------------------------------------------------------------------*
  242. *       FORM EXIT_PROGRAM                                             *
  243. *---------------------------------------------------------------------*
  244. FORM exit_program.
  245. *  CALL METHOD G_CUSTOM_CONTAINER->FREE.
  246. *  CALL METHOD CL_GUI_CFW=>FLUSH.
  247.   LEAVE TO SCREEN 0.
  248. ENDFORM.                    "EXIT_PROGRAM
  249. *&--------------------------------------------------------------------*
  250. *&      Form  prepare_field_catalog
  251. *&--------------------------------------------------------------------*
  252. *       text
  253. *---------------------------------------------------------------------*
  254. *      -->PT_FIELDCATtext
  255. *---------------------------------------------------------------------*
  256. FORM prepare_field_catalog TABLES pt_fieldcat TYPE lvc_t_fcat .
  257.   FIELD-SYMBOLS <f> TYPE lvc_s_fcat.
  258.   DATA ls_fcat TYPE lvc_s_fcat .
  259.  
  260.   CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  261.     EXPORTING
  262.       i_structure_name       = c_structure
  263.     CHANGING
  264.       ct_fieldcat            = pt_fieldcat[]
  265.     EXCEPTIONS
  266.       inconsistent_interface = 1
  267.       program_error          = 2
  268.       OTHERS                 = 3.
  269.  
  270.   IF sy-subrc <> 0.
  271. *--Exception handling
  272.   ENDIF.
  273.  
  274.   CLEAR ls_fcat.
  275.   READ TABLE pt_fieldcat INTO ls_fcat WITH KEY fieldname = 'STFLG'.
  276.   IF sy-subrc = 0.
  277.     ls_fcat-domname = 'FLAG'.
  278.     ls_fcat-dd_outlen = '1'.
  279.     ls_fcat-intlen = '1'.
  280.     ls_fcat-coltext = 'Select'.
  281.     ls_fcat-reptext = 'Select'.
  282.     ls_fcat-checkbox = 'X'.
  283.     ls_fcat-scrtext_l = 'Auswahl'.
  284.     ls_fcat-scrtext_m = 'Auswahl'.
  285.     ls_fcat-scrtext_s = 'Auswahl'.
  286.     ls_fcat-ref_table  = 'KAEP_COAC'.
  287.     ls_fcat-tabname = '1'.
  288.     ls_fcat-just = 'C'.
  289.     MODIFY pt_fieldcat FROM ls_fcat INDEX sy-tabix.
  290.  
  291.   ENDIF.
  292.  
  293.   CLEAR ls_fcat.
  294.   READ TABLE pt_fieldcat INTO ls_fcat WITH KEY fieldname = 'ICON'.
  295.   IF sy-subrc = 0.
  296.     ls_fcat-just = 'C'.
  297.     MODIFY pt_fieldcat FROM ls_fcat INDEX sy-tabix.
  298.  
  299.   ENDIF.
  300.  
  301. *  CLEAR ls_fcat.
  302. *  READ TABLE pt_fieldcat INTO ls_fcat WITH KEY fieldname = 'NAME'.
  303. *  ls_fcat-fieldname = 'STFLG'.
  304. *  ls_fcat-domname = 'FLAG'.
  305. *  ls_fcat-dd_outlen = '1'.
  306. *  ls_fcat-intlen = '1'.
  307. *  ls_fcat-coltext = 'Select'.
  308. *  ls_fcat-reptext = 'Select'.
  309. *  ls_fcat-checkbox = 'X'.
  310. *  ls_fcat-scrtext_l = 'Auswahl'.
  311. *  ls_fcat-scrtext_m = 'Auswahl'.
  312. *  ls_fcat-scrtext_s = 'Auswahl'.
  313. *  ls_fcat-ref_table  = 'KAEP_COAC'.
  314. *  ls_fcat-tabname = '1'.
  315. *  INSERT ls_fcat INTO pt_fieldcat INDEX 1.
  316.  
  317.  
  318. *  LOOP AT pt_fieldcat ASSIGNING <f>.
  319. *    <f>-col_pos = sy-tabix.
  320. *  ENDLOOP.
  321.  
  322.  
  323. ENDFORM .                    "prepare_field_catalog
  324. *&--------------------------------------------------------------------*
  325. *&      Form  prepare_layout
  326. *&--------------------------------------------------------------------*
  327. *       text
  328. *---------------------------------------------------------------------*
  329. *      -->PS_LAYOUT  text
  330. *---------------------------------------------------------------------*
  331. FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
  332.   ps_layout-zebra = 'X' .
  333. *ps_layout-cwidth_opt ='X'.
  334.   ps_layout-numc_total = ' '.
  335.   ps_layout-no_merging = 'X'.
  336.   ps_layout-no_rowmark = ' '.
  337.   ps_layout-sel_mode = 'A'.
  338. *  ps_layout-grid_title = 'Flights' .
  339. *  ps_layout-smalltitle = 'X' .
  340. ENDFORM.                    "prepare_layout
  341.  
  342. *&--------------------------------------------------------------------*
  343. *&      Form  handle_hotspot_click
  344. *&--------------------------------------------------------------------*
  345. *       text
  346. *---------------------------------------------------------------------*
  347. *      -->E_ROW_ID   text
  348. *      -->E_COLUMN_IDtext
  349. *      -->ES_ROW_NO  text
  350. *---------------------------------------------------------------------*
  351. FORM handle_double_click USING e_row e_column es_row_no .
  352.  
  353. *  DATA csum(15).
  354. *
  355. ** Bei Doppelclick auf eine ganze Spalte ist der Rowindex 0 !
  356. *  CHECK e_row NE 0.
  357. *
  358. *  READ TABLE it_data INDEX e_row.
  359. *  IF it_data-stflg = 'X'.
  360. *    it_data-stflg = ' '.
  361. *  ELSE.
  362. *    it_data-stflg = 'X'.
  363. *  ENDIF.
  364. *  MODIFY it_data INDEX e_row.
  365. *
  366. *  CLEAR sum.
  367. *
  368. *
  369. *  LOOP AT it_data.
  370. *    IF NOT it_data-stflg IS INITIAL.
  371. *      sum = sum + it_data-wkgbtr.
  372. *    ENDIF.
  373. *  ENDLOOP.
  374. *
  375. *  WRITE sum TO csum.
  376. *  CONDENSE csum NO-GAPS.
  377. *
  378. *  CALL FUNCTION 'C14Z_DYNP_WRITE_FIELD'
  379. *    EXPORTING
  380. *      i_program               = dyname
  381. *      i_dynpro                = dynumb
  382. *      i_fieldname             = 'DISTWERT'
  383. *      i_line                  = 0
  384. **   I_FLG_AT_ENTER          = ESP1_TRUE
  385. **   I_FLG_READ_BEFORE       = ESP1_FALSE
  386. *      i_value                 = csum.
  387. *
  388. *  CALL METHOD grid1->refresh_table_display
  389. ** EXPORTING
  390. ** IS_STABLE =
  391. ** I_SOFT_REFRESH =
  392. *  EXCEPTIONS
  393. *  finished = 1
  394. *  OTHERS = 2 .
  395.  
  396. ENDFORM.                    "handle_hotspot_click
  397.  
  398. *&--------------------------------------------------------------------*
  399. *&      Form  handle_toolbar
  400. *&--------------------------------------------------------------------*
  401. *       text
  402. *---------------------------------------------------------------------*
  403. *      -->I_OBJECT   text
  404. *---------------------------------------------------------------------*
  405. FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set
  406. e_interactive .
  407.  
  408.   DATA: ls_toolbar TYPE stb_button.
  409.  
  410. * Paltzhalter / Seperator
  411.   CLEAR ls_toolbar.
  412.   MOVE 3 TO ls_toolbar-butn_type.
  413.   APPEND ls_toolbar TO i_object->mt_toolbar.
  414.  
  415. * Button REFRESH
  416.   CLEAR ls_toolbar.
  417.   MOVE 'REFRESH' TO ls_toolbar-function.                    "#EC NOTEXT
  418.   MOVE icon_refresh TO ls_toolbar-icon.
  419.   MOVE 'Refresh'(201) TO ls_toolbar-quickinfo.
  420.   MOVE ' Refresh'(201) TO ls_toolbar-text.
  421.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  422.   APPEND ls_toolbar TO i_object->mt_toolbar.
  423.  
  424. * Button MARKIEREN
  425.   CLEAR ls_toolbar.
  426.   MOVE 'MARK' TO ls_toolbar-function.                       "#EC NOTEXT
  427.   MOVE icon_checkbox TO ls_toolbar-icon.
  428.   MOVE 'TOGGLE Select'(201) TO ls_toolbar-quickinfo.
  429.   MOVE ' TOGGLE Select'(201) TO ls_toolbar-text.
  430.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  431.   APPEND ls_toolbar TO i_object->mt_toolbar.
  432.  
  433. * Button MARK all Filtered
  434.   CLEAR ls_toolbar.
  435.   MOVE 'MARK_ALL_FILTERED' TO ls_toolbar-function.          "#EC NOTEXT
  436.   MOVE  icon_filter TO ls_toolbar-icon.
  437.   MOVE 'MARK ALL FILTERED'(201) TO ls_toolbar-quickinfo.
  438.   MOVE ' MARK ALL FILTERED'(201) TO ls_toolbar-text.
  439.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  440.   APPEND ls_toolbar TO i_object->mt_toolbar.
  441.  
  442. * Button ALLE MARKIERUNGEN LÖSCHEN
  443.   CLEAR ls_toolbar.
  444.   MOVE 'CLEAR' TO ls_toolbar-function.                      "#EC NOTEXT
  445.   MOVE icon_deselect_all TO ls_toolbar-icon.
  446.   MOVE 'RESET Selection'(202) TO ls_toolbar-quickinfo.
  447.   MOVE ' RESET Selection'(202) TO ls_toolbar-text.
  448.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  449.   APPEND ls_toolbar TO i_object->mt_toolbar.
  450.  
  451. * Button Aus LISTE LÖSCHEN
  452.   CLEAR ls_toolbar.
  453.   MOVE 'DELROW' TO ls_toolbar-function.                     "#EC NOTEXT
  454.   MOVE icon_delete_row TO ls_toolbar-icon.
  455.   MOVE 'Delete from Selection'(203) TO ls_toolbar-quickinfo.
  456.   MOVE ' Delete from Selection'(203) TO ls_toolbar-text.
  457.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  458.   APPEND ls_toolbar TO i_object->mt_toolbar.
  459.  
  460. * Paltzhalter / Seperator
  461.   CLEAR ls_toolbar.
  462.   MOVE 3 TO ls_toolbar-butn_type.
  463.   APPEND ls_toolbar TO i_object->mt_toolbar.
  464.  
  465. * Button Speichern
  466.   CLEAR ls_toolbar.
  467.   MOVE 'SAVE' TO ls_toolbar-function.                       "#EC NOTEXT
  468.   MOVE icon_page_down TO ls_toolbar-icon.
  469.   MOVE 'Save to Frontend'(204) TO ls_toolbar-quickinfo.
  470.   MOVE ' Save to Frontend'(204) TO ls_toolbar-text.
  471.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  472.   APPEND ls_toolbar TO i_object->mt_toolbar.
  473.  
  474. * Button Speichern
  475.   CLEAR ls_toolbar.
  476.   MOVE 'LOAD' TO ls_toolbar-function.                       "#EC NOTEXT
  477.   MOVE icon_page_up TO ls_toolbar-icon.
  478.   MOVE 'Upload from Frontend'(205) TO ls_toolbar-quickinfo.
  479.   MOVE ' Upload from Frontend'(205) TO ls_toolbar-text.
  480.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  481.   APPEND ls_toolbar TO i_object->mt_toolbar.
  482.  
  483. ** Paltzhalter / Seperator
  484.   CLEAR ls_toolbar.
  485.   MOVE 3 TO ls_toolbar-butn_type.
  486.   APPEND ls_toolbar TO i_object->mt_toolbar.
  487.  
  488. * Button Löschen
  489.   CLEAR ls_toolbar.
  490.   MOVE 'KILL' TO ls_toolbar-function.                       "#EC NOTEXT
  491.   MOVE icon_delete TO ls_toolbar-icon.
  492.   MOVE 'DELETE Serverfile'(206) TO ls_toolbar-quickinfo.
  493.   MOVE ' DELETE Serverfile'(206) TO ls_toolbar-text.
  494.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  495.   APPEND ls_toolbar TO i_object->mt_toolbar.
  496.  
  497. ENDFORM .                    "handle_toolbar
  498.  
  499. *&--------------------------------------------------------------------*
  500. *&      Form  Change_buttons
  501. *&--------------------------------------------------------------------*
  502. *       text
  503. *---------------------------------------------------------------------*
  504. FORM change_buttons .
  505. * Kein Symbol für Drucken / Graphik / Info
  506.   ls_exclude = cl_gui_alv_grid=>mc_fc_print_back.
  507.   APPEND ls_exclude TO lt_exclude.
  508.   ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
  509.   APPEND ls_exclude TO lt_exclude.
  510.   ls_exclude = cl_gui_alv_grid=>mc_fc_info.
  511.   APPEND ls_exclude TO lt_exclude.
  512.  
  513. ENDFORM.                    "Change_buttons
  514. *&--------------------------------------------------------------------*
  515. *&      Form  handle_before_user_command
  516. *&--------------------------------------------------------------------*
  517. *       text
  518. *---------------------------------------------------------------------*
  519. *      -->I_UCOMM    text
  520. *---------------------------------------------------------------------*
  521. FORM handle_before_user_command USING i_ucomm TYPE syucomm .
  522.   CASE i_ucomm .
  523.     WHEN '&MB_FILTER' OR '&DELETE_FILTER' OR '&FILTER'.
  524.   ENDCASE .
  525. ENDFORM .                    "handle_before_user_command
  526. *&--------------------------------------------------------------------*
  527. *&      Form  handle_user_command
  528. *&--------------------------------------------------------------------*
  529. *       text
  530. *---------------------------------------------------------------------*
  531. *      -->I_UCOMM    text
  532. *---------------------------------------------------------------------*
  533. FORM handle_user_command USING i_ucomm TYPE syucomm .
  534.   DATA lt_selected_rows TYPE lvc_t_roid .
  535.   DATA ls_selected_row TYPE lvc_s_roid .
  536.   DATA lv_name TYPE epsfili-name.
  537.   DATA lv_flag(1).
  538.   DATA lv_stable TYPE lvc_s_stbl.
  539.   DATA i TYPE i.
  540.   DATA lv_tit(80).
  541.  
  542.   DATA lfiltered TYPE lvc_t_fidx.
  543.  
  544.  
  545.   FIELD-SYMBOLS <p> LIKE it_data.
  546.  
  547.   LOOP AT it_data ASSIGNING <p> WHERE icon NE space.
  548.     .CLEAR <p>-icon.
  549.  
  550.   CASE i_ucomm .
  551.  
  552.     WHEN 'REFRESH'.
  553.       PERFORM get_data.
  554.  
  555.     WHEN 'MARK' .
  556.  
  557.       CALL METHOD grid1->get_selected_rows
  558.         IMPORTING
  559.           et_row_no = lt_selected_rows.
  560. *     War was selektiert ?
  561.       READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1 .
  562.  
  563.       IF sy-subrc NE 0 .
  564.         MESSAGE s000(su) WITH 'Select a row!'(205).
  565.       ELSE.
  566.         LOOP AT lt_selected_rows INTO ls_selected_row.
  567.           IF ls_selected_row-row_id NE 0.
  568.  
  569.             READ TABLE it_data ASSIGNING <p> INDEX ls_selected_row-row_id.
  570.             IF <p>-stflg = 'X'.
  571.               <p>-stflg = space.
  572.             ELSE.
  573.               <p>-stflg = 'X'.
  574.             ENDIF.
  575.             lv_flag = <p>-stflg.
  576.  
  577.           ENDIF.
  578.         ENDLOOP.
  579.  
  580.       ENDIF .
  581.  
  582.     WHEN 'MARK_ALL_FILTERED'.
  583.  
  584.       CALL METHOD grid1->get_filtered_entries
  585.         IMPORTING
  586.           et_filtered_entries = lfiltered.
  587.  
  588.       LOOP AT it_data ASSIGNING <p>.
  589.         READ TABLE lfiltered WITH KEY = sy-tabix TRANSPORTING NO FIELDS.
  590.         IF sy-subrc NE 0.
  591.           <p>-stflg = 'X'.
  592.         ENDIF.
  593.       ENDLOOP.
  594.  
  595.     WHEN 'CLEAR' .
  596.       LOOP AT it_data ASSIGNING <p>.
  597.         <p>-stflg = space.
  598.       ENDLOOP.
  599.  
  600.     WHEN 'DELROW'.
  601.  
  602.       DELETE it_data WHERE stflg = 'X'.
  603.  
  604.     WHEN 'SAVE'.
  605.       PERFORM save2pc.
  606.       LOOP AT it_data ASSIGNING <p>.
  607.         <p>-stflg = space.
  608.       ENDLOOP.
  609.  
  610.     WHEN 'LOAD'.
  611.       PERFORM load_pc.
  612.       PERFORM get_data.
  613.  
  614.     WHEN 'KILL'.
  615.       PERFORM delete_file.
  616.       PERFORM get_data.
  617.  
  618.       LOOP AT it_data ASSIGNING <p>.
  619.         <p>-stflg = space.
  620.       ENDLOOP.
  621.  
  622.   ENDCASE .
  623.  
  624.   lv_stable-row = 'X'.
  625.   CALL METHOD grid1->refresh_table_display
  626.     EXPORTING
  627.       is_stable = lv_stable
  628.     EXCEPTIONS
  629.       finished  = 1
  630.       OTHERS    = 2.
  631.  
  632.  
  633.  
  634.   CLEAR i.
  635.   LOOP AT it_data ASSIGNING <p> WHERE NOT stflg IS INITIAL.
  636.     i = i + 1.
  637.  
  638.   WRITE i TO lv_tit.
  639.   CONDENSE lv_tit NO-GAPS.
  640.   CONCATENATE text-001 '/' lv_tit 'selected' INTO lv_tit SEPARATED BY space.
  641.   SET TITLEBAR 'AUSW' WITH lv_tit.
  642.  
  643.  
  644.  
  645.   lv_stable-row = 'X'.
  646.   CALL METHOD grid1->refresh_table_display
  647.     EXPORTING
  648.       is_stable = lv_stable
  649.     EXCEPTIONS
  650.       finished  = 1
  651.       OTHERS    = 2.
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659. ENDFORM.                    "handle_user_command
  660.  
  661. *&--------------------------------------------------------------------*
  662. *&      Form  deletr
  663. *&--------------------------------------------------------------------*
  664. *       text
  665. *---------------------------------------------------------------------*
  666. FORM delete_file.
  667.   DATA: i_file TYPE string,
  668.         rc     TYPE abap_bool,
  669.         o_path TYPE string.
  670.   DATA sep(1).
  671.  
  672. ** Ermittle Trenner
  673.   IF sy-opsys CS 'WINDOWS'.
  674. * Windows NT/2000
  675.     sep = '\'.
  676.   ELSE.
  677. * UNIX
  678.     sep = '/'.
  679.   ENDIF.
  680.  
  681.   o_path  = zcl_gui_backend_services=>directory_get_alias_path( p_dir ).
  682.  
  683.   LOOP AT it_data WHERE stflg = 'X'.
  684.     CONCATENATE o_path sep it_data-name INTO i_file.
  685.     zcl_gui_backend_services=>file_delete( i_file ).
  686.  
  687.   MESSAGE ID 'SY' TYPE 'S' NUMBER '002' WITH
  688.             'file(s) DELETED'(E01).
  689.  
  690. ENDFORM.                    "delete_file
  691.  
  692. *&---------------------------------------------------------------------*
  693. *&      Form  save2pc
  694. *&---------------------------------------------------------------------*
  695. *       text
  696. *----------------------------------------------------------------------*
  697. FORM save2pc.
  698.  
  699.   FIELD-SYMBOLS <d> TYPE ty_data.
  700.  
  701.   DATA:
  702.     sep(1),
  703.     flen        TYPE i,
  704.     lv_filename TYPE char200,
  705.     o_path      TYPE string,
  706.     l_file      TYPE string,
  707.     t_data      TYPE solix_tab.
  708.  
  709. ** Ermittle Trenner
  710.   IF sy-opsys CS 'WINDOWS'.
  711. * Windows NT/2000
  712.     sep = '\'.
  713.   ELSE.
  714. * UNIX
  715.     sep = '/'.
  716.   ENDIF.
  717.  
  718.   o_path  = zcl_gui_backend_services=>directory_get_alias_path( p_dir ).
  719.  
  720.   LOOP AT it_data ASSIGNING <d> WHERE stflg = 'X'.
  721.  
  722.     lv_filename = <d>-name.
  723.  
  724.     CONCATENATE o_path sep lv_filename INTO l_file .
  725.  
  726.     CALL METHOD zcl_gui_backend_services=>file_read_bin
  727.       EXPORTING
  728.         file          = l_file
  729.       IMPORTING
  730.         filesize      = flen
  731.       RECEIVING
  732.         data          = t_data
  733.       EXCEPTIONS
  734.         no_permission = 1
  735.         open_failed   = 2
  736.         read_error    = 3
  737.         path_error    = 4
  738.         OTHERS        = 5.
  739.  
  740.     IF sy-subrc <> 0.
  741.       <d>-icon = '@5C@'.
  742.       CONTINUE.
  743.     ENDIF.
  744.  
  745.     CONCATENATE pc_verz lv_filename INTO l_file .
  746.  
  747.     CALL METHOD cl_gui_frontend_services=>gui_download
  748.       EXPORTING
  749.         bin_filesize            = flen
  750.         filename                = l_file
  751.         filetype                = 'BIN'
  752.       CHANGING
  753.         data_tab                = t_data
  754.       EXCEPTIONS
  755.         file_write_error        = 1
  756.         no_batch                = 2
  757.         gui_refuse_filetransfer = 3
  758.         invalid_type            = 4
  759.         no_authority            = 5
  760.         unknown_error           = 6
  761.         header_not_allowed      = 7
  762.         separator_not_allowed   = 8
  763.         filesize_not_allowed    = 9
  764.         header_too_long         = 10
  765.         dp_error_create         = 11
  766.         dp_error_send           = 12
  767.         dp_error_write          = 13
  768.         unknown_dp_error        = 14
  769.         access_denied           = 15
  770.         dp_out_of_memory        = 16
  771.         disk_full               = 17
  772.         dp_timeout              = 18
  773.         file_not_found          = 19
  774.         dataprovider_exception  = 20
  775.         control_flush_error     = 21
  776.         not_supported_by_gui    = 22
  777.         error_no_gui            = 23
  778.         OTHERS                  = 24.
  779.     IF sy-subrc <> 0.
  780.     ELSE.
  781.       <d>-icon = '@5B@'.
  782.  
  783.     ENDIF.
  784.  
  785.  
  786. ENDFORM.                                                    "save2pc
  787.  
  788. *&---------------------------------------------------------------------*
  789. *&      Form  load_pc
  790. *&---------------------------------------------------------------------*
  791. *       text
  792. *----------------------------------------------------------------------*
  793. *&---------------------------------------------------------------------*
  794. *&      Form  load_pc
  795. *&---------------------------------------------------------------------*
  796. *       text
  797. *----------------------------------------------------------------------*
  798. FORM load_pc.
  799.   DATA o_path TYPE string.
  800.   DATA sep(1).
  801.  
  802. ** Ermittle Trenner
  803.   IF sy-opsys CS 'WINDOWS'.
  804. * Windows NT/2000
  805.     sep = '\'.
  806.   ELSE.
  807. * UNIX
  808.     sep = '/'.
  809.   ENDIF.
  810.  
  811.   o_path  = zcl_gui_backend_services=>directory_get_alias_path( p_dir ).
  812.  
  813.  
  814.   DATA lt_files TYPE filetable WITH HEADER LINE.
  815.   DATA rc TYPE i.
  816.   DATA lv_inidir TYPE string.
  817.  
  818.   DATA lt_tmp TYPE filetable WITH HEADER LINE.
  819.   DATA i TYPE i.
  820.   DATA bin_data TYPE solix_tab.
  821.   DATA l_file TYPE string.
  822.   DATA flen TYPE i.
  823.   DATA lv_filename TYPE string.
  824.  
  825.   lv_inidir = pc_verz.
  826.   CALL METHOD cl_gui_frontend_services=>file_open_dialog
  827.     EXPORTING
  828.       window_title            = 'Select Files:'
  829.       initial_directory       = lv_inidir
  830.       multiselection          = 'X'
  831.     CHANGING
  832.       file_table              = lt_files[]
  833.       rc                      = rc
  834.     EXCEPTIONS
  835.       file_open_dialog_failed = 1
  836.       cntl_error              = 2
  837.       error_no_gui            = 3
  838.       not_supported_by_gui    = 4
  839.       OTHERS                  = 5.
  840.  
  841.   IF sy-subrc <> 0.
  842.  
  843.   ENDIF.
  844.  
  845.   CHECK rc NE 0.
  846.  
  847.  
  848.   LOOP AT lt_files.
  849.  
  850. * extract filename
  851.     SPLIT lt_files AT '\' INTO TABLE lt_tmp.
  852.     i = lines( lt_tmp ).
  853.  
  854.  
  855.     READ TABLE lt_tmp INDEX i INTO lv_filename.
  856.  
  857.     IF sy-subrc = 0.
  858.  
  859.       l_file = lt_files.
  860.  
  861.       CALL METHOD cl_gui_frontend_services=>gui_upload
  862.         EXPORTING
  863.           filename                = l_file
  864.           filetype                = 'BIN'
  865.         IMPORTING
  866.           filelength              = flen
  867. *         header                  =
  868.         CHANGING
  869.           data_tab                = bin_data
  870.         EXCEPTIONS
  871.           file_open_error         = 1
  872.           file_read_error         = 2
  873.           no_batch                = 3
  874.           gui_refuse_filetransfer = 4
  875.           invalid_type            = 5
  876.           no_authority            = 6
  877.           unknown_error           = 7
  878.           bad_data_format         = 8
  879.           header_not_allowed      = 9
  880.           separator_not_allowed   = 10
  881.           header_too_long         = 11
  882.           unknown_dp_error        = 12
  883.           access_denied           = 13
  884.           dp_out_of_memory        = 14
  885.           disk_full               = 15
  886.           dp_timeout              = 16
  887.           not_supported_by_gui    = 17
  888.           error_no_gui            = 18
  889.           OTHERS                  = 19.
  890.  
  891.       CONCATENATE o_path sep lv_filename INTO l_file.
  892.  
  893.       CALL METHOD zcl_gui_backend_services=>file_write_bin
  894.         EXPORTING
  895.           data             = bin_data
  896.           file             = l_file
  897.           i_file_overwrite = ' '
  898.           i_file_size      = flen
  899.         EXCEPTIONS
  900.           no_permission    = 1
  901.           open_failed      = 2
  902.           ap_file_exists   = 3
  903.           close_failed     = 4
  904.           write_failed     = 5
  905.           OTHERS           = 6.
  906.       IF sy-subrc <> 0.
  907. * Implement suitable error handling here
  908.       ENDIF.
  909.  
  910.     ENDIF.
  911.  
  912.  
  913.  
  914. ENDFORM.                    "load_pc
  915.  
  916. *&---------------------------------------------------------------------*
  917. *&      Form  load_pc
  918. *&---------------------------------------------------------------------*
  919. *       text
  920. *----------------------------------------------------------------------*
  921.  
  922. FORM get_data.
  923.  
  924.   DATA o_path TYPE string.
  925.   DATA i_mask TYPE string.
  926.   DATA t_data TYPE zcstt_epsfili.
  927.   DATA s_data TYPE epsfili.
  928.  
  929.   REFRESH: t_data,it_data.
  930.   o_path  = zcl_gui_backend_services=>directory_get_alias_path( p_dir ).
  931.  
  932.   i_mask =  pfilmsk.
  933.  
  934.   CALL METHOD zcl_gui_backend_services=>directory_list
  935.     EXPORTING
  936.       i_path                 = o_path
  937.       i_mask                 = i_mask
  938.     RECEIVING
  939.       dirlist                = t_data
  940.     EXCEPTIONS
  941.       wrong_parameter        = 1
  942.       invalid_eps_subdir     = 2
  943.       sapgparam_failed       = 3
  944.       build_directory_failed = 4
  945.       no_authorization       = 5
  946.       read_directory_failed  = 6
  947.       too_many_read_errors   = 7
  948.       empty_directory_list   = 8
  949.       OTHERS                 = 9.
  950.  
  951.  
  952.   IF sy-subrc <> 0.
  953.     MESSAGE ID 'SY' TYPE 'S' NUMBER '002' WITH
  954.              'Fehler beim Lesen der Files.'.
  955.   ENDIF.
  956.  
  957.   LOOP AT t_data INTO s_data.
  958.     it_data-icon = ' '.
  959.     MOVE-CORRESPONDING s_data TO it_data.
  960.     APPEND it_data.
  961.  
  962.  
GeSHi ©
Tron
.....
.....
 
Posts: 1098
Joined: Sat Aug 04, 2007 10:21 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron
  • Latest Topics