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

abt char to numeric conversion

Former Member
0 Likes
1,523

There is a field named bcode in data base that is of char length 3 , i want 1 to 10 insert in dat field, is it possible , i know yes , so tell me dat field is behaving like character when i m selecting values from selection screen , what i want when i m entering 1 to 7 it should show only then as a numeric field do , how we can do dat? tell me in details?

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,484

OK, I understand now.

>SO IT SHOULD ALSO SHOW 3 INSIDE THE VALUSE ,

No, it shouldn't. You're data types are wrong. The problem you've got is the sort order of your data - it is alpha sorting, not numeric. It's the same as if you'd put A, AB and C into the database. If you then select A to AB, you won't get C. ( 1 to 12, you won't get 3 ).

I imagine you have something like this for your selection screen.

DATA: num TYPE c LENGTH 3.

SELECT-OPTIONS s_num FOR num.

AT SELECTION-SCREEN ON s_num.

  IF s_num CN ' 0123456789'.
    MESSAGE e000(s1) WITH 'Numerics only'.
  ENDIF.

The best course of action is change your datatypes in the database, to match the data being held.

matt

There is a field named bcode in data base that is of char length 3 , i want 1 to 10 insert in dat field, is it possible , i know yes , so tell me dat field is behaving like character when i m selecting values from selection screen , what i want when i m entering 1 to 7 it should show only then as a numeric field do , how we can do dat? tell me in details?

11 REPLIES 11
Read only

Former Member
0 Likes
1,484

what i want , for example ,

we ahve inserted 1 then 12 then 3

so value will be 1 , 12 , 3 , n when we are selecting by selection screen from 1 to 12 dat will show only 1 to 12 , 3 will not there i want 3 should also be there based on selection.

reply plz

Read only

0 Likes
1,484

reply plzzzzzzzzzz

Read only

matt
Active Contributor
0 Likes
1,484

I'd be delighted to help, but I do not understand what you are asking.

matt

Read only

0 Likes
1,484

then sort them before selecting so that u can get 3

Read only

0 Likes
1,484

DAT FIELD IS CHARACTER SO SORTING CANT HELP THERE.

Read only

0 Likes
1,484

HI I M REPEATING MY QUESTION , HERE DAT , I HAVE A FIELD OF CHAR LENGTH 3 ,

NOW I HAVE ADDED 3 VALUES 1 , 12, 3 TO DAT FIELD IN THE DATABASE,

NOW I M SELECTING VALUE THROUGH THE SELECTION SCREEN N

I M SELECTING ALL THE VALUES BETWEEN 1 TO 12 , SO

IT SHOULD ALSO SHOW 3 INSIDE THE VALUSE ,

BUT DAT IS NOT HAPPENING , BCOZ IT WAS A CHARACTER FIELD SO IT IS SHOWING 1 N 12 ,

SO I WANT TO KNOW HOW CAN WE SOLVE DAT PRB ,

?

Read only

0 Likes
1,484

reply plz

Read only

0 Likes
1,484

Hi,

You have a data type Character in database.


data:  t_test(12) type c,
         n(10) type n.
         n = t_test.

You can assign character to numerical value.

Create one internal table with a single field

n(10) type n.

Loop at the database table and insert all the values of the character field from the database table to the character field.

Then select based on the other internal table . Give condition like \

your database table field name = internal table field name.

Regards

Sandipan

Read only

matt
Active Contributor
0 Likes
1,485

OK, I understand now.

>SO IT SHOULD ALSO SHOW 3 INSIDE THE VALUSE ,

No, it shouldn't. You're data types are wrong. The problem you've got is the sort order of your data - it is alpha sorting, not numeric. It's the same as if you'd put A, AB and C into the database. If you then select A to AB, you won't get C. ( 1 to 12, you won't get 3 ).

I imagine you have something like this for your selection screen.

DATA: num TYPE c LENGTH 3.

SELECT-OPTIONS s_num FOR num.

AT SELECTION-SCREEN ON s_num.

  IF s_num CN ' 0123456789'.
    MESSAGE e000(s1) WITH 'Numerics only'.
  ENDIF.

The best course of action is change your datatypes in the database, to match the data being held.

matt

Read only

Former Member
0 Likes
1,484

HI MAtt, thanks for ur suggestion , i got ur point but problem is not solved , the database we cant change that is the requirement , so we will have to take character s only , so tell me any other solution , u got right same is happening its taking alpha numeric sorting , so solve plz if possible.

Read only

matt
Active Contributor
0 Likes
1,484

Then follow Sandipan Ghosh's suggestion above. Read the database table into an internal table, convert the character numeric data to integer. Change your select option to be integer.

Or create a table, e.g. z_numtab, with two fields - CH3 type CHAR 3, and INT type INT1. Populate it with all the numbers 0-999. Then use it to convert the select option to a series of equalities.

DATA: num TYPE c LENGTH 3,
      int TYPE i.

DATA: lt_numtab TYPE STANDARD TABLE OF z_numtab.

SELECT-OPTIONS: s_num FOR num.

RANGES: r_num FOR i.

FIELD-SYMBOLS: <ls_numtab> TYPE z_numtab.

AT SELECTION-SCREEN..

  LOOP AT s_num.
    IF s_num-low CN ' 0123456789' OR s_num-high CN ' 0123456789'.
      MESSAGE e000(s1) WITH 'Numerics only'.
    ENDIF.
  ENDLOOP.

START-OF-SELECTION.

  LOOP AT s_num.
    r_num-option = s_num-option.
    r_num-sign   = s_num-sign.
    r_num-low    = s_num-low.
    r_num-high   = s_num-high.
    APPEND r_num.
  ENDLOOP.

  SELECT * FROM z_numtab INTO TABLE lt_numtab WHERE int IN r_num.

  REFRESH s_num.

  s_num-sign = 'I'.
  s_num-option = 'EQ'.
  LOOP AT lt_numtab ASSIGNING <ls_numtab>.
    s_num-low = <ls_numtab>-ch3.
  ENDLOOP.

  SELECT * FROM dbtab INTO TABLE lt_dbtab WHERE bcode IN s_num.

matt