Range的用法几种基本用法

时间:2024-02-24 21:02:28

RANGE用法类似SELECT-OPTION,为带表头的内表,有OPTION、SIGN、LOW、HIGH四个字段值。

定义形式:DATA R_TIME TYPE RANGE OF ZTPUBLOG-LASTP WITH HEADER LINE.

或者 RANGES R_TIME FOR ZTPUBLOG-LASTP.

1.用法一:筛选以“3*”开头的相关数据。(OPTION = ‘CP’)

  DATA R_WERKS_3 TYPE RANGE OF VBAP-WERKS WITH HEADER LINE.
  R_WERKS_3-SIGN = \'I\'.
  R_WERKS_3-OPTION = \'CP\'.
  R_WERKS_3-LOW = \'3*\'.
  APPEND R_WERKS_3.

2.用法二:筛选值等于“CD01”~“CD07”的相关数据。(LOW值)

  DATA R_WERKS_CD TYPE RANGE OF VBAP-WERKS WITH HEADER LINE。
  R_WERKS_CD-SIGN = \'I\'.
  R_WERKS_CD-OPTION = \'EQ\'.
  R_WERKS_CD-LOW = \'CD01\'. APPEND R_WERKS_CD.
  R_WERKS_CD-LOW = \'CD02\'. APPEND R_WERKS_CD.
  R_WERKS_CD-LOW = \'CD03\'. APPEND R_WERKS_CD.
  R_WERKS_CD-LOW = \'CD04\'. APPEND R_WERKS_CD.
  R_WERKS_CD-LOW = \'CD05\'. APPEND R_WERKS_CD.
  R_WERKS_CD-LOW = \'CD06\'. APPEND R_WERKS_CD.
  R_WERKS_CD-LOW = \'CD07\'. APPEND R_WERKS_CD.

3.用法三:筛选以时间为区间的相关数据。(OPTION = ‘BT’)

  DATA R_WERKS_CD TYPE RANGE OF VBAP-WERKS WITH HEADER LINE.
  CONCATENATE SY-DATUM SY-UZEIT INTO LV_ETIME.
  R_TIME-SIGN = \'I\'.
  R_TIME-OPTION = \'BT\'.
  SELECT SINGLE LASTP FROM ZTPUBLOG INTO LV_STIME WHERE FEILBM EQ SY-REPID.
  IF SY-SUBRC EQ 0.
    R_TIME-LOW = LV_STIME.
  ELSE.
    LV_TIME  = SY-UZEIT - 300.
    CONCATENATE SY-DATUM LV_TIME INTO LV_ETIME.
    R_TIME-LOW = LV_ETIME.
  ENDIF.
CONCATENATE SY-DATUM SY-UZEIT INTO LV_ETIME. R_TIME
-HIGH = LV_ETIME. APPEND R_TIME.

 4.用法四:新语法下的多值选择。

DATA:R_DATA TYPE RANGE OF VBAP-WERKS.
R_DATA = VALUE #( SIGN = \'I\' OPTION = \'BT\'  ( LOW = 10 HIGH = 20 )
                                            ( LOW = 100 HIGH = 150 )
                             OPTION = \'GT\'  ( LOW = 180 )
                             OPTION = \'LT\'  ( LOW = 200 )
                             OPTION = \'EQ\'  ( LOW = 8 )
                  SIGN = \'E\' OPTION = \'BT\'  ( LOW = 15 HIGH = 18 )
                 ).
CL_DEMO_OUTPUT=>WRITE( R_DATA ).
CL_DEMO_OUTPUT=>DISPLAY(  ).