on 2024 Aug 08 3:49 PM
I have been trying to get to grips with RAP and have been following tutorials, which ironically explain nothing, and am unable to understand what <root_key> is used for. I am following the following the tutorial Enhance Behavior With Action and Validation | SAP Tutorials and at step 4, I am asked to enter the following code snippet.
*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
CLASS lhc_travel DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
TYPES tt_travel_update TYPE TABLE FOR UPDATE zi_travel_m_xxx.
METHODS validate_customer FOR VALIDATE ON SAVE IMPORTING keys FOR travel~validateCustomer.
METHODS validate_dates FOR VALIDATE ON SAVE IMPORTING keys FOR travel~validateDates.
METHODS validate_agency FOR VALIDATE ON SAVE IMPORTING keys FOR travel~validateAgency.
METHODS set_status_completed FOR MODIFY IMPORTING keys FOR ACTION travel~acceptTravel RESULT result.
METHODS get_features FOR FEATURES IMPORTING keys REQUEST requested_features FOR travel RESULT result.
METHODS CalculateTravelKey FOR DETERMINE ON MODIFY IMPORTING keys FOR Travel~CalculateTravelKey.
ENDCLASS.
CLASS lhc_travel IMPLEMENTATION.
********************************************************************************
*
* Implements the dynamic feature handling for travel instances
*
********************************************************************************
METHOD get_features.
"%control-<fieldname> specifies which fields are read from the entities
READ ENTITY zi_travel_m_xxx FROM VALUE #( FOR keyval IN keys
( %key = keyval-%key
" %control-travel_id = if_abap_behv=>mk-on
%control-overall_status = if_abap_behv=>mk-on
) )
RESULT DATA(lt_travel_result).
result = VALUE #( FOR ls_travel IN lt_travel_result
( %key = ls_travel-%key
%features-%action-acceptTravel = COND #( WHEN ls_travel-overall_status = 'A'
THEN if_abap_behv=>fc-o-disabled ELSE if_abap_behv=>fc-o-enabled )
) ).
ENDMETHOD.
METHOD validate_agency.
READ ENTITY zi_travel_m_xxx\\travel FROM VALUE #(
FOR <root_key> IN keys ( %key-mykey = <root_key>-mykey
%control = VALUE #( agency_id = if_abap_behv=>mk-on ) ) )
RESULT DATA(lt_travel).
DATA lt_agency TYPE SORTED TABLE OF /dmo/agency WITH UNIQUE KEY agency_id.
" Optimization of DB select: extract distinct non-initial customer IDs
lt_agency = CORRESPONDING #( lt_travel DISCARDING DUPLICATES MAPPING agency_id = agency_id EXCEPT * ).
DELETE lt_agency WHERE agency_id IS INITIAL.
CHECK lt_agency IS NOT INITIAL.
" Check if customer ID exist
SELECT FROM /dmo/agency FIELDS agency_id
FOR ALL ENTRIES IN @LT_agency
WHERE agency_id = @LT_agency-agency_id
INTO TABLE @DATA(lt_agency_db).
" Raise msg for non existing customer id
LOOP AT lt_travel INTO DATA(ls_travel).
IF ls_travel-agency_id IS NOT INITIAL AND NOT line_exists( lt_agency_db[ agency_id = ls_travel-agency_id ] ).
APPEND VALUE #( mykey = ls_travel-mykey ) TO failed-travel.
APPEND VALUE #( mykey = ls_travel-mykey
%msg = new_message( id = /dmo/cx_flight_legacy=>agency_unkown-msgid
number = /dmo/cx_flight_legacy=>agency_unkown-msgno
v1 = ls_travel-agency_id
severity = if_abap_behv_message=>severity-error )
%element-agency_id = if_abap_behv=>mk-on ) TO reported-travel.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD calculatetravelkey.
ENDMETHOD.
METHOD set_status_completed.
ENDMETHOD.
METHOD validate_customer.
ENDMETHOD.
METHOD validate_dates.
ENDMETHOD.
ENDCLASS.
On line no 53, keys is looped into <root_key>. It feels like a special token or a keyword cause the loop in line no 34 is looping keys into the keyval variable. What does <root_key> do? Is it a keyword or something cause I can't find any documentation for it.
It's a question neither related to READ ENTITY, nor <root_key> has a system meaning, it's just a Field Symbol with any name, so your question is about what this ABAP block (valid since ABAP 7.40) is:
VALUE #( FOR <root_key> IN keys
( %key-mykey = xxxxxxx
%control = xxxxxxx ) )
VALUE is a Constructor Expression, FOR is a loop at an internal table (KEYS), each line is assigned to the field symbol <root_key>, the code between parenthesis is a line to be inserted (components %KEY and %CONTROL) in a new internal table (which can be used temporarily in any ABAP statement or stored in a variable).
See ABAP Documentation:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the answer, but I am aware of what VALUE does and the question is not entirely about the ABAP block.
I am having tihis question as I didn't realise that <root-key> was used as a field symbol here as I don't see why a field symbol would be used. In fact, in line 34, a field symbol is not used whereas it is used in 53.
User | Count |
---|---|
62 | |
10 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.