Application Development and Automation 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: 
Read only

internal table formatting

Former Member
0 Likes
361

Dear Experts,

My requirement is to convert the internal table to different format,

input:

1 a

2 a

3 b

4 b

ouput:

1,2 a

3,4 b

Thanks and regards,

thirukumaran. R

2 REPLIES 2
Read only

MarcinPciak
Active Contributor
0 Likes
332

Something like this?


TYPES: BEGIN OF ts_template,
        f1 TYPE string,
        f2 TYPE c,
       END OF ts_template.

types: tt_template type table of ts_template with key f2.

DATA: it_input TYPE tt_template WITH HEADER LINE,
      it_output TYPE tt_template WITH HEADER LINE.

it_input-f1 = '1'.
it_input-f2 = 'a'.
APPEND it_input.
it_input-f1 = '2'.
it_input-f2 = 'a'.
APPEND it_input.
it_input-f1 = '3'.
it_input-f2 = 'b'.
APPEND it_input.
it_input-f1 = '4'.
it_input-f2 = 'b'.
APPEND it_input.
it_input-f1 = '5'.
it_input-f2 = 'd'.
APPEND it_input.
it_input-f1 = '6'.
it_input-f2 = 'e'.
APPEND it_input.

WRITE: 'Input:'.

LOOP AT it_input.
  READ TABLE it_output WITH KEY f2 = it_input-f2.
  IF sy-subrc = 0.
    CONCATENATE it_output-f1 it_input-f1
                INTO it_output-f1 SEPARATED BY ','.
    it_output-f2 = it_input-f2.
    MODIFY TABLE it_output FROM it_output.
  ELSE.
    it_output-f1 = it_input-f1.
    it_output-f2 = it_input-f2.
    APPEND it_output.
  ENDIF.

  WRITE: / it_input-f1, it_input-f2.
ENDLOOP.

WRITE / 'Output'.

LOOP AT it_output.
  WRITE: / it_output-f1, it_output-f2.
ENDLOOP.

Regards

Marcin

Read only

Former Member
0 Likes
332

Moderator message - Please try this yourself and if you still have problems, ask a specific question - post locked Rob