Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Merge an internal table into a string stream

Hello,

i need to merge an internal table (2 column) layout:

ELEMENT

VALUE

into one string stream.

E.g.:

ELEMENT | VALUE

test1 | 1111111111111111111

test1 | 2222222222222222222

result should be:

test1 | 11111111111111111112222222222222222222 (= type string!)

too bad you cant use offset while working with a field of type string and im sure there is a ABAP class which does do this.

regards,

Markus

Tags:
replied

Try this Markus:

REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 255.

DATA: BEGIN OF itab OCCURS 0,
        element TYPE string,
        value   TYPE string,
      END   OF itab.

DATA: BEGIN OF itab2 OCCURS 0,
        element TYPE string,
        value   TYPE string,
      END   OF itab2.

DATA: next LIKE sy-tabix VALUE 1,
      old_element LIKE itab-element.

PERFORM load_itab.
sy-subrc = 0.

DO.
  READ TABLE itab INDEX next.
  IF sy-subrc <> 0.
    EXIT.
  ELSE.
    IF itab-element <> old_element.
      IF next <> 1.
        APPEND itab2.
        CLEAR itab2.
      ENDIF.
      itab2-element = itab-element.
      old_element = itab-element.
    ENDIF.
    CONCATENATE itab2-value itab-value INTO itab2-value.
    next = next + 1.
  ENDIF.
ENDDO.
IF itab2-element <> space.
  APPEND itab2.
ENDIF.

break rburbank.

*&---------------------------------------------------------------------*
*&      Form  load_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM load_itab.

  REFRESH: itab,
           itab2.
  CLEAR  : itab,
           itab2.

  itab-element = 'test1'.
  itab-value   = '1111111111111111111'.
  APPEND itab.

  itab-element = 'test1'.
  itab-value   = '2222222222222222222'.
  APPEND itab.

  itab-element = 'test2'.
  itab-value   = '3333333333333333333'.
  APPEND itab.

  itab-element = 'test2'.
  itab-value   = '4444444444444444444'.
  APPEND itab.

ENDFORM.                    " load_itab

Rob

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question