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

String Modifications

Former Member
0 Likes
746

Hi Experts,

I have a requirement to take first 10 characters of a string including spaces and numbers but eliminating punctuations marks.

So can someone please help me with the punctuation part i.e is there a way to include all punctuations or do i have to write explicitly all of them.

Thanks in anticipation.

1 ACCEPTED SOLUTION
Read only

manthanraja
Active Participant
0 Likes
723

First of all welcome to SDN and please read the engagement rules ..

Do search before posting such basic questions

Still i am giving you this code .. Not exactly what you want .. but i am sure you can tweak it to your requirements ..


REPORT zstring. 
DATA : ipstr TYPE string. 
DATA : opstr TYPE string. 
DATA : len TYPE i VALUE 0. 
DATA : ch TYPE char1. 
DATA : num TYPE i VALUE 0.   "No of Characters to be taken 
DATA : pos TYPE char3.       "Position of Char in the Input String 
*Input string 
ipstr = '<FT><H><T> Line Clearance </></></>'. 
*Removing only "</>" 
REPLACE ALL OCCURRENCES OF '</>' IN ipstr WITH ' '. 
*Removing only "<" 
REPLACE ALL OCCURRENCES OF '<' IN ipstr WITH ' '. 
CONDENSE ipstr. 
*Length of Input String 
len = STRLEN( ipstr ). 
  DO len TIMES. 
*Char by Char 
  ch = ipstr+pos(1). 
  pos = pos + 1. 
*Scan each char in input String for ">" 
  FIND '>' IN ch IGNORING CASE. 
  IF sy-subrc = 0. 
    num = len - pos. 
*Output String 
    opstr = ipstr+pos(num). 
  ENDIF. 
ENDDO. 
  WRITE :/ opstr.   

This will help you to modify any type of strings .. in the code i have pasted it removes HTML tags .. instead of that just give the punctuation marks ..

Hope this answer helps you

Regards ..

Manthan

6 REPLIES 6
Read only

Former Member
0 Likes
723

Suppose

L_STR = ' 123456789'.

then do like this...

L_str1 = l_str+0(10).

Read only

manthanraja
Active Participant
0 Likes
724

First of all welcome to SDN and please read the engagement rules ..

Do search before posting such basic questions

Still i am giving you this code .. Not exactly what you want .. but i am sure you can tweak it to your requirements ..


REPORT zstring. 
DATA : ipstr TYPE string. 
DATA : opstr TYPE string. 
DATA : len TYPE i VALUE 0. 
DATA : ch TYPE char1. 
DATA : num TYPE i VALUE 0.   "No of Characters to be taken 
DATA : pos TYPE char3.       "Position of Char in the Input String 
*Input string 
ipstr = '<FT><H><T> Line Clearance </></></>'. 
*Removing only "</>" 
REPLACE ALL OCCURRENCES OF '</>' IN ipstr WITH ' '. 
*Removing only "<" 
REPLACE ALL OCCURRENCES OF '<' IN ipstr WITH ' '. 
CONDENSE ipstr. 
*Length of Input String 
len = STRLEN( ipstr ). 
  DO len TIMES. 
*Char by Char 
  ch = ipstr+pos(1). 
  pos = pos + 1. 
*Scan each char in input String for ">" 
  FIND '>' IN ch IGNORING CASE. 
  IF sy-subrc = 0. 
    num = len - pos. 
*Output String 
    opstr = ipstr+pos(num). 
  ENDIF. 
ENDDO. 
  WRITE :/ opstr.   

This will help you to modify any type of strings .. in the code i have pasted it removes HTML tags .. instead of that just give the punctuation marks ..

Hope this answer helps you

Regards ..

Manthan

Read only

0 Likes
723

Hi ,

Please see my question " I have asked do i need to explictly give all the punctuations marks or is there is some other way round".

Anyways thanks for ur Advise and Help.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
723

Hello,

Which version of SAP are you in ?

If you have Reg-ex available then you can make use of [:punct:]

E.g.,

REPLACE ALL OCCURENCES OF REGEX [:punct:] IN V_STRING WITH ` `.

BR,

Suhas

Edited by: Suhas Saha on Feb 23, 2010 3:00 PM

Read only

0 Likes
723

Hi Paresh,

the correct format would be,

REPLACE ALL OCCURRENCES OF REGEX '[[:punct:]]' IN v_string WITH ''.

Regards,

Herwin.

Edited by: Herwin Wilmet Dsouza on Feb 23, 2010 11:11 AM

Read only

Former Member
0 Likes
723

Answered.