This process is very simple in 1.13+, you only need to use
/execute store together with
/data get to store a player's "
Pos" array into three scores (instructions see here). But 1.12 has neither of these commands, so you need to do something called a "binary search" through the entire world.
How this works: You first select half of the world, for example from X=0 to X=30000000 and check whether the player is in it (using the
dz selector arguments). If the player is in the negative half, you continue there, otherwise in the positive half. There you select half of the remaining world again, in this case for example from X=0 to X=15000000. After that you can half the search area again and again, until after just 27 steps you have narrowed down this 60 million block range into less than one block range. And you can continue, if you want the position to be even more precise. Then you do the same for Y and Z, after 62 steps you have all three coordinates precise to one block and can put it into a scoreboard.
But it's still quite a lot of effort to write down all of these commands, so luckily someone did it for you and made a datapack: https://www.reddit.com/r/Minecraft/comments/6id4k0/112_coordinate_finder_function/ (datapack archive)