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: 

Passing the characters to the variable from other skipping some characters in ABAP

Former Member
0 Kudos

How to copy the characters to a variable skipping the first character and the last 2?
For Example: H1 = 0123456
Required Output: H2 = 1234.
How can i use H2 = H1 ?

Please suggest.

Moderator message: very basic -> un-marked as question

Message was edited by: Thomas Zloch

3 REPLIES 3

Former Member
0 Kudos

how about H2 = H1+1(4).

This is pretty basic ABAP syntax. 

I am assuming H1 and H2 are CHAR data type.  You did not say what the data type was.

Also, if the length of the value is unknown, you might want to do it this way:

LEN = strlen( H1+1).

if LEN > 2.

  LEN = LEN - 2.

else.

  LEN = 1.

endif.

H2 = H1+1(LEN).

You may want to consider getting a book on basic ABAP programming before asking such a basic question again.

kaushalya
Active Participant
0 Kudos

To get a sub string of a string u can use the following syntax:

fieldname+starting_position(field_length)

The fieldname is the source. The plus sign precedes the starting position of the substring. The first position in the string is 0. Immediately after (no space) comes the length of the substring you are going to use.

So, the answer is

H2 = H1+2(4)

Former Member
0 Kudos

Kaushalya,

Not to be spiting hairs here, but as you said, the starting position is relative to 0, So the correct answer is H2 = H1+1(4).