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: 

Converting text in itab of length 255 to 132 (SOLI to TLINE)

Pyc
Participant
0 Kudos
6,185

G'day all,

Hopefully an easy one.

I have a table of line type SOLI which contains a stream of text with Carriage Returns and Line Feeds (CR/LF) included.

I need to convert this table to TLINE format, which means that I want to break it up into 132 chunks and take the CR/LFs into account so that it remains logically formatted i.e. I want a new line in the table whenever a CR/LF is present.

I'm after a Function Module or Method to do this. I know I can scan the table text myself looking for the CR/LFs as hex characters and split it into 132 pieces, but I really don't want to.

I've played with CONVERT_STREAM_TO_ITF_TEXT which is really close to what I want. It will take a table of unspecified line length and convert it and return it in TLINE structure format. Unfortunately it goes a little too far and handles characters like & and < as special characters and in my case they're not special.

Further and possible unnecessary specifics about my scenario:

I'm recieving an inbound email via a class based on IF_INBOUND_EXIT_BCS which will give me access to the email body in a table based on BCSS_DBPC-CONT_TEXT. I need to convert this into TLINE (more specifically RFC_TLINE) format for a function call which creates Long Text against a document (specifically a Notification).

Many thanks,

Mark

Yes I will award points for useful answers, but please don't ask.

8 REPLIES 8

Former Member
0 Kudos
1,208

data: itab_d like swastrtab occurs 0 with header line.

data string type string.

string = 'pass ur text'.

CALL FUNCTION 'SWA_STRING_SPLIT'

EXPORTING

INPUT_STRING = string

MAX_COMPONENT_LENGTH = 132

  • TERMINATING_SEPARATORS =

  • OPENING_SEPARATORS =

TABLES

STRING_COMPONENTS = itab_d

  • EXCEPTIONS

  • MAX_COMPONENT_LENGTH_INVALID = 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.

0 Kudos
1,208

Thanks for the quick response. Unfortunately this function doesn't handle CR/LF and does perform special handling of < ( [ breaking the line at each. As my input is an email any of these characters could appear but should not be handled differently to any other standard characters.

At least it gives me some simple code to copy and paste if no else knows an existing function/method.

Thanks,

Mark

Former Member
0 Kudos
1,208

Hello Mark,

Try with this FM.


DATA DIGIT(11) VALUE '0123456789'.
PARAMETERS: VAR(16) DEFAULT '276,00'.
DATA VAR_NEW(16).
DATA S(2) VALUE ' 0'.
DATA: L_INT TYPE I,
      L_INT1 TYPE I.
VAR_NEW = VAR.

CALL FUNCTION 'PREPARE_STRING'
     EXPORTING
          I_VALID_CHARS  = DIGIT
          I_XVALID_CHECK = 'X'
          I_XCHAR_REPL   = 'X'
          I_XTOUPPER     = 'X'
     CHANGING
          C_STRING       = VAR_NEW.

REgards,

Vasanth

0 Kudos
1,208

Sorry Vasanth, but I don't think you quite understood my requirement. That function is about stripping out unwanted characters from a string - not something I want to do. I need to keep the content as is, but split it into a smaller line length table taking CR/LF into account.

athavanraja
Active Contributor
0 Kudos
1,208

first convert the soli to string using

SOTR_SERV_TABLE_TO_STRING

and then

use

SOTR_SERV_STRING_TO_TABLE

to convert string to tline.

(in both the cases you have to option to retain line breaks and the option to specify line lengths.)

0 Kudos
1,208

So close!

These functions looked great, but unfortunately they give the option of taking the CR/LF out or leaving it in, but if you leave them in SOTR_SERV_STRING_TO_TABLE doesn't actually interpret them and give you a new line when they occur.

Thanks,

Mark

0 Kudos
1,208

can you try with C14W_STRING_TO_TLINE for string to table.

0 Kudos
1,208

Unfortunately this function only deals with Line Feed, but not carriage return.

I know realise that there are many variables in a requirement like this and a standard function to achieve what I wanted seems unlikely. It seemed a standard sort of a requirement to being with.

I've now got a solution I can live with - thanks for all responses.

Below is my very ugly and bodgy test code.... BTW in the end I changed my reqt to be 72 rather than 132 characters.

Have fun,

Mark

loop at ls_bodypart_content-CONT_TEXT into lv_bp_cont_line.

if lfl_space_reqd is initial.

concatenate lv_email_as_str lv_bp_cont_line into lv_email_as_str.

else.

concatenate lv_email_as_str lv_bp_cont_line into lv_email_as_str

SEPARATED by space.

clear lfl_space_reqd.

endif.

if lv_bp_cont_line+254(1) = space.

lfl_space_reqd = 'X'.

endif.

endloop.

split lv_email_as_str at cl_abap_char_utilities=>cr_lf

into table lt_paragraphs.

loop at lt_paragraphs into lv_paragraph.

if lv_paragraph is initial.

append space to lt_total_char72.

else.

shift lv_paragraph left deleting leading space.

CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'

EXPORTING

TEXT = lv_paragraph

FLAG_NO_LINE_BREAKS = space

TABLES

TEXT_TAB = lt_tmp_char72.

append lines of lt_tmp_char72 to lt_total_char72.

clear lt_tmp_char72.

endif.

endloop.