‎2011 Mar 15 9:10 AM
hi, i have a quick question and im new in abap.
lets say i have an internal table gt_output and it has 10 fields and each fields are filled with weekly data.lets say i have 5 rows of data. how do i split the column/fields so that every field can become one text file?
thank you.
‎2011 Mar 15 9:14 AM
Hi,
Create two new tables with the fields.
Loop on main table and append corresponding fields from main to other tables.
‎2011 Mar 15 9:14 AM
Hi,
Create two new tables with the fields.
Loop on main table and append corresponding fields from main to other tables.
‎2011 Mar 15 9:18 AM
Hi,
well if i understood correctly, you have data in one table and you want to download data in diff files for each week.
1) Are you downloading it on PC or UNIX
2) Do one thing....
For example: You have Below table
COL1 COL2 COL3
1WK X Y
1WK X1 Y1
2WK X2 Y2
3WK X Y
CREATE ANOTHER TABLE WITH SAME STRUCTURE
LOOP ON YOUR TABLE.
ON CHANGE OF COL1.
YOURNEWTABLE = MAINTABLE
DELETE YOURNEWTABLE WHERE COL1 NE YOURMAINTABLE-COL1
****NOW YOU WILL HAVE ONLY 1WK DATA IN YOURNEWTABLE
DOWNLOAD THE YOURNEWTABLE.
****IN 2ND LOOK, YOU WILL GET 2WK DATE, AND NEXT 3 WK DATA SO ON
ENDON.
ENDLOOP
Hope it help.
br,
Piyush
‎2011 Mar 15 9:23 AM
lets say i have 10 fields in an internal table
column c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
row1 1 2 3 4 5 6 7 8 9 10
row2 11 12 13 14 15 16 17 18 19 20.
my requirement is to convert every column into a file..so thats means i will have 10 text file with 2 rows of data.
‎2011 Mar 15 9:32 AM
loop on yourtable.
younewtable1-col = yourtable-col1
append younewtable1
younewtable2-col = yourtable-col2
append younewtable2.
younewtable3-col = yourtable-col3
append younewtable3.
and so on....
if there are more col...better to use field symbols.
endloop.
‎2011 Mar 15 9:36 AM
So if you're internal table has 10 columns, you need 10 files. If you have 50 columns you need 50 files.
a possible soultion would be:
data: gt_string type table of string.
data: wa_string type string.
data: gv_file type string.
field-symbols: <fs_field> type any.
loop at gt_output into wa_output.
do.
assign component sy-index of structure wa_output to <fs_field>.
if sy-subrc ne 0.
exit.
endif.
concatenate 'c:\file_' sy-index '.txt' into gv_file.
wa_string = <fs_field>.
clear gt_string[].
append wa_string to gt_string.
call method cl_gui_frontend_services=>gui_download
exporting
filename = gv_file
append = 'X'
filetype = 'ASC'
changing
data_tab = gt_string[]
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
not_supported_by_gui = 22
error_no_gui = 23
others = 24.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
enddo.
endloop.
‎2011 Mar 15 9:37 AM
in my requirement i have 82 columns..so i will need to split to 82 internal tables?
how to use field symbol? care to clarify?
‎2011 Mar 15 10:00 AM
actually i still dont understand..it's helpful though..but how to assign the field symbol so that all the rows in the collumn included into 1 file? and next column with rows in another file?
‎2011 Mar 15 10:34 AM
assign component sy-index of structure wa_output to <fs_field>.
if sy-subrc ne 0.
exit.
endif.
concatenate 'c:\file_' sy-index '.txt' into gv_file.
wa_string = <fs_field>.
clear gt_string[].
append wa_string to gt_string.Basically, each column value is captured in an internal table. And that internal table always hold one single record: the value of the column assigned to the field-symbol. And the content of that internal table is APPENDED to a file.
As you can see, each column will get its own filename:
concatenate 'c:\file_' sy-index '.txt' into gv_file.So if you have 2 columns and 2 rows like:
C1 C2
A B
C D
Then during the LOOP
on the first record:
1. value A is appended to file 'c:\file_1.txt
2. value B is appended to file 'c:\file_2.txt
on the second record
1. value C is appended to file 'c:\file_1.txt
2. value D is appended to file 'c:\file_2.txt
Hope you understand now.
‎2011 Mar 15 5:34 PM
my bad..i accidently delete a few lines and it makes my program creating files for every field..i understand your program now its very helpful...
but i still dont understand how field symbol works as i now having a problem..im trying to format the string(text) before
downloading them as a text file. i need to put header and then format them according to my requirement..i tried to change the field symbol, and also format them according according to my requirement...but no luck..
eg:
column : matnr wk01 wk02
rows : 1234 1000 10001
1245 1099 1098
file 1.
matnr qty
1234 1000
1245 1099
file2.
matnr qty
1234 10001
1245 1098
my requirement is something like this..and i have almost 100 field/column in the internal table. so i will have almost 100 txt files.
do i need to create 100 internal table? how do i use field symbol?
thank you in advance..
‎2011 Mar 16 1:53 AM
hi, regarding the field symbol, care to explain how to use it? i still haven;t had any clue how to program as per my requirement.
thank you.
‎2011 Mar 17 9:07 AM
thank you guys.your tips are helpful.i have found the way already...i created global structure and use field symbol.