‎2006 Nov 17 7:33 AM
Hello Friends,
I have a small problem .
My scenario is like this:-
1, Say I have an internal table with 4 columns.
columns-> C1 C2 C3 C4
Row1-> A a 1 - (empty)
Row2 -> B b 2 -
Row3-> C c 3 -
Row4-> D d 2 -
Row5-> E e 5 -
2, Now I need to do a manipulation such that in each row the C4 must contain the concatenated values of column C3 separated by "," and should not repeat i.e say the column C3 contains the number 2 more than once then the string in column C4 must not conatain this number "2" twice.
I.e my output should be :-
columns-> C1 C2 C3 C4
Row1-> A a 1 1,2,3,5
Row2-> B b 2 1,2,3,5
Row3-> C c 3 1,2,3,5
Row4-> D d 2 1,2,3,5
Row5-> E e 5 1,2,3,5
can anyone help me out in acheiving this ?
waiting for ur reply................
Regards,
Deepu.K
‎2006 Nov 17 8:24 AM
Deepu,
here is the solution..
DATA: begin of t_t occurs 0,
c1(1),
c2(1),
c3(1),
c4(10),
end of t_t,
begin of t_tt occurs 0,
c3(1),
end of t_tt,
v_t(10).
t_t-c1 = 'A'.
t_t-c2 = '2'.
t_t-c3 = '1'.
append t_t.
clear t_t.
t_t-c1 = 'B'.
t_t-c2 = 'b'.
t_t-c3 = '2'.
append t_t.
clear t_t.
t_t-c1 = 'C'.
t_t-c2 = 'c'.
t_t-c3 = '3'.
append t_t.
clear t_t.
t_t-c1 = 'D'.
t_t-c2 = 'd'.
t_t-c3 = '2'.
append t_t.
clear t_t.
t_t-c1 = 'E'.
t_t-c2 = 'e'.
t_t-c3 = '5'.
append t_t.
clear t_t.
loop at t_t.
t_tt-c3 = t_t-c3.
append t_tt.
clear t_tt.
endloop.
sort t_tt by c3.
delete adjacent duplicates from t_tt.
loop at t_tt.
if v_t is initial.
v_t = t_tt-c3.
else.
concatenate v_t t_tt-c3 into v_t separated by ','.
endif.
endloop.
loop at t_t.
t_t-c4 = v_t.
modify t_t transporting c4.
endloop.
loop at t_t.
write:/ t_t-c1, space, t_t-c2, space, t_t-c3, space, t_t-c4, space.
endloop.
-Anu
‎2006 Nov 17 7:58 AM
Loop thro the first internal table first and concatenate the values into a string.
Then loop thro the second table and assign column 4 to this string for all the records.
Reward points if this helps.
Regards
Meera
‎2006 Nov 17 8:04 AM
For eg:
c_comma has the value ','.
l_value is defined as a string. It can be a maximum of only 255 characters/
Loop at int_tab1.
concatenate l_value c_comma l_col3 into l_value.
endloop.
loop at int_tab2.
l_col4 = l_value.
endloop.
Reward points if this helps.
Regards
MEera
‎2006 Nov 17 8:05 AM
Hi Deepu,
You can do something like this. Check if this logic works.
declare a variable g_var.
Loop at first itab.
if itab-c4 NE g_var.
concatenate itab-c4 into g_var.
read itab with key c1,c2,c3
modify itab.
endloop.
‎2006 Nov 17 8:24 AM
Deepu,
here is the solution..
DATA: begin of t_t occurs 0,
c1(1),
c2(1),
c3(1),
c4(10),
end of t_t,
begin of t_tt occurs 0,
c3(1),
end of t_tt,
v_t(10).
t_t-c1 = 'A'.
t_t-c2 = '2'.
t_t-c3 = '1'.
append t_t.
clear t_t.
t_t-c1 = 'B'.
t_t-c2 = 'b'.
t_t-c3 = '2'.
append t_t.
clear t_t.
t_t-c1 = 'C'.
t_t-c2 = 'c'.
t_t-c3 = '3'.
append t_t.
clear t_t.
t_t-c1 = 'D'.
t_t-c2 = 'd'.
t_t-c3 = '2'.
append t_t.
clear t_t.
t_t-c1 = 'E'.
t_t-c2 = 'e'.
t_t-c3 = '5'.
append t_t.
clear t_t.
loop at t_t.
t_tt-c3 = t_t-c3.
append t_tt.
clear t_tt.
endloop.
sort t_tt by c3.
delete adjacent duplicates from t_tt.
loop at t_tt.
if v_t is initial.
v_t = t_tt-c3.
else.
concatenate v_t t_tt-c3 into v_t separated by ','.
endif.
endloop.
loop at t_t.
t_t-c4 = v_t.
modify t_t transporting c4.
endloop.
loop at t_t.
write:/ t_t-c1, space, t_t-c2, space, t_t-c3, space, t_t-c4, space.
endloop.
-Anu
‎2006 Nov 21 9:43 AM
Hello All,
Thanks for all ur replies.
It helped me to solve my problem.
Thanks friends. (; (; (;
Points are awarded (; (; (;
<b>PS: Sorry for my late reply.</b>
Regards,
Deepu.K
Message was edited by:
deepu k
‎2006 Nov 21 9:45 AM