Skip to Content
0
Jan 22, 2013 at 07:50 PM

Prevent uploading # character from a file

32 Views

Hello

I need to enchance a code given below. I'm not an ABAP programmer so it is really difficult to me. Here is a problem. I have a program that allows users to upload csv documents to BW that are push to DSO by DTP. Most of users know that # character is not allowed in csv file, but some of them by mistake or not try to upload files with such a character. That causes data corruption and DTP fail.

What I'd like to do is to let them upload files with any data they want and modify the program that way it removes any # character it finds.

Example of a file:

MATERIAL, APO Attribute 1 ,APO Attribute 2

000345654, #, #

334542454, Essential, Essential

I'd like it to be uploaded:

MATERIAL, APO Attribute 1 ,APO Attribute 2

000345654, ,

334542454, Essential, Essential

The program is quite long but as I understand ABAP this is the part that is important from my point of view because here the program uploads data from a file.

How to prevent # loading? How to trim that character?

*eject
*&---------------------------------------------------------------------*
*& Form 1000_get_data
*&---------------------------------------------------------------------*
* uploading data into internal table
*----------------------------------------------------------------------*
form 1000_get_data.

call function 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = t_rec
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10.

if sy-subrc ne 0.
message s999 with text-004.

stop.
endif.

refresh t_upload.

if p_skip ne c_space or
p_skip ne 0.
delete t_rec to p_skip.
endif.

loop at t_rec into line.

CONCATENATE line ',' INTO line.

SPLIT line AT c_comma INTO TABLE t_columns.

LOOP AT t_columns into wa_columns.

translate wa_columns to upper case.

if wa_columns eq c_delete or
wa_columns eq c_caps.
clear wa_columns.
modify t_columns from wa_columns.
elseif wa_columns eq c_space.
wa_columns = C_X.
modify t_columns from wa_columns.
endif.

clear wa_columns.
endloop.
CONCATENATE LINES OF t_columns INTO record SEPARATED BY c_comma.

split record at c_comma into t_upload-MATERIAL
t_upload-/BIC/ZCAPOATT1
t_upload-/BIC/ZCAPOATT2

append t_upload.

w_counter = w_counter + 1.

loop at t_upload from w_counter.

if t_upload-MATERIAL ne space and
t_upload-MATERIAL co ' 0123456789'.
shift t_upload-MATERIAL right deleting trailing space.
translate t_upload-MATERIAL using c_spzero.
endif.

perform 2100_convert_matnr_18 changing t_upload-MATERIAL.

clear /BIC/ZMATTABLE00.
select single
MATERIAl
RECORDMODE
/BIC/ZCAPOATT1
/BIC/ZCAPOATT2

into /BIC/ZMATTABLE00
from /BIC/ZMATTABLE00
where MATERIAL eq t_upload-MATERIAL.

if sy-subrc eq 0 or
sy-subrc eq 4.


if t_upload-/BIC/ZCAPOATT1 eq 'X'.
t_upload-/BIC/ZCAPOATT1 = /BIC/ZMATTABLE00-/BIC/ZCAPOATT1.
modify t_upload.
clear /BIC/ZMATTABLE00-/BIC/ZCAPOATT1.
endif.
if
t_upload-/BIC/ZCAPOATT2 eq 'X'.
t_upload-/BIC/ZCAPOATT2 = /BIC/ZMATTABLE00-/BIC/ZCAPOATT2.
modify t_upload.
clear /BIC/ZMATTABLE00-/BIC/ZCAPOATT2.
endif.

endif.
endloop.

endloop.

endform. "1000_get_data