2007 Jul 18 11:09 AM
My exact requirement is,
1) I want to extract data from PA0001 into internal table itab. ....No problem here.
2) I want to create tab delimited text file on different application server
and store itab data into that file.
3) This program will execute in background only. ( file will create in background)
So my problem is.
1) How to create tab delimited file on different application server ?
Please reply immediately its urgent
Thanks
Vijay
2007 Jul 18 11:16 AM
&----
*& Report ZUS_SDN_FILE_SYSTEM_MANAGER
*&
&----
*&
*&
&----
REPORT zus_sdn_file_system_manager.
TYPE-POOLS: truxs.
DATA:
gt_t001 TYPE STANDARD TABLE OF t001,
gt_text_data TYPE truxs_t_text_data,
gd_record LIKE LINE OF gt_text_data. " NOTE: max. 4096 chars !!!
" NOTE: sample .txt file with company code data (T001)
PARAMETERS:
p_path TYPE char512 DEFAULT 'X:\usr\sap\trans\tmp\t001_data.txt'.
START-OF-SELECTION.
" (1) Create sample file on application server
SELECT * FROM t001 INTO TABLE gt_t001.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
i_tab_sap_data = gt_t001
CHANGING
i_tab_converted_data = gt_text_data " TAB-delimited
EXCEPTIONS
conversion_failed = 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.
" (2) Save data onto application server
OPEN DATASET p_path FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
LOOP AT gt_text_data INTO gd_record.
TRANSFER gd_record TO p_path.
ENDLOOP.
CLOSE DATASET p_path.
" (3) Read file from application server
OPEN DATASET p_path FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
CLEAR: gd_record.
REFRESH: gt_text_data.
DO.
READ DATASET p_path INTO gd_record.
IF ( syst-subrc NE 0 ).
EXIT.
ENDIF.
APPEND gd_record TO gt_text_data.
ENDDO.
CLOSE DATASET p_path.
" (4) Convert TAB-delimited format to SAP data
REFRESH: gt_t001.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
I_LINE_HEADER =
i_tab_raw_data = gt_text_data
I_FILENAME =
TABLES
i_tab_converted_data = gt_t001
EXCEPTIONS
conversion_failed = 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.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'T001'
TABLES
t_outtab = gt_t001
EXCEPTIONS
program_error = 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.
END-OF-SELECTION.
<b>reward point for helpful answer......</b>
regards...
Abhay SIngh.
&----
*& Report ZUS_SDN_FILE_SYSTEM_MANAGER
*&
&----
*&
*&
&----
REPORT zus_sdn_file_system_manager.
TYPE-POOLS: truxs.
DATA:
gt_t001 TYPE STANDARD TABLE OF t001,
gt_text_data TYPE truxs_t_text_data,
gd_record LIKE LINE OF gt_text_data. " NOTE: max. 4096 chars !!!
" NOTE: sample .txt file with company code data (T001)
PARAMETERS:
p_path TYPE char512 DEFAULT 'X:\usr\sap\trans\tmp\t001_data.txt'.
START-OF-SELECTION.
" (1) Create sample file on application server
SELECT * FROM t001 INTO TABLE gt_t001.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
i_tab_sap_data = gt_t001
CHANGING
i_tab_converted_data = gt_text_data " TAB-delimited
EXCEPTIONS
conversion_failed = 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.
" (2) Save data onto application server
OPEN DATASET p_path FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
LOOP AT gt_text_data INTO gd_record.
TRANSFER gd_record TO p_path.
ENDLOOP.
CLOSE DATASET p_path.
" (3) Read file from application server
OPEN DATASET p_path FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
CLEAR: gd_record.
REFRESH: gt_text_data.
DO.
READ DATASET p_path INTO gd_record.
IF ( syst-subrc NE 0 ).
EXIT.
ENDIF.
APPEND gd_record TO gt_text_data.
ENDDO.
CLOSE DATASET p_path.
" (4) Convert TAB-delimited format to SAP data
REFRESH: gt_t001.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
I_LINE_HEADER =
i_tab_raw_data = gt_text_data
I_FILENAME =
TABLES
i_tab_converted_data = gt_t001
EXCEPTIONS
conversion_failed = 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.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'T001'
TABLES
t_outtab = gt_t001
EXCEPTIONS
program_error = 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.
END-OF-SELECTION.
<b>reward point for helpful answer......</b>
regards...
Abhay SIngh.
2007 Jul 18 11:12 AM
use ws_download or gui_download function module. there you can specify the delimiter in the FM. and download to your presentaion server.
regards,
srinivas
<b>*reward for useful answers*</b>
2007 Jul 18 11:13 AM
&----
*& Report ZTEST_INT044
*&
&----
*&
*&
&----
REPORT ZTEST_INT044.
DATA : w_file type string.
types:begin of t_main,
text(200),
end of t_main.
data:it_main type table of t_main with header line.
parameters :
p_appup type ibipparms-path modif id 001.
selection-screen skip.
parameters : p_appdn type ibipparms-path modif id 001.
selection-screen skip.
PRESENTATION SERVER SELECTION.
parameters :p_preup type ibipparms-path modif id 003.
selection-screen skip.
parameters : p_predn type ibipparms-path modif id 003.
at selection-screen on value-request for p_preup.
Calling funtion for presentation server files
call function 'F4_FILENAME' "Capture filename from Presentation
exporting "Server
program_name = sy-cprog
dynpro_number = sy-dynnr
importing
file_name = p_preup.
start-of-selection.
w_file = p_preup.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = w_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = it_main
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Open dataset p_appup for input in text mode encoding default.
*
*Do.
Read dataset p_appup into it_main.
*
If sy-subrc = 0.
Append it_main.
Else.
Exit.
Endif.
*
Enddo.
Close dataset p_appup.
Application server download
Open dataset p_appdn for output in text mode encoding default.
If sy-subrc = 0.
Loop at it_main.
Transfer it_main to p_appdn.
Endloop.
Close dataset p_appdn.
Endif.
Try this progarm.
<b>Sirjee rewards point if helpful...</b>
thanks....
2007 Jul 18 11:22 AM
Hi Abhay,
What is this ?
I have already mention that I want to execute this program in background and
still you are giving me presentation server related code. Is it work in background ?
Please read question carefully first.
Sorry.
Vijay
2007 Jul 18 11:16 AM
&----
*& Report ZUS_SDN_FILE_SYSTEM_MANAGER
*&
&----
*&
*&
&----
REPORT zus_sdn_file_system_manager.
TYPE-POOLS: truxs.
DATA:
gt_t001 TYPE STANDARD TABLE OF t001,
gt_text_data TYPE truxs_t_text_data,
gd_record LIKE LINE OF gt_text_data. " NOTE: max. 4096 chars !!!
" NOTE: sample .txt file with company code data (T001)
PARAMETERS:
p_path TYPE char512 DEFAULT 'X:\usr\sap\trans\tmp\t001_data.txt'.
START-OF-SELECTION.
" (1) Create sample file on application server
SELECT * FROM t001 INTO TABLE gt_t001.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
i_tab_sap_data = gt_t001
CHANGING
i_tab_converted_data = gt_text_data " TAB-delimited
EXCEPTIONS
conversion_failed = 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.
" (2) Save data onto application server
OPEN DATASET p_path FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
LOOP AT gt_text_data INTO gd_record.
TRANSFER gd_record TO p_path.
ENDLOOP.
CLOSE DATASET p_path.
" (3) Read file from application server
OPEN DATASET p_path FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
CLEAR: gd_record.
REFRESH: gt_text_data.
DO.
READ DATASET p_path INTO gd_record.
IF ( syst-subrc NE 0 ).
EXIT.
ENDIF.
APPEND gd_record TO gt_text_data.
ENDDO.
CLOSE DATASET p_path.
" (4) Convert TAB-delimited format to SAP data
REFRESH: gt_t001.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
I_LINE_HEADER =
i_tab_raw_data = gt_text_data
I_FILENAME =
TABLES
i_tab_converted_data = gt_t001
EXCEPTIONS
conversion_failed = 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.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'T001'
TABLES
t_outtab = gt_t001
EXCEPTIONS
program_error = 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.
END-OF-SELECTION.
<b>reward point for helpful answer......</b>
regards...
Abhay SIngh.
2007 Jul 18 11:16 AM
Assume that you have the data in an internal table itab.
open dataset <filename> for output in text mode.
if sy-subrc = 0.
loop at itab.
concatenate itab-field1 itab-field2 itab-field3....into v_string separated by
cl_abap_char_utilities=>horizontal_tab.
transfer v_string to <filename>.
endloop.
endif.
close dataset.
Regards,
Ravi
2007 Jul 18 11:44 AM
Hi Ravi,
Thanks for reply, it will help me to create tab delimited file.
Can you tell me how to give application server path ?
bcause..I am going to create this file on diffrent application server.
Thanks,
Vijay
2007 Jul 18 11:50 AM
Define a parameter for file name
parameters p_file like rlgrap-filename.
data: l_path type DXFIELDS-LONGPATH.
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
I_LOCATION_FLAG = 'P'
I_SERVER = '?'
I_PATH =
FILEMASK = '.'
FILEOPERATION = 'R'
IMPORTING
O_LOCATION_FLAG =
O_SERVER =
O_PATH = l_path
ABEND_FLAG =
EXCEPTIONS
RFC_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
message i000 with 'Error providing F4 help'(034).
ENDIF.
p_file = l_path.
This code will enable you to chose the files using F4 button.
Then you can use p_file for open dataset, transfer statements.
Regards,
Ravi
2007 Jul 18 12:16 PM
Hi Ravi
This is my code....
REPORT zv003.
TABLES : pa0001.
data: v_string type string.
DATA: itab LIKE pa0001 OCCURS 10 WITH HEADER LINE.
DATA: file TYPE string VALUE '
192.168.1.20\kfa_abap\trial.txt'.
SELECT * FROM pa0001 INTO CORRESPONDING FIELDS OF TABLE itab.
open dataset file for output in text mode encoding default.
if sy-subrc = 0.
loop at itab.
concatenate itab-PERNR itab-ENDDA itab-BEGDA into v_string separated by
cl_abap_char_utilities=>horizontal_tab.
transfer v_string to file.
endloop.
endif.
close dataset file.
-
its creating a file into /usr/sap/UBD/DVEBMGS11/work directory
( HOME DIRECTORY of current appli.server )
and giving filename like this..
192.168.1.20\kfa_abap\trial.txt
But I want to create file trial.txt into
192.168.1.20\kfa_abap\ server.
hopes it will clear to you.
Thanks.
vijay
2007 Jul 18 11:19 AM
Try to use the following code
open dataset p_dataset for output in text mode.
if sy-subrc <> 0.
write: / text-e00, sy-subrc.
stop.
endif.
loop at itab.
transfer i_contracts1 to p_dataset.
endloop.
close dataset p_dataset.
P_dataset is the file name in application layer
2007 Jul 18 11:22 AM
Since you are downloading to application server, you have to use the
OPEN DATASET.....
TRANSFER rec_line ......
here your rec_line is should be separated by '|'
:hints
LOOP AT ITAB.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE itab TO <fs>.
IF sy-subrc <> 0.
*----
no more component.
EXIT.
ELSEIF <fs> IS ASSIGNED.
CONCATENATE <FS> 'I' INTO REC_LINE. "<----TAB separator
ENDIF.
ENDDO.
TRANSFER rec_line.
ENDLOOP.
2007 Jul 18 11:25 AM
use the below para in GUI_DOWNLOAD.
WRITE_FIELD_SEPARATOR = '#'
give points if use full.
2007 Jul 18 12:04 PM
Since you are downloading to a different server, one possible soln could be also:
Create a RFC FM with the code as mentioned in my previous post.
In the RFC interface pass the table data.
Regards,
A.Singh
2007 Jul 18 12:33 PM
hi vijay
try out in this way
parameters : p_filename type rlgrap-filename.
open dataset <filename> for output in text mode/binary mode.
if sy-subrc = 0.
loop at itab.
concatenate itab-field1 itab-field2 itab-field3....into v_string separated by//either TAB or ASC separated
transfer v_string to <filename>.
endloop.
endif.
close dataset.
this helps you in storing the itab data into file.
reward if useful......!!
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |