The setting absolutely does shape the characters in "After Twenty Years" in this short story. Of course, setting can be divided into two parts: setting of time and setting of place. Both of these are important to the characters of "the policeman" (Jimmy Wells) and "the waiting man" ("Silky" Bob).
First, let's look at the setting of time, especially in regards to the interval between meetings. This is where the setting even goes back to the title. Twenty years are significant. During that time, "the policeman" (Jimmy Wells) has stayed in New York and obviously made a wonderful career in the NYC police department. This implies that "the policeman" (Jimmy Wells) has become "a good man" during that time, trying to rid the city streets of evildoers. For "the waiting man" ("Silky" Bob), the twenty year interval has done something completely different. "The waiting man" ("Silky" Bob) chose to leave New York City and move out west. During that twenty years, something has happened to"the waiting man" ("Silky" Bob) that isn't good: he is wanted by the law. "The policeman" (Jimmy Wells) notices and sends a plainclothes cop to do the arrest. The exchange is an interesting comment on the setting of time:
"You're not Jimmy Wells. Twenty years is a long time, but not long enough to change a man's nose from a roman to a pug."
"It sometimes changes a good man into a bad man," says the tall man. "You've been under arrest for ten minutes 'Silky' Bob."
The setting of place, of course, shapes the characters as well. The two important general places of interest are New York City and the West. How did these places shape the characters? Well, "the policeman" (Jimmy Wells) was certainly shaped by the city of New York. He has grown up, gotten a good job, and patrols his usual beat with dignity. He has grown so loyal to the law and to New York City that he is willing to arrest his friend, "the waiting man" ("Silky" Bob) knowing that he is now "a bad man." The only way "the policeman" (Jimmy Wells) takes the sting out of the arrest is by sending a plainclothes cop to do the job for him. The West has shaped the specific character of "the waiting man" ("Silky" Bob). Bob now has a "small white scar near his right eyebrow" and is wanted by the law in Chicago. Bob is no longer the "friend" he was to Jimmy Wells before the West got a hold of him.
In conclusion, we should also mention a more specific element of the setting of place that also shapes the characters: "About that long ago there used to be a restaurant where this store stands." It was in that restaurant that the two friends decided to meet at the same place twenty years later. Sure enough, that is just where the two characters stand at that time.
Another way of looking at how setting shapes the characters in "After Twenty Years" is to consider O. Henry's creative imagination. After all, the characters are not real people but mental creations, or illusions. In another story, "The Furnished Room," the narrator, O. Henry himself presumably, writes:
Hence the houses of this district, having had a thousand dwellers, should have a thousand tales to tell...
This suggests that O. Henry must have been in the habit of inventing stories to suit the look and mood of particular settings. He may have seen a man standing in the darkened doorway of a hardware store and wondered what such a well-dressed, middle-aged man would be doing there at that hour. Probably waiting for someone. But who? An old friend. But why a hardware store and not a restaurant? Maybe the restaurant had been torn down a long time ago and replaced by a row of shops. The man in the doorway seems to be a little furtive, as if he wants to keep out of sight. Maybe he is wanted by the law. What if a cop came along? What if that cop just happened to be the man he was waiting for, but he didn't know he had become a cop during the years in which they had lost contact. What would the cop do if he recognized the man in the doorway as his old friend? Maybe he would get another cop to arrest him. This could lead to the creation of 'Silky' Bob, the wanted man; to Jimmy Wells, the old friend who had become a cop; and to the plainclothes detective who makes the arrest that Jimmy is unwilling to make himself.
O. Henry was a prolific writer. He had to be, because he wrote for newspapers and was always under tight deadlines. He had to keep coming up with stories, rain or shine, drunk or sober. He must have gotten many of his story ideas, and hence many of his characters, from settings such as Greenwich Village, where he created a couple of young female aspiring artists and a temperamental German painter; or Washington Square, where he saw a bum sleeping on a bench under a mound of Sunday newspapers on a cold autumn morning. O. Henry had a exceptionally fertile creative imagination. As he says in "The Furnished Room," the houses in a certain district could have a thousand tales to tell. He believed that every person in the city of New York had a story to tell, which meant that he could invent four million stories to fit the city's population at the time. Only a writer like O. Henry could sense the possibility of four million stories--but if he could make a story out of a man standing in the darkened doorway of a hardware store, then four million stories would be a conservative estimate.