2007 Feb 12 1:02 PM
Hello to everyone.
I know that i can find many threads about concatenation here but, i think i am that dummy i cant make them work, so a little bit of help is be apreciated.
I have the following internal table:
MaterialNumber | TEXT -- those are the columns in the internal table.
For material 100100 i have 3 texts as follows:
100100 TEXT1
100100 TEXT2
100100 TEXT3.
I want to concatenate the second column into another internal table like this:
MaterialNumber | STRING
100100 TEXT1 TEXT2 TEXT3 (separated by space or whatever).
Thank you for your time.
Cristian.
Message was edited by:
Cristian Boartes
2007 Feb 12 2:10 PM
report ychatest.
data : begin of itab occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of itab.
data : begin of itab1 occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of itab1.
data : v_string type string,
v_flag.
itab-matnr = '10000'.
itab-maktx = 'OneOne'.
append itab.
clear itab.
itab-matnr = '10000'.
itab-maktx = 'OneTwo'.
append itab.
clear itab.
itab-matnr = '10000'.
itab-maktx = 'OneThree'.
append itab.
clear itab.
itab-matnr = '10001'.
itab-maktx = 'TwoOne'.
append itab.
clear itab.
itab-matnr = '10001'.
itab-maktx = 'TwoTwo'.
append itab.
clear itab.
loop at itab.
clear v_flag.
at new matnr.
v_flag = 'X'.
read table itab index sy-tabix.
itab1-matnr = itab-matnr.
concatenate v_string itab-maktx into v_string.
endat.
if v_flag ne 'X'.
concatenate v_string itab-maktx into v_string separated by space.
endif.
at end of matnr.
itab1-maktx = v_string.
append itab1.
clear :itab1 , v_string.
endat.
endloop.
loop at itab1.
write : / itab1-matnr , itab1-maktx.
endloop.
Hello to everyone.
I know that i can find many threads about concatenation here but, i think i am that dummy i cant make them work, so a little bit of help is be apreciated.
I have the following internal table:
MaterialNumber | TEXT -- those are the columns in the internal table.
For material 100100 i have 3 texts as follows:
100100 TEXT1
100100 TEXT2
100100 TEXT3.
I want to concatenate the second column into another internal table like this:
MaterialNumber | STRING
100100 TEXT1 TEXT2 TEXT3 (separated by space or whatever).
Thank you for your time.
Cristian.
Message was edited by:
Cristian Boartes
2007 Feb 12 1:04 PM
execute the code .
use the logic in the loop .
data : begin of itab occurs 0,
f1(10) type c,
f2(20) type c,
end of itab.
DATA: VAL(60) TYPE C.
DATA: V_F1(10) TYPE C,
V_F2(10) TYPE C.
data : v_sum(8) type c .
DATA: C TYPE I.
itab-f1 = '20000025'.
itab-f2 = '1000'.
APPEND ITAB.
itab-f1 = '20000025'.
itab-f2 = '2000'.
APPEND ITAB.
itab-f1 = '20000025'.
itab-f2 = '3000'.
APPEND ITAB.
itab-f1 = '20000030'.
itab-f2 = '500'.
APPEND ITAB.
itab-f1 = '20000030'.
itab-f2 = '1000'.
APPEND ITAB.
C = 10.
SORT ITAB BY F1 .
LOOP AT ITAB.
* WRITE:/ ITAB-F1, ITAB-F2.
V_F1 = ITAB-F1.
V_F2 = ITAB-F2.
AT NEW F1.
CONCATENATE V_F1 SPACE INTO VAL+0(10).
ENDAT.
C = C + 10.
CONCATENATE V_F2 SPACE INTO VAL+C(10).
v_sum = v_sum + v_f2.
AT END OF F1.
CONCATENATE V_sum space INTO VAL+50(10).
CONDENSE VAL.
WRITE:/ VAL NO-GAP.
CLEAR: VAL , C , v_sum.
ENDAT.
ENDLOOP.regards,
vijay
2007 Feb 12 1:07 PM
Let the internal table be ITAB1 and the resultant be ITAB2.
DATA itab3 LIKE TABLE OF itab1 WITH HEADER LINE.
itab3[] = itab1[].
SORT itab3 BY matnr.
DELETE ADJACENT DUPLICATES FROM itab3 COMPARING matnr.
LOOP AT itab3.
itab2-matnr = itab3-matnr.
CLEAR itab2-desc.
LOOP AT itab1 WHERE matnr = itab3-matnr.
CONCATENATE itab2-desc itab3-desc INTO itab2-desc SEPARATED BY space.
ENDLOOP.
APPEND itab2.
ENDLOOP.
2007 Feb 12 1:14 PM
CLEAR v_matnr.
LOOP AT itab1. (MaterialNumber | TEXT)
CONCATENATE itab1-text v_matnr INTO v_matnr.
AT END OF MATNR.
CONCATENATE itab1-text v_matnr INTO itab2-string.
itab2-matnr = itab1-matnr.
APPEND itab2.
CLEAR v_matnr.
END AT.
clear itab1.
ENDLOOP.Hope this will solve ur problem.
2007 Feb 12 1:16 PM
Wenceslaus G, thank you for the help.
However, the result is something like TEXT1 TEXT1 TEXT1. Hope ill find the problem.
2007 Feb 12 1:59 PM
Judith,
its a good solution. But...if i have more then 1 material in the internal table it concatenates all the texts of all materials in one string. I need a new string for each material.
2007 Feb 12 2:07 PM
Thats y i have used<b> AT END OF MATNR.</b>
So at each new matnr it will bring a new line.
U check this debugging mode, and if chanegs needed change it.
Ur final table will have only one row with sring for each matnr.
hope this is what u want.
Hi whether my code worked or not?
Message was edited by:
Judith Jessie Selvi
2007 Feb 12 2:10 PM
report ychatest.
data : begin of itab occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of itab.
data : begin of itab1 occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of itab1.
data : v_string type string,
v_flag.
itab-matnr = '10000'.
itab-maktx = 'OneOne'.
append itab.
clear itab.
itab-matnr = '10000'.
itab-maktx = 'OneTwo'.
append itab.
clear itab.
itab-matnr = '10000'.
itab-maktx = 'OneThree'.
append itab.
clear itab.
itab-matnr = '10001'.
itab-maktx = 'TwoOne'.
append itab.
clear itab.
itab-matnr = '10001'.
itab-maktx = 'TwoTwo'.
append itab.
clear itab.
loop at itab.
clear v_flag.
at new matnr.
v_flag = 'X'.
read table itab index sy-tabix.
itab1-matnr = itab-matnr.
concatenate v_string itab-maktx into v_string.
endat.
if v_flag ne 'X'.
concatenate v_string itab-maktx into v_string separated by space.
endif.
at end of matnr.
itab1-maktx = v_string.
append itab1.
clear :itab1 , v_string.
endat.
endloop.
loop at itab1.
write : / itab1-matnr , itab1-maktx.
endloop.
2007 Feb 12 2:18 PM
I think the problem is solved, thank you all. I am quite a beginner so i hope i wont annoy you with my questions.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |