ABAP中的枚举对象

枚举对象是枚举类型的数据对象。枚举对象只能包含类型为枚举类型的枚举值。ABAP从版本7.51开始支持它们。

这是一种常见的模式。在ABAP 7.51之前,人们通常用如下方式实现类似的功能:

CLASS cx_wrong_size DEFINITION INHERITING FROM cx_static_check. ENDCLASS. CLASS shirt DEFINITION. PUBLIC SECTION. TYPES tsize TYPE i. CONSTANTS: size_s TYPE tsize VALUE 0, size_m TYPE tsize VALUE 1, size_l TYPE tsize VALUE 2, size_xl TYPE tsize VALUE 3. METHODS constructor IMPORTING size TYPE tsize RAISING cx_wrong_size. ... PRIVATE SECTION. DATA size TYPE tsize. ENDCLASS. CLASS shirt IMPLEMENTATION. METHOD constructor. IF size <> size_s AND size <> size_m AND size <> size_l AND size <> size_xl. RAISE EXCEPTION TYPE cx_wrong_size. ENDIF. me->size = COND #( WHEN size <> size_s AND size <> size_m AND size <> size_l AND size <> size_xl THEN THROW cx_wrong_size( ) ELSE size ). ENDMETHOD. ENDCLASS.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdysd.html