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: 

Variables problem.

Former Member
0 Kudos

1). I have value ...123.

sometimes values is like ..123.

How to count number of dots (.) in that variable.

2).One more thing is I am using

DATA :

lv_var1(6) TYPE c,

lv_var2(6) type c,

lv_var3(6) type c.

( because in my SAPSCRIPT data is coming thru structure itcsy ( itcsy-value which is character ), I am taking character )

and I am calculating

lv_var3 = lv_var2 - lv_var1.

in my subroutine pool program which is used for script.

It is working fine.

Please suggest me whether I am correct or not ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Sam,

I think as suggested by another user to use Split. Surely, it would do the needful only if you string starts with '1' but in case it is not than it would give incorrect results.

In case it can start with any other number you can use the below logic.

1. Get the strlen of the string l_var1.

2. translate l_var1 replacing '.' with '0'.

3. write the variable with no-zero.

4. condense

5. Get the strlen again for l_var1.

6. Difference between the first and second strlen output is the number of dots.

Surely, you can use the common do..enddo logic where you read in each character and check if it is a dot and count.

Regards

Anurag

10 REPLIES 10

Former Member
0 Kudos

hi Sam,

1. Use Split statement i.e, <b>split at '1'.</b> and collect the dots in a variable and then make use of strlen statment for knowing the number of dots ..

2. I feel that what ever you are doing is correct

Regards,

Santosh

Former Member
0 Kudos

Hi Sam,

1. Try the code:

<b> If var CS '123' .

count = SY-FDPOS .

Endif.</b>

2. You are correct. It will work fine.

Regards,

Pragya

Former Member
0 Kudos

Hello Sam,

I think as suggested by another user to use Split. Surely, it would do the needful only if you string starts with '1' but in case it is not than it would give incorrect results.

In case it can start with any other number you can use the below logic.

1. Get the strlen of the string l_var1.

2. translate l_var1 replacing '.' with '0'.

3. write the variable with no-zero.

4. condense

5. Get the strlen again for l_var1.

6. Difference between the first and second strlen output is the number of dots.

Surely, you can use the common do..enddo logic where you read in each character and check if it is a dot and count.

Regards

Anurag

Former Member
0 Kudos

translate l_var1 replacing '.' with '0'.

what is the exact syntax to o the above .

Could any body help me.

Former Member
0 Kudos

translate l_var1 replacing '.' with '0'.

what is the exact syntax to o the above .

Could any body help me.

0 Kudos

DATA: letters(20) TYPE C VALUE 'abcabcabcXab',

change(15) TYPE C VALUE 'aXbaYBabZacZ'.

TRANSLATE letters USING change.

Here is the syntax

Anurag

Former Member
0 Kudos

Hi Sam,

Try this code:

<b>REPLACE

ALL OCCURRENCES OF '.'

IN l_var1 WITH '0'.</b>

Regards,

Pragya

Former Member
0 Kudos

...123

or

..256

How to put spaces instead of dots (.).

I want syntax.

your help will be appreciatd.

0 Kudos

Translate dot to zero.

TRANSLATE l_var1 USING '.0'.

Translate dot to space.

TRANSLATE l_var1 USING '. '.

Regards

Anurag

Former Member
0 Kudos

Hi Sam,

Try this code:

<b>REPLACE

ALL OCCURRENCES OF '.'

IN var1 WITH ' '.</b>

Regards,

Pragya