2011 Jul 22 7:32 AM
Hi,
I have a requirement to upload data in text file using the function module 'GUI_UPLOAD'. The format of my text file looks like this:
TCODEWERKSSTLANPOSNRMENGEPOSTPMATNRSTLNRSTLALBMENGBMEINDATUVSTLSTIDNRKMEINS
CS01M019100101.000LTRT4500100000097011.000PC2001.09.041000000005989031072PCTRITON X45 CS01M019100201.000LTRT4500100000097011.000PC2001.09.041000000005989031282PCTRITON X45
When I tried to upload it, it seems that those values do not correspond on its specific fields in the internal table maybe because of the field length.How can I go about this? Hoping for your response.
Thanks a lot!
2011 Jul 22 7:37 AM
for which transaction your are uploading , if possible post the code .
if you think that it is because of field length the try to declare a temp variable with more field lenget and assign the value to it.
data: temp(23) type char.
2011 Jul 22 8:16 AM
Hi,
GUI_UPLOAD eaxcepts onlt tab saperated file and your file is '^' saperated, hence as a workaround you can try below code,
REPORT ztest_u_6.
TYPES: BEGIN OF ty_data,
tcode TYPE sy-tcode,
werks TYPE werks,
stlan TYPE stlan,
posnr TYPE posnr,
menge TYPE char16,
postp TYPE postp,
matnr TYPE matnr,
stlnr TYPE num8,
stlal TYPE stlal,
bmeng TYPE char16,
bmein TYPE bmein,
datuv TYPE datuv,
stlst TYPE stlst,
idnrk TYPE idnrk,
meins TYPE meins,
END OF ty_data.
DATA : it_data TYPE table of ty_data,
wa_data TYPE ty_data.
TYPES: BEGIN OF ty_up,
val TYPE char120,
END OF ty_up.
DATA : it_up TYPE table of ty_up,
wa_up TYPE ty_up.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\Encrypt\sdn.txt'
* FILE = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = it_up
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_ = 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
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_up INTO wa_up.
SPLIT :wa_up AT '^'
INTO wa_data-tcode
wa_data-werks
wa_data-stlan
wa_data-posnr
wa_data-menge
wa_data-postp
wa_data-matnr
wa_data-stlnr
wa_data-stlal
wa_data-bmeng
wa_data-bmein
wa_data-datuv
wa_data-stlst
wa_data-idnrk
wa_data-meins.
APPEND wa_data to it_data.
CLEAR : wa_data,
wa_up.
endloop.
LOOP AT it_data INTO wa_data.
write / wa_data.
ENDLOOP.
2011 Jul 22 8:33 AM
Uman,
GUI_UPLOAD eaxcepts onlt tab saperated file and your file is '^' saperated is NOT TRUE.
GUI_UPLOAD can upload ^ separated text File also, just try with a small example.
Ysera,
Just use table of type ls_data_str in TABLES section of GUI_UPLOAD and then loop over it to do a move-corresponding to ls_data.
BR,
Diwakar
Edited by: Diwakar Aggarwal on Jul 22, 2011 3:33 PM
2011 Jul 22 9:15 AM
> GUI_UPLOAD eaxcepts onlt tab saperated file and your file is '^' saperated is NOT TRUE.
> GUI_UPLOAD can upload ^ separated text File also, just try with a small example.
Can you elaborate what you mean by this? As per the documentation these GUI* FMs only recognize horizontal tabs only!
2011 Jul 22 10:39 AM
Suhas,
I tried it with a small example to upload a notepad file having ^ separated data and it works fine.
I paste below the sample code, do let me know if I am missing something.
=================================================================
TYPES: begin of lty_data_str, "Character type
tcode type char4,
delimit1 type c,
werks type char4,
delimit2 type c,
stlan type char1,
end of lty_data_str.
TYPES: begin of lty_data, "real data type
tcode type sy-tcode,
werks type werks_d,
stlan type stlan,
end of lty_data.
data: lt_data_str type TABLE OF lty_data_str,
lt_data type TABLE OF lty_data,
ls_data_str type lty_data_str,
ls_data type lty_data.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\AL11\TEST.TXT'
tables
data_tab = lt_data_str.
loop at lt_data_str into ls_data_str.
MOVE-CORRESPONDING ls_data_str to ls_data.
APPEND ls_data to lt_data.
clear: ls_data_str, ls_data.
endloop.
===============================================
My notepad file contains below data::
MM011234P
MM022323M
===============================================
I am able to get data in lt_data table in relevant fields, please share if you see any problem with this code.
BR,
Diwakar
2011 Jul 22 10:56 AM
Obviously if you declare a seperate field for the delimiter, it would work. But its not what is intented to be done. What you have done is just a workaround.
What Suhas and the documentation meant was that, it would work without any extra fields for delimiters only for horizontal tabs.
Vikranth
2011 Jul 22 10:59 AM
Hello Diwakar,
This is a classic case of lost in translation
Of course GUI_UPLOAD will upload files with '^', but not as a separator!(HAS_FIELD_SEPARATOR param).
BR,
Suhas
2011 Jul 22 11:04 AM
Hi Suhas,
Great to see you with the 'M' tag. Congratulations
Vikranth
2011 Jul 22 11:14 AM
yes nice to see suhas with 'M' tag... Congrats...Your suggestions really awesome..
Regards,
Nagaraj
2011 Jul 22 11:36 AM
Well, probably downloading lots of Files from last many days from application server having all kinds of separators triggered me to this solution Rightly said, lost in translation .....anyways thanks all for your comments
2011 Jul 22 8:22 AM
Ysera,
IF you are having fixed length of fields in your file (which looks the case for you), then it is simple to use any character strings first and then transfer to the respective fields using move-corresponding.
=======================================================
data: begin of ls_data_str, "Character type
tcode type char4,
delimit1 type c,
werks type char4,
delimit2 type c,
stlan type char4,
-
so on
end of ls_data_str.
data: begin of ls_data, "actual data types
tcode type sy-tcode,
werks type werks_d,
stlan type stpo-stlan,
-
so on
end of ls_data.
read dataset xyz into ls_data_str.
if sy-subrc = 0.
move-corresponding ls_data_str to ls_data.
endif.
ls_data is your actual data.
============================
If length of fields in file is not fixed (^ is not at same position for every row), then you need to use field symbols for uploading, let me know if you need help there.
2011 Jul 22 10:37 AM
2011 Jul 22 12:06 PM
Hi,
check the below code. it will work fine.
TYPES: BEGIN OF ty_data,
tcode TYPE sy-tcode,
werks TYPE werks,
stlan TYPE stlan,
posnr TYPE posnr,
menge TYPE char16,
postp TYPE postp,
matnr TYPE matnr,
stlnr TYPE num8,
stlal TYPE stlal,
bmeng TYPE char16,
bmein TYPE bmein,
datuv(10) TYPE c, "datuv,
stlst TYPE stlst,
idnrk TYPE idnrk,
meins TYPE meins,
fval(10) TYPE c,
END OF ty_data.
DATA : it_data TYPE TABLE OF ty_data,
wa_data TYPE ty_data.
TYPES: BEGIN OF ty_up,
val TYPE char120,
END OF ty_up.
DATA : it_up TYPE TABLE OF ty_up,
wa_up TYPE ty_up.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\Encrypt\sdn.txt'
FILE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
TABLES
data_tab = it_up[].
LOOP AT it_up INTO wa_up.
SPLIT :wa_up AT '^'
INTO wa_data-tcode
wa_data-werks
wa_data-stlan
wa_data-posnr
wa_data-menge
wa_data-postp
wa_data-matnr
wa_data-stlnr
wa_data-stlal
wa_data-bmeng
wa_data-bmein
wa_data-datuv
wa_data-stlst
wa_data-idnrk
wa_data-meins
wa_data-fval.
APPEND wa_data TO it_data.
CLEAR : wa_data,
wa_up.
ENDLOOP.
LOOP AT it_data INTO wa_data.
WRITE / wa_data.
ENDLOOP.
Ram.