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: 

FM to split a string into multiple table lines

Former Member
0 Kudos

Hi all !

In the past i used a FM to convert a long string (or sequence of chars) into multiple table lines (rel. 4.6C)

Import param:

- string (or chars?)

- length of output lines

Export param:

- standard table

I can't remember what FM it was. Could anyone help me ?

Thanks in advance !

Manuel

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Try Function SOTR_SERV_STRING_TO_TABLE

Pass TEXT & LINE LENGTH.

Cheers

11 REPLIES 11

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Check out FORMAT_TEXTLINES.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

SPLIT_LINE is the fm

Sri

0 Kudos

Hi Rich and Sri,

I tried to use the FM you suggested but I dont think they are useful in this case (or maybe i have made a mistake calling the FM).

FORMAT_TEXTLINES: i can't pass any string parameter

SPLIT_LINE: im passing TEXT, LEN and MAXLEN but it seems that it doesn't split anything

I make an example to clarify my problem.

1. I have a very long sring : var_1(1000) type c

2. I need to split this string in string with max length=50

3. the result should be an internal table of strings with 1000/50= 20 lines and length=50 chars.

Any suggestions ?

Many thanks,

Manuel

0 Kudos

Hi,

You need to fill LEN as well as MAXLEN..

LEN should be the length of your string..

Hope this helps.

It works for me

Pass '' for SEP_BEFORE and SEP_BEHIND and COMMENT if you dont need them.

Sri

guillaume-hrc
Active Contributor
0 Kudos

You can pass your string in the LINES table of the FORMAT_TEXTLINES, can't you ?

Former Member
0 Kudos

Try Function SOTR_SERV_STRING_TO_TABLE

Pass TEXT & LINE LENGTH.

Cheers

0 Kudos

Hi all (and really thanks for your help)

For Guillaume:

I think i can't use LINES table.

Unfortunately this table has a structure with length 132 and I need to pass very long strings (1000 chars or more).

For Sri:

Maybe im passing something wrong...


data: text(1000),
      begin of tab occurs 0,
      text(10),
      end of tab.

text = 'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'.
call function 'SPLIT_LINE'
  exporting
    text                   = text
    len                    = 10
    maxlen                 = 10
   SEP_BEFORE             = ''
   SEP_BEHIND             = ''
   COMMENT                = ''
  tables
    result_tab             = tab.

at this point table TAB contains

aaaaaaaaaa

instead of:

aaaaaaaaaa

bbbbbbbbbb

cccccccccc

dddddddddd

eeeeeeeeee

Regards,

Manuel

0 Kudos

Yes, you pass the text in the TABLES parameter. Please implement the following example program.




report zrich_0002 .

data: lines type table of tline with header line.



lines-tdline = 'These are the lines that you want to be formatted.  '.
append lines.
lines-tdline = 'You can have as many lines as you want.'.
append lines.



call function 'FORMAT_TEXTLINES'
 exporting
*   CURSOR_COLUMN           = 0
*   CURSOR_LINE             = 0
*   ENDLINE                 = 99999
    formatwidth             = 20
*   LINEWIDTH               = 132
*   STARTLINE               = 1
*   LANGUAGE                = SY-LANGU
* IMPORTING
*   NEW_CURSOR_COLUMN       =
*   NEW_CURSOR_LINE         =
  tables
    lines                   = lines
* EXCEPTIONS
*   BOUND_ERROR             = 1
*   OTHERS                  = 2
          .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

loop at lines.

  write:/ lines-tdline.
endloop.

Regards,

Rich Heilman

0 Kudos

Hi Sanjay ,

It works ! Thank you !!!

0 Kudos

Hi Manuel,

len should be really the length of the entire text..

use STRLEN function and then pass it as LEN..

Sri

0 Kudos

While FM SOTR_SERV_STRING_TO_TABLE works, it has an internal maximum string length of 255 characters! This is because it uses data element SOTR_TXT.