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

How to perform DataType validation?

Former Member
0 Likes
2,164

Hi

I have a table called Z_Char_Table with <b>all the fieldname type of CHAR</b>. After i import my flat file data into this table. I need to perform datatype validation on individual data to determine the datatype of the data.

Is it possible to do that? If not, what are the simple concept / logic to do a datatype validation after i import the flat file data to the database?

Regards,

Rayden

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,711

Hi Rayden,

Since all your fields are TYPE CHAR in the Z TABLE, I believe you need the validation so that you can use this data in some program for either executing some FM or to upload into some standard table or something like that.

In anycase since the fields are of TYPE CHAR in ZTABLE you cannot check the datatype.

What you can do instead is do logical checks.

Example:

If column 1 has number and values then it's numeric.

If it has 8 char and numeric then it's date <-- this is not the correct reasoning but indicator of how you can do.

Alternatively and this is the best approach:

Check the design and usage of ZTABLE.

You'll know whether first field needs to be numeric or date etc

and you can do reverse check:

for example : if field contains Alphabets then it's not integet or Date

If field is supposed to be a DATE then it should have 8 char and all numerals etc

Hope this helps

Regards

Nishant

10 REPLIES 10
Read only

Former Member
0 Likes
1,711

What validation are you looking for? Are the values stored in custom table related to any SAP fields- for eg if table stores Sales Order No then you can validate data with VBAK-VBELN.

Can you focus more on your requirement?

Read only

0 Likes
1,711

Hi Ashish,

I need to perform DataType validation on the data. To determine whether is it numeric / date / time or other type. By the way, the custom table is not related to any SAP fields.

Regards,

Rayden

Read only

0 Likes
1,711

It is hard to decide if a column contains a numeric value or a date value or an amount value as all contain just numbers.

Do you have any idea about file? Like first column will always contain characters. Second column will always contain DATE. IF this is clear, it will help to validate file.

ashish

Read only

0 Likes
1,711

Hi Ashish,

Oh ya.. forget to mention. there is actually a validation rule table (Z_V_R_Table) to determine by the user who do the import of file. He will determine the field type of the particular field. Base on this, how do i do the validation on the imported data to Z_Char_Table? What logic would you advice to perform this validation?

Best Regards,

Rayden

Read only

0 Likes
1,711

It is simple then.

For each value of the file (which will be loaded in to an internal table)

Check if there is an entry in the rule table. (you need to see this field wise. Like ITAB-FIELD1 value should match to rule table respective field.).

In this way, you can validate all data and proceed further.

Hope this helps.

ashish

Read only

Former Member
0 Likes
1,712

Hi Rayden,

Since all your fields are TYPE CHAR in the Z TABLE, I believe you need the validation so that you can use this data in some program for either executing some FM or to upload into some standard table or something like that.

In anycase since the fields are of TYPE CHAR in ZTABLE you cannot check the datatype.

What you can do instead is do logical checks.

Example:

If column 1 has number and values then it's numeric.

If it has 8 char and numeric then it's date <-- this is not the correct reasoning but indicator of how you can do.

Alternatively and this is the best approach:

Check the design and usage of ZTABLE.

You'll know whether first field needs to be numeric or date etc

and you can do reverse check:

for example : if field contains Alphabets then it's not integet or Date

If field is supposed to be a DATE then it should have 8 char and all numerals etc

Hope this helps

Regards

Nishant

Read only

0 Likes
1,711

Hi Nishant,

That was useful. Thanks.

1 quick question, let say a data contain numeric type with 8 length, it can be either a date or telephone number. How do i know it a date or telephone number? Is there any method / module that allow me to check if it is a date?

Regards,

Rayden

Read only

0 Likes
1,711

This is tricky.

You can put multiple conditions like

if first four char are greater than 1900 and less than 3000 ( Assuming dates are for future years! )

If next two char are between 1 and 12

if next two char are between 1 and 31

and also if you are making this for a particulare area or you know that typically it's going to start with a particular digit say 8XXXXXX then you can just check the first char and determine whether it's a tel num or a date

Hope this helps

Regards

Nishant

Read only

0 Likes
1,711

Hi Rayden,

The other way to check if it is date or not is

just check value between 19000101 To 20991231.

You may not get 100% correct result but you will near to that.

Regards,

Atish

Read only

Former Member
0 Likes
1,711

Hi Guys,

Thanks for the valuable information and guidance, now i have abit clearer picture on how to go about doing the validation.

Regards,

Rayden