Skip to Content
author's profile photo Former Member
Former Member

How to increment a character variable?

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2008 at 07:05 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2008 at 07:10 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2008 at 07:10 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2008 at 07:19 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2008 at 07:32 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.