2011 Oct 19 2:52 PM
Hi
I have a result set as below.
Ticket No Customer Contact Person Reporter
100 1000001 # #
100 # 1000002 #
100 # # 1000003
The ticket number is the same. What abap statement do i use to merge the result into a single line. The result should show as
Ticket No Customer Contact Person Reporter
100 1000001 1000002 1000003
Please can someone let me know.
Thanks
2011 Oct 20 8:43 PM
similar questions are asked so many times, and you should search...in the meantime, consider:
loop at itab into ls_itab..
if ls_itab-key ne lastkey. "variable to hold key field value.
if sy-tabix > 1.
append outrec to output_tab.
clear outrec. "structure of your output table type.
endif.
lastkey = ls_itab-key. "set var to new key value
outrec-key =ls_itab-key. "build first two parts of outrec (structure of type of output table...
outrec-value = ls_itab-value. "1st value...
else.
concatenate outrec-value ls_itab-value "put the next value into the output line, since key is the same.
into outrec-value separated by space.
endif.
endloop.
if outrec is not initial.
append outrec to output_tab.
endif.
the dataset is now reduced to one line per instance of the each unique value of the key field(s).
2011 Oct 21 12:35 AM
I will suggest you use AT END statement. Sort the internal table based on the Ticket number and do the rest processing,
TYPES: BEGIN OF x_temp,
ticket TYPE char3,
cp TYPE char10,
END OF x_temp,
BEGIN OF x_final,
ticket TYPE char3,
cp TYPE string,
END OF x_final.
DATA: l_wa TYPE x_temp,
l_wa_final TYPE x_final,
l_i_temp TYPE STANDARD TABLE OF x_temp,
l_i_final TYPE STANDARD TABLE OF x_final.
SORT l_i_temp BY ticket.
LOOP AT l_i_temp INTO l_wa.
IF l_wa_final-cp IS INITIAL.
l_wa_final-cp = l_wa-cp.
ELSE.
CONCATENATE l_wa_final-cp l_wa-cp INTO l_wa_final-cp SEPARATED BY space.
ENDIF.
AT END OF ticket.
l_wa_final-ticket = l_wa-ticket.
APPEND l_wa_final TO l_i_final.
CLEAR: l_wa_final.
ENDAT.
ENDLOOP.
Here in the internal table l_i_final have the final data.
cheers !!!
2011 Oct 21 1:30 AM
Hi,
In short, no single statement can perform this task.
Thanks.
Ravi