Hide and password-protect any ABAP's source
By Imre Kabai
This tip is published with the permission of Imre Kabai.
This program hides any ABAP's source code and protects it with a password. One can still run the ABAP (the load version is intact) but it can not be displayed, edited, traced, transported or generated. If the ABAP is not hidden, the program hides it. If it is hidden, it unhides it. The password is hard-coded in a source code, so the first candidate to be hidden should be ZHIDE itself.
PROGRAM ZHIDE NO STANDARD PAGE HEADING. SELECTION-SCREEN BEGIN OF BLOCK BLOCK. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(8) PWD. SELECTION-SCREEN POSITION 35. PARAMETERS: PASSWORD(8) MODIF ID AAA. SELECTION-SCREEN END OF LINE. PARAMETERS: PROGRAM(8). SELECTION-SCREEN END OF BLOCK BLOCK. * AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. IF SCREEN-GROUP1 = 'AAA'. SCREEN-INVISIBLE = '1'. MODIFY SCREEN. ENDIF. ENDLOOP. * INITIALIZATION. PWD = 'PASSWORD'. * START-OF-SELECTION. TABLES: TRDIR. * User name and passsword check IF SY-UNAME <> 'IMRE' OR PASSWORD <> 'TITOK'. WRITE: / 'Wrong password'. EXIT. ENDIF. * SAP owned? IF NOT PROGRAM CP 'Z*' AND NOT PROGRAM CP 'Y*'. WRITE: / 'Do not hide original SAP programs!'. EXIT. ENDIF. * Exists? SELECT SINGLE * FROM TRDIR WHERE NAME = PROGRAM. IF SY-SUBRC <> 0. WRITE: / 'Program does not exists!'. EXIT. ENDIF. * Does it have a current generated version? DATA: F1 TYPE D, F3 TYPE D. DATA: F2 TYPE T, F4 TYPE T. EXEC SQL. SELECT UDAT, UTIME, SDAT, STIME INTO :F1, :F2, :F3, :F4 FROM D010LINF WHERE PROG = :PROGRAM ENDEXEC. IF F1 < F3 OR ( F1 = F3 AND F2 < F4 ). WRITE: / 'The program has no recent generated version!'. EXIT. ENDIF. * Compose a new program name DATA: NEW_NAME(8), I TYPE I, J TYPE I. NEW_NAME = PROGRAM. DO 8 TIMES. I = SY-INDEX - 1. NEW_NAME+I(1) = '_'. * Search for acceptable program name variations J = 0. SELECT * FROM TRDIR WHERE NAME LIKE NEW_NAME. J = J + 1. ENDSELECT. IF J = 1. EXIT. ENDIF. NEW_NAME = PROGRAM. ENDDO. * Can not generate appropriate program name IF J > 1. WRITE: / 'Can not generate appropriate program name'. EXIT. ENDIF. * Check if it is already in d010s (already hidden) DATA: F5(8). EXEC SQL. SELECT PROG INTO :F5 FROM D010S WHERE PROG = :NEW_NAME ENDEXEC. IF F5 IS INITIAL. * There is no such hidden program, hide it EXEC SQL. UPDATE D010S SET PROG = :NEW_NAME WHERE PROG = :PROGRAM ENDEXEC. ELSE. * There is already a hidden program there, unhide it EXEC SQL. UPDATE D010S SET PROG = :PROGRAM WHERE PROG = :NEW_NAME ENDEXEC. ENDIF.
Visit Kabai.com to view this tip or to browse through a collection of other useful ABAP programs.
Did you like this tip? If so (or if not) let us know. Send an email to sound off. Or go to our tips page and rate this and other tips, or send us one of your own.
ABAP/4: Programming the SAP R/3 System, Second Edition
Author: Bernd Matzke
Publisher: Addison Wesley
Cover Type: Hard Cover
Published: Nov 2000
Many of the introductory SAP books currently on the market provide only a brief overview of ABAP. In ABAP/4: Programming the SAP R/3 System, Bernd Matzke builds on this information to look in depth at the programming language at the heart of the SAP R/3 system. This definitive guide to ABAP/4 aims to make the fundamentals of this evolving programming language accessible to anybody developing or maintaining an SAP R/3 system. Starting with the basic principles, it explains the essential characteristics of ABAP/4 and the SAP programming concept. With this book you will learn how to: master the ABAP/4 commands in order to analyze existing standard applications and write new programs; understand function modules to use program code from other applications; use the Workbench organizer and On-line Debugger to relay applications and document changes; and create your own programs and construct your own test environments with an expansive set of examples designed to build up knowledge and programming skills. The sample programs in the book were developed on a 3.0 system but can also run on other versions of the R/3 system. The accompanying CD-ROM contains sample programs used in this book for Version 3.0C together with a modified set of programs for systems running on Version 2.2E. --This text refers to the Paperback edition.