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: 

Shorten path

former_member2492
Active Participant
0 Kudos
1,760

Hello,

I select the document using method

cl_gui_frontend_services=>file_open_dialog

which gives me the path to the folder type STRING.Then I read the file using Function Module : TEXT_CONVERT_XLS_TO_SAP

which has an importing parameter i_filename type RLGRAP-FILENAME , length limited to 128 CHAR.

Sometimes the path can be longer than 128 Char and like this the prg does not find the file.

Do you know a way to shorten the path or read the file path entirely?

Please let me know!

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
655

Just duplicate TEXT_CONVERT_XLS_TO_SAP and increase the length of the parameter.

Duplication of such a simple function module is not an issue, as it's not important to apply future patches.

19 REPLIES 19

former_member1716
Active Contributor
0 Kudos
655

Hello Jonathan Blavatsky,

Recommend you to Kindly stick to the file path less than 128 Characters,

You can try using GUI_UPLOAD FM but not sure if its supports all File formats

Regards

0 Kudos
655

I cant get it to work with XLS

0 Kudos
655
if you provide an answer where GUI_Upload can upload an excel file,I will accept your answer ,but as far as I have searched and tried there is problem with data convertion

Sandra_Rossi
Active Contributor
655

You may define a drive which points to a directory (Windows Explorer "map network drive"), that will shorten the path.

0 Kudos
655

can you please elaborate a little more

0 Kudos
655

sorry but this is not a solution to provide to the client,since not all clients will change the directory of their pc's

DoanManhQuynh
Active Contributor
655

your root problem is because that function module only accept a path up to 128 characters. you may use upload using gui_upload and BIN file type, then read the file detail with XML class or transformations...or else you should change to CSV file or xlsx.

former_member1716
Active Contributor
0 Kudos
655

Hello Jonathan Blavatsky,

Try the below Code, This should work:

FORM receive_file .
* Function to Provide F4 for receiving the file
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = s_fname.

*Get the File path to local variable
gw_fname = s_fname.
*Receive the data into an Internal Table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gw_fname
filetype = 'DAT'
TABLES
data_tab = gt_upload
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
ENDFORM.

Try the below steps for formatting the file that you want to load.
1) Prepare the Excel file first with the data in CSV format.
2) Now copy the data from Excel file and paste it in Note pad (Along with Column Name)
3) Paste the Text File as DAT format in your machine
4) Now load your DAT file into the program.

Note: Your GT_UPLOAD Internal table should have the same structure as the File with Data Type   String for all columns. Later you process the Internal table to the required Data type by      passing the Values to Another Internal table which is defined with actual Data Type.

0 Kudos
655

have tried it like this,it does not work,the characters are all wrong and it has only one column ,instead of all the columns that I have already specified from the structure

0 Kudos
655

Sorry maybe I was clear...I will not do any process manually.The goal is to select the file using open file dialog and then call this FM...which turns the data into Binay format...not what I want.the goal to simply select the file and upload it programatically.

0 Kudos
655

It is not logic what you request: "then call this FM" if it does not work it will never work until somebody change the code inside. And I am pretty sure it will never append.

So,

You could use Abap2xls

You could copy the function group & the function module to change the size of the file (the code used the FM GUI_UPLOAD, and this FM used a string)

You could create your own code based on the classes used in this FM

0 Kudos
655
Satish Kumar Balasubramanian It's important that you move your comment (the 4 steps) into your answer (people rarely read the comments).

0 Kudos
655

Thanks for the comment Sandra Rossi, Just Did it 🙂

0 Kudos
655

I'm surprised: couldn't you just edit your answer, instead of adding a new one?

0 Kudos
655
Sandra Rossi , Its Done!

0 Kudos
655

Sandra_Rossi
Active Contributor
656

Just duplicate TEXT_CONVERT_XLS_TO_SAP and increase the length of the parameter.

Duplication of such a simple function module is not an issue, as it's not important to apply future patches.

0 Kudos
655

not the best solution,but its a solution.