Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Merge result set based on Ticket Number

tom_darsy
Participant
0 Kudos

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

3 REPLIES 3

Former Member
0 Kudos

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).

Subhankar
Active Contributor
0 Kudos

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 !!!

raviahuja
Contributor
0 Kudos

Hi,

In short, no single statement can perform this task.

Thanks.

Ravi