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: 

Verify SSN in the string

Former Member
0 Kudos

Hi ,

I have a requirement while reading the input file.

Input file is mixed up with several header records and data records

Every data record has SSN starting at fixed position.

So we need to identify the SSN in the data record and store that entire record and skip other records.

SSN format is xxx-xx-xxxx . All are numbers .

I think there might be easier to way to compare and identify this format.

Could anyone suggest the best way to do these.(May be comparing patterns,some string operation etc).Also i need to check all the 'X' are numbers.

Thanks for the help.

Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Kumar,

First Grab those SSN number in a variable of type CHAR11 say var_ssn.

Then if var_ssn+4(1) = '-'

and var_ssn+7(1) = '-'

and var_ssn+0(3) CO '1234567890'

and var_ssn+5(2) CO '1234567890'

and var_ssn+8(4) CO '1234567890'.

Then it contains SSN number and is confirmed to be a data record.

endif.

Hope this helps!

Regards,

Vimal.

11 REPLIES 11

Former Member
0 Kudos

>

> Every data record has SSN starting at fixed position.

> So we need to identify the SSN in the data record and store that entire record and skip other records.

If the SSN is at a fixed position, then that position identifies it.

Rob

0 Kudos

Rob,

I am sorry for not specific.

Actually i need to identify the data record(differentiate between data record and other lines based on the SSN).

So based on the SSN format , i could exactly know that string has an SSN and therefore identify it as data record.

Also as SSN starts at fixed position,First I shall grab the 11 literals from that position and i need to verify whether that part of string is in the format XXX-XX-XXXX.I just need the logic to verify that part.

Thank you.

Edited by: Kumar B on Aug 12, 2009 5:44 PM

0 Kudos

Try using RegEx using pattern :

^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$

search in SCN on how to use this pattern.

Former Member
0 Kudos

Hi Kumar,

First Grab those SSN number in a variable of type CHAR11 say var_ssn.

Then if var_ssn+4(1) = '-'

and var_ssn+7(1) = '-'

and var_ssn+0(3) CO '1234567890'

and var_ssn+5(2) CO '1234567890'

and var_ssn+8(4) CO '1234567890'.

Then it contains SSN number and is confirmed to be a data record.

endif.

Hope this helps!

Regards,

Vimal.

former_member194669
Active Contributor
0 Kudos

Try this code by cut & paste into a test program and try


report zars
  no standard page heading line-size 255.
parameters : ssn(15) type c.
data matcher type ref to cl_abap_matcher.
matcher = cl_abap_matcher=>create(
             pattern = `^d{3}-d{2}-d{4}$`
             ignore_case = 'X'
             text = ssn ).

if matcher->match( ) is initial.
  message 'Invalid ssn Format' type 'I'.
else.
  message 'Valid ssn format' type 'I'.
endif.

0 Kudos

Hi a®s,

Could you please expain the above the pattern u specified.

Any links that could help to understand the patterns and more about the class cl_abap_matcher.

Thank you

0 Kudos

You can get Regex info from this link

http://www.regular-expressions.info/

You can test these regex in SAP by using program DEMO_REGEX_TOY

0 Kudos

a®s

The above presentation,I had just read this morning..

Thanks for the same.Kindly post if you have any other links etc regarding the same .

I assigned the points..

Thank you Vimal for the post.I feel that was a nice and simple way.

0 Kudos

You'll find help on regular expressions everywhere on the web. Now I guess your question is answered... you may close the thread. Thx

Former Member
0 Kudos

Or you can use FM BCA_US_VALIDATE_SSN

Rob