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

Reading CSV(TAB) file in Background.Split command it's not working any idea

Former Member
0 Likes
1,511

I am working SAP ECC 6.0

I want to upload a file from application server using open data set …..The file is CSV or tab delimited; I could read perfectly into a string, but when I use the Split command it’s not working because it’s not considering the tab delimiter. I am trying at least to find out this character (TAB) and get all the offset into the string using FIND command.

I created a small program to represent my problem and I used REGEX expression to find out the TAB values. Could somebody check this REGEX expression and tell me what I am missing?. What is wrong?. (I know is the Regex expression) How can I find out specifically the tab character?

  1. = TAB CHARACTER.

Wa_string value

DH#10022006#Z2#9210#10022006#SUBSCRIBR REFUND# # # #

2 11 14 17 27 37 44

Line LINE Offset Length

1 0 1 1

2 0 10 1

3 0 13 1

4 0 18 1

5 0 27 1

6 0 37 1

7 0 44 1

READ DATASET P_BFILE INTO wa_string.

FIND ALL OCCURRENCES OF

REGEX [\S\b]

in wa_string

RESULTS tabresult_tab.

This function is returning the line 6 in the table, which means SPACE. I just need that return only the TAB offset.

I will thank your help.

Example code:

REPORT ZTEST5.

data P_BFILE LIKE RLGRAP-FILENAME value '/usr/filewithtabdelim.txt'.

data: begin of t_input OCCURS 0,

field type string,

end of t_input,

text TYPE string,

tabresult_tab TYPE match_result_tab,

WA_STRING TYPE STRING.

Start-OF-SELECTION.

open dataset P_BFILE for input

in text mode ENCODING DEFAULT.

break-point.

do 1 times.

READ DATASET P_BFILE INTO wa_string.

FIND ALL OCCURRENCES OF

REGEX '\S\b'

  • REGEX \[^:space:]]+\

in wa_string

RESULTS tabresult_tab.

write: / wa_string.

enddo.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,175

Dear Jose

For tab delimeted file:

Declare a variable as below:

data: l_tab(1) type c value cl_abap_char_utilities=>horizontal_tab.

Now use this for split command...

spli <string> at l_tab into <wa>-fld1 <wa>-fld2....

Hope this might help you.

Kind Regards

Eswar

I am working SAP ECC 6.0

I want to upload a file from application server using open data set …..The file is CSV or tab delimited; I could read perfectly into a string, but when I use the Split command it’s not working because it’s not considering the tab delimiter. I am trying at least to find out this character (TAB) and get all the offset into the string using FIND command.

I created a small program to represent my problem and I used REGEX expression to find out the TAB values. Could somebody check this REGEX expression and tell me what I am missing?. What is wrong?. (I know is the Regex expression) How can I find out specifically the tab character?

  1. = TAB CHARACTER.

Wa_string value

DH#10022006#Z2#9210#10022006#SUBSCRIBR REFUND# # # #

2 11 14 17 27 37 44

Line LINE Offset Length

1 0 1 1

2 0 10 1

3 0 13 1

4 0 18 1

5 0 27 1

6 0 37 1

7 0 44 1

READ DATASET P_BFILE INTO wa_string.

FIND ALL OCCURRENCES OF

REGEX [\S\b]

in wa_string

RESULTS tabresult_tab.

This function is returning the line 6 in the table, which means SPACE. I just need that return only the TAB offset.

I will thank your help.

Example code:

REPORT ZTEST5.

data P_BFILE LIKE RLGRAP-FILENAME value '/usr/filewithtabdelim.txt'.

data: begin of t_input OCCURS 0,

field type string,

end of t_input,

text TYPE string,

tabresult_tab TYPE match_result_tab,

WA_STRING TYPE STRING.

Start-OF-SELECTION.

open dataset P_BFILE for input

in text mode ENCODING DEFAULT.

break-point.

do 1 times.

READ DATASET P_BFILE INTO wa_string.

FIND ALL OCCURRENCES OF

REGEX '\S\b'

  • REGEX \[^:space:]]+\

in wa_string

RESULTS tabresult_tab.

write: / wa_string.

enddo.

7 REPLIES 7
Read only

Former Member
0 Likes
1,176

Dear Jose

For tab delimeted file:

Declare a variable as below:

data: l_tab(1) type c value cl_abap_char_utilities=>horizontal_tab.

Now use this for split command...

spli <string> at l_tab into <wa>-fld1 <wa>-fld2....

Hope this might help you.

Kind Regards

Eswar

Read only

former_member69765
Contributor
0 Likes
1,175

Very Simple Dude....

The TAB that u see in windows is not what u see in the Unix.. In unix it appears as a # .

This # is diffrent from windows #. It is a unicode character.

So u need to do this -- Declare a variable as follows --

data : c_tab type x value '09'.

split string at c_tab into fld_1 fld_2 ...

Remeber.. U might get an error saying unicode check active or inactive something...

Then Go to Attributes and in the botttom there willl be chek box sayin Unicode checks active... Just un-check or may be check (I am not sure.. try both) it... It will work perfectly...

Plz reward points if it was useful.

Read only

0 Likes
1,175

Dear Varun

The info you have provided is suitable only for NON-UNICODE systems. While we are in UNICODE enabled system:

<b>1. We can not remove/uncheck "UNICODE Checks Active" from program attributes.

2. We can declare a variable of type "X".</b>

Above info is just for your knowledge.

Kind Regards

Eswar

Read only

0 Likes
1,175

Oh great... that is something I was not aware of....

Then its fine.. .we can directly go with type x declaration.

Read only

0 Likes
1,175

Sorry, it was my typo error:

We <b>CAN NOT declare</b> a variable of type "X".

Hence we have to use class CL_ABAP_CHAR_UTILITIES, for characters that we normally use like tab, carriage return, line feed...

Regards

Eswar

Read only

0 Likes
1,175

But my freind... I hvae tried it many times... and It works...

Read only

0 Likes
1,175

Have you checked when the attribute for "Unicode Checks active" is set to "X". This is incase of UNICODE enabled system???

Regards

Eswar