on 2024 Feb 26 11:24 AM
Please us know which badi needs to select and write the above validations for the PAN field.
Thank you for your request, @sarat1258 and @Sudhanshuj.
In S/4HANA Cloud Public Edition, CDS View I_SUPPLIER has standard fields
"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."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
9 | |
8 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.