Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

pipe delimited file on application server.

Former Member
0 Kudos

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.

6 REPLIES 6

matteo_montalto
Contributor
0 Kudos

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

Former Member
0 Kudos

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.

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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

Former Member
0 Kudos

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