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

Open Dataset error

Former Member
0 Likes
700

Hi Experts,

I am seeing a strange error while loading a .txt file into SAP via a program.

The flat file format is:

<u>rec_type|operation1|relation1|timeunit1|operation2|relation2|timeunit2</u>

00001|100001|FS|DAY|100002|FS|HR

00002|100003|SS|DAY|100004|SS|HR

00003|100005|FS|DAY|100006|SS|HR

......................................................

I have the code like this:

<b>data: c_delimit(1) type c value '|'.

data: begin of i_input occurs 0,

data(1000) type c,

end of i_input.

data: begin of i_data occurs 0,

rec_type(1) type c,

operation1(16) type c,

relation1(16) type c,

timeunit1(3) type c,

operation2(16) type c,

relation2(16) type c,

timeunit2(3) type c,

end of i_data.

....................................

....................................

....................................

open dataset p_file for input in text mode.

do.

read dataset p_file into i_input.

if sy-subrc <> 0.

exit.

endif.

append i_input.

clear i_input.

enddo.

close dataset p_file.

................................

................................

................................

loop at i_input.

split i_input-data at c_delimit into i_data-rec_type

i_data-operation1

i_data-relation1

i_data-timeunit1

i_data-operation2

i_data-relation2

i_data-timeunit2.

append i_data.

clear i_data.</b>

But I am seeing the records in internal table "i_input" as:

00001|100001||DAY|100002|FS|HR

00002|100003||DAY|100004|SS|HR

00003|100005||DAY|100006|SS|HR

i.e, i am not seeing only the "relation1' values in the internal table.

Any thoughts???

I appreciate your help.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
672

Also make sure that you have '|' not '!' which may appear to be same.

7 REPLIES 7
Read only

Former Member
0 Likes
672

I don't see anything wrong here. Check in debugging, what you are getting in the "loop at i_input" after the split statement.

Read only

0 Likes
672

Thanks all for your replies. Sorry for getting back to you late.

Srinivas, I have checked it in debugging. I am seeing the same afer split statement though it still shows up the 'i_input-data' as:

00001|100001|FS|DAY|100002|FS|HR

This is what I am seeing in 'i_data':

00001|100001||DAY|100002|FS|HR

Thanks.

Read only

0 Likes
672

Are you using the '|' when showing the i_data record here in this thread just to tell us how it is split or is the '|' appearing in i_data in reality? Because, i_data should have individual field values after the split and i_data-relation1 value in debugging should be correctly filled.

Read only

Former Member
0 Likes
672

HI,

Can you see it in i_input table after the read statement...

I think that field does not have value.. but ur program is reading and i think the current file that you are reading does not have relation1 value..

Check the file

Thanks,

Mahesh

Read only

0 Likes
672

Are you sure the logic you have provided matches the problem program - e.g. you show rec_type as 1 byte but 4 in the file... I've cut-and-pasted your code and tested it in isolation, and it seems to be OK - try the sample below:

report zlocal_jc_dataset_split.

start-of-selection.
  perform logic.

*&---------------------------------------------------------------------*
*&      Form  logic
*&---------------------------------------------------------------------*
form logic.

  constants:
    lc_delimit(1)       type c value '|'.

  data:
   begin of ls_input,
     data(1000)         type c,
   end of ls_input,
   lt_input             like ls_input occurs 10.

  data:
    begin of ls_data,
      rec_type(4)       type c,  "was (1) in example provided
      operation1(16)    type c,
      relation1(16)     type c,
      timeunit1(3)      type c,
      operation2(16)    type c,
      relation2(16)     type c,
      timeunit2(3)      type c,
   end of ls_data,
   lt_data              like ls_data occurs 10.

*" Dummy up the data load
  append '00001|100001|FS|DAY|100002|FS|HR' to lt_input.
  append '00002|100003|SS|DAY|100004|SS|HR' to lt_input.
  append '00003|100005|FS|DAY|100006|SS|HR' to lt_input.

*" Do the split
  loop at lt_input into ls_input.

    split ls_input-data at lc_delimit
      into
        ls_data-rec_type
        ls_data-operation1
        ls_data-relation1
        ls_data-timeunit1
        ls_data-operation2
        ls_data-relation2
        ls_data-timeunit2.
    append ls_data to lt_data.
    clear: ls_data.

  endloop.
break-point.
  loop at lt_data into ls_data.
    write: / ls_data.
  endloop.

endform.                    "logic

Read only

Former Member
0 Likes
673

Also make sure that you have '|' not '!' which may appear to be same.

Read only

0 Likes
672

Thanks Srinivas.

I just used '|' in this thread to distinguish the records. I found the bug in my program. It works now finely.

Thanks all for your support.

null