abap describe的用法(程序示例)

来源:互联网 发布:同志交友软件blued 编辑:程序博客网 时间:2024/05/16 15:42

describe 用来输出变量(field structure table)的有关属性

主要有以下3种用法:

Field Properties

1. DESCRIBE FIELD ...

Properties of an Internal Table

2. DESCRIBE TABLE ...

Distance Between Two Fields

3. DESCRIBE DISTANCE ...

以下程序演示了相关用法:

 REPORT demo_describe_field.

TYPES: surname(20)  TYPE c,
       street(30)   TYPE c,
       zip_code(10) TYPE n,
       city(30)     TYPE c,
       phone(20)    TYPE n,
       date         TYPE sy-datum.

TYPES: BEGIN OF address,
         name TYPE surname,
         code TYPE zip_code,
         town TYPE city,
         str  TYPE street,
       END OF address.

TYPES: BEGIN OF phone_list,
         adr TYPE address,
         tel TYPE phone,
       END OF phone_list.

TABLES spfli.

DATA: BEGIN OF test,
  col1(3) TYPE c,
  col2(2) TYPE c,
  col3 TYPE i,
END OF test,
dist TYPE i.

DATA: text(8) TYPE VALUE 'abcdefgh', len TYPE i,
      numtext(10) TYPE VALUE '0123456789', typ(1) TYPE c,
      pl TYPE phone_list,
      n TYPE i,
      float TYPE f, out TYPE i,
      pack TYPE DECIMALS 2, dec(1) TYPE c.


DESCRIBE FIELD text LENGTH len IN CHARACTER MODE.
WRITE: text, 'has length', len.

DESCRIBE FIELD numtext TYPE typ.
WRITE: / 'Numerical text has type', typ.
DESCRIBE FIELD spfli-fltime TYPE typ.
WRITE: 'and SPFLI-FLTIME has type', typ.

DESCRIBE FIELD float LENGTH len IN BYTE MODE OUTPUT-LENGTH out.
WRITE: / 'Floating point number has length', len,
                        'and output length', out.

DESCRIBE FIELD pack DECIMALS dec.
WRITE: / pack, 'has', dec, 'Decimals'.

DESCRIBE FIELD pl TYPE typ COMPONENTS n.
WRITE: / 'The complex field PL has type', typ, 'with', n, 'components'.

DESCRIBE DISTANCE BETWEEN test-col3 AND test-col1 INTO dist
         IN BYTE MODE.
WRITE: / 'The distance between TEST-COL3 and TEST-COL1 is', dist.