SAP SAP_QUERY_AD_HOC Function Module for
SAP_QUERY_AD_HOC is a standard sap query ad hoc SAP function module available within SAP R/3 or S/4 Hana systems, depending on your version and release level. It is used to perform a specific ABAP function and below is the pattern details, showing its interface including any import and export parameters, exceptions etc. there is also a full "cut and paste" ABAP pattern code example, along with implementation ABAP coding, documentation and contribution comments specific to this or related objects.
See here to view full function module documentation and code listing for sap query ad hoc FM, simply by entering the name SAP_QUERY_AD_HOC into the relevant SAP transaction such as SE37 or SE38.
Function Group: AQ_SAP_QUERY
Program Name: SAPLAQ_SAP_QUERY
Main Program:
Appliation area:
Release date: N/A
Mode(Normal, Remote etc): Normal Function Module
Update:

Function SAP_QUERY_AD_HOC pattern details
In-order to call this FM within your sap programs, simply using the below ABAP pattern details to trigger the function call...or see the full ABAP code listing at the end of this article. You can simply cut and paste this code into your ABAP progrom as it is, including variable declarations.CALL FUNCTION 'SAP_QUERY_AD_HOC'".
EXPORTING
* I_WORK' ' = ' ' "Work Area
* I_USERGROUP = ' ' "
* I_INFOSET = ' ' "
* I_QUERY = ' ' "Name of a Query
* I_CHECK_ONLY = ' ' "
* I_USER_CHECK = ' ' "
EXCEPTIONS
ILLEGAL_QUERY_ENVIRONMENT = 1 USER_NOT_ASSIGNED = 2
IMPORTING Parameters details for SAP_QUERY_AD_HOC
I_WORKSPACE - Work Area
Data type: AQADEF-WSIDDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
I_USERGROUP -
Data type: AQADEF-BGNAMEDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
I_INFOSET -
Data type: AQADEF-SGNAMEDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
I_QUERY - Name of a Query
Data type: AQADEF-QUNAMEDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
I_CHECK_ONLY -
Data type: AQADEF-FLAGDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
I_USER_CHECK -
Data type: AQADEF-FLAGDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
EXCEPTIONS details
ILLEGAL_QUERY_ENVIRONMENT -
Data type:Optional: No
Call by Reference: Yes
USER_NOT_ASSIGNED -
Data type:Optional: No
Call by Reference: Yes
Copy and paste ABAP code example for SAP_QUERY_AD_HOC Function Module
The ABAP code below is a full code listing to execute function module POPUP_TO_CONFIRM including all data declarations. The code uses the original data declarations rather than the latest in-line data DECLARATION SYNTAX but I have included an ABAP code snippet at the end to show how declarations would look using the newer method of declaring data variables on the fly. This will allow you to compare and fully understand the new inline method. Please note some of the newer syntax such as the @DATA is not available until a later 4.70 service pack (SP8), which i why i have stuck to the origianl for this example.| DATA: | ||||
| lv_i_workspace | TYPE AQADEF-WSID, " SPACE | |||
| lv_illegal_query_environment | TYPE AQADEF, " | |||
| lv_i_usergroup | TYPE AQADEF-BGNAME, " SPACE | |||
| lv_user_not_assigned | TYPE AQADEF, " | |||
| lv_i_infoset | TYPE AQADEF-SGNAME, " SPACE | |||
| lv_i_query | TYPE AQADEF-QUNAME, " SPACE | |||
| lv_i_check_only | TYPE AQADEF-FLAG, " SPACE | |||
| lv_i_user_check | TYPE AQADEF-FLAG. " SPACE |
|   CALL FUNCTION 'SAP_QUERY_AD_HOC' " |
| EXPORTING | ||
| I_WORKSPACE | = lv_i_workspace | |
| I_USERGROUP | = lv_i_usergroup | |
| I_INFOSET | = lv_i_infoset | |
| I_QUERY | = lv_i_query | |
| I_CHECK_ONLY | = lv_i_check_only | |
| I_USER_CHECK | = lv_i_user_check | |
| EXCEPTIONS | ||
| ILLEGAL_QUERY_ENVIRONMENT = 1 | ||
| USER_NOT_ASSIGNED = 2 | ||
| . " SAP_QUERY_AD_HOC | ||
ABAP code using 7.40 inline data declarations to call FM SAP_QUERY_AD_HOC
The below ABAP code uses the newer in-line data declarations. This allows you to see the coding differences/benefits of the later inline syntax. Please note some of the newer syntax below, such as the @DATA is not available until 4.70 EHP 8.| "SELECT single WSID FROM AQADEF INTO @DATA(ld_i_workspace). | ||||
| DATA(ld_i_workspace) | = ' '. | |||
| "SELECT single BGNAME FROM AQADEF INTO @DATA(ld_i_usergroup). | ||||
| DATA(ld_i_usergroup) | = ' '. | |||
| "SELECT single SGNAME FROM AQADEF INTO @DATA(ld_i_infoset). | ||||
| DATA(ld_i_infoset) | = ' '. | |||
| "SELECT single QUNAME FROM AQADEF INTO @DATA(ld_i_query). | ||||
| DATA(ld_i_query) | = ' '. | |||
| "SELECT single FLAG FROM AQADEF INTO @DATA(ld_i_check_only). | ||||
| DATA(ld_i_check_only) | = ' '. | |||
| "SELECT single FLAG FROM AQADEF INTO @DATA(ld_i_user_check). | ||||
| DATA(ld_i_user_check) | = ' '. | |||
Search for further information about these or an SAP related objects