Read Address Data using FM ADDR_GET instead of Querying ADRC Table
This ABAP tutorial includes ABAP codes which read address data from ADRC table using ADDR_GET ABAP function module.
In SAP Smartform documents ABAP developers frequently display document partner address data like Bill-to party address or Ship-to party address on their Smartform outputs.
And generally it is not enough to use the build-in Address control to display required address structure on the Smart Form output.
What can ABAP developers do is to display data from interface address structures like IS_BIL_INVOICE-HD_ADR for Invoice or ZTVBDPA for Sales Order Confirmation Smartform outputs.
Additionally SAP address table ADRC can be queried by using a OSQL SELECT statement with partner address key fields.
But the most convenient method for reading address from SAP table ADRC (address table in SAP) is using a function module.
One of the function modules to read address that ABAP developers can use is SAP function module ADDR_GET
Here is two methods of reading address information from ABAP address table ADRC.
The best practise is using function module ADDR_GET.
lv_post_code1 LIKE adrc-post_code1,
lv_city1 LIKE adrc-city1,
lv_region LIKE adrc-region,
lv_po_box_loc TYPE ad_pobxloc,
lv_post_code2 TYPE ad_pstcd2.
DATA ls_adrc TYPE adrc.
SELECT SINGLE * INTO ls_adrc FROM adrc
WHERE addrnumber = gv_address_no_bp.
IF sy-subrc = 0.
lv_post_code1 = ls_adrc-post_code1.
lv_city1 = ls_adrc-city1.
lv_region = ls_adrc-region.
lv_po_box_loc = ls_adrc-po_box_loc.
lv_post_code2 = ls_adrc-post_code2.
ls_address_selection LIKE addr1_sel,
ls_address_value LIKE addr1_val.
ls_address_selection-addrnumber = gv_address_no_bp.
CALL FUNCTION 'ADDR_GET'
address_selection = ls_address_selection
address_value = ls_address_value
parameter_error = 1
address_not_exist = 2
version_not_exist = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc = 0.
lv_post_code1 = ls_address_value-post_code1.
lv_city1 = ls_address_value-city1.
lv_region = ls_address_value-region.
lv_po_box_loc = ls_address_value-po_box_loc.
lv_post_code2 = ls_address_value-post_code2.