Search This Blog

Sunday, March 3, 2019

Validate National Code







    data:  first_number type I,
           num  
type I,
           counter  
type I,
           s  
type I,
           r  
type I,
           rr  
type I,
           
i  type I.


    
clearx_stcd1_Str x_stcd1_Len .
    x_stcd1_Str 
i_lfa1-stcd1.
    
SHIFT  x_stcd1_Str  LEFT DELETING LEADING space.
    
CONDENSE x_stcd1_Str NO-GAPS.


    first_number 
=  SUBSTRINGVAL =  x_stcd1_Str OFF LEN ) .


    
do times.
       num 
=  SUBSTRINGVAL =  x_stcd1_Str OFF sy-index 1  LEN ) .
       
if  num first_number .
           counter 
counter + 1.
       
endif.
       s 
s + num * 11 sy-index ).
    
enddo.


    r 
Mod 11 .

    
If r > .
       r 
11 .
    
endif.

    rr 
SUBSTRINGVAL =  x_stcd1_Str OFF LEN ) .
    
If rr And counter < .
       
MESSAGE 'National Code is valid !' TYPE 'I'.
    
else.
       
MESSAGE 'National Code is not valid !' TYPE 'E'.
    
endif.  

No comments:

Post a Comment