14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Declaring and Creating Variables 2.2

Traditionally, if you created a huge application with locally defined internal tables

and structures and constants and the like and then suddenly realized that you

wanted to reuse a lot of thes e somewhere else, then using a TYPE POOL was the

only way to create such reusable constructs. If you didn’t declare a TYPE POOL ,

then the compiler would complain that your ABAP_TRUE statement was unknown.

Even though the introduction of Z table types in ABAP 6.40 removed part of the

need for TYPE POOLS, they were still used, because there was no other way to have

a globally available constant like ABAP_TRUE. However, as of release 7.02, this is

no longer the case; you can use ABAP_TRUE anywhere you want, and the compiler

will no longer complain. In other words, all existing TYPE POOL statements are

now global.

However, there’s a catch: you’re no longer supposed to create any new TYPE POOL

statements. You may be thinking to yourself, “Why shouldn’t I create TYPE POOLS

any more just because SAP says so?” That ’s a valid question. The answer is that

TYPE POOLS were created to address a specific gap in functionality—a gap which

no longer exists. This is like taking a picture with a Kodak camera or sending a

fax; you could still do these things if you wanted to, but there is no need to do so

any longer.

As it turns out, there is now a solution that deals with both constants and internal

table definitions that have not been crea ted in the form of Z table types: public

type definitions of global Z classes. An example of no longer having to create a Z

table type is when the global class has a public attribute that is a custom table type

defined within the Z class, and the call ing program wants to call a method that

needs that table type passed in. The ca lling program can do something like the

example in Listing 2.11.

DATA: lt_monsters TYPE zcl_monsters=>mtt_monster_table.

zcl_monsters->make_monsters_dance( lt_monsters ).

Listing 2.11 Using a Custom Table Type Declared within a Z Class

This has the advantage that there is now no need to bloat the repository with Z

table types. It is exactly the same with co nstants; if they are a public attribute of

a class, then they can be used anywhere in the system. (In fact, there are standard

SAP classes that contain nothing except constant definitions; you could call them

the younger brothers of TYPE POOLS.)

91

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

Saved successfully!

Ooh no, something went wrong!