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

STRANGE PROBLEM WHILE MOVING DATA TO NUMERIC FIELD

Former Member
0 Likes
862

Hi all,

IAM HAVING A STRANGE PROBLEM WHILE UPLOADING.

iAM UPLOADING A TEXT FILE AND ONE FIELD IS TYPE N

SAY INT(4) TYPE N.

IAM SPLITTING THE FILE BECAUSE ITS A TAB DELIMITED FILE.

WHEN MY INT VALUE IS 1 IT SHOULD BECOME 0001 RIGHT BECAUSE ITS A TYPE N AND LENGTH 4 . BUT ITS NOT HAPPENING

ITS TAKING AS 1

WHEN I SORT THE INTERNAL TABLE BASED ON INT.

IT SORTS BASED ON FIRST FIELD.

tHIS SHOULDN'T HAPPEN I GUESS BECAUSE ITS TYPE N BUT TO WORK NORMALLY THE FIELD SHOULD CONTAIN LEADING ZEROS.

WHEN I CHECKED LIKE

data : begin of itab occurs 0,

my_num(4) type N,

end of itab .

itab-my_num = 221 . append itab.

ITAB HAS VALUE 0221.

AND WHEN I SORT IT WORKS FINE.

dOES ANYONE HAVE AN IDEA AS TO WHAT IS HAPPENING IN HERE

THANKS IN ADVANCE

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
829

Can you post the exact code where you are seeing this. It should be giving a value of 0001

Regard,

Rich Heilman

Read only

Former Member
0 Likes
829

HI,

i have writen the same program in my system, itis giving the correct result.

can you copy this program and test in your system whether you are getting the correct data ....

data : begin of itab occurs 0,
my_num(4) type N,
end of itab .
itab-my_num = 221 . append itab.
itab-my_num = 222 . append itab.

loop at itab.
write:/ itab-my_num.
endloop.

Result is: 0221

0222

Regards

Sudheer

Read only

0 Likes
829

hi

use UNPACK command.

UNPACK int to int.

hope this helps...

if u send a code we can help u more..

Regards

Read only

Former Member
0 Likes
829

Hi,

its difficult to say what happens without seeing the code how you read-in the file.

Generally, when handling with file input and output, I don't rely on the ABAP mechanisms with type coercions here, which can lead to obscure results. Read in ALL data as CHARS or STRINGs and convert them afterwards. Thas much safer

Hope that helps

Joachim

Read only

0 Likes
829

Hi all

data : begin of header_file occurs 0,

text(1024) type c,

end of header_file.

constants: con_tab type x value '09'.

Types : begin of itype,

id(4) type n,

plant like marc-werks,

storage like mard-lgort,

end of itype.

data: itab type table of itype with header line.

INITIALIZATION.

h_repid = sy-repid.

  • F4 Value for File

at selection-screen on value-request for h_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = h_repid

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = h_file

start-of-selection.

header = h_file.

*footer = f_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = header

FILETYPE = 'ASC'

*HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = header_file

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.

LOOP AT header_FILE.

split header_file at con_tab

into itab-id

itab-plant

itab-storage.

append itab.

endloop.

my record in itab is

1 abc abc

mt text file record is

1 tabspave abc tabspace abc

Thanks

Read only

0 Likes
829

I tried your earlier code in our system and got the same results you did (I was a bit surprised). I think your best alternative is to use the UNPACK command as suggest by Sinu.

Rob

Read only

0 Likes
829

Not sure why it doesn't work but here is a work around.



........


start-of-selection.

  header = h_file.
*footer = f_file.
  call function 'GUI_UPLOAD'
  exporting
  filename = header
  filetype = 'ASC'
*HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
  tables
  data_tab = header_file
  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.

<b>  data: temp(4) type c.</b>

  loop at header_file.

    split header_file at con_tab
    into itab-id
    itab-plant
    itab-storage.

<b>    temp = itab-id.
    itab-id = temp.</b>

    append itab.
  endloop.

  loop at itab.
    write:/ itab-id, itab-plant, itab-storage.
  endloop.

Regards,

Rich Heilman

Read only

0 Likes
829

Hi all,

Rich , did it work for you

i doesn't work right. strange---

any how i used the FM TO ADD LEADING ZEROS AND THEN SORT IT.

LOOP AT ITAB.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = itab-id

IMPORTING

OUTPUT = itab-id.

MODIFY ITAB.

ENDLOOP.

Let me know is there any trick to overcome this

Thank you guys.

Read only

0 Likes
829

HI suchitra,

u can do like this as i told before..

LOOP AT ITAB.

UNPACK itab-id TO itab-id.

MODIFY ITAB.

ENDLOOP.

Regards

Reward to all Helpful answers.