09-19-2007 4:48 AM
Hi Experts,
Pls. clarify my simple doubts, in data EXTRACTing prog.,(data extract from SAP to text file in Application server, prog. runs in back ground)
For the Dataware house mapping, I hv been asked to make the following changes,
1) Presently, there is NO column headings in Text file, so I need to add the column Headings - How to get it done?
2) presently, its NOT tab deliminated, so, I need to make it to TAB deliminated- How to achieve it?
I am here paste some piece of code, so that U will get understand well.
PERFORM open_dataset_zdata_whouse_04.
DESCRIBE FIELD i_tab LENGTH tfr_length IN BYTE MODE.
LOOP AT i_itab.
TRANSFER i_itab TO transfer_file1 LENGTH tfr_length.
ENDLOOP.
CLOSE DATASET transfer_file1.
ThaNQ.
09-19-2007 4:55 AM
See the below code :
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.
translate itab using ' # '.
concatenate itab-field1 itab-field2 itab-field2
into str
separated by con_tab.
translate str using ' # '.
transfer str to d1.
endloop.
close dataset d1.
above code for tab delimited.
for heading then you can write simple logic in the loop of internal table
loop at itab.
if sy-tabix = 1'
move heading data to file.
endif.
endloop.
Thanks
Seshu
09-19-2007 4:55 AM
See the below code :
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.
translate itab using ' # '.
concatenate itab-field1 itab-field2 itab-field2
into str
separated by con_tab.
translate str using ' # '.
transfer str to d1.
endloop.
close dataset d1.
above code for tab delimited.
for heading then you can write simple logic in the loop of internal table
loop at itab.
if sy-tabix = 1'
move heading data to file.
endif.
endloop.
Thanks
Seshu
09-19-2007 5:29 AM
thanq,
I paste ur code and observed the behaviour in debug mode. ok, i picked some file name from AL11 and i used, but getting sy-subrc = 8, will look into it.
but, pls. culd u explain me in detail, abt. th folllowing, (like,
1) Why u used #; Wht does it mean?
2) in 2nd statemnt, is it that all spaces r changed/transalated to #?
3) con_tab = 09, Why?
4) again Why ur translating with #, in str?
5) mine is 4.6, I think I can use, <i><b>cl_abap_char_utilities=>HORIZONTAL_TAB.</b></i>
<i><b>loop at itab.
translate itab using ' # '.
concatenate itab-field1 itab-field2 itab-field2
into str
separated by con_tab.
translate str using ' # '.
transfer str to d1.
endloop.</b></i>
thanq.
09-19-2007 1:53 PM
thanq,
pls. can u clarify my doubts. like,
Why do u used # , Is it mean that SAP take it asTAB deliminated?
Why 09 mentioned?
why 2nd transöalted into str?
thanq.
09-19-2007 2:14 PM
Hi..Shikar..
This is the Simple way you can download the ITAB with Tab delimiter:
DATA : V_REC(200).
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ITAB INTO WA.
Concatenate WA-FIELD1 WA-FIELD2
INTO V_REC
SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
TRANSFER V_REC TO P_FILE.
ENDLOOP.
CLOSE DATASET P_FILE.
Note: if there are any Numeric fields ( Type I, P, F) In your ITAB then before CONCATENATE you have to Move them to Char fields ..
Reward if Helpful.
09-19-2007 2:26 PM
09 is the hexa decimal value ,i posted one program ,i got this program from Rich .
Sorry for late reply.
- it means space
either you can use concatenate field1 field2 into field3 separated by space ,or you can use rich program.
When you download the data into application server in certain path,you get values
123#abcd#text -> # - means space.
Thanks
Seshu
09-19-2007 4:08 PM
thanq,
When I see in T code> AL 11-> /tmp file---> I got the column headings very exactly like,(I implemeted ur code, which is for TAB deliminated) at the first row.
Column11#Column12#COlumn13#Total
so Is it OK? I mean, Is the TAB deliminated is working? Am I getting correctly the data in text file?
thanq,
Message was edited by:
Srikhar
Message was edited by:
Srikhar
09-19-2007 4:28 PM
thanq,
am getting the data, as I mentioned in above response to Varma. So, pls. let me know that iS IT OK?
THANQ.
09-19-2007 4:42 PM
Yes Srikhar,output is correct .
It is like space and it works like tab.
Thanks
Seshu
09-20-2007 5:05 AM
Hi Srikhar..
In AL11 the Tab delimited file shows the '#' as delimiter. So it is Ok.
regards.
Varma