DATA语句
变量定义
DATA:l_str TYPE string.
现在可能是这样的
DATA(l_str) = 'China'.
行内定义
SELECT
but000~partner,
but000~name_org1,
but000~bu_group,
lfa1~nodel
FROM but000 INNER JOIN lfa1 ON but000~partner = lfa1~lifnr
FOR ALL ENTRIES IN @gt_partner
WHERE but000~partner = @gt_partner-partner
INTO TABLE @DATA(lt_but).
注意@DATA(TAB)语句的强大,有了它,我们在访问数据库的时候,只要对着FS写SELECT就好了,不需要构建各式各样 的内表和表类型了。注意在使用FOR ALL ENTRIES 语句的时候,关联的内表前面要加上@
FIELD-SYMBOL(<FS>)
LOOP AT gt_partner ASSIGNING FIELD-SYMBOL(<fs_part>).
gs_alv-partner = <fs_part>-partner.
READ TABLE lt_but INTO DATA(wa_but) WITH KEY partner = <fs_part>-partner.
IF sy-subrc EQ 0.
gs_alv-name_org1 = wa_but-name_org1.
gs_alv-bu_group = wa_but-bu_group.
gs_alv-nodel = wa_but-nodel.
APPEND gs_alv TO gt_alv.
ENDLOOP.
工作区
READ TABLE ITAB INTO DATA(WA_ITAB).
字符串
DATA:l_str1 TYPE string VALUE 'I ',
l_str2 TYPE string VALUE 'LOVE ',
l_str3 TYPE string VALUE 'CHINA ',
l_str4 TYPE string.
l_str4 = l_str1 && l_str2 && l_str3.
WRITE:/ l_str4.
输出结果:ILOVECHINA (注意拼接的时候会忽略空格,不支持respect blank语句)。
前导零处理
DATA: ld_message TYPE string,
ld_message1 TYPE char20.
DATA: ld_delivery_number TYPE vbeln_vl VALUE '0080003371'.
DATA: ls_delivery_header TYPE likp.
ld_message = |{ ld_delivery_number ALPHA = OUT }|.
ld_message1 = |{ ld_delivery_number ALPHA = IN }|.
WRITE: / ld_message,
ld_message1.
输出结果:80003371 00000000000080003371
VALUE语句
工作区
... VALUE dtype|#( [let_exp]
[BASE dobj]
comp1 = dobj1 comp2 = dobj2 ... ) ...
DATA:BEGIN OF wa_person,
age TYPE i,
name TYPE char4,
sex TYPE char2,
END OF wa_person.
DATA:BEGIN OF wa_personid,
age TYPE i,
name TYPE char4,
sex TYPE char2,
id TYPE char10,
country TYPE char2,
END OF wa_personid.
DATA:wa_lucy LIKE wa_person,
wa_lucyid LIKE wa_personid.
wa_person = VALUE #(
age = 12
name = 'jack'
sex = 'male'
).
wa_personid = VALUE #( BASE wa_person
id = '111'
country = 'CN'
) .
内表
CORRESPONDING语句
工作区
struct2 = CORRESPONDING #( struct1 ).
MOVE-COREESPONDING struct1 TO struct2.
内表
itab1 = CORRESPONDING itab1( itab1 FROM itab2 USING value = value ).
LOOP AT itab2 INTO wa_tab2.
MOVE-CORESSPONDING wa_tab2 TO wa_tab1.
APPEND wa_tab1 TO itab1.
ENDLOOP.