cancel
Showing results for 
Search instead for 
Did you mean: 

convert structure to string separated by string

daniel_humberg
Contributor
0 Kudos

I have a method with a parameter itab of the type ANY TABLE.

Now i want to loop over this itab and convert each line into a string, whereas each field shall be separated by a certain string.

The problem is, that I don't know which fields the table's structure has.

Any ideas?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If you know the structure that the table needs to be moved to then it is possible with assign..

pls check the code below...



REPORT  yytest88 LINE-COUNT 20 NO STANDARD PAGE HEADING.

TYPES: BEGIN OF ty_test,
         f1(10),
         f2(10),
       END OF ty_test.

DATA : wa_type(10) VALUE 'TY_TEST'.

DATA : BEGIN OF itab OCCURS 0,
         f(20),
       END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,
         f(35),
       END OF itab1.

FIELD-SYMBOLS : <fs1> TYPE any.
FIELD-SYMBOLS : <fs2> TYPE any.
FIELD-SYMBOLS : <fs3> TYPE any.


itab-f = '12345678901234567890'.
APPEND itab.
itab-f = '09876543210987654321'.
APPEND itab.

LOOP AT itab.

  ASSIGN itab-f TO <fs1> CASTING TYPE (wa_type).
  IF sy-subrc = 0.
    do.
      assign component sy-index of structure <fs1> to <fs2>.
      if sy-subrc = 0.
        if itab1-f is initial.
          concatenate itab1-f <fs2> into itab1-f.
        else.
          concatenate itab1-f <fs2> into itab1-f separated by 'BREAK'.
        endif.
      else.
        exit.
      endif.
    enddo.
    APPEND itab1.
    clear : sy-subrc, itab1-f.
  ENDIF.
ENDLOOP.

LOOP AT itab1.
  WRITE 😕 itab1-f.
ENDLOOP.

daniel_humberg
Contributor
0 Kudos

HI Renjith,

I don't know the structure.

It shall work with any kind of (flat) structure.

But I think that is is possible with


do.
  assign component SY-INDEX of structure <fs1> to <fs2>.
  if sy-subrc = 4.
    exit.
  else.
    "concatenate....
  endif.
enddo.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, this will work for any possible structure. You may have a problem if there are any packed fields in there.



do.
  assign component SY-INDEX of structure <fs1> to <fs2>.
  if sy-subrc = 4.
    exit.
  else.
    "concatenate....
  endif.
enddo.




Regards,

Rich Heilman

Answers (0)