Tuesday, October 14, 2014

A Suicide Bomber: Report Program which deletes itself after execution

Functional Consultant:  I need one report which deletes the junk entries from the table (which are created due to program errors.)

(But the next statement which he added made me to think)

Functional Consultant:  The Report should be such that it should be executed only once and just after the execution it should be deleted automatically. Just like a suicide bomber. So that there is no chance that the user can executes that report by mistake once again.

Requirement is confusing???? But let’s don’t get into functional things. So now I have a requirement that my program should delete the unwanted records from the table based on some condition and just after that it should delete itself. At first glance it sound strange but it is not at all difficult.

See the Diagram below:
1

 When you create a program and generate it . It generates LOAD.  The LOAD consists largely of byte code whose statements are linked with C functions. So next time when you call this program application server use this LOAD and execute it. The actual source code is stored in the Repository. In the database in the form in which they are developed. These are the only versions that can be displayed in the Workbench.

The LOAD is generated automatically when the program is called if none exists yet or if the LOAD in the database or the program buffer is obsolete. You can also generate programs explicitly, for example, in the ABAP Editor with menu path Program -> Generate.

A saved or buffered LOAD is considered obsolete when:

  • The developed version of the program was changed.

  • An object that the program uses was changed in the Data Dictionary.

I got the following function module which can be used to delete a Report Program. (Note: This FM deletes the Source code of the program which is stored inside the DATABASE in Repository)

I know what you are thinking now!!!!!

What would happen to the LOAD when you delete the report program from the database?

The answer is: The LOAD will be removed from the buffer automatically when Application server realised that the Report program is deleted from the database (Don’t ask me how much time application server takes, as it is in micro-second).

So finally my program is look like:



REPORT ZDELENTREIS.



“CODE TO DELETE UNWANTED ENTRIES FROM THE TABLE

“AS PER CLIENT REQUIREMENT



DATA: L_SUBRC TYPE I.

“CALL FUNCTION MODULE RKE_DELETE_REPORT

“TO DELETE THIS REPORT TO AVOID RE USE



CALL FUNCTION ’RKE_DELETE_REPORT’

EXPORTING

PROGRAM = ‘ZDELENTREIS’

IMPORTING

SUBRC   = L_SUBRC.





Post a Comment