abap基础语法练习

更新时间:2024-07-06 23:17:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

REPORT ztest_lianxi.

**data类型的定义与statics类型的定义区别。

*PERFORM datatest1. *PERFORM datatest1. *PERFORM datatest2. *PERFORM datatest2. *

**&--------------------------------------------------------------------- *

**& Form DATATEST1

**&--------------------------------------------------------------------- *

** text

**---------------------------------------------------------------------- *

*FORM datatest1.

* TYPES f_word(5) TYPE c.

* DATA f_text TYPE f_word VALUE 'INIT'. * WRITE f_text.

* f_text = '12345'. * WRITE f_text.

*ENDFORM. \ *

**&--------------------------------------------------------------------- *

**& Form DATATEST2

**&--------------------------------------------------------------------- *

** text

**---------------------------------------------------------------------- *

*FORM datatest2.

* TYPES f_word(5) TYPE c.

* STATICS f_text TYPE f_word VALUE 'INIT'. * WRITE f_text.

* f_text = 'ABCDE'. * WRITE f_text.

*ENDFORM. \

*----------------------------------------------------------------------*

*i类型的变量,为什么是从后往前截取。

*DATA: NUMBER TYPE I VALUE '1234556', * TEXT(15) VALUE 'ABSCCCSDFGD'. *WRITE:(5) NUMBER, /(6) TEXT.

*----------------------------------------------------------------------*

*显示图标,需要引用系统的图标群组

*INCLUDE . *INCLUDE .

*WRITE: 'PHONE SYMBOL:',SYM_PHONE AS SYMBOL. *WRITE:/ 'ALARM ICON:',ICON_ALARM AS ICON. *

*----------------------------------------------------------------------*

*SKIP TO LINE 5. *WRITE 'PASS'.

*----------------------------------------------------------------------*

*CHECKBOX的应用

*PARAMETERS:CHECK1 AS CHECKBOX DEFAULT 'X', *CHECK2 AS CHECKBOX.

*----------------------------------------------------------------------*

*复制功能

*DATA: BEGIN OF ADDRESS,

* FIRSTNAME(10) TYPE C VALUE 'LULU', * LASTNAME(10) TYPE C VALUE 'CHOU', * TEL(12) TYPE C VALUE '4660570', * END OF ADDRESS. *DATA: BEGIN OF NAME,

* FIRSTNAME(10) TYPE C, * LASTNAME(10) TYPE C, * E_MAIL(30) TYPE C, * END OF NAME.

*MOVE-CORRESPONDING ADDRESS TO NAME. *

*WRITE :NAME-FIRSTNAME.

*----------------------------------------------------------------------*

*赋值语句的练习

*DATA:NAME(20) TYPE C VALUE 'SOCRCE', * SOURCE(10) TYPE C VALUE 'LILY', * TARGET(10) TYPE C. *WRITE NAME TO TARGET. *WRITE / TARGET.

*----------------------------------------------------------------------*

*shift的练习

*DATA:STRING(10) TYPE C VALUE 'ABCDEFJ'. * WRITE: STRING. * SHIFT STRING.

* WRITE :/ STRING. * SHIFT STRING LEFT. * WRITE:/ STRING.

* SHIFT STRING RIGHT. * WRITE:/ STRING.

* SHIFT: STRING RIGHT. * WRITE:/ STRING.

*----------------------------------------------------------------------*

*REPLACE的练习

*DATA: STRING(10) TYPE C VALUE 'ABCDEFGHT', * STR1(3) TYPE C VALUE 'DEF', * STR2(3) TYPE C VALUE '123'. *REPLACE STR1 WITH STR2 INTO STRING. *WRITE: STRING.

*----------------------------------------------------------------------*

*SEARCH的使用方法

*DATA: STRING(10) TYPE C VALUE 'ABCDEFJ'. *SEARCH STRING FOR 'C'. *WRITE: STRING.

*IF SY-SUBRC <> 0. * WRITE: SY-SUBRC. *ELSE.

* WRITE: SY-SUBRC. *ENDIF.

*----------------------------------------------------------------------*

*SPLIT的使用

*DATA: STRING(60),

* P1(20) VALUE '++++++++', * P2(20) VALUE '++++++++', * P3(20) VALUE '++++++++', * P4(20) VALUE '++++++++', * DEL(3) VALUE '***'.

*STRING = 'PART1***PART2***PART3***PART4***PART5'. *WRITE STRING.

*SPLIT STRING AT DEL INTO P1 P2 P3 P4. *WRITE:/ P1,/ P2,/ P3,/ P4.

*----------------------------------------------------------------------*

*日期的使用

*DATA: MDATA TYPE D. *MDATA = SY-DATUM. *WRITE MDATA.

*MDATA+6(2) = '01'. *WRITE / MDATA.

*MDATA = MDATA - 1. *WRITE / MDATA.

*----------------------------------------------------------------------*

*时间的使用

*DATA: HOURS TYPE I, * MINUTES TYPE I,

* T2 TYPE T VALUE '200000', * T1 TYPE T VALUE '183000'. *HOURS = ( T2 - T1 ) / 3600. *MINUTES = ( T2 - T1 ) / 60. *

*WRITE: HOURS,/ MINUTES.

*DATA: BEGIN OF ITAB OCCURS 3, * COL1(3) TYPE C, * COL2 TYPE I, * END OF ITAB. *ITAB-COL1 = 'ABC'. *ITAB-COL2 = 10. *COLLECT ITAB.

*ITAB-COL1 = 'XYZ'. *ITAB-COL2 = 20. *COLLECT ITAB.

*ITAB-COL1 = 'ABC'. *ITAB-COL2 = 30. *COLLECT ITAB. *LOOP AT ITAB.

* WRITE:/ ITAB-COL1,/ ITAB-COL2. *ENDLOOP.

*----------------------------------------------------------------------*

**NEW PAGE的应用

*DATA: IT_SPFLI TYPE TABLE OF SPFLI WITH HEADER LINE. *NEW-PAGE LINE-COUNT 11. *

*SELECT * FROM SPFLI INTO TABLE IT_SPFLI. *

* LOOP AT IT_SPFLI.

*WRITE: / SY-VLINE,(15) IT_SPFLI-CARRID,SY-VLINE,(15) *IT_SPFLI-CONNID,SY-VLINE,

*(15) IT_SPFLI-COUNTRYTO,SY-VLINE,(15) IT_SPFLI-CITYFROM,SY-VLINE,

*(15) IT_SPFLI-AIRPFROM,SY-VLINE. *ULINE AT /(91). * ENDLOOP. *

* TOP-OF-PAGE.

* FORMAT COLOR COL_HEADING. * ULINE AT /(91).

*WRITE: / SY-VLINE,(15) '航线承运人',SY-VLINE,(15) '航班连接',SY-VLINE,

*(15) '国家代码',SY-VLINE,(15) '起飞城市',SY-VLINE, *(15) '起飞机场',SY-VLINE. *ULINE AT /(91). *FORMAT COLOR OFF.

*----------------------------------------------------------------------*

*热点的设定

START-OF-SELECTION.

WRITE '请按'.

FORMAT HOTSPOT ON COLOR 6 INVERSE ON. WRITE '热点'.

FORMAT HOTSPOT OFF COLOR OFF. AT LINE-SELECTION. WRITE 'WELCOME!'.

*SELECT * FROM SPFLI INTO TABLE IT_SPFLI. *

* LOOP AT IT_SPFLI.

*WRITE: / SY-VLINE,(15) IT_SPFLI-CARRID,SY-VLINE,(15) *IT_SPFLI-CONNID,SY-VLINE,

*(15) IT_SPFLI-COUNTRYTO,SY-VLINE,(15) IT_SPFLI-CITYFROM,SY-VLINE,

*(15) IT_SPFLI-AIRPFROM,SY-VLINE. *ULINE AT /(91). * ENDLOOP. *

* TOP-OF-PAGE.

* FORMAT COLOR COL_HEADING. * ULINE AT /(91).

*WRITE: / SY-VLINE,(15) '航线承运人',SY-VLINE,(15) '航班连接',SY-VLINE,

*(15) '国家代码',SY-VLINE,(15) '起飞城市',SY-VLINE, *(15) '起飞机场',SY-VLINE. *ULINE AT /(91). *FORMAT COLOR OFF.

*----------------------------------------------------------------------*

*热点的设定

START-OF-SELECTION.

WRITE '请按'.

FORMAT HOTSPOT ON COLOR 6 INVERSE ON. WRITE '热点'.

FORMAT HOTSPOT OFF COLOR OFF. AT LINE-SELECTION. WRITE 'WELCOME!'.

本文来源:https://www.bwwdw.com/article/x5m.html

Top