Application Development 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: 

Need help - Split statement

Former Member
0 Kudos

Hi there,

I am using the following code to read data from application server.

open dataset l_ap_file for input

in text mode

encoding default.

if sy-subrc eq 0.

do.

  • Reading a line from the input file.

read dataset l_ap_file into wa_data.

if sy-subrc ne 0.

exit.

endif.

split wa_data at cl_abap_char_utilities=>horizontal_tab

into gs_input-matnr

gs_input-s1qty

gs_input-s2qty

gs_input-s3qty

gs_input-s4qty

gs_input-s5qty

gs_input-s6qty

gs_input-s7qty

gs_input-s8qty

gs_input-s9qty

gs_input-datab

gs_input-datbi.

gs_input-datbi is a 10 character field. If the input data is 2/28/2010, after split statement, gs_input-datbi looks like 2/28/2010# which is not correct.

I want to eliminate the hash symbol which is the field separator...

I used REPLACE statement to remove # symbol. Still not able to solve the issue...

Could anyone please help me to solve this issue...

Your help is greatly appreciated...

Thanks,

Geetha

1 ACCEPTED SOLUTION

Former Member
0 Kudos

In this case I would also try to rectify the main issue why you are getting the # character at the end. This is possibly the end of line character which you are getting due to incorrect file transfer method.

Is this file comming from a Windows sytem to a Unix system? If yes than you should use the right transfer mode(ASCII) when transferring the file, so that the windows end of line character is converted to Unix end of line character.

10 REPLIES 10

JozsefSzikszai
Active Contributor
0 Kudos

hi,

there are more possibilities:

1.

TRANSLATE gs_input-datbi USING '# '.

this will replace the # with space

2.

SHIFT gs_input-datbi RIGHT DELETING TRAILING '#'.

this will move the date to the right end

hope this helps

ec

former_member188685
Active Contributor
0 Kudos

That is Newline symbol. so to remove that you can use

CL_ABAP_CHAR_UTILITIES=>NEWLINE

using REPLACE statement and NEWLINE you can eliminate that.

0 Kudos

I updated the following statements

read dataset l_ap_file into wa_data.

if sy-subrc ne 0.

exit.

endif.

replace all occurrences of cl_abap_char_utilities=>newline

in wa_data with space.

split wa_data at cl_abap_char_utilities=>horizontal_tab

into gs_input-matnr

gs_input-s1qty

gs_input-s2qty

gs_input-s3qty

gs_input-s4qty

gs_input-s5qty

gs_input-s6qty

gs_input-s7qty

gs_input-s8qty

gs_input-s9qty

gs_input-datab

gs_input-datbi.

Still last field gs_input-datbi has '#' at the end which is a field separator / new line tab.

If I use REPLACE / TRANSLATE command, it's not working.

Any suggestion please...

Thanks & Regards,

Geetha

Former Member
0 Kudos

Hello,

Try this:


TRANSLATE gs_input-datbi USING '# '.

Regards.

Former Member
0 Kudos

Following code is working.


data: w_var type char10.
w_var = '2/28/2010#'.
REPLACE '#' in w_var WITH ''.

Former Member
0 Kudos

You might want to split into char fields first.

Your Problem is the wrong data format of your date.

Internal data format for date fields is YYYYMMDD.

To achieve this you can use FM conversion_exit_budat_input.

Former Member
0 Kudos

In this case I would also try to rectify the main issue why you are getting the # character at the end. This is possibly the end of line character which you are getting due to incorrect file transfer method.

Is this file comming from a Windows sytem to a Unix system? If yes than you should use the right transfer mode(ASCII) when transferring the file, so that the windows end of line character is converted to Unix end of line character.

0 Kudos

Yes...I transfered the file(Text tab delimited) from my PC to Unix server using CG3Z TCode.

Thanks,

Geetha

0 Kudos

When you do the transfer, Use ASCII mode. You will not get the # character at the end.

P.S This will work provided your file doesnt have more than 255 characters in one line.

0 Kudos

Wow...It works. I transferred the file using ASCII format. Now everything looks OK...

Thanks a lot...

Regards,

Geetha