Application Development and Automation 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: 
Read only

BAD DATA FORMAT using cl_gui_frontend_services=>gui_upload

0 Likes
3,346

Hello SAPients!

I'm using the method cl_gui_frontend_services=>gui_upload to upload a file to my program like this

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = lvs_input_f1

filetype = 'ASC'

CHANGING

data_tab = in_rec[]

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.

The SY-.SUBRC field always returns with a value of 8 (Bad data format?). The thing is that the last field of the structure IN_REC is of type i (integer) and I think this is the problem. I modified the file with a text editor and set the last field with 2, 4, 8 and 16 chars but I always receive the same error. I can't change the last field to char. Does any one have an idea of what is the problem? How can I ensure that the last field have an integer value?

Thank you.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,338

If you want, you can send me a copy of the file and the program code and I can test it out here. See my email address on my business card.

Regards,

Rich Heilman

Hello SAPients!

I'm using the method cl_gui_frontend_services=>gui_upload to upload a file to my program like this

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = lvs_input_f1

filetype = 'ASC'

CHANGING

data_tab = in_rec[]

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.

The SY-.SUBRC field always returns with a value of 8 (Bad data format?). The thing is that the last field of the structure IN_REC is of type i (integer) and I think this is the problem. I modified the file with a text editor and set the last field with 2, 4, 8 and 16 chars but I always receive the same error. I can't change the last field to char. Does any one have an idea of what is the problem? How can I ensure that the last field have an integer value?

Thank you.

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,339

If you want, you can send me a copy of the file and the program code and I can test it out here. See my email address on my business card.

Regards,

Rich Heilman

Read only

0 Likes
2,338

Hi,

i encountered a similar problem. It looks like only the key fields of a structure can be integers when working with alv. We also had a date field, and when the end users tried to sort on this field it gave them some weird result since the systems considers the dates as chars. I solved this by entering the date as yyyymmdd. This way the sorting works eg 2001 01 01 then 2001 01 12 etc.

Hope to see if there is another way of solving this.

Best regards,

Kevin.

Read only

0 Likes
2,338

Sorry read to quick. My answer isn't really related.

Read only

0 Likes
2,338

Ok, I have modified the code a bit, you might want to try it. First upload to a table of type STRING, then move the values to the other internal table.



report zrich_0001 .

data: begin of in_rec occurs 0,
         matnr(18),        "Material Number
         bwkey like mbew-bwkey,         " For Plant
         werks like mbew-bwkey,         " Add Plant
         type(2) type c,                " TYPE.
         cname(50) type c,              " Changble Name
         bom(1) type c,                 " BOM Usage
         task(2) type c,                " task type
         verid_nd like ckmlmv001-verid_nd,  "Production Version
         perc(16) type c,               " Percent for Plant1
* above are user inputs ; below are program flag.
         flag(1) type c,                " Program flag.
         kalnr like ckmlmv001-kalnr,     "
         mix_flag(1) type c,                " Program flag.
         cnt type i,
      end of in_rec.

data: istr type table of string with header line.

parameters: p_file type localfile.


at selection-screen on value-request for p_file.

  data retfiletable type filetable.
  data retrc type sysubrc.
  data retuseraction type i.

  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      multiselection    = abap_false
    changing
      file_table        = retfiletable
      rc                = retrc
      user_action       = retuseraction.
  read table retfiletable into p_file index 1.

start-of-selection.

  perform open_file.




*&---------------------------------------------------------------------*
*&      Form  OPEN_FILE
*&---------------------------------------------------------------------*
form open_file.
*------------------------ Begin Change - UN001 ------------------------*
*  CALL FUNCTION 'WS_UPLOAD'
*    EXPORTING
*      filename = input_f1
*      filetype = 'DAT'
*    TABLES
*      data_tab = in_rec.
  data:
    lvs_input_f1 type string.              " To store filename
*    lit_mat_tbl  TYPE TABLE OF lt_raw_tab, " To store file lines
*    lwa_mat_tbl  TYPE lt_raw_tab.          " Work area
*
  lvs_input_f1 = p_file.
*    lvs_input_f1 = input_f1.

  call method cl_gui_frontend_services=>gui_upload
    exporting
      filename                = lvs_input_f1
      filetype                = 'ASC'
    changing
      data_tab                = istr[]
    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                  = 19.


  if sy-subrc ne 0.
*    WRITE / text-e01.
    message e000(fb) with text-e01.
  endif.


  loop at istr.
    in_rec = istr.
    append in_rec.
  endloop.

  loop at in_rec.
    write:/ in_rec.
  endloop.

*------------------------ End Change   - UN001 ------------------------*

*SKD 08/02/06---------DEVK980441-----------v
  delete in_rec where perc = 0.
*SKD 08/02/06---------DEVK980441-----------^

endform.                    "OPEN_FILE

Regards,

Rich Heilman

Read only

0 Likes
2,338

Rich,

I tried your solution and get the error ""IN_REC" and "ISTR" are not mutually convertible in a Unicode program". I forgot to mention that we are converting everything to be Unicode enabled.

I also tried to move the fields based on the offset, one by one but when I get to the integer field, it fails.

Read only

0 Likes
2,338

Can you get rid of the || at the end of each line? If so, do so, because this is causing your problem.

Regards,

Rich Heilman

Read only

0 Likes
2,338

How did you fix your problem; I have similar problem uploading files to a structure with INT4 data type

thanks

Read only

Former Member
0 Likes
2,338

Hai

Check the following Code

tables : mara.

types : begin of t_mara,

matnr type mara-matnr,

meins type mara-meins,

end of t_mara.

data : it_mara type standard table of t_mara with header line.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

FILENAME = 'C:\Documents and Settings\sreenivasulup\Desktop\mat_file.txt'

FILETYPE = 'ASC'

CHANGING

data_tab = it_mara[]

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.

loop at it_mara.

write 😕 it_mara-matnr,

it_mara-meins.

endloop.

The flat file Structure as follows

SREE_MAT011 KG

SREE_MAT012 KG

SREE_MAT013 KG

Regards

Sreeni

Read only

0 Likes
2,338

Sreeni,

I appreciate you take the time to answer, but I don't have problems when all the fields are of type Char, the problem occurs because the last field is of type I.

This is the structure where I'm trying to load the data from the file:

DATA: BEGIN OF in_rec OCCURS 0,

matnr(18), "Material Number

bwkey LIKE mbew-bwkey, " For Plant

werks LIKE mbew-bwkey, " Add Plant

type(2) TYPE c, " TYPE.

cname(50) TYPE c, " Changble Name

bom(1) TYPE c, " BOM Usage

task(2) TYPE c, " task type

verid_nd LIKE ckmlmv001-verid_nd, "Production Version

perc(16) TYPE c, " Percent for Plant1

  • above are user inputs ; below are program flag.

flag(1) TYPE c, " Program flag.

kalnr LIKE ckmlmv001-kalnr, "

mix_flag(1) TYPE c, " Program flag.

cnt TYPE i,

END OF in_rec.

You can see the CNT field is of type i (integer) and for some reason the system can't interpret that.

Read only

0 Likes
2,338

Hai

Check the code again

tables : mara.

types : begin of t_mara,

matnr type mara-matnr,

sno type I,

meins type mara-meins,

end of t_mara.

data : it_mara type standard table of t_mara with header line.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

FILENAME = 'C:\Documents and Settings\sreenivasulup\Desktop\file.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

DAT_MODE = 'X'

CHANGING

data_tab = it_mara[]

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.

loop at it_mara.

write 😕 it_mara-matnr,

it_mara-sno,

it_mara-meins.

endloop.

endif.

Flat file structure like the following way

SREE_MAT014 1 KG

SREE_MAT015 2 KG

SREE_MAT016 3 KG

regards

Sreeni