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

efficient and smallest equivalent abap code

Former Member
0 Likes
524

hi, this is a sample i am trying out..

my java code is:


int i=100;
String mystring = "abcd";
String newstring = mystring + i + "xyz";  
System.out.println(newstring); //this will print "abcd100xyz"
i++; //increament value of i by 1.
System.out.println(mystring + i); //this will print "abcd101"

for achieving this in abap,

i am using concatenate, but it does not allow the int type to be used in concatenate statement, and it is becoming more work to create intermediate string variables.

what could be an efficient and smallest chunk of code equivalent to above java code.

thanks in advance.

Madhu.

1 ACCEPTED SOLUTION
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
481

Try this:

DATA : ls_s TYPE string.

DATA : ls_n(3) TYPE n.

DATA: ls_s_new TYPE string.

DATA: ls_s_new_1 TYPE string.

ls_n = 100.

ls_s = 'abcd'.

CONCATENATE ls_s ls_n 'xyxz' INTO ls_s_new.

WRITE : ls_s_new.

ls_n = ls_n + 1.

CONCATENATE ls_s ls_n INTO ls_s_new_1.

WRITE : ls_s_new_1.

3 REPLIES 3
Read only

anup_deshmukh4
Active Contributor
0 Likes
481

move your type I to string...and condense it..b4 Concatination

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
482

Try this:

DATA : ls_s TYPE string.

DATA : ls_n(3) TYPE n.

DATA: ls_s_new TYPE string.

DATA: ls_s_new_1 TYPE string.

ls_n = 100.

ls_s = 'abcd'.

CONCATENATE ls_s ls_n 'xyxz' INTO ls_s_new.

WRITE : ls_s_new.

ls_n = ls_n + 1.

CONCATENATE ls_s ls_n INTO ls_s_new_1.

WRITE : ls_s_new_1.

Read only

0 Likes
481

DATA : i(3) TYPE n VALUE 100,

mystring TYPE string VALUE 'abcd',

newstring TYPE string.

CONCATENATE mystring i 'xyz' INTO newstring. "this will print "abcd100xyz"

WRITE newstring.

i = i + 1.

CONCATENATE mystring i INTO mystring. "this will print "abcd101"

WRITE / mystring.