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

concatenating integer and a char (possible?)

Former Member
19,312

Hi,

Im new in ABAP developmet.

Please help.

I need to CONCATENATE integer and a char.

EXAMPLE:  

data: v_num1      type i  value 11,

         v_num2      type i value 14,

         v_res          type i,

         v_percent   type c value '%',

         v_concat    type string.

v_res = (v_num1 / v_num2) * 100.   " to get the percentage.

CONCATENATE v_res v_percent into v_concat.    "<===== is this POSSIBLE. if not HOW?

I need to output, v_res%

thanks..

1 ACCEPTED SOLUTION
Read only

Former Member
7,140

You can only concatenate character fields.

Move the integer field to a character or string field and do the concatenation.

data v_res_c type string.

move v_res to v_res_c.

concatenate v_res_c v_percent into v_concat.

You can only concatenate character fields.

Move the integer field to a character or string field and do the concatenation.

data v_res_c type string.

move v_res to v_res_c.

concatenate v_res_c v_percent into v_concat.

6 REPLIES 6
Read only

Former Member
7,141

You can only concatenate character fields.

Move the integer field to a character or string field and do the concatenation.

data v_res_c type string.

move v_res to v_res_c.

concatenate v_res_c v_percent into v_concat.

Read only

PeterJonker
Active Contributor
7,140

Define another field type stirng and place v_res in there after the calculation. Use that field in stead in your concatenate statement. . In your case with v_res being integer you will get 100 %.

If you define v_res with decimals you will get a better result I think e.g:

DATA: v_num1      TYPE VALUE 11,
        v_num2      TYPE i VALUE 14,
        v_res          TYPE p DECIMALS 3,
        v_percent   TYPE c VALUE '%',
        v_concat    TYPE string,
        v_string_res TYPE string.

  v_res = ( v_num1 / v_num2 ) * 100.   " to get the percentage.

  v_string_res = v_res.

  CONCATENATE v_string_res v_percent INTO v_concat.

Read only

Former Member
7,140

In addition of Susmitha,

You can CONCATENATE Numc(Numeric text). So do the same thing use numc as place of I(interger).


demo code:


data lv_str TYPE numc2.
data lv_str1 TYPE string.

CONCATENATE lv_str lv_str1 INTO lv_str1.

Read only

Former Member
0 Likes
7,140

As everybody said above, You need to copy integer variable to another character variable and then concatenate both the fields.

This will resolve your  problem.

Thanks

Siddarth

Read only

former_member191562
Participant
0 Likes
7,140

Hello Reiner,

CONCATENATE statement will not allow any integer variable to be part of its argument.

Try using a temporary variable to store v_res after the calculation and do concatenation with that variable.

Like..

DATA: v_temp(3) TYPE c.

v_res = (v_num1 / v_num2) * 100.   " to get the percentage.

v_temp = v_res.

CONCATENATE v_temp v_percent into v_concat.

Read only

former_member220538
Active Participant
0 Likes
7,140

Hi,

CONCATENATE wont work with integer ,You can do the following

Change the type of the variable v_res to string or character  type   OR  Assign the v_res to a string or char variable then concatenate.