ABAP_OO

ABAP_OOP_Sample_1.01

"示例程序1.1
REPORT zrep_error_check_01.

DATA:
  gv_result TYPE p LENGTH 8 DECIMALS 2,
  gv_exref  TYPE REF TO cx_root,
  gv_msgtxt TYPE string.

DATA:
  gv_cuotient TYPE i,
  gv_dividend TYPE i VALUE 19,
  gv_divisor  TYPE i VALUE 0,
  gv_s_numbr     TYPE string VALUE '1234567890',
  gv_position_11 TYPE i VALUE 11.

TRY.
    gv_result = gv_dividend / gv_divisor. " no short dump here. catch it.
  CATCH cx_root INTO gv_exref.
    gv_msgtxt = gv_exref->get_text( ).
    WRITE: / gv_msgtxt.
  CLEANUP.
ENDTRY.


TRY.
    gv_s_numbr = gv_s_numbr(gv_position_11). " no short dump here. catch it.
  CATCH cx_root INTO gv_exref.
    gv_msgtxt = gv_exref->get_text( ).
    WRITE: / gv_msgtxt.
  CLEANUP.
ENDTRY.

 

ABAP_OOP_Sample_2.01

"示例程序2.1
REPORT zrep_cls_07.

DATA gv_top(20) TYPE c VALUE 'Top of the World'.
DATA gv_on_the_way(20) TYPE c VALUE 'Because it is there'.

DATA: gv_char(20) TYPE c,
      gv_float TYPE f,
      gv_float_origin(10) TYPE c VALUE '10.90',
      gv_float_new LIKE gv_float_origin.


DO 6 TIMES.
  "避免在循环中定义并初始化变量
  "并不是每次循环都会重新初始化变量
  DATA: gv_elevation TYPE i VALUE 6688.
  "如果一定要定义,循环中要将变量及时赋值
  "gv_elevation = 6688.
  IF sy-index = 3.
    gv_elevation = 8848.
  ENDIF.
  IF gv_elevation = 8848.
    WRITE sy-index.
    WRITE gv_elevation.
    WRITE gv_top.
  ELSE.
    WRITE sy-index.
    WRITE gv_elevation.
    WRITE gv_on_the_way.
  ENDIF.
  NEW-LINE.
ENDDO.

 

ABAP_OOP_Sample_2.02

ABAP_OOP_Sample_2.03

ABAP_OOP_Sample_2.04

ABAP_OOP_Sample_2.05

ABAP_OOP_Sample_2.06

ABAP_OOP_Sample_2.07

ABAP_OOP_Sample_2.08

ABAP_OOP_Sample_4.01

ABAP_OOP_Sample_4.02

ABAP_OOP_Sample_4.03

ABAP_OOP_Sample_4.04

ABAP_OOP_Sample_4.05

ABAP_OOP_Sample_4.06

ABAP_OOP_Sample_4.07

posted @ 2019-09-25 17:25  蜡哲图  阅读(288)  评论(0编辑  收藏  举报
目录内容