分类: Web开发
2020-05-06 08:29:50
2.内表操作
3.opensql
1)声明符号: DATA(...)
再也不需要建立一堆的临时变量了
2)指针声明符:FILED-SYMBOL(…)
*&---------------------------------------------------------------------*
7.40之前-变量
DATA text TYPE string. text = `...`.
7.40之后-变量
DATA(text) = `...`.
*&---------------------------------------------------------------------*
7.40之前-工作区
DATA wa like LINE OF itab. LOOP AT itab INTO wa. ... ENDLOOP.
7.40之后-工作区
LOOP AT itab INTO DATA(wa). ... ENDLOOP.
*&---------------------------------------------------------------------*
7.40之前-返回参数
DATA xml TYPE xstring. CALL TRANSFORMATION ... RESULT XML xml.
7.40之后-返回参数
CALL TRANSFORMATION ... RESULT XML DATA(xml).
*&---------------------------------------------------------------------*
7.40之前-传输参数
DATA a1 TYPE ... DATA a2 TYPE ... oref->meth( IMPORTING p1 = a1 IMPORTING p2 = a2 ... )
7.40之后-传输参数
oref->meth( IMPORTING p1 = DATA(a1) IMPORTING p2 = DATA(a2) ... )
*&---------------------------------------------------------------------*
7.40之前-引用声明
DATA ixml TYPE REF TO if_ixml. DATA stream_factory TYPE REF TO if_ixml_stream_factory. DATA document TYPE REF TO if_ixml_document. ixml = cl_ixml=>create( ). stream_factory = ixml->create_stream_factory( ). document = ixml->create_document( ).
7.40之后-引用声明
DATA(ixml) = cl_ixml=>create( ). DATA(stream_factory) = ixml->create_stream_factory( ). DATA(document) = ixml->create_document( ).
*&---------------------------------------------------------------------*
740之前-指针声明
FIELD-SYMBOL:LIKE LINE OF ITAB. LOOP AT itab ASSIGNING . ... ENDLOOP.
740之后-指针声明
LOOP AT ITAB ASSIGNING FIELD-SYMBOL(). … ENDLOOP. READ TABLE itab assigning field-symbol( ) ....
结构赋值
... VALUE dtype | #( [BASE dobj] comp1 = dobj1 comp2 = dobj2 ... ) ...
内表赋值
... VALUE dtype | #( [BASE itab] ( (line1-com1 = dobj1) ( line2 ..) ... ) ...
"内表不能带表头 IT_VKORG = VALUE #( KUNNR = E_KNA1-KUNNR ( VKORG = '3000' ) ( VKORG = '6008' ) ) .
DATA itab TYPE RANGE OF i. itab = VALUE #( sign = 'I' option = 'BT' ( low = 1 high = 10 ) ( low = 21 high = 30 ) ( low = 41 high = 50 ) option = 'GE' ( low = 61 ) ). cl_demo_output=>DISPLAY( itab ).
… itab[ … ] …
相当于read table itab ….
如果对应没找到,会抛出CX_SY_ITAB_LINE_NOT_FOUND异常
系统变量SY-SUBRC不会记录成功与否
IF line_exists ( itab[…] )
…..
ENDIF
通过这行语法判断行是否查找到
加强版本的loop at语法,与REDUCE、VALUE关键字配合使用
…FOR i = ... [THEN expr] UNTIL | WHILE log_exp ...
…VALUE itab( FOR i = … [THEN expr] UNTIL | WHILE log_exp ... )
…REDUCE type( INIT FOR …. NEXT …..
REDUCE语法
GROUP BY语法
FELTER语法
可以根据指定值(一个)或者指定内表(多个)的值过滤itab并返回itab类型的结果集
FILTER type( itab [EXCEPT] [IN ftab] [USING KEY keyname ]
WHERE c1 op f1 [AND c2 op f2 [...] ] ) ...
FILTER type( itab …) 对应一个值过滤
FILTER type( itab in tab …)对应多个值过滤
EXCEPT如果不指定则表示满足条件的找出来,如果指定则表示不满足条件的找出来
WHERE对应过滤的条件,是必须要指定的
3. OPEN SQL
SELECT SINGLE @ABAP_TRUE INTO @DATA(EXISTS) FROM KNA1 WHERE KUNNR EQ @I_KNA1-KUNNR. IF EXISTS <> ABAP_TRUE. ENDIF.