In case you wish to extract the Bank Data for a particular customer, you can use the following BAPI. This BAPI extracts the Customer's Address, General Data, Company Code Data and the Bank Details.
SAP ABAP to get customer Bank Details
BAPI_CUSTOMER_GETDETAIL2
For reference please find below the transaction codes to Create/Change/Display a customer
VD01 Create Customer Sales and Distribution VD02 Change Customer Sales and Distribution VD03 Display Customer Sales and Distribution
Also Find below the tables related to the BAPI BAPI_CUSTOMER_GETDETAIL2
KNBK-Customer Master (Bank Details) ADRC- Addresses (central address admin.) KNA1-General Data in Customer Master KNB1-Customer Master (Company Code)
The following code extracts the above mentioned details from the SAP R/3 System
REPORT ZEX_CUSTOMERBANK .
Parameters: p_kunnr like BAPICUSTOMER_ID-CUSTOMER, p_bukrs like BAPICUSTOMER_ID-COMP_CODE.
Data: ty_knbk type knbk, ty_custadd type BAPICUSTOMER_04, ty_custgendet type BAPICUSTOMER_KNA1, ty_custcompdet type BAPICUSTOMER_05, d_ret like BAPIRET1.
Data: wa_custadd like ty_custadd, wa_custgendet like ty_custgendet, wa_custcompdet like ty_custcompdet.
In case you wish to read the customer data you can use the following BAPI, it retrieves the Customer Master (Company Code) Data and the General Data in Customer Master.
SAP ABAP BAPI to Read Customer Master Data
CUSTOMER_READ
You need to pass the Customer Number and the Company Code. See the example given below.
REPORT ZEX_CUSTOMERREAD .
Parameters: p_bukrs like KNB1-BUKRS, p_kunnr like KNA1-KUNNR.
Data: ty_kna1 type kna1, ty_knb1 type knb1.
Data: int_kna1 like ty_kna1, int_knb1 like ty_knb1.
CALL FUNCTION 'CUSTOMER_READ' EXPORTING I_BUKRS = p_bukrs I_KUNNR = p_kunnr IMPORTING E_KNA1 = int_Kna1 E_KNB1 = int_knb1 EXCEPTIONS NOT_FOUND = 1 OTHERS = 2 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
Always use Pretty Printer and Extended Program Check before releasing the code.
Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.