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

File Handling on Application server

Former Member
0 Likes
1,512

Hi All,

After lots of hard work I am posting this query. It may be easy for you but I need the solution as soon as possible.

Problem: I have a txt file on application server. Which has got 3 fields. First 2 are character and third is currency field. (E.G. Currency field value may be - 125.26) This text file is tab delimited.

E.G.

0000012 12121 12.26

0001742 54844 125.15

Now if you see this file on App. Server on AL11 it looks like '#' character is there instead of tab space. I want to get all these 3 fields into internal table.

I am facing the problem with '#'. Its neither accessible nor I can perform any string operation on it. In internal table also record is coming like this ::

0000012#12121#12.26

Can anyone help me getting these fields seperately?

Thanks in advance,

Jignesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,321

Hi jignesh,

1. For capturing / detecting this character

(its nothing but a horiontal tab,

shown as #)

2. use

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

(the above is nothing but TAB character)

regards,

amit m.

Hi All,

After lots of hard work I am posting this query. It may be easy for you but I need the solution as soon as possible.

Problem: I have a txt file on application server. Which has got 3 fields. First 2 are character and third is currency field. (E.G. Currency field value may be - 125.26) This text file is tab delimited.

E.G.

0000012 12121 12.26

0001742 54844 125.15

Now if you see this file on App. Server on AL11 it looks like '#' character is there instead of tab space. I want to get all these 3 fields into internal table.

I am facing the problem with '#'. Its neither accessible nor I can perform any string operation on it. In internal table also record is coming like this ::

0000012#12121#12.26

Can anyone help me getting these fields seperately?

Thanks in advance,

Jignesh.

10 REPLIES 10
Read only

Former Member
0 Likes
1,322

Hi jignesh,

1. For capturing / detecting this character

(its nothing but a horiontal tab,

shown as #)

2. use

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

(the above is nothing but TAB character)

regards,

amit m.

Read only

0 Likes
1,321

Hi Amit.. can you put a code snippet how to use this while parsing ??

Read only

0 Likes
1,321

Hi again,

1. we can use like this.

2. suppose your whole 1st line,

is in some long character variable myline,

(after uploading)

3. and itab is your final internal table,

where values should go,

4.

split myline at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

into table itab.

regards,

amit m.

Read only

0 Likes
1,321

Hi,

The '#' represents the Tab . becasue the file is tabdelimited file.

0000012#12121#12.26

you have to use <b>CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB</b> (equivalent for '#' ) to replace with ' ' . use replace or split and then remove '#' in your file.

Regards

vijay

Read only

0 Likes
1,321

Thanks all... Problem solved.. I learned one new thing.... Thanks again !!! You all are appreciated with points

Jignesh

Read only

0 Likes
1,321

Hi Jignesh

   Consider the below code.

Ignore l_cr part if you dont have problem with Carriage Return when you read your input file.


parameters: p_file like rlgrap-filename.

data: l_tab(1) type c value cl_abap_char_utilities=>horizontal_tab.
data: l_cr(1) type c value cl_abap_char_utilities=>cr_lf.
data: l_text(100) type c.
data: begin of itab occurs 0,
        text1(10) type c,
        text2(10) type c,
      end of itab.

  open dataset p_file in text mode for input encoding default.
  if sy-subrc ne 0.
*** error message
  else.
    do.
      read dataset p_file into l_text.
      if sy-subrc ne 0.
         exit.
      else.
         replace l_cr in l_text with space.
         clear: itab.
         split l_text at l_tab into itab-text1 itab-text2.
         append itab.
      endif.
    enddo.
  endif.


Kind Regards
Eswar


Am slow to respond, maybe next time.

Message was edited by: Eswar Rao Boddeti

Read only

Former Member
0 Likes
1,321

Hi Jignesh

The problem is with the code-page conversion. Try using ENCODING NON-UNICODE and see if it works.

Also as suggested by Amit, split the text read with method horizantal_tab of class *char_utilities to get to the work area

Kind Regards

Eswar

Message was edited by: Eswar Rao Boddeti

Read only

Former Member
0 Likes
1,321

use SPLIT itab at w_delimitor.

Cheers

VJ

Read only

Former Member
0 Likes
1,321

The hash is a tab character.

use the CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB can be used to identify the so called # and replace it

Regards,

ravi

Read only

0 Likes
1,321

open dataset file for input.

OPEN DATASET file IN TEXT MODE ENCODING DEFAULT FOR INPUT.

DO.

READ DATASET file INTO line.

IF sy-subrc <> 0.

EXIT.

ENDIF.

split line at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into wa_line.

append wa_line to it_line.

clear it_line.

ENDDO.

  • wa_line should have three fields yo uhave mentioned and it line should be a table having the same structure

Regards,

ravi