cancel
Showing results for 
Search instead for 
Did you mean: 

optimal length in FM "RKD_WORD_WRAP"

Former Member
0 Kudos

Hi all,

Regarding the usage of FM "RKD_WORD_WRAP",

when wrapping a sentence with pure English characters, it is easy to decide the max. line length (OUTPUTLEN), but what if a sentence that is a mixture of Chinese characters and English characters (in which the distribution is not fixed every time in a sentence)? How to determine the optimal line length so that no overlapping would occur after calling the FM?

Thanks a lot!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Try to execute without giving the Output Length.

Regards,

VIshwa.

Former Member
0 Kudos

But without defining the output length, the default length 35 (which is too short) would be used.

Any other methods?

Thanks!

Former Member
0 Kudos

Hi

OK. Lets try this:

DATA: string(25) TYPE c. " you can have it maximum.

len TYPE I.

"pass ur sentence to the variable string.

len = strlen( string ). "here u will get the length of the sentence.

move len to var.

pass var to the FM.

..

Regards,

Vishwa.

Edited by: Vishwa Sri Hari on Oct 15, 2008 4:07 PM

Former Member
0 Kudos

"pass ur sentence to the variable string.

But my sentence is of length > 25 which varies each time since it contains unknown no. of Chinese characters and English characters. (as input by users)

Then what should I do?

Thanks!

Former Member
0 Kudos

Hi

The keyword "strlen", will give the length of the whole sentence which includes chinese and english..

As mentioned earlier, take that value and pass it to FM.

Regards,

Vishwa.

Former Member
0 Kudos

Thanks for your resply first.

But the fact is like this:

user types in the long text, e.g. in a service order, the text is retrieved by FM read_text and the text is stored in the table of type TLINE whose line length is 132 CHAR. And the output area is 16 cm long which is supposed to be able to print a line > 132 CHAR, so I just combine the TLINE-tdline into a string and pass it to the FM RKD_WORD_WRAP. But I donno the optimal length to be passed. I've tried many no. e.g. 105, sometimes it works perfectly, but sometimes it does not and the characters overlap in one line, so I'd like to dynamically get the magic no. instead of hardcode it.

Or is there any other method to accurately show the texts utilizing maximum area?

Thanks a lot!

Former Member
0 Kudos

Hi

so I just combine the TLINE-tdline into a string and pass it to the FM RKD_WORD_WRAP. But I donno the optimal length to be passed

U have mentioned that u pass the string to the FM, before that just pass it to the keyword "strnlen" like this:

data:len type i,
       var type i.

len = strlen(string).

move len to var.

CALL FUNCTION 'RKD_WORD_WRAP'
  EXPORTING
    TEXTLINE                  = STRING
*   DELIMITER                 = ' '
   OUTPUTLEN                 = VAR
* IMPORTING
*   OUT_LINE1                 =
*   OUT_LINE2                 =
*   OUT_LINE3                 =
* TABLES
*   OUT_LINES                 =
* EXCEPTIONS
*   OUTPUTLEN_TOO_LARGE       = 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.

I really dont see anything hard coding,you are finding the correct length before hand and passing it to the FM...

If you give a value like 105..then it is called hard coding.

Regards,

Vishwa.

Former Member
0 Kudos

Let me make it clearer.

Let's say the strlen( string ) is 500 which is too long to print the entire contents in a single line, it is expected after calling the FM, it would automatically cut into pieces of lines that could fit into the printing area...so I have to pass the optimal length to the FM to tell it where to cut, but it seems that the method you suggested can't ....Any ideas ? Thanks!

Former Member
0 Kudos

OK.

This is some part of the code in the FM that ur using:

CONSTANTS:
          MAX_OUTPUTLEN       TYPE I         VALUE 256.   "WP210396/30D

  DATA:   IPOS                LIKE SY-FDPOS,          "cut position
          LNUM                TYPE I,                 "line number
          STRING_LENGTH       LIKE SY-FDPOS,          "remaining length
          OUTLINE(MAX_OUTPUTLEN).                     "tmp: textline

  DATA:  TEXTLEN              TYPE I.      " len of textline    H48596

  data: begin of lt_lines occurs 0,                          "H799865
          line(256) type c,                                  "H799865
        end of lt_lines.                                     "H799865

  FIELD-SYMBOLS: <F>   type C,         "looks for DELIMITER
                 <OUT> type C.         "outline reference

  IF OUTPUTLEN > MAX_OUTPUTLEN.
    RAISE OUTPUTLEN_TOO_LARGE.
  ENDIF.

  DESCRIBE FIELD TEXTLINE LENGTH TEXTLEN in character mode.
  IF TEXTLEN LT OUTPUTLEN.
    OUTPUTLEN = TEXTLEN.
  ENDIF.

  IPOS = OUTPUTLEN.
  LNUM = 1.
  CLEAR OUT_LINES.
  STRING_LENGTH = STRLEN( TEXTLINE ).                     "H799865
  if delimiter eq space or string_length gt outputlen.      "H799865
  DO.
    CASE LNUM.
      WHEN 1.
        ASSIGN OUT_LINE1 TO <OUT>.
      WHEN 2.
        ASSIGN OUT_LINE2 TO <OUT>.
      WHEN 3.
        ASSIGN OUT_LINE3 TO <OUT>.
      WHEN OTHERS.
        ASSIGN OUTLINE TO <OUT>.
    ENDCASE.
    IPOS = IPOS - 1.
    STRING_LENGTH = STRLEN( TEXTLINE ).

If u see the max. outputlen is given 256,if it is more than that then it is going to raise exception.. I think now u might have got an idea about the optimal length.

Regards,

Vishwa.

Former Member
0 Kudos

Thanks for your quick response.

I know it should be less than 256,

but just donno what is the suitable no. to pass into the FM...

Any more ideas?

Thanks!

Former Member
0 Kudos

Hi

As you said, If the string is more than 256,then The code I sent you previiously wont work. Agreed It wont.

SO,let us find the string length first..then put a condition saying if it more than 256.then split, use the following code:

You can split a string into parts as follows.

Example:

DATA:
string(50) TYPE c VALUE 'Venkat,Srinivas,Bhrammam',
w_variable1(10) TYPE c,
w_variable2(10) TYPE c,
w_variable3(10) TYPE c,
partition TYPE c VALUE ','.

SPLIT string AT partition INTO w_variable1 w_variable2 w_variable3

.

Now, you have it in parts which you can pass through the FM and then CONCATENATE IT.

Regards,

Vishwa.