In IFCIDs 59 and 58 for SQL FETCH statements, the package name fields (QW0059PN and QW0058PN) refer to the package that contains the SQL OPEN statement for the cursor used by the FETCH statement. This is not necessarily the package that contains the FETCH statement.
For example, a stored procedure might open a cursor that is subsequently - in the thread that called the stored procedure - used by a FETCH statement. The stored procedure and its calling thread might use different packages. In this case, the 59 and 58 IFCID records for the FETCH statement refer to the package that is used by the stored procedure.
I understand that there is a close relationship between a FETCH statement and its cursor, but this IFCID behavior means that, in this particular situation, you cannot use the following SQL SELECT statement to get the SQL statement text, which (so far, in my experience) works for all other statements:
SELECT STATEMENT FROM SYSIBM.SYSPACKSTMT WHERE NAME='package' AND STMTNO=statement-number
Is this a bug or deliberate (working as designed)?