08-12-2009 10:22 PM
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
08-12-2009 10:53 PM
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.
08-12-2009 10:28 PM
>
> 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
08-12-2009 10:33 PM
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
08-12-2009 11:50 PM
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.
08-12-2009 10:53 PM
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.
08-13-2009 2:07 AM
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.
a®
08-13-2009 4:27 PM
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
08-13-2009 4:33 PM
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
a®
08-13-2009 4:36 PM
08-13-2009 4:41 PM
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.
08-13-2009 9:41 PM
You'll find help on regular expressions everywhere on the web. Now I guess your question is answered... you may close the thread. Thx
08-13-2009 9:52 PM