‎2006 May 16 1:06 PM
Hi,
I'm using the FM Read_Text. I want to create a concatenated string of all the lines in TLINE. Could someone show me some sample code in which to do this.
My code so far:
REPORT zread_test.
DATA: it_lines LIKE TABLE OF tline WITH HEADER LINE.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'LTXT'
language = sy-langu
name = '000001100184'
object ='AUFK'
* IMPORTING
* HEADER =
TABLES
lines = it_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.
Data: mystring type string.
LOOP AT it_lines.
* want to append it_lines-tdline to mystring.
ENDLOOP.
WRITE: 'Full Long Text', myString.
Any help with this would be greatly appreciated.
Regards,
Philip Johannesen
‎2006 May 16 1:09 PM
Just replace the loop with the following..
LOOP AT it_lines.
concatenate mystring it_lines-tdline into mystring
separated by space.
ENDLOOP.
Regards,
Suresh Datti
‎2006 May 16 1:09 PM
Just replace the loop with the following..
LOOP AT it_lines.
concatenate mystring it_lines-tdline into mystring
separated by space.
ENDLOOP.
Regards,
Suresh Datti
‎2006 May 16 1:09 PM
LOOP AT it_lines.
concatenate MyString it_lines-tdline into MyString.
ENDLOOP.
‎2006 May 16 1:14 PM
Hai,
Replace the following code in your code.
loop at it_lines.
condense it_lines-TDLINE NO-GAPS.
concatenate mystring it_lines-tdline into mystring.
endloop.
Cheers,
Umasankar
‎2006 May 16 1:16 PM
Data: mystring type string.
LOOP AT it_lines.
* want to append it_lines-tdline to mystring.
concatenate mystring it_lines-tdline into mystring separated by space.
ENDLOOP.Regards
vijay
‎2006 May 16 1:20 PM
Hello,
Hope this helps you. The reason we dont straight away concatenate the lines with or without spaces is that read text gets the data in internal table, but you never know where the line has a space in the end or not i.e. a word could be like this.
This is the first lin
e and this is the second.
So if you concatenate it separated with spaces, you end up getting
This is the first lin e and this is the second.
regards,
Satya
The TLINE has a limitation of 132 characters, you have to do a word wrapping basically for your output. The maximum characters in a line that you can have would be 132.
DATA: it_lines LIKE TABLE OF tline WITH HEADER LINE.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'LTXT'
language = sy-langu
name = '000001100184'
object ='AUFK'
IMPORTING
HEADER =
TABLES
lines = it_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.
wrap the table it_lines to 100 characters in this case (code for subroutine is given below)
perform wrap_line tables IT_LINES
using 100
'CHAR100'.
ENDIF.
The subroutine WRAP_LINE
&----
*& Form wrap_text
&----
To wrap the text with specified length
----
-->FT_LINES Lines in the source text
-->F_LEN characters after which to be wrapped
-->F_TYPE data type
----
FORM wrap_line TABLES ft_lines STRUCTURE tline
USING f_len TYPE i
f_type TYPE c.
TYPES:
BEGIN OF ty_outtext_l,
line TYPE tdline,
END OF ty_outtext_l.
DATA:
t_outtext_l TYPE STANDARD TABLE OF ty_outtext_l,
t_lines_l LIKE tline OCCURS 0 WITH HEADER LINE,
st_outtext_l TYPE ty_outtext_l,
st_lines_l TYPE tline,
w_string_l TYPE string.
CHECK NOT ft_lines[] IS INITIAL.
t_lines_l[] = ft_lines[].
REFRESH ft_lines.
CLEAR: ft_lines,
t_lines_l,
w_string_l.
IF NOT f_type IS INITIAL.
LOOP AT t_lines_l.
w_tabix = sy-tabix + 1.
IF t_lines_l-tdformat <> c_contline AND
t_lines_l-tdformat <> c_null.
CONCATENATE w_string_l t_lines_l-tdline INTO w_string_l.
ELSE.
CONCATENATE w_string_l t_lines_l-tdline INTO w_string_l
SEPARATED BY space.
ENDIF.
CLEAR st_lines_l.
READ TABLE t_lines_l INTO st_lines_l INDEX w_tabix.
IF st_lines_l-tdformat = c_asterisk. "Value *
REFRESH t_outtext_l.
CLEAR t_outtext_l.
CALL METHOD z_cl_rs_utilities=>string_separator
EXPORTING
i_string = w_string_l
i_length = f_len
i_field_type = f_type
CHANGING
it_table_string = t_outtext_l.
IF sy-subrc IS INITIAL.
CLEAR st_outtext_l.
LOOP AT t_outtext_l INTO st_outtext_l.
ft_lines-tdline = st_outtext_l-line.
APPEND ft_lines.
ENDLOOP. "LOOP AT t_outtext_l INTO st_outtext_l.
ENDIF. "IF sy-subrc IS INITIAL.
CLEAR w_string_l.
ENDIF.
ENDLOOP."loop at t_lines_l
REFRESH t_outtext_l.
CLEAR t_outtext_l.
CALL METHOD z_cl_rs_utilities=>string_separator
EXPORTING
i_string = w_string_l
i_length = f_len
i_field_type = f_type
CHANGING
it_table_string = t_outtext_l.
IF sy-subrc IS INITIAL.
CLEAR st_outtext_l.
LOOP AT t_outtext_l INTO st_outtext_l.
ft_lines-tdline = st_outtext_l-line.
APPEND ft_lines.
ENDLOOP. "LOOP AT t_outtext_l INTO st_outtext_l.
ENDIF. "IF sy-subrc IS INITIAL.
CLEAR w_string_l.
ELSE.
ft_lines[] = t_lines_l[].
ENDIF. "IF NOT f_type IS INITIAL.
ENDFORM. " wrap_line
CLASS METHOD STRING_SEPARATOR
*/----
*/ Class Method 'STRING_SEPARATOR':
*/----
*/ ===> I_STRING String value for processing
*/ ===> I_LENGTH Separate String into ? Lengths (<=255)
*/ <=== IT_TABLE_STRING Returned Separated String values
*/----
METHOD STRING_SEPARATOR.
*/----
*/ Method Field Symbols:
*/----
FIELD-SYMBOLS:
<FS_LTEXT> TYPE ANY. "Field Symbol for LTEXT
DATA:
W_COUNT type I.
Generate Run-Time Variable W_LTEXT_COPY.
CREATE DATA W_LTEXT_COPY type (I_FIELD_TYPE).
data type of I_FIELD_TYPE is FIELDNAME
ASSIGN: W_LTEXT_COPY->* TO <FS_LTEXT>.
Check the value for Import Parameter I_LENGTH.
IF ( I_LENGTH IS INITIAL ) OR
( I_LENGTH < C_LENGTH_MINIMUM ) OR "Value of min. 1
( I_LENGTH > C_LENGTH_MAXIMUM ). "Value of max. 132
Stop processing...
RAISE: INCORRECT_LENGTH.
ENDIF.
Copy Import Parameter I_STRING.
CLEAR: W_STRING. W_STRING = I_STRING.
Re-Set Internal Table T_TEXTS.
REFRESH: T_TEXTS.
Calculate Maximum Work Area.
COMPUTE: W_LIMIT = ( I_LENGTH - 1 ).
Calculate the Total Length for the Import Parameter I_STRING. "Data type string
CLEAR: W_TOTAL_LENGTH.
COMPUTE: W_TOTAL_LENGTH = STRLEN( W_STRING ).
Re-Set Continue Work Area.
CLEAR: W_CONTINUE.
Continue according to the Total Length calulated.
WHILE ( W_CONTINUE = SPACE ).
Check the Total Length exceeds the allowed Length.
IF ( W_TOTAL_LENGTH > I_LENGTH ).
Copy the first ? characters to a Work Area.
CLEAR: <FS_LTEXT>,
W_COUNT.
<FS_LTEXT> = W_STRING(I_LENGTH).
Delete the last word of the Text only...
WHILE ( <FS_LTEXT>+W_LIMIT(1) <> SPACE ).
Move Text to the Right.
SHIFT <FS_LTEXT> BY 1 PLACES RIGHT.
W_COUNT = W_COUNT + 1.
ENDWHILE.
Move entire Text to the Left.
CONDENSE: <FS_LTEXT>.
Cater for a null Text value.
IF ( <FS_LTEXT> = SPACE ).
Copy the first ? characters to a Work Area.
<FS_LTEXT> = W_STRING(I_LENGTH).
ENDIF.
Save details to Internal Table T_TEXTS.
CLEAR: ST_TEXTS.
ST_TEXTS = <FS_LTEXT>.
IF ( I_LENGTH <> W_COUNT ). "NS01
SHIFT ST_TEXTS BY W_COUNT PLACES LEFT.
ENDIF. "NS01
APPEND ST_TEXTS TO T_TEXTS. " a table type with single field of data type 132 characters
Calculate the Output Length of the Text just copied.
CLEAR: W_TOTAL_LENGTH.
COMPUTE: W_TOTAL_LENGTH = STRLEN( <FS_LTEXT> ).
COMPUTE: W_TOTAL_LENGTH = I_LENGTH - W_COUNT.
IF ( I_LENGTH EQ W_COUNT ). "NS01
W_TOTAL_LENGTH = I_LENGTH. "NS01
ENDIF. "NS01
Remove the copied Text from the String.
SHIFT W_STRING BY W_TOTAL_LENGTH PLACES LEFT.
CONDENSE: W_STRING.
Calculate the Total Length for the Import Parameter I_STRING.
CLEAR: W_TOTAL_LENGTH.
COMPUTE: W_TOTAL_LENGTH = STRLEN( W_STRING ).
ELSE.
Copy the first ? characters to a Work Area.
CLEAR: <FS_LTEXT>.
<FS_LTEXT> = W_STRING.
Move entire Text to the Left.
CONDENSE: <FS_LTEXT>.
Save details to Internal Table T_TEXTS.
CLEAR: ST_TEXTS.
ST_TEXTS = <FS_LTEXT>.
APPEND ST_TEXTS TO T_TEXTS.
Set Continue Indicator.
W_CONTINUE = C_SELECTED.
ENDIF.
ENDWHILE.
Generate Export Parameter IT_TABLE_STRING.
IT_TABLE_STRING[] = T_TEXTS[].
ENDMETHOD.
Message was edited by: Satyadev Dutta
Message was edited by: Satyadev Dutta
‎2006 May 16 1:26 PM
Hi Philip,
try
LOOP AT IT_LINES.
concatenate mystring IT_LINES-TDLINE into mystring.
ENDLOOP.
*
Hope it helps.
Regards, Dieter
‎2006 May 16 1:35 PM
Philip,
If your question has been answered, please reward points accordingly and close the thread.
If not, please provide more details of your problem.
Thanks!
‎2006 May 16 2:50 PM
Points awarded as promised.
Many thanks for all your quick responses.
Regards,
Philip Johannesen