Join list of strings with a comma

2020-04-19 06:39发布

I am learning ABAP. In the past I used python.

Python: ', '.join(['one', 'two', 'three'])
Result: 'one, two, three'

How can I join a list of strings with , and create a string containing one, two, three?

System release is 740.

标签: sap abap
2条回答
放荡不羁爱自由
2楼-- · 2020-04-19 06:51

Another way of writing CONCATENATE LINES OF ... is to use the 7.40 function concat_lines_of( [table =] itab [sep = sep] )

cl_demo_output=>display( concat_lines_of(
          table = value string_table( ( `one` ) ( `two` ) ( `three` ) )
          sep   = `, ` ) ).

(Result: 'one, two, three')

查看更多
别忘想泡老子
3楼-- · 2020-04-19 07:06

I'm kind of spitballin' here but the following should work. You got a table of strings lt_strings and a variable for output lv_concatenated. ABAP has a built in command called concatenate and you can feed a table as input.

data: lt_strings type string_table,
      lv_concatenated type string.

concatenate lines of lt_strings into lv_concatenated separated by ','.
查看更多
登录 后发表回答