declaration of data types and constants

Upload: alydeden

Post on 01-Mar-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 Declaration of Data Types and Constants

    1/3

    Declaration of Data Types and Constants

    Background

    Data types and constants can be declared in the following contexts:

    Cross-program

    in the ABAP Dictionary

    in global classes and interfaces

    in type groups

    ocal program

    in the global declaration part of a program

    in global classes and interfaces

    in procedures !"ethods#

    Technically speaking$ type groups$ global classes and interfaces are also ABAP programs$ in

    which data types and constants are created using the T%P&' and C()'TA)T' statements* +n

    contrast to other ABAP programs$ the declarations can also be statically ,isible in otherprograms$ depending on the ,isibility section* Absolute type names enable you to dynamically

    access the types of all programs*

    ule

    Declare data types and constants in the appropriate context

    Declare data types and constants in the context that guarantees the best possible encapsulation*

    Details

    Data types and constants should be declared in the context$ in which they are ,isiblefor all

    potential users but not anywhere else:

    ocal program data types and constants

  • 7/26/2019 Declaration of Data Types and Constants

    2/3

    Data types that are only re.uired by local data ob/ects !usually helper ,ariables# or

    constants that are only re.uired in a procedure !method# should be declared as local data

    types or constants*

    Data types and constants that are only re.uired within local classes should be declared in

    the corresponding ,isibility section of the classes or integrated using an interface*

    +f data types are re.uired in multiple local classes and interfaces of a program$ they

    should be created in the appropriate ,isibility section of a local class or an interface*

    ocal classes or interfaces can be used that contain nothing else apart from these types orconstants* +n the global declaration part of programs$ declarations of data types or

    constants are not re.uired for semantic reasons*

    Cross-program data types and constants

    Date types and constants$ that a user re.uires to use a class0interface$ should be declared

    in the public !or package-public# ,isibility section of the global class0interface* &xamplesinclude data types used to type interface parameters of methods$ and constants expected

    as actual parameters by methods$ such as +Ds of exception textsin exception classes*

    Data types re.uired by different programs$ classes$ or interfaces are declared as real types

    of the ABAP Dictionary !not in type groups#* These are usually semantically independent

    types$ for which the ABAP Dictionary pro,ides additional ser,ices$ such as descripti,etexts and documentation options* +n this context$ you must consider the separation of

    concerns*

    1or example$ a structure of the ABAP Dictionary should ne,er be used to type !2eb#Dynpro fields and to simultaneously define a database table* +deally$ data types should be

    declared in encapsulated packages$ which manage the cross-package use of their

    repository ob/ects and which only expose types actually re.uired outside the package in

    their package interfaces*%ou should generally a,oid declaring or e,en exposing purely technical types without

    semantic meaning$ in application de,elopment packages of the ABAP Dictionary* The

    declaration of these types !such as +)T3 or C4A56# should be restricted to fundamentalbasis packages*

    %ou should not create any new type groups* Data types should be declared in global

    classes or interfaces$ or as real types of the ABAP Dictionary* %ou should only create

    constants in global classes or interfaces* 4owe,er$ the use of existing type groups isstillallowed* +t is no longer necessary to load type groups explicitly using the T%P&-

    P((' statement* 4owe,er$ you only need to declare new types or constants in a

    context$ if no semantically appropriatetypes or constants exist that are more global* 1orexample$ if an appropriate ABAP Dictionary data type exists$ it is not necessary to create

    a local data type in the class$ to type an interface parameter of a global class method* +n

    this case$ the data type in the ABAP Dictionary might ha,e to be published in the samepackage interface as the class* This would also be the case$ howe,er$ if an interface

  • 7/26/2019 Declaration of Data Types and Constants

    3/3

    parameter is typed with a data type of the class that refers to an ABAP Dictionary data

    type*

    )ote

    The misuse of include programs for the declaration of data types and data ob/ects that can bereused across ,arious programs is not allowed*

    Bad example

    The following source code shows the declaration of constants in a type group that are re.uired

    across different programs* The name of the type group must precede the names of the constantsas a prefix* %ou should not create any new type groups* 1or constants that are re.uired in ,arious

    different programs$ the abo,e rule recommends a declaration in global classes or interfaces*

    T%P&-P(( 7icon*

    T%P&' 7icon8icon T%P& ***C()'TA)T':

    7icon8cancel T%P& 7icon8icon 9A& icon8cancel$

    7icon8check T%P& 7icon8icon 9A& icon8check$7icon8check8words T%P& 7icon8icon 9A& icon8intensify$

    7icon8document T%P& 7icon8icon 9A& icon8hlp$

    7icon8download T%P& 7icon8icon 9A& icon8export$

    ***

    ;ood example

    The following source code illustrates the declaration of the constants in the abo,e example in aglobal class* The ,isibility of the constants is restricted to the current package* +n other programs$

    the constants are addressed using cl8***8icons