SAP ABAP source hide and unhide 代码隐藏与取消隐藏

1.可以在SE38或者用函数“ RPY_PROGRAM_READ”查看代码
所有的代码都是存放在表REPOSRC中并以压缩模式存放
不能查看源代码。

2.代码加密程序如下,不过要谨慎使用,一旦代码加密,在SAP中将不能查看源代码
参考链接 https://archive.sap.com/discussions/thread/740272

REPORT z_hide_abap
  NO STANDARD PAGE HEADING.
 
DATA: gt_code(72)  TYPE c OCCURS 0,
      gv_code      LIKE LINE OF gt_code,
      gt_code2(72) TYPE c OCCURS 0.
 
PARAMETERS: program LIKE sy-repid.
 
START-OF-SELECTION.
 
  READ REPORT program INTO gt_code.
 
  IF sy-subrc NE 0.
    MESSAGE e398(00) WITH 'Report' program 'not found.'.
*   ATTENTION:
*   READ REPORT on a hidden source code return SY-SUBRC=8 !!!
  ENDIF. "IF sy-subrc NE 0
 
  READ TABLE gt_code INDEX 1 INTO gv_code.
 
* append *special* 1st line to hide cource code
  APPEND '*@#@@[SAP]' TO gt_code2.
  LOOP AT gt_code INTO gv_code.
    APPEND gv_code TO gt_code2.
  ENDLOOP.
 
  INSERT REPORT program FROM gt_code2.

3.代码还原
参考链接 https://www.daniel-berlin.de/devel/sap-dev/decompress-abap-source-code/

下载代码https://github.com/daberlin/sap-reposrc-decompressor
用vs2015编译源代码生成命令行程序,例如decompress.exe
使用下面代码下载加密代码,如ztme11

*&---------------------------------------------------------------------*
*& Report ZS_REPOSRC_DOWNLOAD
*&---------------------------------------------------------------------*
*& Purpose: Download compressed source code from table REPOSRC
*& Author : Daniel Berlin
*& Version: 1.0.1
*& License: CC BY 3.0 (http://creativecommons.org/licenses/by/3.0/)
*&---------------------------------------------------------------------*

REPORT zs_reposrc_download.

DATA: v_fnam TYPE rlgrap-filename,  " Local file name
     v_file TYPE string,           " Same, but as a string
     v_xstr TYPE xstring,          " Source (compressed)
     v_xlen TYPE i,                " Length of source
     t_xtab TYPE TABLE OF x255.    " Source plugged into a table

PARAMETERS: report TYPE progname DEFAULT sy-repid           "#EC *
                  MATCHCODE OBJECT progname OBLIGATORY.

START-OF-SELECTION.

 " -- Select local file name
 WHILE v_fnam IS INITIAL.
   v_fnam = report.

   CALL FUNCTION 'NAVIGATION_FILENAME_HELP'
     EXPORTING
       default_path      = v_fnam
       mode              = 'S'
     IMPORTING
       selected_filename = v_fnam.
 ENDWHILE.

 v_file = v_fnam.

 " -- Fetch compressed source code
 SELECT SINGLE data INTO v_xstr FROM reposrc
         WHERE progname = report AND r3state = 'A'.

 v_xlen = XSTRLEN( v_xstr ).

 " -- Plug source into a table
 CALL METHOD cl_swf_utl_convert_xstring=>xstring_to_table
   EXPORTING
     i_stream = v_xstr
   IMPORTING
     e_table  = t_xtab
   EXCEPTIONS
     OTHERS   = 1.

 " -- Download to local file
 CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filetype     = 'BIN'
     filename     = v_file
     bin_filesize = v_xlen
   TABLES
     data_tab     = t_xtab
   EXCEPTIONS
     OTHERS       = 0.

假如下载的程序为ztme11,将ztme11移到decompress.exe所在的目录。
在cmd中切换到decompress.exe所在的目录,运行如下命令:

  decompress.exe ztme11 ztme11.abap -u

用文本编辑器打开当前目录中的ztme11.abap,就可以查看加密之前的代码了

你可能感兴趣的:(SAP ABAP source hide and unhide 代码隐藏与取消隐藏)