on 05-16-2006 2:56 PM
i'm posting this QA again becuse its very important to me and i tried all the answer and did not .
i download ztable into file.txt (gui_download)
my problem:
i want the field to download as is , if matnr is 10 and in data element 18 i need 1o and 8 space and after that i need ',' delimeter.
i made loop that make ',' at the end of matnr but it takes the space, i also add WRITE_FIELD_SEPARATOR = ','
but i get err and it not make this
HELP.
Hi Liat,
Try this code.
data: begin of it_material occurs 0,
matnr like mara-matnr,
delim1,
maktx like makt-maktx,
delim2,
meins like mara-meins,
-
-
end of it_material,
file your table with data...
at the end ... before wring it to a file do the following..
data it_string(250) type c occurs 0 with header line.
loop at it_material.
move ',' to: it_material-delim1,
it_material-delim2,
-
-
move it_material to it_string.
append it_string.
endloop.
call function 'GUI_DOWNLOAD'
exporting filename = 'C:/test.txt'
tables data_tab = it_string
exceptions others = 22.
Thanks,
Susmitha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please see the following program, it picks material number and plant and writes a comma delimited file to the C:\ drive. It writes the material number as internal format.
report zrich_0001 .
data: begin of itab occurs 0,
matnr type mara-matnr,
werks type marc-werks,
end of itab.
data: iflat type table of string,
xflat type string.
field-symbols: <fs>.
select mara~matnr marc~werks into table itab
from mara
inner join marc
on mara~matnr = marc~matnr
up to 100 rows.
loop at itab.
do.
assign component sy-index of structure itab to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
xflat = <fs>.
else.
concatenate xflat <fs> into xflat separated by ','.
endif.
enddo.
append xflat to iflat.
endloop.
call function 'GUI_DOWNLOAD'
exporting
filename = 'C:text.txt'
tables
data_tab = iflat
exceptions
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
others = 22.
Regards,
RIch Heilman
there is it:
i made a Ztable of mine.
REPORT ZDW_ZCAL_MSTR_M_DWLO MESSAGE-ID bd..
tables : zcal.
data : begin of i_tab occurs 0.
include structure zcal.
data: end of i_tab.
DATA: v_subrc(2),
v_recswritten(6).
data: iflat type table of string,
xflat type string.
field-symbols: <fs>.
PARAMETERS: p_file(80)
DEFAULT 'C:\Documents and Settings\zcal.txt'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = p_file
mask = ',*.txt.'
mode = 'O'
title = 'UDOWNLOAD File'(078)
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
leave screen.
ENDIF.
START-OF-SELECTION.
DATA: filename TYPE string.
filename = p_file.
SELECT * FROM zcal INTO TABLE I_TAB.
Loop at i_tab.
clear i_tab-mandt.
modify i_tab. " from w_tab.
endloop.
loop at i_tab.
do.
assign component sy-index of structure i_tab to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
xflat = <fs>.
else.
concatenate xflat <fs> into xflat separated by ','.
endif.
enddo.
append xflat to iflat.
endloop.
If text fields appear right justified or columns not lined up in
*output set
TRUNC_TRAILING_BLANKS to X
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = filename
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = iflat .
SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *
IF sy-subrc <> 0.
v_subrc = sy-subrc.
MESSAGE e899 WITH 'File Open Error' v_subrc.
ENDIF.
DESCRIBE TABLE i_tab LINES v_recswritten.
MESSAGE i899 WITH v_recswritten 'Records Written from zcal_mstr_m'.
It appears to me, that if you are not getting the data as needed, then it is not being stored that way in the database. Notice in my program above, I'm not doing anything special with the data, just pulling it from database.
Check to see how the data is being stored in ZCAL.
Regards,
Rich Heilman
Hi,
i too had many fields with all sales related fields which was an outbound interface going to a legacy system.
As Legacy system requires each field with fixed length & field separator, i implemented it in that passion.
may be coding part is more but that time i used that technique.in that first i populated each field with its offset (based on its length)
regards
Srikanth
Notice, here I have modified your program to use MARA instead of ZCAL. Notice, that in the DO loop, I'm skipping over the first field MANDT. No need for the other loop to clear it out. Also, you can see that the MATNR fields is 18 characters(left zero filled). Are you see the same results?
report zdw_zcal_mstr_m_dwlo message-id bd..
data : begin of i_tab occurs 0.
<b> include structure mara.</b>
data: end of i_tab.
data: v_subrc(2),
v_recswritten(6).
data: iflat type table of string,
xflat type string.
field-symbols: <fs>.
parameters: p_file(80)
default 'C:test.txt'.
at selection-screen on value-request for p_file.
call function 'WS_FILENAME_GET'
exporting
def_filename = p_file
mask = ',*.txt.'
mode = 'O'
title = 'UDOWNLOAD File'(078)
importing
filename = p_file
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
if sy-subrc <> 0.
leave screen.
endif.
start-of-selection.
data: filename type string.
filename = p_file.
<b> select * from mara into table i_tab up to 100 rows.</b>
<b>* loop at i_tab.
* clear i_tab-mandt.
* modify i_tab. " from w_tab.
* endloop.</b>
loop at i_tab.
do.
<b> check sy-index > 1. " Skip over MANDT</b>
assign component sy-index of structure i_tab to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 2.
xflat = <fs>.
else.
concatenate xflat <fs> into xflat separated by ','.
endif.
enddo.
append xflat to iflat.
endloop.
* If text fields appear right justified or columns not lined up in
*output set
* TRUNC_TRAILING_BLANKS to X
call function 'GUI_DOWNLOAD'
exporting
* BIN_FILESIZE =
filename = filename
filetype = 'ASC'
* APPEND = ' '
write_field_separator = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = iflat .
* SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *
if sy-subrc <> 0.
v_subrc = sy-subrc.
message e899 with 'File Open Error' v_subrc.
endif.
describe table i_tab lines v_recswritten.
message i899 with v_recswritten 'Records Written from zcal_mstr_m'.
Regards,
Rich Heilman
Ok, check this. Notice the changes that I've made to the program. This will fill the rest of the space with "%" sign, after the string is built, then you can replace it with space.
report zdw_zcal_mstr_m_dwlo message-id bd..
data : begin of i_tab occurs 0.
include structure mara.
data: end of i_tab.
data: v_subrc(2),
v_recswritten(6).
data: iflat type table of string,
xflat type string.
field-symbols: <fs>.
parameters: p_file(80)
default 'C:test.txt'.
at selection-screen on value-request for p_file.
call function 'WS_FILENAME_GET'
exporting
def_filename = p_file
mask = ',*.txt.'
mode = 'O'
title = 'UDOWNLOAD File'(078)
importing
filename = p_file
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
if sy-subrc <> 0.
leave screen.
endif.
start-of-selection.
data: filename type string.
filename = p_file.
select * from mara into table i_tab up to 100 rows.
.
* loop at i_tab.
* clear i_tab-mandt.
* modify i_tab. " from w_tab.
* endloop.
loop at i_tab.
do.
check sy-index > 1. " Skip over MANDT
assign component sy-index of structure i_tab to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 2.
<b> overlay <fs> with '%%%%%%%%%%%%%%%%%%'.</b>
xflat = <fs>.
else.
concatenate xflat <fs> into xflat separated by ','.
endif.
enddo.
<b> translate xflat using '% '.</b>
append xflat to iflat.
endloop.
* If text fields appear right justified or columns not lined up in
*output set
* TRUNC_TRAILING_BLANKS to X
call function 'GUI_DOWNLOAD'
exporting
* BIN_FILESIZE =
filename = filename
filetype = 'ASC'
* APPEND = ' '
write_field_separator = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = iflat .
* SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *
if sy-subrc <> 0.
v_subrc = sy-subrc.
message e899 with 'File Open Error' v_subrc.
endif.
describe table i_tab lines v_recswritten.
message i899 with v_recswritten 'Records Written from zcal_mstr_m'.
Regards,
Rich Heilman
hi friends
i mark it as answered
but i tried it again and i have problem.
if i make FM gui download to ztable i get
10 20 30 40 500 555555 99999
and if i made your solution all of them
i get
10,20,30....
or
0010,0020,.......
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
YOu can try using CONVERSION_EXIT_ALPHA_OUTPUT to fields to use actual field length. For example:
DATA : BEGIN OF t_output OCCURS 0,
matnr TYPE mara-matnr,
werks TYPE marc-werks,
END OF t_output.
DATA : BEGIN OF t_output1 OCCURS 0,
string TYPE string,
END OF t_output1.
t_output-matnr = '000000000010000000'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = t_output-matnr
IMPORTING
output = t_output-matnr.
t_output-werks = '0001'.
CONCATENATE t_output-matnr t_output-werks INTO t_output1-string.
APPEND t_output1.
APPEND t_output.
t_output-matnr = '000000000000010001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = t_output-matnr
IMPORTING
output = t_output-matnr.
t_output-werks = '0001'.
CONCATENATE t_output-matnr t_output-werks INTO t_output1-string.
APPEND t_output1.
APPEND t_output.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'ASC'
filename = 'c:\test.txt'
wk1_t_format = '1'
TABLES
data_tab = t_output1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can try out this.
define an internal table as below.
data : begin of IT_DOWNLOAD OCCURS 0,
LINE(400) TYPE C,
end of it_download.
now populate your values to it_download-line based on offset instead of just populating values.
check below code(for example)
loop at it_mara.
it_download-line+0(18) = it_mara-matnr.
it_download-line+18(1) = ','.
*--and so on..
*--
it_download-line+19(4) = it_mara-mtart.
it_download-line+23(1) = ','.
*--and so onnnnn
append it_download.
endloop.
*--now IT_DOWNLOAD will have data as you require with spaces.
now just call GUI_DOWNLOAD WITH this internal table & file type as ASC.
regards
srikanth
Message was edited by: Srikanth Kidambi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Liat,
IN GUI_DOWNLOAD give the file type as <b>'DAT'</b> instead of <b>'ASC</b>' i guess by this you can achieve the same...
Regards,
Santosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.