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

Sorting Numeric Characters as numbers

Former Member
0 Likes
5,381

Hey guys,

I have an ALV Grid that needs to display a column of numbers with a percent at the end and any negative values in the front.

-35.4%

8.7%

13.4%

-100.3%

8732.9%

This was done, but while within the ALV, if they click on the sorting buttons, it does not sort correctly.

It is because the system column HAS to be a string to display it like it is, but as a string it sorts differently from how numbers sort.

Has anyone come up with a solution to this?

1 ACCEPTED SOLUTION
Read only

rosenberg_eitan
Active Contributor
0 Likes
3,867

Hi,

I did a small test using CONVERSION_EXIT.

Here is the output:

Regards.

12 REPLIES 12
Read only

Former Member
0 Likes
3,867

Why dont you put '%', eg Marks in % ,in the heading of the column and put just the values in column?

Your issue would be solved.

Regards,

Susmitha

Read only

0 Likes
3,867

That's similar to the answer I proposed, I added a new column with % in the column.

BUT they still want the - sign to be in front of the number, not behind the number.

In order to put the - sign in front, I have to use strings. Which gives me the exact same problem I had before; SAP uses the sorting rules for strings, not for numerics.

Because the % is at the end, it is a constant and I can find work arounds for it.

But to have the negative symbol in front of the string causes the problems.

Read only

Former Member
0 Likes
3,867

If we convert its type by NUMC i thing then also it will work. Just give a try.

BR

ChanS

Read only

former_member185177
Contributor
0 Likes
3,867

Hi Tom

I agree with "Susmitha's" reply please go through that one your issue will resolve.

Regards,

Krishna Chaitanya.

Read only

former_member209120
Active Contributor
0 Likes
3,867

Hi

Field Text instead of  displaying in filed ,

Remove % in column

Display values lie this

Field Name %

-35.4

8.7

13.4

-100.3

8732.9

instead of

Field Name

-35.4%

8.7%

13.4%

-100.3%

8732.9%

Read only

0 Likes
3,867

This does not fix the problem, because I still have to use strings to move the negative sign.

Read only

rosenberg_eitan
Active Contributor
0 Likes
3,867

Hi,

If the end customer insist that you use the format 13.4% .

You can hold your data as numeric (for sorting).

Create your own CONVERSION_EXIT_PRCNT_OUTPUT and put  ==PRCNT in the EDIT_MASK for this field in the field catalog .

Use can use the edit_mask of in the field catalog for formatting the output.

http://help.sap.com/saphelp_erp2004/helpdata/en/ff/4649baf17411d2b486006094192fe3/content.htm

http://help.sap.com/saphelp_erp2004/helpdata/en/33/206bc8012e11d3b495006094192fe3/content.htm

Regards.

Read only

rosenberg_eitan
Active Contributor
0 Likes
3,868

Hi,

I did a small test using CONVERSION_EXIT.

Here is the output:

Regards.

Read only

0 Likes
3,867

How did you set up the edit mask for this to work?

Read only

0 Likes
3,867

Hi ,

Some blood some sweat some tears some luck.....

I will upload the code shortly.

Regards.

Read only

0 Likes
3,867

Hah, thanks!

Read only

0 Likes
3,867

Hi,

Function: (Any CONVERSION_EXIT_????_OUTPUT can be used as a skeleton)

Code:

FORM conversion_yts01

  USING

    p_input

  CHANGING

    p_output .

  DATA: buffer_1 TYPE char32 .

  WRITE p_input TO buffer_1 NO-SIGN NO-ZERO RIGHT-JUSTIFIED .

  IF p_input IS INITIAL .

    p_output = space .

    RETURN.

  ENDIF .

  CONDENSE buffer_1 .

  CONCATENATE '+' buffer_1 '%' INTO buffer_1 .

  IF p_input LT 0 .

    WRITE '-' TO buffer_1+0(1) .

  ENDIF .

  CONDENSE buffer_1 .

  p_output = buffer_1 .

ENDFORM.                    " CONVERSION_YTS01

Program:

In this case I use CL_SALV_TABLE ALV but this will work also in other ALV.

Just use the EDIT_MASK in the field catalog.

Full source included.

Regards.