cancel
Showing results for 
Search instead for 
Did you mean: 

Validation On PAN Card Number for Vendor Master in S4 Hana Public cloud

sarat1258
Explorer
532
Requirement :  Need Validation On PAN Card for Vendor Master .
Validation :  
  • PAN Card Number Length 10 Character
  • First Five Character from A to Z
  • Four Numeric 0 to 9
  • Last One Character from A to Z
  • Like Valid PAN Card : "ABPQR7662A"

Please us know which badi needs to select and write the above validations for the PAN field.

Sudhanshuj
Discoverer
0 Kudos
I am looking for a solution for the same requirement.
View Entire Topic
AndreasMuno
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for your request, @sarat1258 and @Sudhanshuj.

In S/4HANA Cloud Public Edition, CDS View I_SUPPLIER has standard fields

  • 'BusinessPartnerPanNumber' as Permanent Account Number, CHAR 40,   
  • 'BPPanReferenceNumber' as PAN Reference Number, CHAR 40,
  • 'BPPanValidFromDate' as PAN Valid From Date, DATS 8.
 
Here is an implementation suggestion based on some new and not yet released generative AI (yes, I know, with a real chance of hallucinations). Please assess carefully as you implement, there may be some errors in this code, and I have no way to validate it myself. In particular I have doubts that structure 'I_SupplierCompany' is correct. Please use your own due diligence as you implement and test well:

"To implement the BAdI `MDBPCV_VALIDATE_BP` for suppliers with the given requirements, we need to validate the PAN Card Number based on the specified criteria. The PAN Card Number should be 10 characters long, with the first five characters being alphabetic (A-Z), the next four characters being numeric (0-9), and the last character being alphabetic (A-Z).

Here is a step-by-step approach to implement this BAdI:

### Step 1: Analyze the BAdI Document
The BAdI `MDBPCV_VALIDATE_BP` is used to validate business partner data. We need to ensure that the PAN Card Number meets the specified format.

### Step 2: Generate the BAdI Implementation Code
We will use the CDS View `I_SupplierCompany` to retrieve the supplier data, including the PAN Card Number. The validation logic will be implemented in the BAdI method.

### BAdI Implementation Code
```abap
CLASS zcl_mdbpcv_validate_bp IMPLEMENTATION.
METHOD if_mdbpcv_validate_bp~validate_bp_data
RAISING cx_ble_runtime_error.

DATA: lt_supplier_data TYPE TABLE OF i_suppliercompany,
lv_pan_number TYPE c LENGTH 40,
lv_valid TYPE abap_bool.

" Retrieve supplier data from CDS View I_SupplierCompany
SELECT BusinessPartnerPanNumber
FROM I_SupplierCompany
INTO TABLE @lt_supplier_data
WHERE BusinessPartner = @iv_business_partner.

LOOP AT lt_supplier_data INTO DATA(ls_supplier).
lv_pan_number = ls_supplier-BusinessPartnerPanNumber.

" Validate PAN Card Number
lv_valid = abap_true.

" Check length
IF strlen( lv_pan_number ) <> 10.
lv_valid = abap_false.
ENDIF.

" Check first five characters (A-Z)
IF lv_valid = abap_true AND NOT lv_pan_number+0(5) CO 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
lv_valid = abap_false.
ENDIF.

" Check next four characters (0-9)
IF lv_valid = abap_true AND NOT lv_pan_number+5(4) CO '0123456789'.
lv_valid = abap_false.
ENDIF.

" Check last character (A-Z)
IF lv_valid = abap_true AND NOT lv_pan_number+9(1) CO 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
lv_valid = abap_false.
ENDIF.

" If PAN Card Number is invalid, raise an error
IF lv_valid = abap_false.
MESSAGE 'Invalid PAN Card Number' TYPE 'E'.
ENDIF.
ENDLOOP.

ENDMETHOD.
ENDCLASS.
```

### Explanation of the Generated Code
1. **Data Declaration**: We declare a table `lt_supplier_data` to hold the supplier data retrieved from the CDS View `I_SupplierCompany`. We also declare a variable `lv_pan_number` to hold the PAN Card Number and a boolean `lv_valid` to indicate the validity of the PAN Card Number.

2. **Data Retrieval**: We use a `SELECT` statement to retrieve the `BusinessPartnerPanNumber` from the CDS View `I_SupplierCompany` for the given business partner.

3. **Validation Logic**:
- We loop through the retrieved supplier data.
- We check the length of the PAN Card Number to ensure it is 10 characters long.
- We check the first five characters to ensure they are alphabetic (A-Z).
- We check the next four characters to ensure they are numeric (0-9).
- We check the last character to ensure it is alphabetic (A-Z).

4. **Error Handling**: If the PAN Card Number is invalid, we raise an error message.

This implementation ensures that the PAN Card Number for suppliers is validated according to the specified format."