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: 

Getting text file from application server with different file names

Former Member
0 Kudos

Hi This is lokesh.

Actually my requirement is to craete sales orders by getting file from other server.for that i have used shell script to connect that server.Ok i am connecting to that different server(not sap server) successfully.

But my problem is getting text file from application SERVER.

That different server people will send the file name as 'DDHHMMSS' (Days,Hours,Minutes,Seconds).

Just suppose if they will send today means that file name will come as 20103025. and with in half an hour if they again send that file file means that file name as '20110025'.

like that file name is always varies.So how can i read that type of text files from the application server.

and one more thing that is there chance to read morethan one text file from application server.

Pls guide me if u know the solution.PLs this requirement is urgent.

Regards,

Lokeshgoud

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hai Lokesh,

First store all your File Names into an internal Table,And then loop at that pass dynamically the File name to the below program:

DATA:

BEGIN OF FS_SPFLI3,

LINE TYPE STRING,

END OF FS_SPFLI3.

DATA:

T_SPFLI3 LIKE

STANDARD TABLE

OF FS_SPFLI3.

REFRESH T_SPFLI3.

DATA:

W_LINE(1023) TYPE C.

DATA:

W_FILE2 TYPE STRING VALUE 'SPFLI_FILE5'.

OPEN DATASET W_FILE2 FOR INPUT

IN TEXT MODE

ENCODING DEFAULT.

DO.

READ DATASET W_FILE2 INTO W_LINE.

IF SY-SUBRC NE 0.

EXIT.

ELSE.

FS_SPFLI3-LINE = W_LINE.

APPEND FS_SPFLI3 TO T_SPFLI3.

ENDIF.

ENDDO.

LOOP AT T_SPFLI3 INTO FS_SPFLI3.

WRITE:

/ FS_SPFLI3-LINE.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'D:/cHARY/FILE9.TXT'

  • FILETYPE = 'ASC'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = T_SPFLI3

  • FIELDNAMES =

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Hope this helps you a lot.

Reward points if it helps you.

Regds,

Rama chary.Pammi

4 REPLIES 4

Former Member
0 Kudos

Hi Lokesh,

Concatenate the filepath with sy-uzeit ( System time ) whenever u want to get the file.

e.g. /COACH/interface/DEV/20103025/ODoutput.txt...... if this is the file path.

Store the system time to one character variable of length 8 say Chartime.

if it is next half an hour it ll be as u said it is '20110025'. So this will be stored in

chartime .

And append like this '/COACH/interface/DEV/' Chartime '/ODoutput.txt' into one variable and input this varible value to your P_INFILE.

Next time ur filepath will become /COACH/interface/DEV/20110025/ODoutput.txt like this.

create one internal table according to your requirement.

e.g:

data: begin of wa,

text type c length 100,

end of wa,

itab like standard table of wa.

DO.

READ DATASET P_INFILE INTO WA.

IF SY-SUBRC = 0.

APPEND WA TO itab.

ELSE.

EXIT.

ENDIF.

ENDDO.

I hope this ll help u.

Thanks & Regards

Santhosh

Former Member
0 Kudos

Hai Lokesh,

First store all your File Names into an internal Table,And then loop at that pass dynamically the File name to the below program:

DATA:

BEGIN OF FS_SPFLI3,

LINE TYPE STRING,

END OF FS_SPFLI3.

DATA:

T_SPFLI3 LIKE

STANDARD TABLE

OF FS_SPFLI3.

REFRESH T_SPFLI3.

DATA:

W_LINE(1023) TYPE C.

DATA:

W_FILE2 TYPE STRING VALUE 'SPFLI_FILE5'.

OPEN DATASET W_FILE2 FOR INPUT

IN TEXT MODE

ENCODING DEFAULT.

DO.

READ DATASET W_FILE2 INTO W_LINE.

IF SY-SUBRC NE 0.

EXIT.

ELSE.

FS_SPFLI3-LINE = W_LINE.

APPEND FS_SPFLI3 TO T_SPFLI3.

ENDIF.

ENDDO.

LOOP AT T_SPFLI3 INTO FS_SPFLI3.

WRITE:

/ FS_SPFLI3-LINE.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'D:/cHARY/FILE9.TXT'

  • FILETYPE = 'ASC'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = T_SPFLI3

  • FIELDNAMES =

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Hope this helps you a lot.

Reward points if it helps you.

Regds,

Rama chary.Pammi

Former Member
0 Kudos

Thank u very much santhosh.

Thank u very much Rama.

With ur code guidance i got result.Thank u very much.

One more thing that i have to sent text file to application server.

when i execute 1st time it has to replace in application server as same format DDHHMMSS.ex : 1st it has to place that as 20110000.

next time after 1 hour it has to place as 20120000.

pls guide me.

0 Kudos

Hi Lokesh,

There is one more statement called DELETE DATASET p_filepath.

if u want to delete the file created before half an hour get the system time and subtract it by half an hour and append it to filepath and pass the filepath to tht statement.

Try with this i hope this will work.

Thanks & Regards

Santhosh

Message was edited by:

santhosh ds