05-22-2009 10:52 AM
Hi , i m creating a text file on application server, i have written below code and file is getting created correctly. however, i want to create pipe delimited file. is there any method for this?
DATA : lv_line(173).
DATA : l_wa_itab_length(4) TYPE c VALUE '173'.
IF NOT p_tab[] IS INITIAL.
SORT p_tab.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc NE 0.
MESSAGE 'Error on output file read' TYPE 'E'.
ELSE.
LOOP AT p_tab.
lv_line = p_tab.
TRANSFER lv_line TO p_file LENGTH l_wa_itab_length.
CLEAR p_tab.
CLEAR lv_line.
ENDLOOP.
CLOSE DATASET p_file.
ENDIF.
ENDIF.
REFRESH p_tab.
05-22-2009 11:03 AM
Hi,
just try to concatenate single fields of p_tab with the clause SEPARATED BY '|' :
...
CONCATENATE p_tab-field1 p_tab-field2 ... INTO lv_line SEPARATED BY '|'.
*don't forget to increase l_wa_itab_length by the numbers of pipes you used!
TRANSFER lv_line TO p_file LENGTH l_wa_itab_length.
...
Hope that helps,
Matteo
05-22-2009 11:07 AM
hi actually p_tab is coming through field_symbol. my program is a generic program and i will not come to know which table user is going to enter. hence i dont know what will be the fields.
05-22-2009 11:09 AM
Hi,
Use cl_abap_char_utilities=>vertical_tab if you are using version >4.6c.
Hope you will be have only one character of much length for final internal table.
While moving the fields use vertical_tab to separate.
LOOP AT t_final INTO w_final.
....
CONCATENATE w_final-f1 lw_fianl-f2 INTO w_output
SEPARATED BY cl_abap_char_utilities=>vertical_tab .
Appending records
APPEND w_output TO t_output.
CLEAR : w_output,
w_final.
ENDLOOP.
05-22-2009 11:18 AM
Hi
Can you check the bellow code it will work
DATA : lv_line(173).
DATA : l_wa_itab_length(4) TYPE c VALUE '173'.
IF NOT p_tab[] IS INITIAL.
SORT p_tab.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc NE 0.
MESSAGE 'Error on output file read' TYPE 'E'.
ELSE.
LOOP AT p_tab.
lv_line = p_tab.
CONCATENATE p_tab-field1 p_tab-field2 ... INTO lv_line SEPARATED BY '|'
TRANSFER lv_line TO p_file LENGTH l_wa_itab_length.
CLEAR p_tab.
CLEAR lv_line.
ENDLOOP.
CLOSE DATASET p_file.
ENDIF.
ENDIF.
REFRESH p_tab.
regards,
Munibabu.k
06-17-2009 10:58 AM
HI,
If for Pipe delimited, value is 173 then what is the value (length) for horizontal tab?
I need the tab delimited file. or what is the other way to do that?
Regards,
Mrunal
05-22-2009 11:22 AM
i m pasting below my entire code.
REPORT zmigration_data_download.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE.
DATA: d_table_ref TYPE REF TO data.
DATA: d_rfc_db_opt TYPE rfc_db_opt.
DATA: it_opt LIKE rfc_db_opt OCCURS 0 WITH HEADER LINE.
DATA: d_file TYPE string.
PARAMETERS: p_tab TYPE dd02l-tabname OBLIGATORY.
PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY DEFAULT '/usr/sap/tmp/test.txt'.
SELECT-OPTIONS: s_opt FOR d_rfc_db_opt NO INTERVALS.
START-OF-SELECTION.
REFRESH it_opt.
LOOP AT s_opt WHERE sign = 'I' OR option = 'EQ'.
it_opt-text = s_opt-low.
APPEND it_opt.
ENDLOOP.
CREATE DATA d_table_ref TYPE TABLE OF (p_tab).
UNASSIGN <fs_table>.
ASSIGN d_table_ref->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
CLEAR <fs_table>.
SELECT * FROM (p_tab) INTO TABLE <fs_table>
WHERE (it_opt).
IF sy-subrc EQ 0.
PERFORM download_file TABLES <fs_table> USING p_file.
MESSAGE i398(00) WITH 'Upload from SAP Successfull'.
ENDIF.
ENDIF.
&----
*& Form download_file
&----
text
----
-->P_<FS_TABLE> text
-->P_P_FILE text
----
FORM download_file TABLES p_tab USING p_file.
DATA : lv_line(173).
DATA : l_wa_itab_length(4) TYPE c VALUE '173'.
IF NOT p_tab[] IS INITIAL.
SORT p_tab.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc NE 0.
MESSAGE 'Error on output file read' TYPE 'E'.
ELSE.
LOOP AT p_tab.
lv_line = p_tab.
TRANSFER lv_line TO p_file LENGTH l_wa_itab_length.
CLEAR p_tab.
CLEAR lv_line.
ENDLOOP.
CLOSE DATASET p_file.
ENDIF.
ENDIF.
REFRESH p_tab.
ENDFORM. " download_file