2008 Apr 11 12:21 PM
Hi All,
I am trying to convert each row of internal table into string using the function module SAP_CONVERT_TO_TXT_FORMAT . Using this I can able to convert into string. But if one of the field is blank, it is concatenating the field and not showing the space for that field. In that place, the next field value is coming.
I want to pass the internal table line items to the string, without concetanating the field values.
Can anyone guide me.
Thanks in advance.
Regards
Ramesh.
2019 Oct 15 4:12 PM
My proposal:
CONCATENATE LINES OF lt_string_table INTO l_single_string SEPARATED BY cl_abap_char_utilities=>cr_lf.
2008 Apr 11 12:27 PM
Why don´t you just copy the content of the whole workarea to a string linewise?
2008 Apr 11 12:30 PM
Hi,
I have 45 fields in my internal table. It is Laborious process to do that.
2008 Apr 11 1:23 PM
Hi,
Thanks for your suggestion. It is resolved.
Regards
Ramesh.
2008 Apr 14 4:10 PM
How was it solved?
For people who are interested, I had the same issue, I finally succeeded with the following code (it may be enhanced by adding a length parameter so that it can be used after cl_gui_frontend_services=>gui_upload to convert text table into string:
REPORT z_merge_itab_respecting_blanks.
DATA it TYPE TABLE OF char20 WITH HEADER LINE.
DATA v TYPE string.
APPEND 'xxxj' TO it.
APPEND 'jj' TO it.
PERFORM table_2_string USING it[] CHANGING v.
WRITE v. "displays xxxj jj
FORM table_2_string USING it TYPE ANY TABLE CHANGING v TYPE string.
FIELD-SYMBOLS <z> TYPE ANY.
DATA str TYPE string.
DATA len TYPE i.
DATA j TYPE i.
DATA blanks TYPE string.
CLEAR v.
LOOP AT it ASSIGNING <z>.
EXIT.
ENDLOOP.
IF sy-subrc EQ 0.
DESCRIBE FIELD <z> LENGTH len IN CHARACTER MODE.
SHIFT blanks RIGHT BY len PLACES.
LOOP AT it ASSIGNING <z>.
str = <z>.
j = len - STRLEN( str ).
IF j EQ 0.
CONCATENATE v str INTO v.
ELSE.
CONCATENATE v str blanks(j) INTO v.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "table_2_string
2008 Apr 15 10:28 AM
Instead of coding yourself the conversion, you can use function module SWA_STRING_FROM_TABLE (available in any sap install) :
* The following converts an internal table into string
* Demo : internal table with 2 lines of 5 characters each:
* ' xxx ' and ' hhh ' is converted into
* ' xxx hhh ' (10 characters long, with one trailing space)
REPORT zz_table_to_string.
DATA itab1 TYPE TABLE OF char5.
DATA str TYPE string.
APPEND ' xxx ' TO itab1.
APPEND ' hhh ' TO itab1.
CALL FUNCTION 'SWA_STRING_FROM_TABLE'
EXPORTING
character_table = itab1
* NUMBER_OF_CHARACTERS =
* LINE_SIZE =
keep_trailing_spaces = 'X'
* CHECK_TABLE_TYPE = ' '
IMPORTING
character_string = str
EXCEPTIONS
no_flat_charlike_structure = 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.
data i type i.
i = strlen( str ).
assert i = 10.
data test(10) type c.
test = str.
assert test = ' xxx hhh'.
write : / str, i.
2014 Jul 03 8:07 AM
How can I replace the space between two string with a comma for the example shown above?
I am expecting for an output like:
xxx, hhh
2014 Jul 03 8:47 AM
Hi,
If you are planning to create CSV file I suggest you follow the rules of CSV .
Comma-separated values - Wikipedia, the free encyclopedia
Regards.
2019 Oct 15 4:12 PM
My proposal:
CONCATENATE LINES OF lt_string_table INTO l_single_string SEPARATED BY cl_abap_char_utilities=>cr_lf.