Skip to content

/AWS1/IF_CWL=>GETQUERYRESULTS()

About GetQueryResults

Returns the results from the specified query.

Only the fields requested in the query are returned, along with a @ptr field, which is the identifier for the log record. You can use the value of @ptr in a GetLogRecord operation to get the full log record.

GetQueryResults does not start running a query. To run a query, use StartQuery. For more information about how long results of previous queries are available, see CloudWatch Logs quotas.

If the value of the Status field in the output is Running, this operation returns only partial results. If you see a value of Scheduled or Running for the status, you can retry the operation later to see the final results.

This operation is used both for retrieving results from interactive queries and from automated scheduled query executions. Scheduled queries use GetQueryResults internally to retrieve query results for processing and delivery to configured destinations.

You can retrieve up to 100,000 log event results from a query, if available, by using pagination. Use the nextToken returned in the response to request additional pages of results, with each page returning up to 10,000 log events.

If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account to start queries in linked source accounts. For more information, see CloudWatch cross-account observability.

Method Signature

METHODS /AWS1/IF_CWL~GETQUERYRESULTS
  IMPORTING
    !IV_QUERYID TYPE /AWS1/CWLQUERYID OPTIONAL
    !IV_NEXTTOKEN TYPE /AWS1/CWLGETQUERYRSLTSNEXTTOK OPTIONAL
    !IV_MAXITEMS TYPE /AWS1/CWLGETQUERYRSLTSMAXITEMS OPTIONAL
  PREFERRED PARAMETER iv_queryid
  RETURNING
    VALUE(OO_OUTPUT) TYPE REF TO /aws1/cl_cwlgetqueryresultsrsp
  RAISING
    /AWS1/CX_CWLINVALIDPARAMETEREX
    /AWS1/CX_CWLRESOURCENOTFOUNDEX
    /AWS1/CX_CWLSERVICEUNAVAILEX
    /AWS1/CX_CWLCLIENTEXC
    /AWS1/CX_CWLSERVEREXC
    /AWS1/CX_RT_TECHNICAL_GENERIC
    /AWS1/CX_RT_SERVICE_GENERIC.

IMPORTING

Required arguments:

iv_queryid TYPE /AWS1/CWLQUERYID /AWS1/CWLQUERYID

The ID number of the query.

Optional arguments:

iv_nexttoken TYPE /AWS1/CWLGETQUERYRSLTSNEXTTOK /AWS1/CWLGETQUERYRSLTSNEXTTOK

The token for the next set of items to return. The token expires after 1 hour.

iv_maxitems TYPE /AWS1/CWLGETQUERYRSLTSMAXITEMS /AWS1/CWLGETQUERYRSLTSMAXITEMS

The maximum number of log events to return in the response. The maximum is 10,000 log events per request. You can retrieve up to 100,000 log event results from a query by paginating with the nextToken.

RETURNING

oo_output TYPE REF TO /aws1/cl_cwlgetqueryresultsrsp /AWS1/CL_CWLGETQUERYRESULTSRSP

Examples

Syntax Example

This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.

DATA(lo_result) = lo_client->getqueryresults(
  iv_maxitems = 123
  iv_nexttoken = |string|
  iv_queryid = |string|
).

This is an example of reading all possible response values

lo_result = lo_result.
IF lo_result IS NOT INITIAL.
  lv_querylanguage = lo_result->get_querylanguage( ).
  LOOP AT lo_result->get_results( ) into lt_row.
    LOOP AT lt_row into lo_row_1.
      lo_row_2 = lo_row_1.
      IF lo_row_2 IS NOT INITIAL.
        lv_field = lo_row_2->get_field( ).
        lv_value = lo_row_2->get_value( ).
      ENDIF.
    ENDLOOP.
  ENDLOOP.
  lo_querystatistics = lo_result->get_statistics( ).
  IF lo_querystatistics IS NOT INITIAL.
    lv_statsvalue = lo_querystatistics->get_recordsmatched( ).
    lv_statsvalue = lo_querystatistics->get_recordsscanned( ).
    lv_statsvalue = lo_querystatistics->get_estimatedrecordsskipped( ).
    lv_statsvalue = lo_querystatistics->get_bytesscanned( ).
    lv_statsvalue = lo_querystatistics->get_estimatedbytesskipped( ).
    lv_statsvalue = lo_querystatistics->get_loggroupsscanned( ).
  ENDIF.
  lv_querystatus = lo_result->get_status( ).
  lv_encryptionkey = lo_result->get_encryptionkey( ).
  lv_getqueryresultsnexttoke = lo_result->get_nexttoken( ).
ENDIF.