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: 

Function module to change length from 132 to 200

Former Member
0 Kudos

Hi all,

After using the FM READ_TEXT I have data with length = 132.

Now I want to display the result but with 200 chars per line.

Please suggest me any FM to do that.

Thanks,

Khanh

16 REPLIES 16

SuhaSaha
Advisor
Advisor
0 Kudos

Hello,

You can use the FM: SX_TABLE_LINE_WIDTH_CHANGE to change the line width from 132 to 200

BR,

SUhas

Former Member
0 Kudos

Hi Suhas,

I did try this function module but the result is not as my expectation


CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
   EXPORTING
*     LINE_WIDTH_SRC                    = 132
     LINE_WIDTH_DST                    = 200
*     TRANSFER_BIN                      = ' '
    TABLES
      CONTENT_IN                        = t1
      CONTENT_OUT                       = t2
   EXCEPTIONS
     ERR_LINE_WIDTH_SRC_TOO_LONG       = 1
     ERR_LINE_WIDTH_DST_TOO_LONG       = 2
     ERR_CONV_FAILED                   = 3
     OTHERS                            = 4
            .

Thanks,

Khanh

Former Member
0 Kudos

Just declare a char variable of length 200 and pass the TDLINE value to it in the sy-subrc of the FM READ_TEXT. Is this not sufficient?

Vikranth

Former Member
0 Kudos

Hi,

I am not completely sure about you requirement, but you can try this:


TYPES: BEGIN OF ts_line200,
        tdformat  TYPE tdformat,
        tdline(200) TYPE c,
      END OF ts_line200.

DATA:   lt_lines TYPE STANDARD TABLE OF tline,
        ls_line TYPE tline,
        lt_lines200 TYPE STANDARD TABLE OF ts_line200,
        ls_line200 TYPE ts_line200.

CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    id                            = lv_id
    language                      = sy-langu
    name                          = lv_name
    object                        = lv_object
*   ARCHIVE_HANDLE                = 0
*   LOCAL_CAT                     = ' '
* IMPORTING
*   HEADER                        =
  TABLES
    lines                         = lt_lines
 EXCEPTIONS
   id                            = 1
   language                      = 2
   name                          = 3
   not_found                     = 4
   object                        = 5
   reference_check               = 6
   wrong_access_to_archive       = 7
   OTHERS                        = 8
          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CLEAR lt_lines200.
LOOP AT lt_lines INTO ls_line.
  ls_line200-tdformat = ls_line-tdformat.
  ls_line200-tdline = ls_line-tdline.
ENDLOOP.

Regards,

Adrian

0 Kudos

Hi Adrian,

When do you append the table 200?

If doing like this, the new table is similar to the old table except the length of the new table.

Thanks,

Khanh

0 Kudos

Hi,

sorry, APPEND statement is missing in my code. It should be before ENDLOOP statement. But probably I do not understand your requirement.

>

> If doing like this, the new table is similar to the old table except the length of the new table.

I thought this is your requirement.

Adrian

0 Kudos

Hi Adrian,

Sorry for my unclear explanation.

My requirement is as following:

In TLine table I have 5 rows for example which each line contains less or equal 132 chars.

If I use this table to display data, each line will contain maximum of 132 chars.

The requirement is to display each line with maximum of 200 chars (so it may be less than 5 rows).

I would like to ask whether we have a FM to do that or we need to create a custom as my specific requirement.

Thanks all,

Khanh

0 Kudos

Hi Knah,

so now I understand your requirement.

Try to do it like this:

LOOP AT lt_lines INTO ls_line.
  CONCATENATE lv_string ls_line-tdline INTO lv_string.
ENDLOOP.


DO.
  ls_line200-tdline = lv_string.
  APPEND ls_line200 TO lt_lines200.
  SHIFT lv_string BY 200 PLACES LEFT.
  IF STRLEN( lv_string ) EQ 0.
    EXIT.
  ENDIF.
ENDDO.

I am afraid that there is no standard FM for this, but maybe I am wrong.

Regards,

Adrian

0 Kudos

Hello,

Does this fit the bill ?

DATA: it_line TYPE STANDARD TABLE OF tline,
      wa_line TYPE tline,
      it_200 TYPE STANDARD TABLE OF char200,
      wa_200 TYPE char200,
      v_string(5000) TYPE c.

CALL FUNCTION 'READ_TEXT'
  EXPORTING
    id                      = 'ST'
    language                = 'E'
    name                    = 'ZTEST01335'
    object                  = 'TEXT'
  TABLES
    lines                   = it_line
  EXCEPTIONS
    id                      = 1
    language                = 2
    name                    = 3
    not_found               = 4
    object                  = 5
    reference_check         = 6
    wrong_access_to_archive = 7
    OTHERS                  = 8.
IF sy-subrc = 0.

  LOOP AT it_line INTO wa_line.
    CONCATENATE v_string wa_line-tdline INTO v_string
    SEPARATED BY space.
    WRITE / wa_line-tdline.
  ENDLOOP.

  CALL FUNCTION 'RKD_WORD_WRAP'
    EXPORTING
      textline            = v_string
      outputlen           = 200
    TABLES
      out_lines           = it_200
    EXCEPTIONS
      outputlen_too_large = 1
      OTHERS              = 2.
  IF sy-subrc = 0.
    LOOP AT it_200 INTO wa_200.
      WRITE / wa_200.
    ENDLOOP.
  ENDIF.

ENDIF.

BR,

Suhas

Former Member
0 Kudos

The function module mentioned 'SX_TABLE_LINE_WIDTH_CHANGE' does work for your requirement.....

Try using that..

Regards,

Lalit Mohan Gupta.

Former Member
0 Kudos

hi you can try like this,

Hello,

Does this fit the bill ?

<blatant_copy&paste_removed_by_moderator>

ENDIF.

Edited by: Julius Bussche on Feb 24, 2010 12:04 PM

If you do this again then there will be BIG trouble coming your way!

0 Kudos

At least make some changes to the code posted by me

0 Kudos

Hi Susha,

Thanks for your great support.

I still have a concern, how will I handle a break line?

Because by using command concatenate, all the text become one string.

@All: Thanks for your time and support.

Thanks,

Khanh

0 Kudos

Hi,

your requirement is becoming probably very specific to be able to do it by standard function modules. But you can probably do it like this:

LOOP AT lt_lines INTO ls_line.
  IF ls_line-tdformat NE gc_line_separator.
    CONCATENATE lv_string ls_line-tdline INTO lv_string.
  ELSE.
    DO.
      ls_line200-tdline = lv_string.
      APPEND ls_line200 TO lt_lines200.
      SHIFT lv_string BY 200 PLACES LEFT.
      IF STRLEN( lv_string ) EQ 0.
        EXIT.
      ENDIF.
    ENDDO.
    lv_string = ls_line-tdline.
  ENDIF.
ENDLOOP.

IF STRLEN( lv_string ) GT 0.
  DO.
    ls_line200-tdline = lv_string.
    APPEND ls_line200 TO lt_lines200.
    SHIFT lv_string BY 2 PLACES LEFT.
    IF STRLEN( lv_string ) EQ 0.
      EXIT.
    ENDIF.
  ENDDO.
ENDIF.

Adrian

0 Kudos

Hi,

Thanks all for your support.

@Adrian: Using SHIFT LEFT is not a good move because it will cause the data broken (lost meaning).

It is better using FM 'RKD_WORD_WRAP' given by Susha.

Anyway, thanks for your ideas.

Thanks,

Khanh

0 Kudos

Hey Khanh,

I am Suhas & not Susha

Cheers,

Suhas