I doubt you'll like this, but the general answer is no; in part because a program is not always loaded from a library; for example, a program loaded and executed by the linking loader function of the Binder can be loaded from the object output of the Assembler. Obviously that's not a library!
However, you can deduce some things, and possibly recover the library.
Step 1. Use the CSVQUERY macro to recover the module name and other module attributes.
Step 2. Use the OUTPID data returned by CSVQUERY to determine the loading service. If it is PGMF (program fetch) you can continue.
Step 3. Use the BLDL macro specifying the module name returned by CSVQUERY. BLDL will tell you if the module came from JOBLIB/STEPLIB (at this point there is no practical difference) or the link list. With difficulty you can then determine the library. Notice that things can still be somewhat indeterminate. For example, consider this JCL.
//A EXEC PGM=IEWL
//SYSLMOD DD DSN=&&TEMP(GO),...
//B EXEC PGM=*.A.SYSLMOD
GO is loaded by program fetch, but it is not from the link list or JOBLIB/STEPLIB.
Now I have never done this, so I have no idea if it will work and I'm not about to waste several hours writing and testing code for this. I have done the step 3 part, so I know that is possible. Good luck.
So when MYPROG is executed, JES will load the program image from MYNAME.LINKLIB(MYPROG) and runs it, right? My question is that if it is possible for MYPROG to know the dataset name 'MYNAME.LINKLIB'?
JES does not "run" a job. It tells the operating system to "run" a job. JES has nothing to do with the mechanics of how the job is run.