如何迭代 string_table 和修改行
How to Iterate string_table and modify lines
为了构建动态 SELECT
我正在遍历字段列表并添加别名。
但是,这会清除列表。
REPORT ZITER_TEST.
CONSTANTS lc_alias TYPE string VALUE 'ref'.
DATA lt_field TYPE string_table.
lt_field = VALUE string_table(
( CONV string( 'PERNR' ) )
( CONV string( 'SUBTY' ) )
).
" lt_field: ['PERNR','SUBTY']
lt_field = VALUE string_table( FOR <lv_tmp> IN lt_field
( lc_alias && `~` && <lv_tmp> )
).
" lt_field: [] instead of: ['ref~PERNR','ref~SUBTY']
你只需要使用一些临时的 table。它适用于我的情况:
REPORT ZITER_TEST.
CONSTANTS lc_alias TYPE string VALUE 'ref'.
DATA: lt_field_temp TYPE string_table,
lt_field TYPE string_table.
lt_field_temp = VALUE string_table(
( CONV string( 'PERNR' ) )
( CONV string( 'SUBTY' ) )
).
lt_field = VALUE string_table( FOR <lv_tmp> IN lt_field_temp
( lc_alias && '~' && <lv_tmp> )
).
ABAP documentation of VALUE 说:
In assignments to a data object, the target variable is used directly and no temporary data object is created. This variable is initialized or overwritten in full before the assignment of the values specified in the parentheses. Its original value, however, is still available in an optional LET expression.
所以,而不是:
lt_field = VALUE string_table( FOR <lv_tmp> IN lt_field
( lc_alias && `~` && <lv_tmp> )
).
使用:
lt_field = VALUE string_table( LET lt_field_temp = lt_field IN
FOR <lv_tmp> IN lt_field_temp
( lc_alias && `~` && <lv_tmp> )
).
使用字段符号循环 table 比使用任何一种形式(LET 或直接分配)的临时 table 要快得多:
LOOP AT lt_field ASSIGNING FIELD-SYMBOL(<field>)
<field> = lc_alias && `~` && <field>.
ENDLOOP.
为了构建动态 SELECT
我正在遍历字段列表并添加别名。
但是,这会清除列表。
REPORT ZITER_TEST.
CONSTANTS lc_alias TYPE string VALUE 'ref'.
DATA lt_field TYPE string_table.
lt_field = VALUE string_table(
( CONV string( 'PERNR' ) )
( CONV string( 'SUBTY' ) )
).
" lt_field: ['PERNR','SUBTY']
lt_field = VALUE string_table( FOR <lv_tmp> IN lt_field
( lc_alias && `~` && <lv_tmp> )
).
" lt_field: [] instead of: ['ref~PERNR','ref~SUBTY']
你只需要使用一些临时的 table。它适用于我的情况:
REPORT ZITER_TEST.
CONSTANTS lc_alias TYPE string VALUE 'ref'.
DATA: lt_field_temp TYPE string_table,
lt_field TYPE string_table.
lt_field_temp = VALUE string_table(
( CONV string( 'PERNR' ) )
( CONV string( 'SUBTY' ) )
).
lt_field = VALUE string_table( FOR <lv_tmp> IN lt_field_temp
( lc_alias && '~' && <lv_tmp> )
).
ABAP documentation of VALUE 说:
In assignments to a data object, the target variable is used directly and no temporary data object is created. This variable is initialized or overwritten in full before the assignment of the values specified in the parentheses. Its original value, however, is still available in an optional LET expression.
所以,而不是:
lt_field = VALUE string_table( FOR <lv_tmp> IN lt_field
( lc_alias && `~` && <lv_tmp> )
).
使用:
lt_field = VALUE string_table( LET lt_field_temp = lt_field IN
FOR <lv_tmp> IN lt_field_temp
( lc_alias && `~` && <lv_tmp> )
).
使用字段符号循环 table 比使用任何一种形式(LET 或直接分配)的临时 table 要快得多:
LOOP AT lt_field ASSIGNING FIELD-SYMBOL(<field>)
<field> = lc_alias && `~` && <field>.
ENDLOOP.