2014 Jun 30 9:17 AM
Hi,
I am new to Abap. I have a problem. When I upload my text file (.txt) to SAP, the spacing during the upload is different.Can someone help me.
My program tab is
DATA: V_SEPARATOR TYPE X.
DATA: L_VALUE TYPE I VALUE 09. "09=TAB 44=, 124=|
V_SEPARATOR = L_VALUE.
2014 Jun 30 9:29 AM
Hello,
Can you send your source code and file so that we can help?
Ali Murat
2014 Jun 30 9:35 AM
2014 Jun 30 9:44 AM
2014 Jun 30 9:50 AM
there are alot of given functions /classes for importing files.
but if you want to know how to do it manuel with open Dataset and read dataset, the best way is to read into a structure which consists only of char fields - make sure that the rows are fixed - e.g. by using leading 0 in number fields and using space in char fields. After that transfer to ur wanted structure and do the mappings into other filedtypes. like int or packed.
regards
Stefan Seeburger
2014 Jun 30 9:33 AM
Hello ,
Do a word wrap in notepad before uploading to SAP.
Thanks
2014 Jun 30 11:42 AM
Hello,
I prepared a sample code for you. The below code is just enough for your requirement.
Please implement this code into your original source code. The below code is the part that reads the data from text file.
Regards
Ali Murat
DATA : BEGIN OF gt_p OCCURS 0 ,
pernr LIKE pa0001-pernr ,
begda(10) ,
status(4) ,
msgtx(100) ,
mark ,
END OF gt_p.
DATA : file TYPE STANDARD TABLE OF file_table.
DATA : wa_file TYPE STANDARD TABLE OF file_table WITH HEADER LINE.
DATA : rc TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file(100) OBLIGATORY DEFAULT 'C:\',
p_mode LIKE ctu_params-dismode DEFAULT 'N' .
SELECTION-SCREEN END OF BLOCK b1 .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_filename.
FORM get_filename .
CLEAR : file, file[].
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select file'
default_extension = 'TXT'
default_filename = 'c:\bb.txt'
initial_directory = 'C:\'
CHANGING
file_table = file
rc = rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ TABLE file INTO wa_file INDEX 1.
MOVE wa_file-filename TO p_file.
ENDFORM. " get_filename
DATA : sfilename TYPE string.
MOVE p_file TO sfilename.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = sfilename
filetype = 'ASC'
has_field_separator = 'X'
CHANGING
data_tab = gt_p[]
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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
EXIT.
ENDIF.
2014 Jun 30 12:57 PM
Hello
try this code
types: begin of tw_customer,
kunnr type kunnr,
ktokd type ktokd,
name1 type name1_gp,
end of tw_customer,
tt_customer type standard table of tw_customer.
data: lf_fname type string,
lt_customer type tt_customer.
selection-screen begin of block bk1 with frame title text-001.
parameters : pa_fname type localfile.
selection-screen end of block bk1.
at selection-screen on value-request for pa_fname.
* F4 functionality for File Name
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
importing
file_name = pa_fname.
START-OF-SELECTION.
lf_fname = pa_fname.
call function 'GUI_UPLOAD'
exporting
filename = lf_fname
filetype = 'ASC'
has_field_separator = 'X'
read_by_line = 'X'
tables
data_tab = lt_customer.
*ENDFORM. " F_GET_USERNAME
end-of-SELECTION.
2014 Jul 02 2:55 AM
Hi guys,
Thank you for the solutions. It does somehow works but in my source data, the spacing of one row (Item1 and Item 2) is using spacing. In my original plan I used tab-delimeted.
Can someone help me how to changed the tab-delimeted to space.
Thank You
2014 Jul 02 6:07 AM
Hi,
Step-1 Take a Backup of source data.
Step-2 Save the file in .XLS
Step-3 Save the source data(.XLS) FILE as CSV comma delimitted
Step-4 save the csv file into .txt(ms-dos) format
step-5 open the txt file u will see tab delimited will be replaced by ,
step-6 goto replace option find comma with SPACE Replace all
Thanks
Sudhi ranjan parija
2014 Jul 02 6:37 AM
HI ranjan,
Can you tell me how to take source code back up..
Thank u
vamshi
2014 Jul 02 6:52 AM
Hi vamshi
Source DATA backup is place tab delimited text file in some other file.
Source code backup is coping program into notepad for each and every include.
u can print it also in pdf by setting in abap editor.
thanks,
Sudhir
2014 Jul 02 8:02 AM
Sudhir,
Im trying to change it at SAP. Where do I change the tab delimit to space..
2014 Jul 02 8:39 AM
Just as a help, don't define the tab delimiter as you have; use instead the constant CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |