cancel
Showing results for 
Search instead for 
Did you mean: 

check a convertion from CHAR TO NUMC

Former Member
0 Kudos

Hi,

I import a flatfile into a structure that contains only CHAR-fields. Then I make a TRY-CATCH construct for every field in P,I,F,N..-datatypes to check if the data is correct.

P,I,F raise a CONVERT-Exception that i can handle.

A move to N-field raise no exception but put a wrong values to the N-field.

Example:

Charfield contains ' 1 1 0000', N-field is '110000'.

A compare in the program like

IF C-Field <> N-Field raise a exception that can't be catched by TRY-Catch.

How can i check if the field is correct?

Anybody understand me and have an idea?

Regards,

Stefan

Accepted Solutions (1)

Accepted Solutions (1)

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Stefan!

I'm not sure, if I could follow you: the If C-field is outside your program?

Nevertheless, add some checks / conversions before you try to move into a N-field:

- Depending if you would like to accept your example, use condense

- replace space with 0 (e.g. use translate ' 0')

- only convert, if c-field CO '0123456789'.

Especially the 'contains only' should prevent any problems during the conversion.

Regards,

Christian

Former Member
0 Kudos

Hi Christian and Rich,

thank you for your fast reply.

I've written one TRY method that has a import-parameter with TYPE ANY and a import-parameter for the target field.

The target field can be everything like P,I,F,N,C,D.

The method checks if the value can be converted into the target field and avoid a shortdump, when the flatfile contains bad data.

So I have to get the type by

cl_abap_typedescr=>describe_by_data

and then make your suggested Conatins-only-check if it is a

cl_abap_typedescr=>typekind_num

???

Thanks,

Stefan

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Stefan,

I have the feeling, I can follow your description a little better now. You are writing an extension / own TRY-method? Wow!

But yes, this would be the logic: in case of typekind_num, place the if ... CO numbers

Isn't this the way, you are checking the other types, too? Of course with different IF-clause, but testing some rules to be fulfilled?

Regards,

Christian

Former Member
0 Kudos

Hi Christian,

Yes, I think I have not to be to lazy and make a special routine for every type.

I hoped that there is a FM or method that can do the check for me.

Thank you very much for your help and 10 points for you.

Best regards,

Stefan

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Stefan!

Thanks

I guess, you have to make some coding (case ... and so on) - if it would be easy, SAP would make the checking easier, too.

Christian

Answers (1)

Answers (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Try something like this...

IF field CN '0123456789'.
* This field is not all numeric
ENDIF.

Regards,

Rich Heilman

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

This may be a little better.



data: field(10) type c value '01223'.
data: length type i.

length = strlen( field ).

if field+0(length) cn '0123456789'.
  write:/ 'this field is not numeric'.
endif.

Regards,

Rich Heilman