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

Addition in character variable

Former Member
0 Likes
1,847

Dear Experts,

Its regarding addition in character type variable. i hv defined a variable type c which takes the valu at runtime in a pattern D11K901841.Now while processing the rest of the report i need to increment the value by 1 .Like from D11K901841 to D11K901842. How can i acieve these. 1 cannot be added direstly as it is a type char.

Pls help me.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,232

Hi ,

You can Achieve this Using The Below Code.

 
Data: w_cnt   type i ,
          w_num type i.

 * Find the String length of the Character variable
w_cnt = strlen( w_name )  -  1.
w_num = w_name+w_cnt(1)  +  1.        " Increment the last Numeric Value in variable
w_name+w_cnt(1) = w_num.             " Modify the Incremented value in Variable                     

With Regards

Kesavaperumal

5 REPLIES 5
Read only

Former Member
0 Likes
1,232

Declare the variable of the type NUMC though you can add one even if it is of type CHAR

Read only

0 Likes
1,232

Hi Vikranth,

its not possible declare a variable of type numc in your program

and i think it wont work .

@ cenosure ,

check these links for some of the possible ways

link:[http://learningabap.wordpress.com/2007/10/29/auto-increment-function-with-alpha-numeric-support/]

Read only

Former Member
0 Likes
1,233

Hi ,

You can Achieve this Using The Below Code.

 
Data: w_cnt   type i ,
          w_num type i.

 * Find the String length of the Character variable
w_cnt = strlen( w_name )  -  1.
w_num = w_name+w_cnt(1)  +  1.        " Increment the last Numeric Value in variable
w_name+w_cnt(1) = w_num.             " Modify the Incremented value in Variable                     

With Regards

Kesavaperumal

Read only

0 Likes
1,232

Hi,

I think the last solution should do the trick!

But i would like to advice to use a larger number: not only the last digit, but the entire string after the D11K:

w_cnt = strlen( w_name ) - 6.

w_num = w_name+w_cnt(6) + 1. " Increment the Numeric Value in variable

w_name+w_cnt(6) = w_num. " Modify the Incremented value in Variable

Good luck!

Regards, Miranda

Read only

0 Likes
1,232

Thank u Both Kesava and M.G.

My problem is solved