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

How to increment a character variable?

Former Member
0 Likes
4,640

Hi,

I need to increment v_chgno by 1. But the following code gives me runtime error. Please can anyone guide me where i am going wrong.

Data: v_chgno TYPE char12 value 'CR0000000000',

v_newchgno TYPE char12.

v_newchgno = v_chgno + 1.

Thanks in advance.

Sunanda.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,946

Hi,

Does the following code solve your problem

Data: v_chgno TYPE char12 value 'CR0000000000',

v_newchgno TYPE char12,

v_char(2) TYPE C,

v_number(10) TYPE N.

SPLIT v_chgno AT '0' INTO v_char v_number.

ADD 1 TO v_number.

CONCATENATE v_char(2) v_number INTO v_newchgno.

WRITE v_newchgno

Regards

Edited by: Jürgen Degraeve on Jan 17, 2008 8:05 AM

6 REPLIES 6
Read only

Former Member
0 Likes
1,947

Hi,

Does the following code solve your problem

Data: v_chgno TYPE char12 value 'CR0000000000',

v_newchgno TYPE char12,

v_char(2) TYPE C,

v_number(10) TYPE N.

SPLIT v_chgno AT '0' INTO v_char v_number.

ADD 1 TO v_number.

CONCATENATE v_char(2) v_number INTO v_newchgno.

WRITE v_newchgno

Regards

Edited by: Jürgen Degraeve on Jan 17, 2008 8:05 AM

Read only

0 Likes
1,946

Hi Jürgen,

Your solution has solved my problem.

Thanks a lot.

Sunanda.

Read only

Former Member
0 Likes
1,946

Hi,,

Data: v_chgno TYPE char12 value 'CR0000000000',

v_newchgno TYPE char12,

w_temp(10) type n value '0000000000',

w_char(2) type c value 'CR'..

do.

w_temp = w_temp + 1.

concatenate w_char w_temp into v_chgno.

if some condition.

exit.

endif.

enddo.

plzz reward if it is usefull

for any further quiries contact me on mutyalasunilkumar@gmail.com

Read only

Former Member
0 Likes
1,946

Hi Sunanda,

Try this code

Data: v_chgno TYPE char12 value 'CR0000000000',

v_newchgno TYPE char12,

number(10) type n.

number = v_chgno+2.

number = number + 1.

concatenate v_chgno(2)

number

into v_newchgno.

Plzz Reward if it is useful,

Mahi.

Read only

Former Member
0 Likes
1,946

Hi,

Since u need a numeric value. Declare with Type N.

Eg:

DATA: L_VAR1(3) TYPE N,

L_INC(3) TYPE N.

L_VAR1 = '080'

L_INC = '001'.

Then:

L_VAR1 = L_VAR1 + L_INC. "This will work.

Read only

Former Member
0 Likes
1,946

Hi,

It is not possible to increment the value when charecters are included in it, else if the variable is numeric even though declared as charecters will support arithemetic operations.

Kindly refer the below code, it should work.

Sample Code

DATA: v_chgno TYPE char12 VALUE 'CR0000000000',

v_chars TYPE char2,

v_numeric_val TYPE char10,

v_newchgno TYPE char12.

v_chars = v_chgno+0(2).

v_numeric_val = v_chgno+2(10).

v_numeric_val = v_numeric_val + 1.

SHIFT v_numeric_val RIGHT DELETING TRAILING space.

OVERLAY v_numeric_val WITH '0000000000'.

CONCATENATE v_chars v_numeric_val INTO v_newchgno.

WRITE / v_newchgno.

Pls do reward if useful.

Regards,

Farheen.