Customer Address Data - Filter postal code by district - street-address

We are creating customers on SAP CRM and replicate these customers to SAP ECC.
User needs to filter postal codes by the district code they choose while creating customer.
This functionality has provided by SAP ECC.
But in CRM we couldnt find any relation between postal codes and district codes.
How can we filter postal codes by district codes in SAP CRM?

Take a look at get_v_postl_cod1 method of ZL_ICCMP_BP_BUPAADDRSTD_CN00 class, this is the getter method for post codes in account overview.
Inside you'll find something like this:
country_id = get_s_struct( attribute_path = 'STRUCT.COUNTRY'
component = 'COUNTRY'
iterator = iterator ).
...
...
...
SELECT * FROM adrpstcode INTO TABLE lt_adrpost_code
WHERE country = country_id.
You can fetch region value in the same way as country value and modify select query to include your region data.
These tables should provide with all required data: ADRPSTCODE, ADRCITY, ADRCITYT, ADRPCDCITY, ADRPOBOX, ADRCITYPRT, ADRSTREET, ADRSTREETT, and ADRSTRPCD.

Related

Retrieving different levels of placeIds

Is there any way to retrieve different levels of placeIds from a specific placeId? Like when you load the address components of a place, you get 'country' 'city' 'region' and so on... But you only get the names of the different levels of position. Is it possible to get the placeId of the country, city.... ?
When I am storing data in the database, I need to also store the country placeId, city placeId together with the original placeId. Do not want to store the name of the places in the database, when a lot of places have the same names.
As you noticed there are no place IDs in address components array. You cannot get this information executing only place details request. Developers have already created a feature request in Google issue tracker:
Add place_id in each address_components
You can star it to add your vote. In the meantime the workaround to get place IDs for country and locality consists in executing a reverse geocoding requests for coordinates of the original place ID with result type locality and country.
For example, I have a place ID ChIJEygrJmSYpBIRUXOjvF0QSLw. The details request for this place
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJEygrJmSYpBIRUXOjvF0QSLw&key=MY_API_KEY
gives coordinates 41.3886875,2.130554. Now I can execute additional reverse geocoding request to get place IDs of locality and country:
https://maps.googleapis.com/maps/api/geocode/json?latlng=41.3886875%2C2.130554&result_type=country%7Clocality&key=MY_API_KEY
The last one gives me
place ID ChIJ5TCOcRaYpBIRCmZHTz37sEQ (Barcelona)
place ID ChIJi7xhMnjjQgwR7KNoB5Qs7KY (Spain)
I hope this helps!

How to find a place id in Google Maps API if city has an identical name as region, province or municipality

Using the Google places API I am trying to fetch place_id's. I have issues when trying to fetch a place_id when multiple parts of the place location have the same name. For example: The city Utrecht (in the Netherlands) lies in the municipality of Utrecht, Which lies in the province of Utrecht. They all have the same name.
When I fetch Utrecht from the places service it returns the place_id for city (which is the default for maps incase there are multiple options)
I found a hack/solution to fetch the administrative areas: adding localised name of the thing i'm trying to fetch. For example I can use Gemeente(municipality) or Provincie(province)
Is there a way to request specifically the type of region I want to fetch from the API?
I see that the places API has all this information, but sofar my attempts to fetch the place_id for the administrative_area_level_2 or administrative_area_level_1 without modifying the address are futile.
My "fix" works for the Netherlands but I have 12 more European countries with similar issues hence my question.
The most common solution is using the reverse geocoding with a result type filter.
For example, your sample request for Utrecht returns the following coordinate 52.09073739999999,5.1214201
Now use reverse geocoding with result type.
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.09073739999999%2C5.1214201&result_type=administrative_area_level_1&key=YOUR_API_KEY
This returns place ID ChIJPzM8M01oxkcRsFwejVreAAM for admin area level 1
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.09073739999999%2C5.1214201&result_type=administrative_area_level_2&key=YOUR_API_KEY
This returns place ID ChIJA9Xkz5BoxkcRzAM9YkCZGTs for admin area level 2
Hope it helps!

Querying Geonames API to get only city country name

Too much useless json data is being fetched when I request a specific country cities by hitting this URL:
http://api.geonames.org/searchJSON?username=ksuhiyp&country=us&maxRows=1000
This returns too many json fields as you can see, question is hot to play with the query to get only city, country name ?
You can try with the additional parameter style=SHORT
http://api.geonames.org/searchJSON?username=ksuhiyp&country=us&maxRows=1000&style=SHORT
The docs says: style, String SHORT,MEDIUM,LONG,FULL (optional), verbosity of returned xml document, default = MEDIUM

BO XI 3.1 List of values prompt item description return item key

I'm trying to define a LOV with Universe Designer that when used in a #Prompt shows the user the item description, but gives back the corresponding item key as result of user selection.
e.g. From a dimension table of countries with two columns as COUNTRY_ISO and COUNTRY_NAME, I would like to show COUNTRY_NAME values to user with #prompt, but get back the corresponding COUNTRY_ISO as return value of #prompt.
This is possible using Index Awareness. I'll describe the solution using the sample "Island Resorts Marketing" universe, but the concept should map to your specific need.
For this example, we'll create a prompt on the "Country" object in the "Resort" class. The prompt will display the country names, but the condition will apply to the country_id field.
First, we need to identify the keys. On the Keys tab of the Resort\Country object, add a new Primary Key using Resort_Country.country_id as the source:
(in your case, you'll do this on the COUNTRY_NAME object, using COUNTRY_ISO as the primary key)
Next, we create the predefined condition that will include the prompt. Create a new Predefined Condition, named "Select country", with the following definition:
Resort_Country.country_id = #Prompt('Choose a country','A','Resort\Country',Mono,primary_key)
What we're doing is is applying the condition to the ID field (resort_country.country_id), but using the country name (the Country object) as the source. Note the "primary_key" parameter -- this tells BO to use the PK from the referenced object.
Now to test. Create a WebI report and select the "Select country" filter along with a field to display. I chose Service Line:
I run the report and am presented with a list of country names. I choose France, and I get a list of the Service Lines associated with France. The SQL generated by this query, reflecting my prompt selection, is:
SELECT
Service_Line.service_line
FROM
Service_Line,
Country Resort_Country,
Resort
WHERE
( Resort_Country.country_id=Resort.country_id )
AND ( Resort.resort_id=Service_Line.resort_id )
AND ( Resort_Country.country_id = 2 )
Note the very last line, which shows that the condition is applied using the ID, even though I selected the country name "France".
References:
- XI3.1 Designer Guide #Prompt info, starting on page 520
- Dave's blog on Index Awareness
- Dave's blog on Index Awareness with prompts

Assigining ID vs object - linq to sql

Say I have an entity Customer which has relationship with city, order etc. Now when I am adding a customer object, should I assign customer.cityid, or customer.city? From the form I get cityid from a dropdown, so to assign the city object, I will have to make a query using id selected.
If you need the City object populated, then get the City and set .City.
If you don't need the City object and are just saving and moving on, setting .CityId without getting the city object will save you the select query fetching it.
In either case, the next time the object loads, City will be available. (Both methods save the same City column in the database unless you have something strange/non-default setup).