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: 

validation of file path

Former Member
0 Kudos
113

OPEN DATASET g_filepath IN TEXT MODE FOR INPUT

MESSAGE g_msg.

IF sy-subrc = 0.

MESSAGE e001 WITH 'File Already Exist' g_msg .

CLOSE DATASET g_filepath.

leave Program.

ELSE .

CLOSE DATASET g_filepath.

ENDIF.

here when control goes to ELSE. then may be file doesnot exist or Invalid File Path.

if File doesnot exist then OK .

what to do when Invalid File Path .

Plz reply

7 REPLIES 7

LucianoBentiveg
Active Contributor
0 Kudos
77

Becose Dataset is never opened.

Former Member
0 Kudos
77

You need not close the dataset in else because if the file path is invalid it will never be opened so you need to throw a message that it is an invalid path.

Former Member
0 Kudos
77

Hai Sarada

Check the following Code

**-- types for data to be downloaded

types: begin of tp_kna1,

KUNNR type kna1-kunnr, " customer number

LAND1 type kna1-land1, " Country Key

NAME1 type kna1-name1, " customer name

ORT01 type kna1-ort01, " city

PSTLZ type kna1-pstlz, " postal code

REGIO type kna1-regio, " region

end of tp_kna1.

----


  • I n t e r n a l T a b l e s

----


**-- Internal table for data to be downloaded

data: it_kna1 type standard table of tp_kna1 with header line.

----


  • S e l e c t i o n S c r e e n

----


selection-screen begin of block b1 with frame title text-001.

parameters: p_afile type rlgrap-filename

default 'customer.txt'.

selection-screen end of block b1.

----


----


  • At selection screen on value request

----


<b>at selection-screen on value-request for p_afile.

*--Get the F4 help for Sales Deal File

perform get_val_help changing p_afile .</b>----


  • S t a r t o f s e l e c t i o n

----


start-of-selection.

*-- Upload the data from Sales Deal file

perform upload_app_file.

end-of-selection.

perform write_data.

*&----


*& Form upload_app_file

*&----


  • Upload the application server file data

*----


form upload_app_file.

data: l_msg(100). " error message

open dataset p_afile for input in text mode encoding default message

l_msg.

if sy-subrc <> 0.

message i004 with l_msg.

else.

do.

read dataset p_afile into it_kna1.

if sy-subrc = 0.

append it_kna1.

clear it_kna1.

else.

exit.

endif.

enddo.

close dataset p_afile.

endif.

endform. " upload_app_file

&----


*& Form write_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_data .

loop at it_kna1.

write:/ it_kna1-kunnr,

it_kna1-land1,

it_kna1-name1,

it_kna1-ort01,

it_kna1-pstlz,

it_kna1-regio.

endloop.

ENDFORM. " write_data

&----


*& Form get_val_help

&----


  • Get F4 help for the File name

----


<b>form get_val_help changing p_file type rlgrap-filename.

call function 'F4_FILENAME'

importing

file_name = p_file

exceptions

others = 1.

if sy-subrc <> 0.

message e001. " File Open Error

endif.

endform. " get_val_help</b>

Regards

Sreeni

ferry_lianto
Active Contributor
0 Kudos
77

Hi Sharadha,

You can use FM <b>RZL_READ_DIR_LOCAL</b> to validate the file path.

Please check this link for sample code.

Hope this will help.

Regards,

Ferry Lianto

Please reward points if helpful.

Former Member
0 Kudos
77

Hi Sharadha,

1) If the file doesnot exists on Application server or File path is invalid then no need of CLOSE DATASET in ELSE condition.

2) Just use WRITE statement or give information message using MESSAGE statement.

3)Or, you can provide user to select an application server file using Function Module <b>/SAPDMC/LSM_F4_SERVER_FILE</b> to get F4 help.

4) Get the file name and use OPEN DATASET and do necessary actions according to requirement.

<b>Note: Plz reward all helpful answers and close thread once it is solved.</b>

Thanks,

Vinay

Former Member
0 Kudos
77

hi shraddha,

it means File does not exist.

give a message in the Else part.

<b>else.</b>

message e000(zz) with g_filepath.

validate the Filepath use the FM <b>RZL_READ_DIR_LOCAL</b>

Former Member
0 Kudos
77

Hi

I think closing the dataset in case of invalid path will give runtime dump.

So avoid writin it

-Paola