Application Development 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: 

want to check whether input field in selection-screen is numeric or not

Former Member
0 Kudos

i have a select -option in selection-screen in which user enters a value.i just want to check if this value is numeric then it should be 18 positions prefixed with zeroes if numeric like 000000000000400000 and needs to be left justified if not numeric like G0032-BTI.

i check the fourm also but it didn't helped me.

i m using the code.

SELECT-OPTIONS : S_MAT FOR CDHDR-OBJECTID,

LOOP AT S_MAT.

if S_MAT ca sy-abcde .

shift s_mat left deleting leading space.

else.

SHIFT s_mat RIGHT DELETING TRAILING SPACE.

TRANSLATE s_mat USING '0'.

ENDIF.

endloop.

can anybody help.

<REMOVED BY MODERATOR>

thanks

Edited by: Alvaro Tejada Galindo on Jan 17, 2008 4:00 PM

1 ACCEPTED SOLUTION

Sougata
Active Contributor
0 Kudos

I have a solution for you! Try this code below, just copy/paste "as-it-is".


TABLES: cdhdr.

DATA: gv_type TYPE dd01v-datatype.

SELECT-OPTIONS : s_mat FOR cdhdr-objectid.

AT SELECTION-SCREEN.
  LOOP AT s_mat.
    CLEAR gv_type.
    IF NOT s_mat-low IS INITIAL.
      CALL FUNCTION 'NUMERIC_CHECK'
        EXPORTING
          string_in = s_mat-low
        IMPORTING
          htype     = gv_type.
      IF gv_type NE 'NUMC'.
        MESSAGE e016 WITH 'Not Numeric'.
      ELSE.
        SHIFT s_mat-low LEFT DELETING LEADING: '0', space.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input  = s_mat-low
          IMPORTING
            output = s_mat-low.
        MODIFY s_mat TRANSPORTING low.
      ENDIF.
    ENDIF.
    IF NOT s_mat-high IS INITIAL.
      CALL FUNCTION 'NUMERIC_CHECK'
        EXPORTING
          string_in = s_mat-high
        IMPORTING
          htype     = gv_type.
      IF gv_type NE 'NUMC'.
        MESSAGE e016 WITH 'Not Numeric'.
      ELSE.
        SHIFT s_mat-high LEFT DELETING LEADING: '0', space.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input  = s_mat-high
          IMPORTING
            output = s_mat-high.
        MODIFY s_mat TRANSPORTING high.
      ENDIF.
    ENDIF.
  ENDLOOP.

I hope this solves your problem.

Cheers,

Sougata.

2 REPLIES 2

Hans
Explorer
0 Kudos

Try using function module conversion_exit_matn1_input. It's the conversion exit for the material number, which is 18 characters long and acts exactly as you describe. Another alternative is to define your select option with a reference to an actual material number field, and then moving it to a range table that's defined as your object id field.

Edited by: Hans Derycke on Jan 17, 2008 1:00 PM

Sougata
Active Contributor
0 Kudos

I have a solution for you! Try this code below, just copy/paste "as-it-is".


TABLES: cdhdr.

DATA: gv_type TYPE dd01v-datatype.

SELECT-OPTIONS : s_mat FOR cdhdr-objectid.

AT SELECTION-SCREEN.
  LOOP AT s_mat.
    CLEAR gv_type.
    IF NOT s_mat-low IS INITIAL.
      CALL FUNCTION 'NUMERIC_CHECK'
        EXPORTING
          string_in = s_mat-low
        IMPORTING
          htype     = gv_type.
      IF gv_type NE 'NUMC'.
        MESSAGE e016 WITH 'Not Numeric'.
      ELSE.
        SHIFT s_mat-low LEFT DELETING LEADING: '0', space.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input  = s_mat-low
          IMPORTING
            output = s_mat-low.
        MODIFY s_mat TRANSPORTING low.
      ENDIF.
    ENDIF.
    IF NOT s_mat-high IS INITIAL.
      CALL FUNCTION 'NUMERIC_CHECK'
        EXPORTING
          string_in = s_mat-high
        IMPORTING
          htype     = gv_type.
      IF gv_type NE 'NUMC'.
        MESSAGE e016 WITH 'Not Numeric'.
      ELSE.
        SHIFT s_mat-high LEFT DELETING LEADING: '0', space.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input  = s_mat-high
          IMPORTING
            output = s_mat-high.
        MODIFY s_mat TRANSPORTING high.
      ENDIF.
    ENDIF.
  ENDLOOP.

I hope this solves your problem.

Cheers,

Sougata.