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

Validate Amount Field against input file values

Former Member
0 Likes
6,270

Hi All,

My Decimal notation profile is USR01-DCPFM  = SPACE ( Blank value ) i.e. Thousand's separator is '.' and decimal is ','

In VA01, if I enter Condition value = 1.24,34 , I get error - ' Input must be in the format __.___.___.__~,__V'.

I want to replicate same standard behavior in my custom report where I will be getting this amounts in excel file.

I want to check if file has invalid entries such as 1.24,34  or not . If yes error message  ' Input must be in the format __.___.___.__~,__V' is to be given.

I tried with FM 'HR99L00_CONV_FROM_EDIT_MASK_IN ' by passing input = 1.24,34  and P_EDIT_MASK = __.___.___.__~,__V.

It gives expected error but for correct value  input = 1.234,45  also it gives error input must be in the format __.___.___.__~,__V.

Can anybody please let me know where I am doing mistake.


Thanks,

Jit

Hi All,

My Decimal notation profile is USR01-DCPFM  = SPACE ( Blank value ) i.e. Thousand's separator is '.' and decimal is ','

In VA01, if I enter Condition value = 1.24,34 , I get error - ' Input must be in the format __.___.___.__~,__V'.

I want to replicate same standard behavior in my custom report where I will be getting this amounts in excel file.

I want to check if file has invalid entries such as 1.24,34  or not . If yes error message  ' Input must be in the format __.___.___.__~,__V' is to be given.

I tried with FM 'HR99L00_CONV_FROM_EDIT_MASK_IN ' by passing input = 1.24,34  and P_EDIT_MASK = __.___.___.__~,__V.

It gives expected error but for correct value  input = 1.234,45  also it gives error input must be in the format __.___.___.__~,__V.

Can anybody please let me know where I am doing mistake.


Thanks,

Jit

21 REPLIES 21
Read only

Juwin
Active Contributor
0 Likes
4,841

I don't think this function module will help you to check the number format. AFAIK, It expects the input to have the same length as the edit mask. I couldn't see a handling of sign in the function module. If you want to convert the input number into SAP format, you can just use this method. It uses user setting to convert input value into number.

Thanks,

Juwin

Read only

Former Member
0 Likes
4,841

Hi Juwin,

I can convert Amount form external format to internal format. But problem is to detect invalid values and throw error for such records in input file.

Eg: if I pass invalid amount 1.24,56 for USR01-DCPFM  = SPACE then I should throe error.

Otherwise this amount will be saved as 124. 56 in database as per the logic to convert values from ext. to internal format.

Is there any way by which I can detect such erroneous values.

Please let me know.

Thanks,

Jit

Read only

Juwin
Active Contributor
0 Likes
4,841

How long is your number field? Does it include signs?

Thanks,

Juwin

Read only

Former Member
0 Likes
4,841

Use a TRY - CATCH - ENDTRY block with a cx_sy-conversion_no_number error.

Rich

Read only

0 Likes
4,841

Hi Rich,

Didn't get your solution. For what you want me to use TRY -CATCH block.

Please elaborate little more.


Thanks,

Jit

Read only

0 Likes
4,841

To perform the functionality that you wish to perform.  ie.  To catch invalid numeric values.

You TRY to move your value from the excel file to a numeric variable,  you then CATCH the exception which is raised when the value does not conform to the definition or a number where by you then issue an appropriate error message.

In your editor type 'TRY',  put the cursor on it and press the F1 key.

Rich

Read only

0 Likes
4,841

Hi Rich,

I want to check if values are invalid in terms of Thousand's separator.

I tried moving value 13.21,19 to variable  declared with below type:

DATA  lv_num(10)        TYPE n.

Although it's invalid number in terms of thousand's separator, it did not raise any exception.

Output - lv_num = 0000132119.

Regards,

Jit

Read only

Juwin
Active Contributor
0 Likes
4,841

This is true even on SAP screens. SAP doesn't expect user to put in thousand separators while entering numbers on screens - it is purely optional.

Thanks,

Juwin

Read only

0 Likes
4,841

And that code will do just that.

Use a numeric field,  NOT a string field that accepts only numbers.  Something like a type of Menge_D.  Then move your invalid number to it and see what happens.

A NUMC field strips out any invalid characters when you move stuff to it.  It is also a string field,  which is not what you were talking about above (ie a number field).

Rich

Read only

0 Likes
4,841

Hi Juwin,

I guess that's partially true.. If you put Condition Amt= 1.23,45  in VA02- Condition tab  it also gives error input must be in the format __.___.___.__~,__V.

So SAP expects to put input in correct format if we are adding thousand separators manually.

So if input file is having  invalid value as 1.23,45 then I should throw an error.

Read only

0 Likes
4,841

Hi Rich,

Solution given by you won't suffice my requirement.

Read only

Juwin
Active Contributor
0 Likes
4,841

Yes, if you add it, then SAP expects them to be in correct format.

Why are you so concerned about the format only? Is your primary intention to read the input value or just validate the format?

Thanks,

Juwin

Read only

0 Likes
4,841

In what way ?

It will detect if the user enters a number that cannot be translated to a number and then you can issue an error message to suit.

In what way does that not suit your requirement ?

Read only

0 Likes
4,841

My requirement is to determine if Amount has correct thousand's separator or not and not whether Amount amount is alphanumeric.

I tried your solution of declaring variable of type 'N' and passing amount field to it but it is not working.

Read only

0 Likes
4,841

Read what I said - a numeric field something like Menge_d,  and not a NUMC field.  (ie a string field that only accepts numbers).

And THEN it will work.

Your requirement is so simple!

Read only

0 Likes
4,841

Rich.. I have already tried your solution..

If you move Amount 1.23,45 to variable declared with Data element NETWR_AP then it will give dump for the obvious reason that 1.23,45 contains comma and it's not in SAP's internal number format.

As I have mentioned my requirement is to determine if Amount has correct thousand's separator.

Moving amt to numeric field with Data element NETWR_AP will not help as it will give dump just because amount is not in internal number format.



Read only

0 Likes
4,841

You obviously have not tried what I suggested if you are getting short dumps.

I will spell it out for you:

Try.

    l_Number_Field = '1.23456,78'.

Catch CX_SY_CONVERSION_NO_NUMBER.

    Message 'That number is erroneous'.

EndTry.

Rich

Read only

0 Likes
4,841

Below is the code I tried again:

DATA : lv_amt TYPE netwr_ap.

TRY.

    lv_amt = '1.234,78'.

  CATCH cx_sy_conversion_no_number.

    MESSAGE 'That number is erroneous' TYPE 'I'.

ENDTRY.

Here 1.234,78 is correct amount from thousand's separator perspective and still the exception is raised which is wrong...

Read only

0 Likes
4,841

Ok,  prior to trying this you need to remove any group separators that are appropriate for the decimal notation being used.  Group separators can either be ',',  '.' or a space.   You can determine the group separator by getting the position of the dot in the string and then the comma or space.

If the comma or space's position is less than the dot then the gs is a comma or space.  If the dot is less than the comma or spaces position then the gs is a dot.  You need to make a special case if these characters do not appear in the string.

At that point you have an answer as to whether the format is somewhat correct.  You can then remove the gs's and use the TRY block to determine if it is an actual number or not.

Rich

Read only

0 Likes
4,841

Richard Harper wrote:

If the comma or space's position is less than the dot then the gs is a comma or space.  If the dot is less than the comma or spaces position then the gs is a dot.  You need to make a special case if these characters do not appear in the string.

Rich

This was my first query which i mentioned in original post.. Is there any standard method ot FM which checks thousand's separator correctness.

Read only

0 Likes
4,841

Hi Jit,

Not really.