‎2006 Jul 18 9:43 PM
Hi,
I need to do an App server download for data in a table. For example, to download data from PA0008 here is what i have.
data: test type pa0008 occurs 0 with header line.
select * from pa0008 into table test up to 10 rows.
DATA: e_file like rlgrap-filename value '/usr/sap/tmp/test1.txt'.
open dataset e_file for output in text mode encoding default.
lOOP AT test.
transfer ????? to e_file.
ENDLOOP.
close dataset e_file.
what should i write after transfer?. I need all columns from pa0008. It has columns of type decimal too.
Thanks,
Sandeep
‎2006 Jul 18 9:46 PM
If there are decimals, I would suggest that you out put the data to a str first then transfer the string. Here is a sample program.
report zrich_0001.
parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.
data: begin of itab occurs 0,
field1(20) type c,
field2(20) type c,
field3(20) type c,
end of itab.
data: str type string.
constants: con_tab type x value '09'.
* if you have a newer version, then you can use this instead.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
start-of-selection.
itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.
itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.
open dataset d1 for output in text mode.
loop at itab.
<b> concatenate itab-field1 itab-field2 itab-field2 into str
separated by con_tab.
transfer str to d1.</b>
endloop.
close dataset d1.
Transfering "TEST" will give you garbage for packed fields.
REgards,
Rich Heilman
‎2006 Jul 18 9:46 PM
Try as below
lOOP AT test.
transfer <b>test</b> to e_file.
ENDLOOP.
Regds
Manohar
‎2006 Jul 18 9:46 PM
‎2006 Jul 18 9:48 PM
‎2006 Jul 18 9:55 PM
You might be able to do this also.
report zrich_0001.
parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.
data: itab type table of pa0008 with header line.
data: str type string.
field-symbols: <fs>.
constants: con_tab type x value '09'.
* if you have a newer version, then you can use this instead.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
start-of-selection.
select * into table itab from pa0008 up to 100 rows.
open dataset d1 for output in text mode.
loop at itab.
do .
assign component sy-index of structure itab to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
str = <fs>.
else.
concatenate str <fs> into str
separated by con_tab.
endif.
enddo.
transfer str to d1.
endloop.
close dataset d1.
Regards,
Rich Heilman
‎2006 Jul 18 9:46 PM
If there are decimals, I would suggest that you out put the data to a str first then transfer the string. Here is a sample program.
report zrich_0001.
parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.
data: begin of itab occurs 0,
field1(20) type c,
field2(20) type c,
field3(20) type c,
end of itab.
data: str type string.
constants: con_tab type x value '09'.
* if you have a newer version, then you can use this instead.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
start-of-selection.
itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.
itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.
open dataset d1 for output in text mode.
loop at itab.
<b> concatenate itab-field1 itab-field2 itab-field2 into str
separated by con_tab.
transfer str to d1.</b>
endloop.
close dataset d1.
Transfering "TEST" will give you garbage for packed fields.
REgards,
Rich Heilman
‎2006 Jul 18 9:51 PM
I tried that earlier with field symbols. In other words assigning field value to a string and then writing it to app server. It worked fine with decimals, but then i faced an issue with date. It writes date in 1.1.2000 format rather than 20000101.
Here is the code for that.
do.
assign component sy-index of structure <w_wa> to <w_field>.
if sy-subrc <> 0.
exit.
endif.
describe field <w_field> output-length v_len.
write <w_field> to <w_data>+v_offset(v_len).
v_offset = v_offset + v_len.
enddo.
transfer <w_data> to p_file.
endloop.
endif.
‎2006 Jul 18 10:01 PM
How about we move the value to a type C field first.
report zrich_0001.
parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.
data: itab type table of pa0008 with header line.
data: str type string.
field-symbols: <fs>.
<b>data: c(100) type c.</b>
constants: con_tab type x value '09'.
* if you have a newer version, then you can use this instead.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
start-of-selection.
select * into table itab from pa0008 up to 100 rows.
open dataset d1 for output in text mode.
loop at itab.
do .
assign component sy-index of structure itab to <fs>.
if sy-subrc <> 0.
exit.
endif.
<b> c = <fs>.
if sy-index = 1.
str = c.
else.
concatenate str c into str
separated by con_tab.
endif.</b>
enddo.
<b> condense str no-gaps.</b>
transfer str to d1.
endloop.
close dataset d1.
This seems to work for me in my system.
Regards,
Rich Heilman
‎2006 Jul 18 10:42 PM
If you are going to read the appserver file into sap again, use open dataset in binary mode for writing and reading.
or
Use function module SAP_CONVERT_TO_TXT_FORMAT to write to file and when reading file use TEXT_CONVERT_TXT_TO_SAP to convert into PA0008 format.
type-pools: truxs.
data: itab_txt type truxs_t_text_data,
itab_line like line of itab_txt.
data: test type pa0008 occurs 0 with header line.
data: e_file like rlgrap-filename value '/tmp/testpa8.txt'.
select * from pa0008 into table test up to 10 rows.
call function 'SAP_CONVERT_TO_TXT_FORMAT'
tables
i_tab_sap_data = test[]
CHANGING
I_TAB_CONVERTED_DATA = itab_txt
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
open dataset e_file for output in binary mode.
loop at itab_txt into itab_line.
transfer itab_line to e_file.
endloop.
close dataset e_file.There are other function modules in func group TRUX, see if you can use them to write and read files.
Regards
Sridhar
Message was edited by: Sridhar K