pub struct Field21 {
pub related_reference: String,
}
Expand description
§Field 21: Related Reference
§Overview
Field 21 contains the sender’s reference to the related transaction or message. This field establishes a link between the current message and a previously sent message or transaction, enabling tracking of related operations and maintaining audit trails across multiple message exchanges in correspondent banking and payment processing workflows.
§Format Specification
Format: 16x
- 16x: Up to 16 alphanumeric characters
- Character set: A-Z, a-z, 0-9, and limited special characters
- Case sensitivity: Preserved as entered
- Padding: No padding required (variable length up to 16 characters)
§Structure and Content
The related reference typically links to:
FT21034567890123
│└─────────────┘
│ Related transaction reference
└── Transaction type prefix (optional)
§Common Reference Patterns
Different institutions use various patterns for related references:
- Sequential linking:
REL000001
,REL000002
,REL000003
- Original reference: Same as Field 20 from original message
- Cover references:
COV001234567
,COV987654321
- Amendment references:
AMD1234567890
,AMD0987654321
- Cancellation references:
CAN12345678
,CAN87654321
§Usage Context
Field 21 is used in numerous SWIFT MT message types:
- MT202: General Financial Institution Transfer
- MT202COV: Cover for customer credit transfer
- MT205: Financial Institution Transfer for its own account
- MT210: Notice to Receive
- MT292: Request for Cancellation
- MT296: Answer to Amendment/Cancellation Request
§Business Applications
- Transaction linking: Connecting related messages and transactions
- Cover operations: Linking cover messages to original customer transfers
- Amendment tracking: Referencing original messages in amendments
- Cancellation requests: Identifying transactions to be cancelled
- Reconciliation: Matching related transactions across systems
- Audit trails: Maintaining complete transaction history chains
- Regulatory reporting: Providing transaction relationship information
§Validation Rules
- Length: Maximum 16 characters
- Character set: Alphanumeric characters and limited special characters
- Non-empty: Cannot be empty or contain only whitespace
- Format consistency: Should follow institutional standards
- Relationship validity: Should reference valid related transactions
§Network Validated Rules (SWIFT Standards)
- Related reference must not exceed 16 characters (Error: T13)
- Must contain valid SWIFT character set (Error: T61)
- Cannot be empty (Error: T18)
- Should reference existing transaction when applicable (Warning: recommended practice)
§Examples
:21:FT21234567890
└─── Related wire transfer reference
:21:COV0000012345
└─── Cover message reference
:21:NYC20241201001
└─── Branch and date-based related reference
:21:AMD123456789A
└─── Amendment reference with check digit
Fields§
Related reference value (maximum 16 characters)
Contains the sender’s reference to the related transaction or message. This value establishes the link between the current message and a previously sent message, enabling transaction tracking and audit trails.
Format: Up to 16 alphanumeric characters Character set: A-Z, a-z, 0-9, and limited special characters Case sensitivity: Preserved as entered Purpose: Links current message to related transaction or message
§Examples
"FT21234567890"
- Related wire transfer reference"COV0000012345"
- Cover message reference"AMD20241201001"
- Amendment reference"CAN123456789A"
- Cancellation reference with check digit
Implementations§
Source§impl Field21
impl Field21
Sourcepub fn new(related_reference: String) -> Self
pub fn new(related_reference: String) -> Self
Create a new Field21 with comprehensive validation
Creates a new related reference field with the provided reference string. The reference is validated for length and character set compliance.
§Arguments
related_reference
- The related reference string (max 16 chars)
§Examples
use swift_mt_message::fields::Field21;
// Standard related reference
let field = Field21::new("FT21234567890".to_string());
// Cover message reference
let field = Field21::new("COV0000012345".to_string());
// Amendment reference
let field = Field21::new("AMD20241201001".to_string());
§Validation
The constructor performs basic validation but full validation
occurs when calling validate()
method or during SWIFT message processing.
Get the related reference value
Returns the related reference string that links this message to a previously sent message or transaction.
§Returns
A string slice containing the related reference
§Example
let field = Field21::new("FT21234567890".to_string());
assert_eq!(field.related_reference(), "FT21234567890");
Sourcepub fn reference_pattern(&self) -> &'static str
pub fn reference_pattern(&self) -> &'static str
Check if the reference follows a common pattern
Analyzes the related reference to determine if it follows common institutional patterns for reference generation.
§Returns
A string describing the detected pattern, or “Custom” if no pattern is detected
§Example
let cover_ref = Field21::new("COV21234567890".to_string());
assert_eq!(cover_ref.reference_pattern(), "Cover Message");
let amd_ref = Field21::new("AMD0000012345".to_string());
assert_eq!(amd_ref.reference_pattern(), "Amendment");
Sourcepub fn is_date_based(&self) -> bool
pub fn is_date_based(&self) -> bool
Check if the reference appears to be date-based
Determines if the related reference contains date information based on common date patterns in reference strings.
§Returns
true
if the reference appears to contain date information
§Example
let date_ref = Field21::new("20241201001".to_string());
assert!(date_ref.is_date_based());
let simple_ref = Field21::new("COV12345".to_string());
assert!(!simple_ref.is_date_based());
Sourcepub fn sequence_number(&self) -> Option<u32>
pub fn sequence_number(&self) -> Option<u32>
Extract potential sequence number from reference
Attempts to extract a sequence number from the related reference, which is commonly found at the end of structured references.
§Returns
Some(number)
if a sequence number is found, None
otherwise
§Example
let seq_ref1 = Field21::new("COV001".to_string());
assert_eq!(seq_ref1.sequence_number(), Some(1));
let seq_ref2 = Field21::new("AMD123456789".to_string());
assert_eq!(seq_ref2.sequence_number(), Some(123456789));
let seq_ref3 = Field21::new("CAN000000042".to_string());
assert_eq!(seq_ref3.sequence_number(), Some(42));
let no_seq1 = Field21::new("CUSTOMREF".to_string());
assert_eq!(no_seq1.sequence_number(), None);
let no_seq2 = Field21::new("COV_NO_NUM".to_string());
assert_eq!(no_seq2.sequence_number(), None);
let all_num = Field21::new("123456789".to_string());
assert_eq!(all_num.sequence_number(), Some(123456789));
let too_long = Field21::new("AMD12345678901".to_string());
assert_eq!(too_long.sequence_number(), None);
Sourcepub fn is_cover_reference(&self) -> bool
pub fn is_cover_reference(&self) -> bool
Check if this is a cover message reference
Determines if the related reference indicates this is related to a cover message operation.
§Returns
true
if the reference appears to be for a cover message
§Example
let cover_ref = Field21::new("COV21234567890".to_string());
assert!(cover_ref.is_cover_reference());
let regular_ref = Field21::new("FT12345".to_string());
assert!(!regular_ref.is_cover_reference());
Sourcepub fn is_amendment_reference(&self) -> bool
pub fn is_amendment_reference(&self) -> bool
Check if this is an amendment reference
Determines if the related reference indicates this is related to an amendment operation.
§Returns
true
if the reference appears to be for an amendment
§Example
let amd_ref = Field21::new("AMD21234567890".to_string());
assert!(amd_ref.is_amendment_reference());
let regular_ref = Field21::new("FT12345".to_string());
assert!(!regular_ref.is_amendment_reference());
Sourcepub fn is_cancellation_reference(&self) -> bool
pub fn is_cancellation_reference(&self) -> bool
Check if this is a cancellation reference
Determines if the related reference indicates this is related to a cancellation operation.
§Returns
true
if the reference appears to be for a cancellation
§Example
let can_ref = Field21::new("CAN21234567890".to_string());
assert!(can_ref.is_cancellation_reference());
let regular_ref = Field21::new("FT12345".to_string());
assert!(!regular_ref.is_cancellation_reference());
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Sourcepub fn is_well_formed(&self) -> bool
pub fn is_well_formed(&self) -> bool
Validate reference format according to institutional standards
Performs additional validation beyond the standard SWIFT field validation, checking for common institutional reference format requirements.
§Returns
true
if the reference follows good practices, false
otherwise
§Example
let good_ref1 = Field21::new("COV21234567890".to_string());
assert!(good_ref1.is_well_formed());
let good_ref2 = Field21::new("AMD-123456".to_string());
assert!(good_ref2.is_well_formed());
let good_ref3 = Field21::new("REL_001.234".to_string());
assert!(good_ref3.is_well_formed());
let good_ref4 = Field21::new("CAN/12345".to_string());
assert!(good_ref4.is_well_formed());
let too_short = Field21::new("AB".to_string());
assert!(!too_short.is_well_formed());
let all_same = Field21::new("AAAAAAA".to_string());
assert!(!all_same.is_well_formed());
let invalid_chars = Field21::new("REF@123#".to_string());
assert!(!invalid_chars.is_well_formed());
let spaces = Field21::new("REF 123".to_string());
assert!(!spaces.is_well_formed());