2007 Jul 19 3:09 PM
Hi all.,
I am trying to transfer data from my internal table to application server in .txt (file), and after the process show a log with the numbers of successful data send to the server, also describe the errors that occur when i am trying to send to the server.
DATA: lwa_datacts like line of gtd_datacts.
OPEN DATASET pi_infile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT gtd_datacts INTO lwa_datacts.
TRANSFER lwa_datacts TO pi_infile.
ENDLOOP.
ELSE.
exit
ENDIF.
CLOSE DATASET pi_ruta.
regards
Guillermo
2007 Jul 19 3:19 PM
Hi,
you can try something like this.
DATA: lwa_datacts like line of gtd_datacts.
data: lv_mess(100) type c.
data: lv_lines type i.
OPEN DATASET pi_infile FOR OUTPUT message lv_mess
IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT gtd_datacts INTO lwa_datacts.
TRANSFER lwa_datacts TO pi_infile.
ENDLOOP.
lv_lines = lines( gtd_datacts ).
write: lv_lines, 'records transferred successfully!'.
ELSE.
write: / 'Error while creating the file!'.
write lv_mess.
exit
ENDIF.
CLOSE DATASET pi_ruta.
Kostas
2007 Jul 19 3:15 PM
Hi,
Try with this code:
**--Move data to application server
data: v_file(10) type c value '.\BDC4.txt'.
open dataset v_file for output in text mode encoding default.
if sy-subrc eq 0.
loop at git_mara.
transfer git_mara to v_file.
endloop.
close dataset v_file.
endif.
clear : git_mara[].
**--read from application server
open dataset v_file for input in text mode encoding default.
if sy-subrc eq 0.
do.
read dataset v_file into git_mara.
if sy-subrc eq 0.
append git_mara.
else.
exit.
endif.
enddo.
close dataset v_file.
endif.
Regards,
Bhaskar
2007 Jul 19 3:19 PM
Hi,
you can try something like this.
DATA: lwa_datacts like line of gtd_datacts.
data: lv_mess(100) type c.
data: lv_lines type i.
OPEN DATASET pi_infile FOR OUTPUT message lv_mess
IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT gtd_datacts INTO lwa_datacts.
TRANSFER lwa_datacts TO pi_infile.
ENDLOOP.
lv_lines = lines( gtd_datacts ).
write: lv_lines, 'records transferred successfully!'.
ELSE.
write: / 'Error while creating the file!'.
write lv_mess.
exit
ENDIF.
CLOSE DATASET pi_ruta.
Kostas
2007 Jul 19 3:33 PM
Thank you guys for the answer, it was helpfull but I also need to show the erros that occurs when i use these statment :
TRANSFER lwa_datacts TO pi_infile.
And show the error for each row of the internal table that couldn't be transfer to the server.
Regards
Guillermo
2007 Jul 19 3:44 PM
Hi,
You have the following possible exceptions when dealing with the files.
DATA : OREF TYPE REF TO CX_ROOT. " To Hold the Exception
data : lv_text(50).
Runtime errors:
DATASET_SEEK_ERROR: Unable to position in the file
Note
Catchable runtime error:
DATASET_TOO_MANY_FILES: Maximum number of open files exceeded
DATASET_WRITE_ERROR: An error occurred while writing to the file
OPEN_DATASET_NO_AUTHORITY: Authorization check for file access failed
you can try this..
try.
transfer data to file.
*-- copy this catch for each of the possble exceptions listed above .. and get the exact text in lv_text
catch DATASET_SEEK_ERROR into oref.
LV_TEXT = OREF->GET_TEXT( ).
*-- Handle Other Exceptions
CATCH CX_ROOT INTO OREF.
LV_TEXT = OREF->GET_TEXT( ).
endtry
Hope this helps.
Cheer's
Mahesh