PreviousNextIndex

CAN-DO function

Checks a string value against two types of comma-separated lists:

Syntax

CAN-DO ( id-list [ , string ] ) 

id-list
string
Examples

The r-cando.p procedure is based on an activity permission table called permission. The permission table is not included in your demo database. However, the records in that table might look something like the following:

Activity
Can-Run
custedit
manager,salesrep
ordedit
manager,salesrep
itemedit
manager,inventory
reports
manager,inventory,salesrep

In r-cando.p the FIND statement reads the record for the activity custedit in the permission table. (This assumes that a unique primary index is defined on the activity field.) The CAN-DO function compares the user ID of the user running the procedure with the list of users in the can-run field of the custedit record. If the user ID is manager or salesrep, the procedure continues executing. Otherwise, the procedure displays a message and control returns to the calling procedure.

r-cando.p
DO FOR permission: 
  FIND permission "custedit". 
  IF NOT CAN-DO(permission.can-run) THEN DO: 
    MESSAGE "You are not authorized to run this procedure". 
    RETURN. 
  END. 
END. 

In this next example, the CAN-DO function compares userid (the user ID for the current user) against the values in id-list. The values in id-list include manager and any user IDs beginning with acctg except acctg8. If there is no match between the two values, the procedure displays a message and then exits.

r-cando2.p
IF NOT CAN-DO("manager,!acctg8,acctg*") THEN DO: 
  MESSAGE "You are not authorized to run this procedure.". 
  RETURN. 
END. 

In addition to performing security checks, you can use the CAN-DO function for looking up any value in a comma-separated list. For example, the following procedure searches your PROPATH for your DLC directory:

r-cando3.p
MESSAGE "The DLC directory " + 
        (IF CAN-DO(PROPATH, OS-GETENV("DLC")) THEN "is" ELSE "is NOT") + 
        " in your PROPATH.". 

Notes
See also

SETUSERID function, USERID function, VALIDATE statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex