Sage X3 has Supplier master where we can define information about supplier, where we have added PAN number field which will store PAN number of supplier. So for that field one of our client requested us to add validation for PAN number which can accept only string in PAN format i.e. length of the string should be 10 digit only first 5 characters should be alphabets, next 4 should be numbers and last one should be alphabet.
So to achieve this requirement programmatically we have added some code on “After Change(AM_XXX)” action on PAN number field:
New Stuff: How to display reserved quantity message in Sales Order screen in Sage X3
#################################################################################
SUBPROG PANValidation(PANNO)
VALUE CHAR PANNO
Local integer I : I = 0
Local integer k : k = 0
LOCAL CHAR TEMP(10) : TEMP = PANNO
Local CHAR CH1(5)
Local CHAR CH2(4)
Local CHAR CH3(1)
IF LEN(TEMP) = 10
CH1 = NUM$(LEFT$(TEMP,5))
CH2 = NUM$(SEG$(TEMP,6,9))
CH3 = NUM$(SEG$(TEMP,10,10))
I = 0
k = 0
for I = 1 to len(CH1)
k = find (seg$(CH1,I,I), “A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”)
IF k = 0
INFBOX “INVALID PAN NUMBER”
mkstat=2
end
ENDIF
NEXT
I = 0
k = 0
for I = 1 to len(CH2)
k = find (seg$(CH2,I,I), “0”,”1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″)
IF k = 0
INFBOX “INVALID PAN NUMBER”
mkstat=2
end
ENDIF
NEXT
I = 0
k = 0
for I = 1 to len(CH3)
k = find (seg$(CH3,I,I), “A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”)
IF k = 0
INFBOX “INVALID PAN NUMBER”
mkstat=2
end
ENDIF
NEXT
ELSE
IF LEN(TEMP) <> 0
INFBOX “INVALID PAN NUMBER”
mkstat=2
ENDIF
ENDIF
END
#################################################################################
In above script we have created one subprogram named as “PANValidation” which is called in ‘after change’ action of PAN number field and has parameter as PAN number. In subprogram firstly we have stored PAN number in TEMP variable and then segregated TEMP to 3 different variables. After this we have validated every character of every variable with alphabet & number as shown in above script.
According to above script if any character of string is not following the condition mentioned in script then it will popup message of “INVALID PAN NUMBER” and not allow to proceed further up to user is not entering valid format.
In this way, we can do PAN number validation on particular field for a specific format of a string in Sage X3.