/AWS1/IF_DYN=>GETITEM()¶
About GetItem¶
The GetItem operation returns a set of attributes for the item with the
given primary key. If there is no matching item, GetItem does not return
any data and there will be no Item element in the response.
GetItem provides an eventually consistent read by default. If your
application requires a strongly consistent read, set ConsistentRead to
true. Although a strongly consistent read might take more time than an
eventually consistent read, it always returns the last updated value.
Method Signature¶
METHODS /AWS1/IF_DYN~GETITEM
IMPORTING
!IV_TABLENAME TYPE /AWS1/DYNTABLEARN OPTIONAL
!IT_KEY TYPE /AWS1/CL_DYNATTRIBUTEVALUE=>TT_KEY OPTIONAL
!IT_ATTRIBUTESTOGET TYPE /AWS1/CL_DYNATTRNAMELIST_W=>TT_ATTRIBUTENAMELIST OPTIONAL
!IV_CONSISTENTREAD TYPE /AWS1/DYNCONSISTENTREAD OPTIONAL
!IV_RETURNCONSUMEDCAPACITY TYPE /AWS1/DYNRETURNCONSUMEDCAP OPTIONAL
!IV_PROJECTIONEXPRESSION TYPE /AWS1/DYNPROJECTIONEXPRESSION OPTIONAL
!IT_EXPRESSIONATTRIBUTENAMES TYPE /AWS1/CL_DYNXPRSNATTRNAMEMAP_W=>TT_EXPRESSIONATTRIBUTENAMEMAP OPTIONAL
RETURNING
VALUE(OO_OUTPUT) TYPE REF TO /aws1/cl_dyngetitemoutput
RAISING
/AWS1/CX_DYNINTERNALSERVERERR
/AWS1/CX_DYNINVALIDENDPOINTEX
/AWS1/CX_DYNPROVTHRUPUTEXCDEX
/AWS1/CX_DYNREQUESTLIMITEXCD
/AWS1/CX_DYNRESOURCENOTFOUNDEX
/AWS1/CX_DYNTHROTTLINGEX
/AWS1/CX_DYNCLIENTEXC
/AWS1/CX_DYNSERVEREXC
/AWS1/CX_RT_TECHNICAL_GENERIC
/AWS1/CX_RT_SERVICE_GENERIC.
IMPORTING¶
Required arguments:¶
iv_tablename TYPE /AWS1/DYNTABLEARN /AWS1/DYNTABLEARN¶
The name of the table containing the requested item. You can also provide the Amazon Resource Name (ARN) of the table in this parameter.
it_key TYPE /AWS1/CL_DYNATTRIBUTEVALUE=>TT_KEY TT_KEY¶
A map of attribute names to
AttributeValueobjects, representing the primary key of the item to retrieve.For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
Optional arguments:¶
it_attributestoget TYPE /AWS1/CL_DYNATTRNAMELIST_W=>TT_ATTRIBUTENAMELIST TT_ATTRIBUTENAMELIST¶
This is a legacy parameter. Use
ProjectionExpressioninstead. For more information, see AttributesToGet in the Amazon DynamoDB Developer Guide.
iv_consistentread TYPE /AWS1/DYNCONSISTENTREAD /AWS1/DYNCONSISTENTREAD¶
Determines the read consistency model: If set to
true, then the operation uses strongly consistent reads; otherwise, the operation uses eventually consistent reads.
iv_returnconsumedcapacity TYPE /AWS1/DYNRETURNCONSUMEDCAP /AWS1/DYNRETURNCONSUMEDCAP¶
Determines the level of detail about either provisioned or on-demand throughput consumption that is returned in the response:
INDEXES- The response includes the aggregateConsumedCapacityfor the operation, together withConsumedCapacityfor each table and secondary index that was accessed.Note that some operations, such as
GetItemandBatchGetItem, do not access any indexes at all. In these cases, specifyingINDEXESwill only returnConsumedCapacityinformation for table(s).
TOTAL- The response includes only the aggregateConsumedCapacityfor the operation.
NONE- NoConsumedCapacitydetails are included in the response.
iv_projectionexpression TYPE /AWS1/DYNPROJECTIONEXPRESSION /AWS1/DYNPROJECTIONEXPRESSION¶
A string that identifies one or more attributes to retrieve from the table. These attributes can include scalars, sets, or elements of a JSON document. The attributes in the expression must be separated by commas.
If no attribute names are specified, then all attributes are returned. If any of the requested attributes are not found, they do not appear in the result.
For more information, see Specifying Item Attributes in the Amazon DynamoDB Developer Guide.
it_expressionattributenames TYPE /AWS1/CL_DYNXPRSNATTRNAMEMAP_W=>TT_EXPRESSIONATTRIBUTENAMEMAP TT_EXPRESSIONATTRIBUTENAMEMAP¶
One or more substitution tokens for attribute names in an expression. The following are some use cases for using
ExpressionAttributeNames:
To access an attribute whose name conflicts with a DynamoDB reserved word.
To create a placeholder for repeating occurrences of an attribute name in an expression.
To prevent special characters in an attribute name from being misinterpreted in an expression.
Use the # character in an expression to dereference an attribute name. For example, consider the following attribute name:
PercentileThe name of this attribute conflicts with a reserved word, so it cannot be used directly in an expression. (For the complete list of reserved words, see Reserved Words in the Amazon DynamoDB Developer Guide). To work around this, you could specify the following for
ExpressionAttributeNames:
{"#P":"Percentile"}You could then use this substitution in an expression, as in this example:
#P = :valTokens that begin with the : character are expression attribute values, which are placeholders for the actual value at runtime.
For more information on expression attribute names, see Specifying Item Attributes in the Amazon DynamoDB Developer Guide.
RETURNING¶
oo_output TYPE REF TO /aws1/cl_dyngetitemoutput /AWS1/CL_DYNGETITEMOUTPUT¶
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->getitem(
it_attributestoget = VALUE /aws1/cl_dynattrnamelist_w=>tt_attributenamelist(
( new /aws1/cl_dynattrnamelist_w( |string| ) )
)
it_expressionattributenames = VALUE /aws1/cl_dynxprsnattrnamemap_w=>tt_expressionattributenamemap(
(
VALUE /aws1/cl_dynxprsnattrnamemap_w=>ts_xprsnattrnamemap_maprow(
value = new /aws1/cl_dynxprsnattrnamemap_w( |string| )
key = |string|
)
)
)
it_key = VALUE /aws1/cl_dynattributevalue=>tt_key(
(
VALUE /aws1/cl_dynattributevalue=>ts_key_maprow(
value = new /aws1/cl_dynattributevalue(
it_bs = VALUE /aws1/cl_dynbinarysetattrval_w=>tt_binarysetattributevalue(
( new /aws1/cl_dynbinarysetattrval_w( '5347567362473873563239796247513D' ) )
)
it_l = VALUE /aws1/cl_dynattributevalue=>tt_listattributevalue(
(
new /aws1/cl_dynattributevalue(
it_bs = VALUE /aws1/cl_dynbinarysetattrval_w=>tt_binarysetattributevalue(
( new /aws1/cl_dynbinarysetattrval_w( '5347567362473873563239796247513D' ) )
)
it_m = VALUE /aws1/cl_dynattributevalue=>tt_mapattributevalue(
(
VALUE /aws1/cl_dynattributevalue=>ts_mapattributevalue_maprow(
key = |string|
value = new /aws1/cl_dynattributevalue(
it_bs = VALUE /aws1/cl_dynbinarysetattrval_w=>tt_binarysetattributevalue(
( new /aws1/cl_dynbinarysetattrval_w( '5347567362473873563239796247513D' ) )
)
it_ns = VALUE /aws1/cl_dynnumsetattrvalue_w=>tt_numbersetattributevalue(
( new /aws1/cl_dynnumsetattrvalue_w( |string| ) )
)
it_ss = VALUE /aws1/cl_dynstrsetattrvalue_w=>tt_stringsetattributevalue(
( new /aws1/cl_dynstrsetattrvalue_w( |string| ) )
)
iv_b = '5347567362473873563239796247513D'
iv_bool = ABAP_TRUE
iv_n = |string|
iv_null = ABAP_TRUE
iv_s = |string|
)
)
)
)
it_ns = VALUE /aws1/cl_dynnumsetattrvalue_w=>tt_numbersetattributevalue(
( new /aws1/cl_dynnumsetattrvalue_w( |string| ) )
)
it_ss = VALUE /aws1/cl_dynstrsetattrvalue_w=>tt_stringsetattributevalue(
( new /aws1/cl_dynstrsetattrvalue_w( |string| ) )
)
iv_b = '5347567362473873563239796247513D'
iv_bool = ABAP_TRUE
iv_n = |string|
iv_null = ABAP_TRUE
iv_s = |string|
)
)
)
it_m = VALUE /aws1/cl_dynattributevalue=>tt_mapattributevalue(
(
VALUE /aws1/cl_dynattributevalue=>ts_mapattributevalue_maprow(
key = |string|
value = new /aws1/cl_dynattributevalue(
it_bs = VALUE /aws1/cl_dynbinarysetattrval_w=>tt_binarysetattributevalue(
( new /aws1/cl_dynbinarysetattrval_w( '5347567362473873563239796247513D' ) )
)
it_l = VALUE /aws1/cl_dynattributevalue=>tt_listattributevalue(
(
new /aws1/cl_dynattributevalue(
it_bs = VALUE /aws1/cl_dynbinarysetattrval_w=>tt_binarysetattributevalue(
( new /aws1/cl_dynbinarysetattrval_w( '5347567362473873563239796247513D' ) )
)
it_ns = VALUE /aws1/cl_dynnumsetattrvalue_w=>tt_numbersetattributevalue(
( new /aws1/cl_dynnumsetattrvalue_w( |string| ) )
)
it_ss = VALUE /aws1/cl_dynstrsetattrvalue_w=>tt_stringsetattributevalue(
( new /aws1/cl_dynstrsetattrvalue_w( |string| ) )
)
iv_b = '5347567362473873563239796247513D'
iv_bool = ABAP_TRUE
iv_n = |string|
iv_null = ABAP_TRUE
iv_s = |string|
)
)
)
it_ns = VALUE /aws1/cl_dynnumsetattrvalue_w=>tt_numbersetattributevalue(
( new /aws1/cl_dynnumsetattrvalue_w( |string| ) )
)
it_ss = VALUE /aws1/cl_dynstrsetattrvalue_w=>tt_stringsetattributevalue(
( new /aws1/cl_dynstrsetattrvalue_w( |string| ) )
)
iv_b = '5347567362473873563239796247513D'
iv_bool = ABAP_TRUE
iv_n = |string|
iv_null = ABAP_TRUE
iv_s = |string|
)
)
)
)
it_ns = VALUE /aws1/cl_dynnumsetattrvalue_w=>tt_numbersetattributevalue(
( new /aws1/cl_dynnumsetattrvalue_w( |string| ) )
)
it_ss = VALUE /aws1/cl_dynstrsetattrvalue_w=>tt_stringsetattributevalue(
( new /aws1/cl_dynstrsetattrvalue_w( |string| ) )
)
iv_b = '5347567362473873563239796247513D'
iv_bool = ABAP_TRUE
iv_n = |string|
iv_null = ABAP_TRUE
iv_s = |string|
)
key = |string|
)
)
)
iv_consistentread = ABAP_TRUE
iv_projectionexpression = |string|
iv_returnconsumedcapacity = |string|
iv_tablename = |string|
).
This is an example of reading all possible response values
lo_result = lo_result.
IF lo_result IS NOT INITIAL.
LOOP AT lo_result->get_item( ) into ls_row.
lv_key = ls_row-key.
lo_value = ls_row-value.
IF lo_value IS NOT INITIAL.
lv_stringattributevalue = lo_value->get_s( ).
lv_numberattributevalue = lo_value->get_n( ).
lv_binaryattributevalue = lo_value->get_b( ).
LOOP AT lo_value->get_ss( ) into lo_row_1.
lo_row_2 = lo_row_1.
IF lo_row_2 IS NOT INITIAL.
lv_stringattributevalue = lo_row_2->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value->get_ns( ) into lo_row_3.
lo_row_4 = lo_row_3.
IF lo_row_4 IS NOT INITIAL.
lv_numberattributevalue = lo_row_4->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value->get_bs( ) into lo_row_5.
lo_row_6 = lo_row_5.
IF lo_row_6 IS NOT INITIAL.
lv_binaryattributevalue = lo_row_6->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value->get_m( ) into ls_row_7.
lv_key = ls_row_7-key.
lo_value_1 = ls_row_7-value.
IF lo_value_1 IS NOT INITIAL.
lv_stringattributevalue = lo_value_1->get_s( ).
lv_numberattributevalue = lo_value_1->get_n( ).
lv_binaryattributevalue = lo_value_1->get_b( ).
LOOP AT lo_value_1->get_ss( ) into lo_row_1.
lo_row_2 = lo_row_1.
IF lo_row_2 IS NOT INITIAL.
lv_stringattributevalue = lo_row_2->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value_1->get_ns( ) into lo_row_3.
lo_row_4 = lo_row_3.
IF lo_row_4 IS NOT INITIAL.
lv_numberattributevalue = lo_row_4->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value_1->get_bs( ) into lo_row_5.
lo_row_6 = lo_row_5.
IF lo_row_6 IS NOT INITIAL.
lv_binaryattributevalue = lo_row_6->get_value( ).
ENDIF.
ENDLOOP.
" Skipping ls_row_7-value to avoid recursion
LOOP AT lo_value_1->get_l( ) into lo_row_8.
lo_row_9 = lo_row_8.
IF lo_row_9 IS NOT INITIAL.
lv_stringattributevalue = lo_row_9->get_s( ).
lv_numberattributevalue = lo_row_9->get_n( ).
lv_binaryattributevalue = lo_row_9->get_b( ).
LOOP AT lo_row_9->get_ss( ) into lo_row_1.
lo_row_2 = lo_row_1.
IF lo_row_2 IS NOT INITIAL.
lv_stringattributevalue = lo_row_2->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_row_9->get_ns( ) into lo_row_3.
lo_row_4 = lo_row_3.
IF lo_row_4 IS NOT INITIAL.
lv_numberattributevalue = lo_row_4->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_row_9->get_bs( ) into lo_row_5.
lo_row_6 = lo_row_5.
IF lo_row_6 IS NOT INITIAL.
lv_binaryattributevalue = lo_row_6->get_value( ).
ENDIF.
ENDLOOP.
" Skipping lo_row_8 to avoid recursion
" Skipping lo_row_8 to avoid recursion
lv_nullattributevalue = lo_row_9->get_null( ).
lv_booleanattributevalue = lo_row_9->get_bool( ).
ENDIF.
ENDLOOP.
lv_nullattributevalue = lo_value_1->get_null( ).
lv_booleanattributevalue = lo_value_1->get_bool( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value->get_l( ) into lo_row_8.
lo_row_9 = lo_row_8.
IF lo_row_9 IS NOT INITIAL.
lv_stringattributevalue = lo_row_9->get_s( ).
lv_numberattributevalue = lo_row_9->get_n( ).
lv_binaryattributevalue = lo_row_9->get_b( ).
LOOP AT lo_row_9->get_ss( ) into lo_row_1.
lo_row_2 = lo_row_1.
IF lo_row_2 IS NOT INITIAL.
lv_stringattributevalue = lo_row_2->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_row_9->get_ns( ) into lo_row_3.
lo_row_4 = lo_row_3.
IF lo_row_4 IS NOT INITIAL.
lv_numberattributevalue = lo_row_4->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_row_9->get_bs( ) into lo_row_5.
lo_row_6 = lo_row_5.
IF lo_row_6 IS NOT INITIAL.
lv_binaryattributevalue = lo_row_6->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_row_9->get_m( ) into ls_row_7.
lv_key = ls_row_7-key.
lo_value_1 = ls_row_7-value.
IF lo_value_1 IS NOT INITIAL.
lv_stringattributevalue = lo_value_1->get_s( ).
lv_numberattributevalue = lo_value_1->get_n( ).
lv_binaryattributevalue = lo_value_1->get_b( ).
LOOP AT lo_value_1->get_ss( ) into lo_row_1.
lo_row_2 = lo_row_1.
IF lo_row_2 IS NOT INITIAL.
lv_stringattributevalue = lo_row_2->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value_1->get_ns( ) into lo_row_3.
lo_row_4 = lo_row_3.
IF lo_row_4 IS NOT INITIAL.
lv_numberattributevalue = lo_row_4->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_value_1->get_bs( ) into lo_row_5.
lo_row_6 = lo_row_5.
IF lo_row_6 IS NOT INITIAL.
lv_binaryattributevalue = lo_row_6->get_value( ).
ENDIF.
ENDLOOP.
" Skipping ls_row_7-value to avoid recursion
" Skipping ls_row_7-value to avoid recursion
lv_nullattributevalue = lo_value_1->get_null( ).
lv_booleanattributevalue = lo_value_1->get_bool( ).
ENDIF.
ENDLOOP.
" Skipping lo_row_8 to avoid recursion
lv_nullattributevalue = lo_row_9->get_null( ).
lv_booleanattributevalue = lo_row_9->get_bool( ).
ENDIF.
ENDLOOP.
lv_nullattributevalue = lo_value->get_null( ).
lv_booleanattributevalue = lo_value->get_bool( ).
ENDIF.
ENDLOOP.
lo_consumedcapacity = lo_result->get_consumedcapacity( ).
IF lo_consumedcapacity IS NOT INITIAL.
lv_tablearn = lo_consumedcapacity->get_tablename( ).
lv_consumedcapacityunits = lo_consumedcapacity->get_capacityunits( ).
lv_consumedcapacityunits = lo_consumedcapacity->get_readcapacityunits( ).
lv_consumedcapacityunits = lo_consumedcapacity->get_writecapacityunits( ).
lo_capacity = lo_consumedcapacity->get_table( ).
IF lo_capacity IS NOT INITIAL.
lv_consumedcapacityunits = lo_capacity->get_readcapacityunits( ).
lv_consumedcapacityunits = lo_capacity->get_writecapacityunits( ).
lv_consumedcapacityunits = lo_capacity->get_capacityunits( ).
ENDIF.
LOOP AT lo_consumedcapacity->get_localsecondaryindexes( ) into ls_row_10.
lv_key_1 = ls_row_10-key.
lo_value_2 = ls_row_10-value.
IF lo_value_2 IS NOT INITIAL.
lv_consumedcapacityunits = lo_value_2->get_readcapacityunits( ).
lv_consumedcapacityunits = lo_value_2->get_writecapacityunits( ).
lv_consumedcapacityunits = lo_value_2->get_capacityunits( ).
ENDIF.
ENDLOOP.
LOOP AT lo_consumedcapacity->get_globalsecondaryindexes( ) into ls_row_10.
lv_key_1 = ls_row_10-key.
lo_value_2 = ls_row_10-value.
IF lo_value_2 IS NOT INITIAL.
lv_consumedcapacityunits = lo_value_2->get_readcapacityunits( ).
lv_consumedcapacityunits = lo_value_2->get_writecapacityunits( ).
lv_consumedcapacityunits = lo_value_2->get_capacityunits( ).
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
To read an item from a table¶
This example retrieves an item from the Music table. The table has a partition key and a sort key (Artist and SongTitle), so you must specify both of these attributes.
DATA(lo_result) = lo_client->getitem(
it_key = VALUE /aws1/cl_dynattributevalue=>tt_key(
(
VALUE /aws1/cl_dynattributevalue=>ts_key_maprow(
value = new /aws1/cl_dynattributevalue( iv_s = |Acme Band| )
key = |Artist|
)
)
(
VALUE /aws1/cl_dynattributevalue=>ts_key_maprow(
value = new /aws1/cl_dynattributevalue( iv_s = |Happy Day| )
key = |SongTitle|
)
)
)
iv_tablename = |Music|
).