2008 Nov 20 5:54 AM
Hi all,
I have my data in my final internal table.
I want to transfer this data to a text file on the application server
using the transfer dataset command.
I am able to do that.
But, what I want to learn is .... how to add a separator like a comma between each field.
So that when I open my text file, each field value will be separated by a comma.
Inputs Please.
Thanking you all in advance.
Hari KIran
2008 Nov 20 6:01 AM
Hi,
Before the transfering data to Application server...
loop thorugh the internal table and take the data into string by cancatenatind all the field values seperated by comma and then pass the string to application server.
2008 Nov 20 6:01 AM
Hi,
Before the transfering data to Application server...
loop thorugh the internal table and take the data into string by cancatenatind all the field values seperated by comma and then pass the string to application server.
2008 Nov 20 6:04 AM
Hi,
Thank you for replying.
I will try that out
and get back.
Regards,
Hari Kiran
2008 Nov 20 6:25 AM
Hi Avinash,
It worked like magic.
Thank you.
I am able to place data in the notepad separated by comma.
I am assigning you points. I don't wamt to close this thread just yet because there is one more slight problem.
One of my fields is PA0002-ANZKD. Datatype is DEC 3 [No. of children]
I was getting the message that the data type of this field has to be of type C, D , N or string.
when I made the necessary change to the datatype and tried to execute, I was getting short dump saying data could not be inserted as field type mismatch.
I commented this field and executed and the program worked.
I got the results I wanted.
But, I need to include this field in my text file.
Hope you/ anyone can enlighten me more on this.
Warm regards,
Hari Kiran
2008 Nov 20 6:49 AM
Move this field PA0002-ANZKD content to a character variable and pass this character variable to concatenate statement
eg,
data : l_anzkd(4).
move PA0002-ANZKD to l_anzkd.
concatenate ........... l_anzkd ...... into ...... separated by ','.
2008 Nov 20 6:54 AM
Hi Kiran
Pass your internal table to this function module and check output of ITAB.
DATA : IT_PA0002 TYPE TABLE OF PA0002,
ITAB(4096) TYPE C occurs 0.
SELECT * FROM PA0002
INTO TABLE IT_PA0002 UP TO 15 ROWS.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
i_field_seperator = ','
* I_LINE_HEADER =
* I_FILENAME =
* I_APPL_KEEP = ' '
tables
i_tab_sap_data = IT_PA0002
CHANGING
I_TAB_CONVERTED_DATA = ITAB
* EXCEPTIONS
* CONVERSION_FAILED = 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.
WRITE 'HAI'.
Regards
2008 Nov 20 6:56 AM
Hi all,
I was able to solve the problem.
I was having 2 internal tables .
One was to pull data from PA0002 table.
and then there was the final Internal table.
I kept the data type of ANZKD as it is in PA0002 internal table.
But I changed the data type of ANZKD to ....ANZKD(3) type N in the final
internal table.
So, first the data was pulled from the PA0002 table and placed in its internal table.
Then I moved it to the final internal table.
No issues got raised and data got placed in the flat file.
Thank you all,
Regards,
Hari Kiran
2008 Nov 20 6:09 AM
Data : Begin of ig_final Occurs 0,
txt(512),
end of ig_final.
LOOP AT ig_tab INTO wg_tab.
concatenate wg_tab-f1 wg_tab-f2 ...... into ig_final-txt separated by ','. "concatenate all the fields of u r table
APPEND ig_final.
CLEAR : wg_tab, ig_final.
ENDLOOP.
OPEN DATASET f_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
MESSAGE a398(00) WITH text-019 f_file2
text-020 sy-subrc.
ENDIF.
LOOP AT ig_final.
TRANSFER ig_final TO f_file LENGTH 512.
ENDLOOP.
CLOSE DATASET f_file.
2008 Nov 20 6:09 AM
Hi Kiran,
Try using this function module. It can add separators.
SAP_CONVERT_TO_TEX_FORMAT
Regards
2008 Nov 20 6:11 AM
Hi,
You can do like below.
OPEN DATASET PATH
FOR APPENDING
IN TEXT MODE
ENCODING DEFAULT.
LOOP AT IT_FINAL.
CONCATENATE IT_FINAL-FIELD1 IT_FINAL-FIELD2 ETC INTO T_STRING SEPARATED BY ','.
TRANSFER T_STRING TO PATH.
ENDLOOP.
CLOSE DATASET PATH.
Regards,
Mithilesh Gor
2008 Nov 20 6:22 AM
Hi Hari Kiran,
Please see the below Logic.
data: w_var(50) TYPE C.
Constants: con_comma VALUE '#'.
Open data set to write field on the application server
OPEN DATASET w_filename FOR OUTPUT
IN TEXT MODE
ENCODING DEFAULT.
LOOP AT it_data INTO wa_data.
clear w_var.
w_var(10) = wa_data-XBLNR.
w_var+10(1) = con_comma.
write wa_data-augdt to w_var+11(10).
w_var+21(1) = con_comma.
write wa_data-wrbtr to w_var+22(20).
TRANSFER w_var TO w_filename.
ENDLOOP.
Close the file
CLOSE DATASET w_filename.
Here Suppose your data is in it_data.
then change your code like this.
thanks,