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

GUI_UPLOAD Issue -Upaloading only 1 row

Former Member
0 Likes
3,184

Hi,

what is wrong in my code.

My intention is to load all entries which I got in internal table i_tab but it is updating only 1 entry.

REPORT zupload MESSAGE-ID bd.

TABLES: zlabor.

TYPES : BEGIN OF t_labor,

zdate TYPE zlabor-zdate,
empid TYPE zlabor-empid,
lname TYPE zlabor-lname,
fname TYPE zlabor-fname,
cycle TYPE zlabor-cycle,
branch TYPE zlabor-branch,
job TYPE zlabor-job,
phase TYPE zlabor-phase,
pdept TYPE zlabor-pdept,
ptype TYPE zlabor-ptype,
zhour TYPE zlabor-zhour,
  END OF t_labor.

DATA: w_tab TYPE t_labor.
DATA: i_tab TYPE STANDARD TABLE OF t_labor.

DATA: v_subrc(2),
v_recswritten(6).

PARAMETERS: p_file(80)
DEFAULT 'C:\sss.TXT'.

DATA: filename TYPE string,
w_ans(1) TYPE c.

filename = p_file.


CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
* FILETYPE = 'ASC
has_field_separator = ','
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_tab
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.

* SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *

IF sy-subrc <> 0.
  v_subrc = sy-subrc.
  MESSAGE e899 WITH 'File Open Error' v_subrc.
ENDIF.

LOOP AT i_tab INTO w_tab.

  MOVE w_tab-zdate TO zlabor-zdate.
  MOVE  w_tab-empid TO zlabor-empid.
  MOVE  w_tab-lname TO zlabor-lname.
  MOVE  w_tab-fname TO zlabor-fname.
  MOVE  w_tab-cycle TO zlabor-cycle.
  MOVE w_tab-branch TO zlabor-branch.
  MOVE w_tab-job TO zlabor-job.
  MOVE w_tab-phase TO zlabor-phase.
  MOVE w_tab-pdept TO zlabor-pdept.
  MOVE w_tab-ptype TO zlabor-ptype.
  MOVE w_tab-zhour TO zlabor-zhour.

  MODIFY zlabor  .
  COMMIT WORK.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,840

Also in my ztable except MANDT field everything is unchecked for key field

That is exactly why you are getting only one record in your z table. You need to have a unique indentifier for each record. You can simply use a rowindex if you want. Define a field, called ROWINDEX and mark it as a key field after MANDT in your table. Then when filling your z table, simply use a counter and increment it and fill the row index field.

Loop at i_tab into wa_tab.

wa_tab-row_index = sy-tabix.
...
...
MODIFY ztable.


endloop.

Regards,

Rich Heilman

Hi,

what is wrong in my code.

My intention is to load all entries which I got in internal table i_tab but it is updating only 1 entry.

REPORT zupload MESSAGE-ID bd.

TABLES: zlabor.

TYPES : BEGIN OF t_labor,

zdate TYPE zlabor-zdate,
empid TYPE zlabor-empid,
lname TYPE zlabor-lname,
fname TYPE zlabor-fname,
cycle TYPE zlabor-cycle,
branch TYPE zlabor-branch,
job TYPE zlabor-job,
phase TYPE zlabor-phase,
pdept TYPE zlabor-pdept,
ptype TYPE zlabor-ptype,
zhour TYPE zlabor-zhour,
  END OF t_labor.

DATA: w_tab TYPE t_labor.
DATA: i_tab TYPE STANDARD TABLE OF t_labor.

DATA: v_subrc(2),
v_recswritten(6).

PARAMETERS: p_file(80)
DEFAULT 'C:\sss.TXT'.

DATA: filename TYPE string,
w_ans(1) TYPE c.

filename = p_file.


CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
* FILETYPE = 'ASC
has_field_separator = ','
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_tab
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.

* SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *

IF sy-subrc <> 0.
  v_subrc = sy-subrc.
  MESSAGE e899 WITH 'File Open Error' v_subrc.
ENDIF.

LOOP AT i_tab INTO w_tab.

  MOVE w_tab-zdate TO zlabor-zdate.
  MOVE  w_tab-empid TO zlabor-empid.
  MOVE  w_tab-lname TO zlabor-lname.
  MOVE  w_tab-fname TO zlabor-fname.
  MOVE  w_tab-cycle TO zlabor-cycle.
  MOVE w_tab-branch TO zlabor-branch.
  MOVE w_tab-job TO zlabor-job.
  MOVE w_tab-phase TO zlabor-phase.
  MOVE w_tab-pdept TO zlabor-pdept.
  MOVE w_tab-ptype TO zlabor-ptype.
  MOVE w_tab-zhour TO zlabor-zhour.

  MODIFY zlabor  .
  COMMIT WORK.

ENDLOOP.

10 REPLIES 10
Read only

Former Member
0 Likes
1,840

Do you have LINE FEED in ur file?

thanq

Read only

0 Likes
1,840

My file is comma delimted text file and has a single header row .

What do you mean by line-feed?

rgds

vara

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,840

I've seen issue with this in the past, if the file has not be created by using GUI_DOWNLOAD and specifiying "WRITE_FIELD_SEPARATOR", then there will be issues with reading it in, using GUI_UPLOAD, and specifiying HAS_FIELD_SEPARATOR. Basically what I would suggest is for you to comment out this parameter in the GUI_UPLOAD function call. And define your internal table as a table of strings, then loop at this internal table and split the line at ','(comma).

Types: begin of t_data,
         line type string,
        end of t_data.
data: i_datatab type table of t_data.
data: x_datatab like line of i_datatab.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
* FILETYPE = 'ASC
* has_field_separator = ','   <-- Comment this
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_datatab
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.

Loop at i_datatab into x_datatab.

split x_datatab at ',' into wa_tab-zdate
wa_tab-empid wa_tab-lname wa_tab-fname wa_tab-cycle wa_tab-branch 
wa_tab-job wa_tab-phase wa_tab-pdept wa_tab-ptype wa_tab-zhour .

append wa_tab to i_tab.
endloop.

Regards

Rich Heilman

Read only

Former Member
0 Likes
1,840

The code looks fine.

You could try creating a file from SAP with something like


 do 3 times.
   w_tab-zdate = sy-datum.
   w_tab-empid = sy-index.
   append w_tab to i_tab2.
 enddo.

   call function 'GUI_DOWNLOAD'
     exporting
       filename                        = filename
       FILETYPE                        = 'ASC'
       WRITE_FIELD_SEPARATOR = ','
     tables
       data_tab                        = i_tab2.

That would work for the upload, and then look at the two files and see what is different between them.

Read only

Former Member
0 Likes
1,840

What do you mean "updating only one entry"?

Is there only one record in i_tab, or is only one record in zlobor changed?

Rob

Read only

Former Member
0 Likes
1,840

Hi,

after the function module call , check how many entries are there in internal table,

if you get all the entries then use the code given below,

"Instead of loop try using 

modify zlabor from table itab.

if you are getting only one entry in the internal table,

check the txt file if the field separator is tab or a single space, because gui_upload accepts only two field separator,

either tab or space...

if its tab then

has_field_separator = 'X'

change this to call function statement

if its space then

has_field_separator = 'X'

if its neither of the above then please make sure that the field separator in the file has a tab space and make the value as 'X' in the program for has_field_separator.

Regards,

Siddarth

Read only

0 Likes
1,840

Rich,

I modified my code accordingly.

Although my Internal table has all entries it is not updating my table.I am only getting a single entry in ztable.

*----------------------------------------------*

REPORT  zlabor                    .

TABLES: zlabor.

TYPES : BEGIN OF t_labor,

zdate TYPE zlabor-zdate,
empid TYPE zlabor-empid,
lname TYPE zlabor-lname,
fname TYPE zlabor-fname,
cycle TYPE zlabor-cycle,
branch TYPE zlabor-branch,
job TYPE zlabor-job,
phase TYPE zlabor-phase,
pdept TYPE zlabor-pdept,
ptype TYPE zlabor-ptype,
zhour TYPE zlabor-zhour,
  END OF t_labor.

DATA: wa_tab TYPE t_labor.
DATA: i_tab TYPE STANDARD TABLE OF t_labor.


PARAMETERS : file TYPE  STRING.

TYPES: BEGIN OF t_data,
        line TYPE string,
       END OF t_data.
DATA: i_datatab TYPE TABLE OF t_data.
DATA: x_datatab LIKE LINE OF i_datatab.


DATA : path TYPE string,
       cnt(5).

path = file.

**********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file.

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    CHANGING
      file_name = file.

**********************************************************************
START-OF-SELECTION.

  PERFORM file_upload.

**
*&---------------------------------------------------------------------*
*&      Form  file_upload
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM file_upload.


  CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
  filename = file
* FILETYPE = 'ASC
* has_field_separator = ','   <-- Comment this
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
  TABLES
  data_tab = i_datatab
  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.

  LOOP AT i_datatab INTO x_datatab.

    SPLIT x_datatab-line AT ',' INTO wa_tab-zdate
    wa_tab-empid wa_tab-lname wa_tab-fname wa_tab-cycle wa_tab-branch
    wa_tab-job wa_tab-phase wa_tab-pdept wa_tab-ptype wa_tab-zhour .

    APPEND wa_tab TO i_tab.
  ENDLOOP.




  LOOP AT i_tab INTO wa_tab.

    MOVE wa_tab-zdate TO zlabor-zdate.
    MOVE  wa_tab-empid TO zlabor-empid.
    MOVE  wa_tab-lname TO zlabor-lname.
    MOVE  wa_tab-fname TO zlabor-fname.
    MOVE  wa_tab-cycle TO zlabor-cycle.
    MOVE wa_tab-branch TO zlabor-branch.
    MOVE wa_tab-job TO zlabor-job.
    MOVE wa_tab-phase TO zlabor-phase.
    MOVE wa_tab-pdept TO zlabor-pdept.
    MOVE wa_tab-ptype TO zlabor-ptype.
    MOVE wa_tab-zhour TO zlabor-zhour.

    MODIFY zlabor.
    COMMIT WORK.

  ENDLOOP.


ENDFORM.                    "file_upload

Also in my ztable except MANDT field everything is unchecked for key field.

Read only

0 Likes
1,840

>

> Also in my ztable except MANDT field everything is unchecked for key field.

That would be it then.

You can only have one entry for each unique key combination. You need to identify what the key fields should be.

Rob

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,841

Also in my ztable except MANDT field everything is unchecked for key field

That is exactly why you are getting only one record in your z table. You need to have a unique indentifier for each record. You can simply use a rowindex if you want. Define a field, called ROWINDEX and mark it as a key field after MANDT in your table. Then when filling your z table, simply use a counter and increment it and fill the row index field.

Loop at i_tab into wa_tab.

wa_tab-row_index = sy-tabix.
...
...
MODIFY ztable.


endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,840

Thank you Rich! It worked!