Search code examples
abapdynpro

Exit program at LOAD-OF-PROGRAM possible?


I am implementing some checks, mainly authorization, on program start and want to abort the program if the user is not allowed to execute it. Explicit auth object assignment via SE93 does not fit for me because it lacks flexibility.

I tried to do it in LOAD-OF-PROGRAM event in two ways:

  • through RETURN statement
  • by throwing message with type E

Both resulted to dump Illegal interruption of the event LOAD-OF-PROGRAM, which is indeed corresponds to ABAP docu:

The event block must be fully executed, otherwise a runtime error occurs

This means that statements can be specified that exit the event block without returning to it.

I interpret the passage This means that statements can be specified that exit the event block without returning to it in the way that neither of the exit statements are allowed in this block. Is my understanding correct?

Now I do abortion/validation in INITIALIZATION block:

INITIALIZATION.
 IF do_validate( ) = abap_false.
  MESSAGE 'You are busted!' TYPE 'E'.
 ENDIF

The problem is that my program has multiple selection screens and INITIALIZATION block is triggered several times. Yes, of course I can differentiate them by screen number, but doing this in LOAD-OF-PROGRAM seems more logical as it is executed only once per program.

The question: is there some way to achieve that in LOP event or other best practice and why?


Solution

  • I don't know if it is best practice, but LEAVE PROGRAM can be used to achieve this goal.

    LOAD-OF-PROGRAM.
    
    IF ...
       LEAVE PROGRAM.
    ENDIF.
    

    https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapleave_program.htm

    "The statement LEAVE PROGRAM can appear anywhere within any processing block. It ends the program regardless of the program or object in which it is executed or in which program group of the internal session."