2005 Jul 20 10:31 AM
Hi abaers,
i need to transfer the internal table data to file,,this file to create in application server.
internal table lineitems contains 100 fields...
i tried in the following method: but 100 fields i have to move each and evry field to t_output-data.. so it is becoming complex.
data: begin of t_output occurs 0,
data(800),
end of t_output.
loop at lineitems.
t_output-data(4) = lineitems-COMP_CODE.
t_output-data+4(10) = lineitems-VENDOR.
...
append t_output.
clear t_output.
endloop.
open dataset filename for output in text mode encoding default.
loop at t_output.
transfer t_output-data to filename.
clear t_outpu-data.
endloop.
close dataset filename.
endif.
is there any other method to do direct transfer from internal table to file..
2005 Jul 20 10:35 AM
Hi,
loop at lineitems.
concatenate comp_code vendor ... into t_output-data.
append t_output.
endloop.
2005 Jul 20 10:35 AM
Hi,
loop at lineitems.
concatenate comp_code vendor ... into t_output-data.
append t_output.
endloop.
2005 Jul 20 10:38 AM
Hi,
Depends on whether u want a fixed length record in APPLN server or a file with a delimeter. Looking at ur code it seems like fixed length record in which case there is no shortcut method.
With regards,
Sharath.
2005 Jul 20 12:32 PM
2005 Jul 20 2:30 PM
Why don't you declare:
data: begin of t_output occurs 0.
include structure lineitems.
data: end of t_output.
and then move the fields.
Rob
2005 Jul 20 2:47 PM
Hi,
I think FM: GET_COMPONENT_LIST would be very useful to u.
i have attached the complete code and it's working absolutely fine with me.
Code **********
types: begin of type_item,
f1(3),
f2(3),
f3(3),
f4(3),
end of type_item.
types: begin of type_data,
data(800),
end of type_data.
data : lineitems type table of type_item with header line,
t_output type table of type_data with header line,
fieldlist type table of RSTRUCINFO with header line.
lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
lineitems-f4 = 'a4'.
append lineitems.
lineitems-f1 = 'b1'.
lineitems-f2 = 'b2'.
lineitems-f3 = 'b3'.
lineitems-f4 = 'b4'.
append lineitems.
lineitems-f1 = 'c1'.
lineitems-f2 = 'c2'.
lineitems-f3 = 'c3'.
lineitems-f4 = 'c4'.
append lineitems.
lineitems-f1 = 'd1'.
lineitems-f2 = 'd2'.
lineitems-f3 = 'd3'.
lineitems-f4 = 'd4'.
append lineitems.
field-symbols : <fs> type any.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = sy-repid
FIELDNAME = 'lineitems'
TABLES
COMPONENTS = fieldlist.
data : fieldname like fieldlist-compname,data_line type type_data,dref
type ref to data.
format color 3.
loop at lineitems REFERENCE INTO dref. .
loop at fieldlist.
fieldname = fieldlist-compname .
assign dref->(fieldname) to <fs>.
concatenate data_line <fs> into data_line .
endloop.
append data_line to t_output.
clear data_line.
endloop.
loop at t_output.
write:/ t_output.
endloop.
Code *************
If u still have any issues please revert back.
Hope it'll help u.
Regards,
Ankur
2005 Jul 20 3:15 PM
Ankur, I like your solution, but it didn't work on my system. I guess you are on a new version, it didn't like some of your syntax. I have modified your code to work in my system(46c).
report zrich_0003.
types: begin of type_item,
f1(3),
f2(3),
f3(3),
f4(3),
end of type_item.
types: begin of type_data,
data(800),
end of type_data.
data: lineitems type table of type_item with header line,
t_output type table of type_data with header line,
fieldlist type table of rstrucinfo with header line.
data: syrepid type sy-repid.
data: fieldname like fieldlist-compname,
data_line type type_data.
field-symbols : <fs1> type any,
<fs2> type any.
lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
lineitems-f4 = 'a4'.
append lineitems.
lineitems-f1 = 'b1'.
lineitems-f2 = 'b2'.
lineitems-f3 = 'b3'.
lineitems-f4 = 'b4'.
append lineitems.
lineitems-f1 = 'c1'.
lineitems-f2 = 'c2'.
lineitems-f3 = 'c3'.
lineitems-f4 = 'c4'.
append lineitems.
lineitems-f1 = 'd1'.
lineitems-f2 = 'd2'.
lineitems-f3 = 'd3'.
lineitems-f4 = 'd4'.
append lineitems.
syrepid = sy-repid.
call function 'GET_COMPONENT_LIST'
exporting
program = syrepid
fieldname = 'lineitems'
tables
components = fieldlist.
format color 3.
loop at lineitems assigning <fs2> .
loop at fieldlist.
fieldname = fieldlist-compname .
assign component fieldname of structure <fs2> to <fs1>.
concatenate data_line <fs1> into data_line .
endloop.
append data_line to t_output.
clear data_line.
endloop.
loop at t_output.
write:/ t_output.
endloop.
Regards,
Rich Heilman
2005 Aug 01 2:45 PM
Hi,
I'm new to SAP and ABAP....
What do these last two programs do?
I didn't understand them. Can you elaborate.
2005 Aug 01 6:31 PM
Hi, vijay srikanth
Let me explain the two program they write.
Theirs are mainly same. The thinking of the program is the append the data into internal table at first.
And then using FM 'GET_COMPONENT_LIST' to get the defination of the internal table you use to store data.
At last concatenate the fields with the dynamic tech of ABAP.
Let me use Rich's code as example.
lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
lineitems-f4 = 'a4'.
append lineitems.
this step is to append the data into internal table, in your scenario, maybe
lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
...........
lineitems-f100 = 'a100'.
append lineitems.
call function 'GET_COMPONENT_LIST'
exporting
program = syrepid
fieldname = 'lineitems'
tables
components = fieldlist.
call FM to get the defination of lineitems, then all of the 100 field name longth info has been stored into fieldlist, they are needed in the concatenate step.
loop at lineitems assigning <fs2> .
loop at fieldlist.
fieldname = fieldlist-compname .
assign component fieldname of structure <fs2> to <fs1>.
concatenate data_line <fs1> into data_line .
there is two loop, the <fs2> assigned line entry of 'lineitems', you can seem it as a line of lineitems. and statement
assign component fieldname of structure <fs2> to <fs1>. is the core to reduce your redundant works in transfer file.
it used to assign the a field of <fs2> whose name = fieldname to the <fs1>.
then concatenate the <fs1> to the tail of data_line.
After the loop at fieldlist, whole 100 filed of a line has been concatenated.
After the loop at lineitems, whole line of internal table has been transfered to t_output.
That's all
Hope it will clear enough.