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

Defining field for sorting

Former Member
0 Likes
1,172

If I have numeric values and alpha values and want to sort them according to numeric and alphabetcial order, should I define the field as NUMC or CHAR?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,078

Hi,

You have to define it as char..As NUMC will not accept alpha values..

Thanks,

Naren

10 REPLIES 10
Read only

Former Member
0 Likes
1,079

Hi,

You have to define it as char..As NUMC will not accept alpha values..

Thanks,

Naren

Read only

Former Member
0 Likes
1,078

Hi,

1. If the field contains Alphabets,

then we cannot take NUMC,

(Bcos NUMC can contain only digits, in char format)

2. Hence, we have to take CHAR.

regards,

amit m.

Read only

Former Member
0 Likes
1,078

u can use CHAR..

later u can sort as u like

Regards

SAB

Read only

Former Member
0 Likes
1,078

DEFINE CHAR

SORT BY CHAR FIELD

Read only

0 Likes
1,078

Hi All,

I have the following scenario with these values:

10

12

2

4

6

8

A

B

C

D

When I use the field as CHAR, the sort becomes

10

12

2

4

6

8

A

B

C

I would want the result to be

2

4

6

8

10

12

A

B

C

What would you recommend on how to approach this. It seems that some ABAP logic is required to to this?

Thanks

null

null

Read only

ferry_lianto
Active Contributor
0 Likes
1,078

Hi,

You may need to define two seperate fields. One is NUMC and the other one is CHAR.


DATA: BEGIN OF I_INPUT OCCURS 0,
        FIELD1(10) TYPE N,
        FIELD2(10) TYPE C,
        MATNR      TYPE MARA-MATNR.
DATA: END OF I_INPUT.

...

SORT T_INPUT BY FIELD1 FIELD2 ASCENDING.

Regards,

Ferry Lianto

Read only

0 Likes
1,078

Hi,

My problem is that I would have to use just one field for these values. I am not sure about your suggestions. Would you clarify

Thanks

Read only

Former Member
0 Likes
1,078

Hi,

If you are in AFS..

you will have a function module that can be used to sort according to the size..

I don't remember the function module name..

GO to SE37..Give JSORTSIZE*

Thanks,

Naren

Read only

ferry_lianto
Active Contributor
0 Likes
1,078

Hi,

Please try this ...


DATA: BEGIN OF ITAB OCCURS 0,
        SORT(1) TYPE C,
        FIELD1(5) TYPE C,.
DATA: END OF ITAB1.

LOOP AT ITAB.
   IF ITAB-FIELD1 CO SY-ABCDE.
     ITAB-SORT = 'B'.
   ELSE.
     ITAB-SORT = 'A'.
   ENDIF. 
  
   MODIFY ITAB.
ENDLOOP.

SORT ITAB BY SORT FIELD1 ASCENDING.

LOOP AT ITAB.
  WRITE: / ITAB-FIELD1.
ENDLOOP.

Regards,

Ferry Lianto

Read only

ferry_lianto
Active Contributor
0 Likes
1,078

Hi,

Please try this ... it works for me.


DATA: BEGIN OF ITAB OCCURS 0,
        SORT(1) TYPE C,
        SEQ(5)  TYPE N,
        FIELD1(5) TYPE C.
DATA: END OF ITAB1.

LOOP AT ITAB.
   IF ITAB-FIELD1(1) CA SY-ABCDE.
     ITAB-SORT = 'B'.
     ITAB-SEQ = '99999'.
   ELSE.
     ITAB-SORT = 'A'.
     ITAB-SEQ = ITAB-FIELD1.
   ENDIF. 
  
   MODIFY ITAB.
ENDLOOP.

SORT ITAB BY SORT SEQ ASCENDING.

LOOP AT ITAB.
  WRITE: / ITAB-FIELD1.
ENDLOOP.

Regards,

Ferry Lianto

Message was edited by:

Ferry Lianto