DATA
:
BEGIN
OF hah
,
flag
TYPE
c
,
sex
TYPE
c
,
END
OF hah
.
DATA it_hah
LIKE
TABLE
OF hah
.
CLEAR hah
.
hah
–flag
=
‘X’
.
hah
–sex
=
‘f’
.
APPEND hah
TO it_hah
.
CLEAR hah
.
hah
–sex
=
‘m’
.
APPEND hah
TO it_hah
.
CLEAR hah
.
hah
–sex
=
‘m’
.
APPEND hah
TO it_hah
.
CLEAR hah
.
hah
–sex
=
‘m’
.
APPEND hah
TO it_hah
.
LOOP
AT it_hah
INTO hah
.
WRITE
:/ hah
–flag
,
‘ ‘
,hah
–sex
.
ENDLOOP.
这个结果是:
现在,我要把凡是flag没有值的,都赋值为’x’,
第一种办法:
DATA : BEGIN OF hah,
flag TYPE c,
sex TYPE c,
END OF hah.
DATA it_hah like TABLE OF hah.
CLEAR hah.
hah-flag = ‘X’.
hah-sex = ‘f’.
APPEND hah to it_hah.
CLEAR hah.
hah-sex = ‘m’.
APPEND hah to it_hah.
CLEAR hah.
hah-sex = ‘m’.
APPEND hah to it_hah.
CLEAR hah.
hah-sex = ‘m’.
APPEND hah to it_hah.
*****************这里**************
LOOP AT it_hah INTO hah.
IF hah-flag is INITIAL.
hah-flag = ‘x’.
ENDIF.
MODIFY it_hah FROM hah.
ENDLOOP.
************************************
LOOP AT it_hah INTO hah.
WRITE :/ hah-flag,’ ‘,hah-sex.
ENDLOOP.
这种办法效率不够高,采用第二种办法的话,效率会高一点:
DATA : BEGIN OF hah,
flag TYPE c,
sex TYPE c,
END OF hah.
DATA it_hah like TABLE OF hah.
CLEAR hah.
hah-flag = ‘X’.
hah-sex = ‘f’.
APPEND hah to it_hah.
CLEAR hah.
hah-sex = ‘m’.
APPEND hah to it_hah.
CLEAR hah.
hah-sex = ‘m’.
APPEND hah to it_hah.
CLEAR hah.
hah-sex = ‘m’.
APPEND hah to it_hah.
*****************这里***************
hah-flag = ‘x’.
MODIFY it_hah FROM hah TRANSPORTING flag WHERE flag is INITIAL.
****************************
LOOP AT it_hah INTO hah.
WRITE :/ hah-flag,’ ‘,hah-sex.
ENDLOOP.
明显第二种效率会高于第一种。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20197.html