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: 

Problem in Text file Format while transferring data from SAP

Former Member
0 Kudos
262

Dear Friends,

i am downloading the Text file with data on Unix server . But though i have two lines in internal table both the Lines are getting Concaniteted .

Please check the following code

DATA : BEGIN OF it_data OCCURS 0,

f1(250) TYPE c,f2(250) TYPE c,f3(250) TYPE c, f4(250) TYPE c,

f5(250) TYPE c,f6(250) TYPE c,f7(250) TYPE c, f8(250) TYPE c,

f9(250) TYPE c,f10(250) TYPE c,f11(250) TYPE c, f12(250) TYPE c,

f13(250) TYPE c,f14(250) TYPE c,f15(250) TYPE c, f16(250) TYPE c.

DATA : END OF it_data.

LOOP AT it_download_bank_details INTO wa_download_bank_details.

APPEND wa_download_bank_details TO it_data.

ENDLOOP.

OPEN DATASET p_unixfn FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

errflag = 'X'.

MESSAGE i002(mg) WITH p_unixfn.

MESSAGE a099(mg).

ENDIF.

LOOP AT it_data.

TRANSFER it_data TO p_unixfn.

IF sy-subrc NE 0.

errflag = 'X'.

MESSAGE i001(mg) WITH p_unixfn.

MESSAGE a099(mg).

ENDIF.

ENDLOOP.

CLOSE DATASET p_unixfn .

Please suggest me a solution.

Regards

Nilesh

1 ACCEPTED SOLUTION

Former Member
0 Kudos
203

HI

1) instead of diclaring type c (250) use standerd data elements which needs to be moved into internal table other wise use atleast type CHAR250 .

f1(250) TYPE c,f2(250) TYPE c,f3(250) TYPE c, f4(250) TYPE c,

f5(250) TYPE c,f6(250) TYPE c,f7(250) TYPE c, f8(250) TYPE c,

f9(250) TYPE c,f10(250) TYPE c,f11(250) TYPE c, f12(250) TYPE c,

f13(250) TYPE c,f14(250) TYPE c,f15(250) TYPE c, f16(250) TYPE c.

DATA : END OF it_data.

2) you need to take all the content into a single char field seperated by the delimitor. check the below code for your reference

data: w_file type string.

*Table for download

data: begin of t_file occurs 0,

line(1000) type c.

data: end of t_file.

parameters: p_fname2 like rlgrap-filename

default '/tmp/ordround.txt'.

&----


*& Form F0405_FILL_T_FILE

&----


  • Description: This routine will fill the t_file table

----


form f0405_fill_t_file.

free : t_file.

clear: w_line.

w_h1 = text-009.

w_h2 = text-012.

w_h3 = text-015.

w_h4 = text-018.

w_h5 = text-021.

w_h6 = text-024.

w_h7 = text-026.

w_h8 = text-029.

w_h9 = text-032.

w_h10 = text-034.

w_h11 = text-036.

w_h12 = text-038.

w_h13 = text-040.

w_h14 = text-043.

w_h15 = text-046.

w_h16 = text-049.

w_h17 = text-052.

w_h18 = text-055.

w_h19 = text-058.

w_h20 = text-055.

w_h21 = text-061.

w_h22 = text-055.

w_h23 = text-063.

w_h24 = text-055.

w_ca1 = text-074.

w_ca2 = text-077.

concatenate w_h1(09) w_h2(07) w_h3(08)

w_ca1(12) w_ca2(11) w_h4(05)

w_h5(10) w_h6(35) w_h7(10)

w_h8(35) w_h9(20) w_h10(07)

w_h11(10) w_h12(12) w_h13(08)

w_h14(19) w_h15(18) w_h16(40)

w_h17(13) w_h18(03) w_h19(17)

w_h20(03) w_h21(35) w_h22(03)

w_h23(35) w_h24(03)

into w_line

separated by u2018|u2019.

move w_line to t_file-line.

append t_file.

unassign <fs_REPORT>.

loop at T_REPORT assigning <fs_REPORT>.

clear: w_line,

concatenate <fs_REPORT>-vkorg <fs_REPORT>-vtweg

<fs_REPORT>-spart <fs_REPORT>-vkbur

<fs_REPORT>-vkgrp <fs_REPORT>-werks

<fs_REPORT>-kunnr <fs_REPORT>-namesold

<fs_REPORT>-kunwe <fs_REPORT>-nameship

<fs_REPORT>-bstnk <fs_REPORT>-bsark

<fs_REPORT>-auart <fs_REPORT>-vbeln

<fs_REPORT>-posnr <fs_REPORT>-erdat

<fs_REPORT>-matnr <fs_REPORT>-arktx

<fs_REPORT>-scmng <fs_REPORT>-schme

<fs_REPORT>-kwmeng <fs_REPORT>-vrkme

<fs_REPORT>-zzv_oriqty <fs_REPORT>-vrkme

<fs_REPORT>-zzediqty <fs_REPORT>-vrkme

into w_line

separated by u2018|u2019.

move w_line to t_file-line.

append t_file.

endloop.

endform. " F0405_FILL_T_FILE

&----


*& Form F0420_DOWNLOAD_UNIX

&----


  • Description: This routine will download the report to UNIX

----


form f0420_download_unix.

open dataset p_fname2 for output in text mode encoding default.

if sy-subrc EQ 0.

loop at t_file.

transfer t_file to p_fname2.

endloop.

close dataset p_fname2.

if sy-subrc ne 0.

message i999 with 'Error closing the file! '(066).

endif.

else.

message i999 with 'Error opening the file!'(065).

endif.

endform.

for any doughts preply me back .

3 REPLIES 3

Former Member
0 Kudos
204

HI

1) instead of diclaring type c (250) use standerd data elements which needs to be moved into internal table other wise use atleast type CHAR250 .

f1(250) TYPE c,f2(250) TYPE c,f3(250) TYPE c, f4(250) TYPE c,

f5(250) TYPE c,f6(250) TYPE c,f7(250) TYPE c, f8(250) TYPE c,

f9(250) TYPE c,f10(250) TYPE c,f11(250) TYPE c, f12(250) TYPE c,

f13(250) TYPE c,f14(250) TYPE c,f15(250) TYPE c, f16(250) TYPE c.

DATA : END OF it_data.

2) you need to take all the content into a single char field seperated by the delimitor. check the below code for your reference

data: w_file type string.

*Table for download

data: begin of t_file occurs 0,

line(1000) type c.

data: end of t_file.

parameters: p_fname2 like rlgrap-filename

default '/tmp/ordround.txt'.

&----


*& Form F0405_FILL_T_FILE

&----


  • Description: This routine will fill the t_file table

----


form f0405_fill_t_file.

free : t_file.

clear: w_line.

w_h1 = text-009.

w_h2 = text-012.

w_h3 = text-015.

w_h4 = text-018.

w_h5 = text-021.

w_h6 = text-024.

w_h7 = text-026.

w_h8 = text-029.

w_h9 = text-032.

w_h10 = text-034.

w_h11 = text-036.

w_h12 = text-038.

w_h13 = text-040.

w_h14 = text-043.

w_h15 = text-046.

w_h16 = text-049.

w_h17 = text-052.

w_h18 = text-055.

w_h19 = text-058.

w_h20 = text-055.

w_h21 = text-061.

w_h22 = text-055.

w_h23 = text-063.

w_h24 = text-055.

w_ca1 = text-074.

w_ca2 = text-077.

concatenate w_h1(09) w_h2(07) w_h3(08)

w_ca1(12) w_ca2(11) w_h4(05)

w_h5(10) w_h6(35) w_h7(10)

w_h8(35) w_h9(20) w_h10(07)

w_h11(10) w_h12(12) w_h13(08)

w_h14(19) w_h15(18) w_h16(40)

w_h17(13) w_h18(03) w_h19(17)

w_h20(03) w_h21(35) w_h22(03)

w_h23(35) w_h24(03)

into w_line

separated by u2018|u2019.

move w_line to t_file-line.

append t_file.

unassign <fs_REPORT>.

loop at T_REPORT assigning <fs_REPORT>.

clear: w_line,

concatenate <fs_REPORT>-vkorg <fs_REPORT>-vtweg

<fs_REPORT>-spart <fs_REPORT>-vkbur

<fs_REPORT>-vkgrp <fs_REPORT>-werks

<fs_REPORT>-kunnr <fs_REPORT>-namesold

<fs_REPORT>-kunwe <fs_REPORT>-nameship

<fs_REPORT>-bstnk <fs_REPORT>-bsark

<fs_REPORT>-auart <fs_REPORT>-vbeln

<fs_REPORT>-posnr <fs_REPORT>-erdat

<fs_REPORT>-matnr <fs_REPORT>-arktx

<fs_REPORT>-scmng <fs_REPORT>-schme

<fs_REPORT>-kwmeng <fs_REPORT>-vrkme

<fs_REPORT>-zzv_oriqty <fs_REPORT>-vrkme

<fs_REPORT>-zzediqty <fs_REPORT>-vrkme

into w_line

separated by u2018|u2019.

move w_line to t_file-line.

append t_file.

endloop.

endform. " F0405_FILL_T_FILE

&----


*& Form F0420_DOWNLOAD_UNIX

&----


  • Description: This routine will download the report to UNIX

----


form f0420_download_unix.

open dataset p_fname2 for output in text mode encoding default.

if sy-subrc EQ 0.

loop at t_file.

transfer t_file to p_fname2.

endloop.

close dataset p_fname2.

if sy-subrc ne 0.

message i999 with 'Error closing the file! '(066).

endif.

else.

message i999 with 'Error opening the file!'(065).

endif.

endform.

for any doughts preply me back .

0 Kudos
203

Dear Penchala ,

thanks for reply , but i am getting same format after opening the text file .

regards

Nilesh Vakil

Former Member
0 Kudos
203

try with below code after OPEN DATA SET...

DO.

READ DATASET p_unixfn INTO lwa_file2.

IF sy-subrc = 0.

  • split the characters between the separators to individual fields.

SPLIT lwa_file2 AT pa_sep INTO lwa_itab-field1

lwa_itab-field2

lwa_itab-field3

lwa_itab-field4.

TRANSFER it_data TO p_unixfn.

ELSE.

EXIT.

ENDIF.

ENDDO.