2022 Aug 12 11:01 AM
hello.
how can i concatenate the tmdocs field if the sales id are same
i create a internal program for this but i don't have any idea what to do next, what syntax i need to use or if there is a function module for this or class.
output should be something like this
2022 Aug 12 11:35 AM
Note: It1 as internal table Img1. It2 as Img2.
Data: wa2 like line of it2,
Lv_tr type string.
Sort It1 by salesid.
Loop at It1 into data(wa1).
If lv_str is initial.
Concatenate lv_str wa1-salesid into lv_str.
Else.
Concatenate lv_str wa1-salesid into lv_str special by ','.
Endif.
At end salesid.
Wa2-saleid = wa1-saleid.
Wa2-tmdocs = lv_str.
Append wa2 to it2.
Clear: wa2, lv_str.
Endat.
Clear wa1-salesid.
Endloop.
2022 Aug 12 11:35 AM
Note: It1 as internal table Img1. It2 as Img2.
Data: wa2 like line of it2,
Lv_tr type string.
Sort It1 by salesid.
Loop at It1 into data(wa1).
If lv_str is initial.
Concatenate lv_str wa1-salesid into lv_str.
Else.
Concatenate lv_str wa1-salesid into lv_str special by ','.
Endif.
At end salesid.
Wa2-saleid = wa1-saleid.
Wa2-tmdocs = lv_str.
Append wa2 to it2.
Clear: wa2, lv_str.
Endat.
Clear wa1-salesid.
Endloop.
2022 Aug 12 12:12 PM
2022 Aug 14 3:35 PM
thanks for this. but it gives me wrong output it concatenated but the value of the second column with salesid of 8100000455 is this 8100000455,8100000455,8100000455,8100000455,8100000455,8100000455,8100000455,8100000455,8100000455,8100000455
2022 Aug 17 11:08 AM
i changed the logic and it works thanks. it concatenate the sales id not the tmdocs
2022 Aug 17 11:09 AM
2023 Sep 20 6:48 AM
yes it can be done using CDS with table functions and usethe STRING_AGGR function
2023 Sep 20 6:49 AM
LOOP AT GROUP BY would be a more modern and relevant syntax to get this done.
2022 Aug 12 12:10 PM
Hi,
let's say the first table from image1 is an internal table called lt_sales. And you want to update the database table in the end. Let's assume the database table is named sales_db_table. The logic is like this:
LOOP AT lt_sales INTO DATA(ls_sales) GROUP BY ls_sales-salesid.
LOOP AT GROUP ls_sales INTO DATA(ls_sales_grouped).
IF lv_conc_string IS INITIAL.
lv_conc_string = ls_sales_grouped-tmdocs
ELSE.
CONCATENATE lv_conc_string ls_sales_grouped-tmdocs INTO lv_conc_string SEPARATED BY ','.
ENDIF.
ENDLOOP.
"now do something with the concatenated string, modify the table where you want to change the tmdocs for instance
UPDATE sales_db_table SET tmdocs = @lv_conc_string WHERE salesid = @ls_sales-salesid.
ENDLOOP.
2022 Aug 12 12:27 PM
DATA(string_table) = VALUE string_table(
( `8100000455` ) ( `8100000151` ) ( `8100004000` ) ( `8100000456` ) ).
DATA(field) = concat_lines_of( sep = `, ` table = string_table ).
ASSERT field = `8100000455, 8100000151, 8100004000, 8100000456`.
2022 Aug 14 2:41 PM
Hi,
try to use a group by like:
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaploop_at_group.htm
type: begin of ty_list,
no type n length 6,
docs type string,
end of ty_list.
data: lt_list type table of ty_list.
DATA(list) = VALUE list( ).
LOOP AT lt_data INTO DATA(wa)
GROUP BY wa-no
ASCENDING
ASSIGNING FIELD-SYMBOL(<list>).
lt_list = VALUE ty_list(
BASE lt_list
( no = <list>
docs = concat_lines_of(
sep = `, `
table = value #( FOR wa IN GROUP <list> ( wa-doc ) )
)
)
).
ENDLOOP.
2023 Jul 18 2:34 PM
Hi,
Same thing i want to write in BW END ROUTINE.
Please provide the updated code.