14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Features 1.2

METHODS: main.

ENDCLASS. "Laboratory Definition

CLASS lcl_laboratory IMPLEMENTATION.

METHOD main.

* Local Variables

DATA: ld_monster_number TYPE i,

ld_number_of_heads TYPE i.

create_monster( id_number_of_heads = ld_number_of_heads ).

ENDMETHOD.

ENDCLASS. "Laboratory Implementation

Listing 1.4 Sample Program with Missing Method

As you can see, the create_monster method does not exist. In the past, you

couldn’t just double-click it; you had to create a definition, and then create an

implementation, and then find your way back to the place you first started, making

you think that maybe FORM routines weren’t so bad after all.

In Eclipse, you put your cu rsor on the not-yet-extant CREATE_MONSTER and press

(CTRL) + (1). A little box appears and asks you if you want to automatically create

the missing method. I know I do; I have b een waiting 14 years for this, so I say

yes.

In Figure 1.13, the definition of the IMPORTING parameter came from the variable

definition you made in the code, which is one better than the FORM-based equivalent

in which you have to manually add the variable type.

Sadly, you may have to manually add the RETURNING parameter; in my version of

ABAP in Eclipse, the autocreation did not work if I entered ld_monster_number =

create_monster( ld_number_of_heads ). Nonetheless, that is probably just a bug

which will be fixed in time. In any event, the end result is as shown in Listing 1.5.

CLASS lcl_laboratory DEFINITION.

PUBLIC SECTION.

METHODS: main.

PRIVATE SECTION.

METHODS create_monster

51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!