‎2013 Mar 30 9:08 AM
Hi all,
I am a fresher and was working on uploading a .prn(space delimited) text file into my internal table. I get this Bad data format exception even after I attempted all trials. Any help is appreciated. Here is the code in the attached text file.
‎2013 Mar 30 10:28 AM
HI Vishnu,
check out the following code........
***************************
Data: d_filename like IBIPPARMS-PATH,
d_file type string.
data : begin of itab occurs 0,
values(1000) type c,
end of itab.
* The following function module calls the File/Path Selector Dialog Box
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = d_filename.
d_file = d_filename.
* The following function module uploads the file into the internal table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = d_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = itab
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.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Output the internal Table
loop at itab.
Write:/ ITAB.
endloop.
thanks and regards,
narayan
‎2013 Mar 30 9:12 AM
Code is here:
types: begin of ty_data,
mandt type mara-mandt,
kunnr type kna1-kunnr,
matnr type mara-matnr,
EDI_UOM type mara-meins,
EPackQty type marc-BASMG,
BUOM type mara-meins,
BUOMQty type marc-BASMG,
AUOM type mara-meins,
AUOMQty type marc-BASMG,
end of ty_data.
data: it_data type table of ty_data with header line,
wa_data type ty_data,
filename type ibipparms-path,
file type string.
data: it_data1 type table of ALSMEX_TABLINE,
wa_data1 like line of it_data1.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = filename
.
file = filename.
*CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
* EXPORTING
* FILENAME = file
* I_BEGIN_COL = 1
* I_BEGIN_ROW = 2
* I_END_COL = 9
* I_END_ROW = 1000
* TABLES
* INTERN = it_data1
** EXCEPTIONS
** INCONSISTENT_PARAMETERS = 1
** UPLOAD_OLE = 2
** OTHERS = 3
* .
*IF SY-SUBRC <> 0.
* else.
* loop at it_data1 into wa_data1.
* write:wa_data1-value.
* ENDLOOP.
*
** Implement suitable error handling here
*ENDIF.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = file
FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_DATA
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
.
IF SY-SUBRC <> 0.
ENDIF.
‎2013 Mar 30 10:28 AM
HI Vishnu,
check out the following code........
***************************
Data: d_filename like IBIPPARMS-PATH,
d_file type string.
data : begin of itab occurs 0,
values(1000) type c,
end of itab.
* The following function module calls the File/Path Selector Dialog Box
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = d_filename.
d_file = d_filename.
* The following function module uploads the file into the internal table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = d_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = itab
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.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Output the internal Table
loop at itab.
Write:/ ITAB.
endloop.
thanks and regards,
narayan
‎2013 Mar 31 8:35 AM
Hi uppu narayan,
Thank you very much for your code. It did work, but I want to work on the individual fields imported from the file. Your code takes each row as only one entry in the internal table. I would want to declare fields of the internal table referring to some data types and then want to move the data into that internal table, so that I can work on each individual field later on.Hope you understand what I mean.
Vishnu
‎2013 Mar 30 10:57 AM
Hello vishnu,
use:
data: filename type localfile.
when you use f4_filename then use before this fm,
at selection screen on value request for <input fieldname>.
use only one function module..if you upload data from excel file, then use only 'ALSM_EXCEL_TO_INTERNAL_TABLE'.
if you upload data from notepad , then use 'GUI_UPLOAD'.
if you use 'GUI_UPLOAD'. then follow my below code:
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = filename
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' | '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_DATA
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
.
you mention that you are a fresher, so right now you practiced on using notepad...dont use excel file....because you have to code for excel...as a fresher first you learn using notepad....
Hope it will be much helpfull for you.....
Thanks
Sabyasachi
‎2013 Mar 30 11:09 AM
Hello,
am forget to tell you one thing...
when you create a note pad then use tab button in key board.
eg:
1000 <then press tab> 10 <press tab>..................
Thanks
Sabyasachi
‎2013 Mar 31 8:43 AM
Hi Sabyasachi,
Thank you very much for your suggestion. I already worked on notepads with tab delimited data.The issue is that I have a csv file which I am saving as text formatted file with space delimited (.prn).I have declared fields of internal table corresponding to the fields from the file. And so, I want to pull data into the internal table. so that I can work on each filed individually. Hope you get me.
‎2013 Mar 31 8:56 AM
Hello,
i have no idea about CSV file...i am worked on EXCELL and notepad...but if you use notepad, then after execution of GUI_UPLOAD FM , you can see your internal table in debugging mode.....you find all records from flat file....
Thanks
Sabyasachi
‎2013 Mar 30 4:41 PM
Hey Vishnu,
I just checked your code, just a general suggestion as you are a fresher:
data: it_data type table of ty_data with header line, ****remove with header line when you are already using wa
wa_data type ty_data,
Regards
Purnand
‎2013 Mar 31 8:28 AM
‎2013 Mar 31 8:38 AM
Pleasure.Please close the thread if your issue is resolved. If not, please do let us know.
Regards
Purnand
‎2013 Apr 02 7:27 AM