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

Why doesn't CONDENSE work on Char field?

Former Member
0 Likes
3,695

Consider the following code. It is quite piped down from the actual code but the point is clear. If you were to put this in you would see a large gap in what the write statement produces. The two variables are hard set at 15 because what can go in there will vary in size. Regardless of what goes in there when the write statement is processed, I want just 1 space between the variables and the next word in the sentence.

Here is what comes out now if you run this:

The value of First_One is: Value1          and the value of Second_One is: Value2          .

Here is what I want it to look like:

The value of First_One is: Value1 and the value of Second_One is: Value2.

I tried to SHIFT right deleting trailing however all it did was move the values and put the extra spaces to the left of the values.

How can I accomplish what I need?

REPORT  Z_Generic_Stuff.

DATA: First_One(15) VALUE 'Value1' TYPE c,

      Second_One(15) VALUE 'Value2' TYPE c.


    CONDENSE First_One.

    CONDENSE Second_One.


    WRITE: /'The value of First_One is:', First_One, 'and the value of Second_One is:', Second_One, '.'..

1 ACCEPTED SOLUTION
Read only

Ashutosht09
Participant
0 Likes
1,865

Concatenate the strings seperated by gaps and then print the variable into which the strings get concatenated.

    Data: V1(100) TYPE c.

    Concatenate 'The value of First_One is:' First_One 'and the value of Second_One is:' Second_One '.' into V1 SEPARATED BY SPACE.
    WRITE: /  V1.

The output will be

The value of First_One is: Value1 and the value of Second_One is: Value2 .

6 REPLIES 6
Read only

Ashutosht09
Participant
0 Likes
1,866

Concatenate the strings seperated by gaps and then print the variable into which the strings get concatenated.

    Data: V1(100) TYPE c.

    Concatenate 'The value of First_One is:' First_One 'and the value of Second_One is:' Second_One '.' into V1 SEPARATED BY SPACE.
    WRITE: /  V1.

The output will be

The value of First_One is: Value1 and the value of Second_One is: Value2 .

Read only

custodio_deoliveira
Active Contributor
0 Likes
1,865

Hi Richard,

there are many many many many ways to do it, depending on your release. Ashutosh showed one way, here comes another one:

REPORT  Z_Generic_Stuff.

DATA: first_one(15) VALUE 'Value1' TYPE c,

       second_one(15) VALUE 'Value2' TYPE c,

       mytext TYPE string.

mytext = |The value of First_One is: { first_one } and the value of Second_One is: { second_one } |.

WRITE mytext.

Regards,

Custodio

Read only

arindam_m
Active Contributor
0 Likes
1,865

Hi,

An F1 would lead you to how the handling of the Keyword condense takes place at compiler. check the below lines in the help

If the data object has a fixed length, any space created by the condense operation is filled with blanks on the right. If the data object is of the type string, its length is adapted to the result of the condense operation

So in your case if you do just the below declaration instead of type c that would suffice your requirement without any additional statements or variable declaration.

DATA: first_one VALUE 'Value1' TYPE string,
          second_one VALUE 'Value2' TYPE string.

Cheers,

Arindam

Read only

0 Likes
1,865

As I said, there are many ways to do it. As usual, the simplest solution is also the best.

Nice stuff.

Read only

Former Member
0 Likes
1,865

Well you were almost right Ashutosh. I did yours and still the written line showed the spaces in the sentence. BUT...I was able to do a CONDENSE on that string and it worked.

So the proper answer to my question is: First Concatenate the character fields into a string field and then run the CONDENSE statement on that string field. Lastly, write out the line.

Custudio : I must say that I tried the code that you had written and it did not work at all. Is the syntax you intended correct with the PIPE-TO ( | ) and the curly brackets (  {}  )?

Arindam Mondal: I did go into F1 long before I got here. While this written example is very much simplified, the real report has a little more to it which required the two variable fields to be of type c and a specified length. Thanks though.

Read only

0 Likes
1,865

Hi Richard,

I'm glad the problem was solved. As I said, there are many ways to do it, depending on your release. The fancy code I gave you works perfectly in my system (7.31 SP7). I'm not sure when the pipes and curly brackets were introduced, but I think it was on 7.02. What's your ABAP version?

Cheers,

Custodio