lunes, 27 de septiembre de 2010

Comprobar si un campo es numerico ABAP

report ztest.

data irefer(60) value '1casa'.
data v_tipo(4).

CALL FUNCTION 'NUMERIC_CHECK'
EXPORTING
string_in = irefer
IMPORTING
* string_out =
htype = v_tipo
EXCEPTIONS
OTHERS = 1.

IF v_tipo EQ 'NUMC'.
if iREFER < 10000.
concatenate '01038' irefer+1(5) into irefer.
else.
concatenate '0100' irefer into irefer.
endif.

ENDIF.
write irefer.

1 comentario:

Stolen dijo...

Otra manera de validarlo es introduciendo el código dentro de un bloque TRY CATCH, por ejemplo:


DATA: dato(4) TYPE c VALUE 'A470',
num TYPE n.

TRY.

num = dato.

CATCH cx_sy_conversion_no_number.

ENDTRY.