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

remove " from file

Former Member
0 Likes
2,258

Hallow Im doing a batch input from file csv (comma dilmeted) In the file I have company that ok and company name with before and after the company name word <b>''</b> how can I get rid of from that . just<b> ''</b> before and after the company name .

*--


table with data from file(csv)--


LOOP AT itab1.

SPLIT itab1 AT ',' INTO:

itab-osek_morsh

<b>itab-company_name</b>

itab-company_code.

APPEND itab.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,226

Use the REPLACe command

Constants c_comma type c value '"'.

REPLACE c_comma in itab-company_name with space.

CONDENSE itab-company_name no-gaps.

22 REPLIES 22
Read only

Former Member
0 Likes
2,227

Use the REPLACe command

Constants c_comma type c value '"'.

REPLACE c_comma in itab-company_name with space.

CONDENSE itab-company_name no-gaps.

Read only

Former Member
0 Likes
2,226

Hi Antonio,

Use the following after making small correction.

constants: c_comma type char01 value ','.

LOOP AT itab1.

SPLIT itab1 AT c_comma INTO:

itab-osek_morsh

itab-company_name

itab-company_code.

APPEND itab.

ENDLOOP.

Please check above code will work.

Regards

Bhupal reddy

Read only

former_member69765
Contributor
0 Likes
2,226

You can just replace " by nothing ... like this - replace all occurrences of '"' in text with ''.

Try this ....hope it works for u.

Read only

Former Member
0 Likes
2,226

Hi Antonio ,

You can use the following commands

REPLACE ALL OCCURRENCES of ' " ' in itab_company_name with sapce.

condense intab-company-name.

Regards

Arun

Read only

Former Member
0 Likes
2,226

Hi Antonio

As you were saying that you will have double quotes before and after company name, a small modification in Dominic's Code.

Use the REPLACe command

Constants c_comma type c value '"'.

*REPLACE c_comma in itab-company_name with space.

<b>REPLACE ALL OCCURENCES OF c_comma in itab-company_name with space.</b>

CONDENSE itab-company_name no-gaps.

Hope Dominic wouldnt mind.

Kind Regards

Eswar

Read only

0 Likes
2,226

No problem at Eswar

All suggestions are welcome. No 'mind' at all

Read only

0 Likes
2,226

hallow eswar how i use it in the loop thankes

Read only

0 Likes
2,226

Hi,

LOOP AT itab1.

SPLIT itab1 AT ',' INTO:

itab-osek_morsh

itab-company_name

itab-company_code.

REPLACE ALL OCCURENCES OF '''' in itab-company_name with ''.

APPEND itab.

ENDLOOP.

Read only

0 Likes
2,226

Hi Antonio

Please check this code:

Constants c_comma type c value '"'.

LOOP AT itab1.
     SPLIT itab1 AT ',' INTO:
           itab-osek_morsh
           itab-company_name
           itab-company_code.
     REPLACE ALL OCCURENCES OF c_comma IN itab-company_name with ' '.
     CONDENSE itab-company_name NO-GAPS.
     APPEND itab. 
ENDLOOP.

Hope this helps you.

Kind Regards

Eswar

Read only

Former Member
0 Likes
2,226
loop at itab.
len  =  strlen(itab-company_name).
len = len - 1.
itab-company_name = itab-company_name+1(len).
modify itab index sy-tabix transporting company_name.
endloop
Read only

0 Likes
2,226

hi chandrasekhar your answer is good but just forthe first occurse ex. if i have a company name like that <b>"</b>microsoft<b>"</b> and i wont to remove both what can i do thankes for your time

Read only

0 Likes
2,226

Hi Antonio ,

Why dont you loop and in that use the <b>replace</b> command.

Hope this help , if not i shall send you the code

Regards

Arun

Read only

0 Likes
2,226

Hi,

My code works fine for that "microsoft"

itab-company_name = itab-company_name+1(len).

the above statement will remove the first and the last characters from the string

the numbering starts from 0 and i had subtracted 1 from len

so 1(len) will start from second character and to length - 1 character

Pls let me know if u need any more clarification

Read only

Former Member
0 Likes
2,226

hi chandrasekhar jagarlamudi how can i use it in my loop regards

Read only

0 Likes
2,226

Hi antonio,

U can check my previous post , that works perfectly , posting the same here

loop at itab.
len  =  strlen(itab-company_name).
len = len - 1.
itab-company_name = itab-company_name+1(len).
modify itab index sy-tabix transporting company_name.
endloop

Read only

0 Likes
2,226

Hallow everybody my problem is a little bit difficult

I use your suggestion with REPLACE ALL OCCURRENCES OF and it work well but if I have a company name like "<b>abcef"ghi</b>" (one word) and between f and g I wont the comma to stay its problem .and when I use <b>strlen</b> like the suggestion it omitting the first letter of the word (because not all the company have coma before and after. Did some one have any idea how to solve this problem regardes

Read only

Former Member
0 Likes
2,226

Hi Antonio ,

If you want to use the strlen option the here is the code

-


<b>Data : v_strlen type i.</b>

LOOP AT itab1.

Clear v_strlen.

SPLIT itab1 AT ',' INTO:

itab-osek_morsh

itab-company_name

itab-company_code.

v<b>_strlen = strlen(itab-company_name).

v_strlen = v_sterlen - 1.

itab-company_name = itab-company_name+0(v_strlen ).</b>

APPEND itab.

ENDLOOP.

-


Regards

Arun

Read only

Former Member
0 Likes
2,226

Hi Antonio ,

Just a small correction in one of the statments , insted of

<i>itab-company_name = itab-company_name+0(v_strlen ).</i>

use

<b>itab-company_name = itab-company_name+1(v_strlen).</b>

Reagrds

Arun

Read only

Former Member
0 Likes
2,226

Hallow everybody my problem is a little bit difficult

I use your suggestion with REPLACE ALL <b>OCCURRENCES</b> OF and it work well but if I have a company name like "<b>abcef"ghi</b>" (one word) and between f and g I wont the comma to stay its problem .and when I use<b> strlen</b> like the suggestion it omitting the first letter of the word (because not all the company have coma before and after. Did some one have any idea how to solve this problem <b>regardes</b>

Read only

Former Member
0 Likes
2,226

hallow antonio your problem is diffcult logic i try to solve it but i cant you have to ask some one with more experience and in this form you have a lot sorry and regardes

Read only

Former Member
0 Likes
2,226

Hi Antonio ,

Now what i understand is that some companies may have " at begining , some may have at end , some may have both and some none .

So your requirement is that if there is a " as the first char or last then we need remove it , for all other cases it is not required.

If my understanding is correct , here is the code which gives the desired result


* Selection Screen 
parameters : p_string type string .
start-of-selection.
DATA : t_result type  MATCH_RESULT_TAB. " Internal table 

data : v_string type i .

v_string = strlen( p_string ).   " Get the lenght of string 

* get the offset of all occurances of " in your string 
FIND ALL OCCURRENCES OF '"' IN P_STRING RESULTS T_RESULT. 
v_string = v_string - 1.  " Here the offset start with zero
* Check if last char is "
read table t_result with key OFFSET = v_string transporting NO FIELDS .
if sy-subrc = 0.
" If yes remove if from string
p_string = p_string+0(v_string).
endif.

*Check if the first char is "
read table t_result with key OFFSET = '0' transporting NO FIELDS .
if sy-subrc = 0.
* if yes replace with space
  replace '"' in p_string with ' ' 
endif.

Check if this serves your purpose , if not please tell what is the concern you have.

Thanks

Arun

Read only

Former Member
0 Likes
2,226

Hello,

Use the REPLACE statement.

Regards,

Shehryar Dahar