Monday, October 13, 2008

How to add extra address fields to Query

If you to want add some of the extra customer address fields such as, Street 2 and Street 3, to a query you will find that they are not part of the standard table KNA1 but are located in the address table that is linked to via the address number field KNA1-ADRNR.
To fetch the values you can make use of the standard function module ADDR_GET_COMPLETE and follow the process set out below to enhance you infoset.
First add the type pool definition used by the function module to the DATA code section plus the data definitions used for the retrieval part.

* Declare transfer structure

* Include type szadr.

type-pools: szadr.

* Data definitions

data: addr1_complete type szadr_addr1_complete.

data: wa_addr1_lin type szadr_addr1_line.



Next define an additional field for the data element.












Then define the source code to retrieve the values for the data element.

* Specify parameters
*break-point.
clear: cust_addr_street2, cust_addr_street3, cust_addr_street3.
*addrnumber = kna1-adrnr.
call function 'ADDR_GET_COMPLETE'
exporting addrnumber = kna1-adrnr
importing addr1_complete = addr1_complete
exceptions parameter_error = 1
address_not_exist = 2
internal_error = 3.
* You can access and process the data read by LOOPing over the tables
* in ADDR1_COMPLETE.
* The subtable ADDR1_TAB has the type structure SZADR_ADDR1_LINE,
* so you must access the fields with ADDR1_COMPLETE-DATA-.
loop at addr1_complete-addr1_tab into wa_addr1_lin.
move wa_addr1_lin-data-str_suppl1 to cust_addr_street2.
move wa_addr1_lin-data-str_suppl2 to cust_addr_street3.
move wa_addr1_lin-data-str_suppl3 to cust_addr_street4.
endloop.

Finally Save and Generate the infoset after assigning the new data element to a report group. The field will then be available for use in the Query definition.

No comments: