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: 

Split string to put into Internal Table

Former Member

Is there a FM, or a seriese of calls, which will allow me to take a string and put that into an internal table? Let me explain why.

I have a free-formated text box, on a webpage, and I need to include this text on a SmartForm. The issue is that I can't predict the length of the text and I can't have any of the text cutoff. My solution is to put the string into an internal table and then loop at that table. This will allow the node, in the SmartForm, to expand, thus keeping each and ever character (not cutting any of it off). I assume this will work but I don't know how to cut this string apart and put it in an internal table.

I could simply cut it at a certain length but that may cut words apart and I can't have that; I need the line breaks in between words.

Any ideas?

Thanks,

Aaron

1 ACCEPTED SOLUTION

GrahamRobbo
Active Contributor

Hi Aaron,

something like this might suit your needs. This example builds a string then puts it into an itab of CHAR128.


  DATA: lv_string   TYPE string,
        lt_split    TYPE TABLE OF char40,
        lt_char128  TYPE TABLE OF char128,
        lv_wa_str   TYPE string,
        lv_len      TYPE int4,
        lr_split    TYPE REF TO char40,
        lr_char128  TYPE REF TO char128.

  DO 50 TIMES.
    CONCATENATE lv_string
    `The quick brown fox jumped over the lazy dog. `
    INTO lv_string.
  ENDDO.

  SPLIT lv_string AT space INTO TABLE lt_split.

  LOOP AT lt_split REFERENCE INTO lr_split.
    lv_len = STRLEN( lv_wa_str ) + STRLEN( lr_split->* ).
    IF lv_len LT 128.
      CONCATENATE lv_wa_str lr_split->* INTO lv_wa_str SEPARATED BY space.
    ELSE.
      APPEND lv_wa_str TO lt_char128.
      lv_wa_str = lr_split->*.
    ENDIF.
  ENDLOOP.
  APPEND lv_wa_str TO lt_char128.

Cheers

Graham Robbo

9 REPLIES 9

Sm1tje
Active Contributor
0 Kudos

try to use:

SPLIT string AT SPACE INTO ITAB

Or instead of SPACE use ' '.

0 Kudos

i have split the string by ' | ' and the internal table is type of standard table name SFLIGHT.

GrahamRobbo
Active Contributor

Hi Aaron,

something like this might suit your needs. This example builds a string then puts it into an itab of CHAR128.


  DATA: lv_string   TYPE string,
        lt_split    TYPE TABLE OF char40,
        lt_char128  TYPE TABLE OF char128,
        lv_wa_str   TYPE string,
        lv_len      TYPE int4,
        lr_split    TYPE REF TO char40,
        lr_char128  TYPE REF TO char128.

  DO 50 TIMES.
    CONCATENATE lv_string
    `The quick brown fox jumped over the lazy dog. `
    INTO lv_string.
  ENDDO.

  SPLIT lv_string AT space INTO TABLE lt_split.

  LOOP AT lt_split REFERENCE INTO lr_split.
    lv_len = STRLEN( lv_wa_str ) + STRLEN( lr_split->* ).
    IF lv_len LT 128.
      CONCATENATE lv_wa_str lr_split->* INTO lv_wa_str SEPARATED BY space.
    ELSE.
      APPEND lv_wa_str TO lt_char128.
      lv_wa_str = lr_split->*.
    ENDIF.
  ENDLOOP.
  APPEND lv_wa_str TO lt_char128.

Cheers

Graham Robbo

0 Kudos

Graham, that works like a charm! Now it is time to study this code.

Thank you so much!

Aaron

0 Kudos

ya its useful.

one more doubt.

i want to assign that string to internal table fields(data: itab type table of sflight).

how we move the string indivudually to each field of internal table.

0 Kudos

how to assin to standard internal table after split a string

Former Member
0 Kudos

I know I'm late for this, but have you tried function module SCMS_STRING_TO_FTEXT?

If you search SCMS_* you have a lot of useful conversion function modules...

Regards,

This function module breaks words 😞

Former Member
0 Kudos

Here is a way to implemnt what you want

DATA: BEGIN OF t_split OCCURS 0,

         vkorg TYPE char4,

       END OF t_split.

RANGES: r_vkorg FOR vbrk-vkorg.

"TYPE TABLE OF char4 WITH HEADER LINE.

REFRESH: t_split[] , r_vkorg[].


SPLIT 'OV01,OV02,OV07,' AT ',' INTO TABLE t_split.

LOOP AT t_split.

   CLEAR r_vkorg.

   r_vkorg-sign   = 'I'.

   r_vkorg-option = 'EQ'.

   r_vkorg-low    = t_split-vkorg.

   APPEND r_vkorg.

ENDLOOP.