‎2007 May 09 6:32 AM
hi all,
i need to transfer data from my internal table to application server in .txt (file) format so what i have to do.
plz help me
regards
amar
‎2007 May 09 6:35 AM
Here is the sample code...
*"Table declarations...................................................
tables:
bkpf. " Accounting Document Header
*"Selection screen elements............................................
select-options:
s_bukrs for bkpf-bukrs, " Company Code
s_gjahr for bkpf-gjahr. " Fiscal Year
*" Type declarations...................................................
"----
types:
begin of type_s_account_info,
comp_code like bkpf-bukrs,
accdoc_head like bkpf-belnr,
fiscal_yr like bkpf-gjahr,
doctype like bkpf-blart,
docdate like bkpf-bldat,
end of type_s_account_info.
"----
Internal table to hold delivery header data *
"----
data:
t_account_info type table
of type_s_account_info
with header line.
"----
START-OF-SELECTION EVENT *
"----
start-of-selection.
perform upload.
&----
*& Form upload
&----
This subroutine uploads bkpf table info to a file in app server *
----
There are no interface parameters to be passed to this subroutine. *
----
form upload .
select bukrs " Company Code
belnr " Accounting Document Number
gjahr " Fiscal Year
blart " Document type
bldat " Document Date in Document
into table t_account_info
from bkpf
where bukrs in s_bukrs
and gjahr in s_gjahr.
loop at t_account_info.
write : / t_account_info-comp_code,
t_account_info-docdate.
endloop.
if sy-subrc eq 0.
open dataset 'd:\account_info.txt' for
output in text mode encoding default.
if sy-subrc ne 0.
write:/ 'Download failed', sy-subrc.
else.
loop at t_account_info.
transfer t_account_info to 'd:\account_info.txt'.
if sy-subrc ne 0.
write:/ sy-subrc.
endif.
endloop.
close dataset 'd:\account_info.txt'.
endif.
endif.
endform. " UPLOAD
‎2007 May 09 6:35 AM
Here is the sample code...
*"Table declarations...................................................
tables:
bkpf. " Accounting Document Header
*"Selection screen elements............................................
select-options:
s_bukrs for bkpf-bukrs, " Company Code
s_gjahr for bkpf-gjahr. " Fiscal Year
*" Type declarations...................................................
"----
types:
begin of type_s_account_info,
comp_code like bkpf-bukrs,
accdoc_head like bkpf-belnr,
fiscal_yr like bkpf-gjahr,
doctype like bkpf-blart,
docdate like bkpf-bldat,
end of type_s_account_info.
"----
Internal table to hold delivery header data *
"----
data:
t_account_info type table
of type_s_account_info
with header line.
"----
START-OF-SELECTION EVENT *
"----
start-of-selection.
perform upload.
&----
*& Form upload
&----
This subroutine uploads bkpf table info to a file in app server *
----
There are no interface parameters to be passed to this subroutine. *
----
form upload .
select bukrs " Company Code
belnr " Accounting Document Number
gjahr " Fiscal Year
blart " Document type
bldat " Document Date in Document
into table t_account_info
from bkpf
where bukrs in s_bukrs
and gjahr in s_gjahr.
loop at t_account_info.
write : / t_account_info-comp_code,
t_account_info-docdate.
endloop.
if sy-subrc eq 0.
open dataset 'd:\account_info.txt' for
output in text mode encoding default.
if sy-subrc ne 0.
write:/ 'Download failed', sy-subrc.
else.
loop at t_account_info.
transfer t_account_info to 'd:\account_info.txt'.
if sy-subrc ne 0.
write:/ sy-subrc.
endif.
endloop.
close dataset 'd:\account_info.txt'.
endif.
endif.
endform. " UPLOAD
‎2007 May 09 6:41 AM
open dataset 'd:\account_info.txt' for
output in text mode encoding default
i think the path u have mentioned here 'd:\account_info.txt' is of the d drive in your computer, but i want the data to be transfered from internal table to application server and in application server it should be saved in .txt file.
Thanks jyothi for your response buy my question is not solved yet plz help
‎2007 May 09 7:40 AM
Hi jyothi ,
i am getting this error while i run my program.
plz help me
REPORT ZASP12.
TABLES : MARD.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARD-MATNR,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
SPEME LIKE MARD-SPEME,
INSME LIKE MARD-INSME,
END OF ITAB.
SELECT MATNR
WERKS
LGORT
LABST
SPEME
INSME FROM MARD INTO TABLE ITAB.
SKIP 5.
LOOP AT ITAB.
ADD ITAB-SPEME TO ITAB-INSME.
DELETE ITAB WHERE LABST = 0 AND INSME = 0.
ENDLOOP.
SORT ITAB BY MATNR LGORT.
LOOP AT ITAB.
WRITE: / ITAB-MATNR,ITAB-WERKS,ITAB-LGORT,ITAB-LABST,ITAB-SPEME,ITAB-INSME.
ENDLOOP.
open dataset 'c:\amar\asp1.txt' for
output in text mode encoding default.
if sy-subrc ne 0.
write:/ 'Download failed', sy-subrc.
else.
loop at itab.
transfer itab to 'c:\amar\asp1.txt'.
if sy-subrc ne 0.
write:/ sy-subrc.
endif.
endloop.
close dataset 'c:\amar\asp1.txt'.
endif.
Error analysis
For the statement
"TRANSFER f TO ..."
only character-type data objects
"f".
In this case. the operand "f" has
current program is a Unicode prog
'X' or structures containing not
regarded as non-character-type.
‎2007 May 09 12:22 PM
Hello Amar
You cannot use a <b>structured </b>variable for transfer to a dataset. The solution is quite simple by using a CLIKE container, e.g. a string variable or a very long character field.
DATA:
ld_record TYPE string,
ls_line LIKE LINE OF itab.
LOOP AT itab INTO ls_line.
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = ls_line
IMPORTING
EX_CONTAINER = ld_record
EXCEPTIONS
ILLEGAL_PARAMETER_TYPE = 1
others = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
TRANSFER ld_record TO 'c:amarasp1.txt'.
ENDLOOP.Regards
Uwe
‎2007 May 09 6:46 AM
Hi Amar,
Absolutely agree with jyothy solution. Try with tha solution. In that solution path was hard coded. Instead of that pass the physical path to FM WS_FILENAME_GET and get the logical path.
Now take one variable type string and move that path to that variable. Now pass the that variable to data set statements.
Hope this helps you. Reply for queries, shall post the updates.
Regards.
Kumar.