LET
- Verwendung innerhalb von Operatoren NEW, VALUE, CONV, COND, SWITCH, REDUCE, FOR …
- es konnen inplace Variablen oder Feldsymbole deklariert werden
- Variablen, die im LET-Ausdruck definiert wurden k?nnen nur innerhalb des jeweiligen Scopes verwendet werden
Variante 1 (Variablendefinition, CONV)
* Carrier PARAMETERS: p_carrid TYPE scarr-carrid DEFAULT 'LH'. START-OF-SELECTION. * Daten holen SELECT * FROM scarr INTO TABLE @DATA(it_carr). TRY. * String zusammenbauen DATA(lv_carr_name) = CONV string( * Hilfsvariablen per LET definieren * ersten Carrier mit Carrid holen, kann Exception CX_SY_ITAB_LINE_NOT_FOUND werfen LET <c> = it_carr[ carrid = p_carrid ] dp = |: | * Hilfsvariablen verwenden IN |{ <c>-carrname }{ dp }{ <c>-url }| ). WRITE: / lv_carr_name. * Exceptions abfangen CATCH cx_root INTO DATA(e_txt). WRITE: / e_txt->get_text( ). ENDTRY.
Variante 2 (Variablendefinition, COND)
DATA(lv_lang) = COND string( * Hilfsvariablen per LET definieren LET lang = cl_abap_syst=>get_language( ) lang_iso = cl_i18n_languages=>sap1_to_sap2( im_lang_sap1 = lang ) * Hilfsvariablen verwenden IN WHEN lang_iso = 'DE' THEN 'Deutsch' WHEN lang_iso = 'EN' THEN 'Englisch' ELSE 'andere Sprache' ). WRITE: / lv_lang.
Variante 3 (Tabelleneinträge, VALUE)
TYPES: BEGIN OF ty_s_adr, id TYPE i, city TYPE string, END OF ty_s_adr. TYPES: ty_it_adr TYPE STANDARD TABLE OF ty_s_adr WITH DEFAULT KEY. TYPES: BEGIN OF ty_s_person, city_id TYPE i, forename TYPE string, surename TYPE string, age TYPE i, END OF ty_s_person. TYPES: ty_it_persons TYPE STANDARD TABLE OF ty_s_person WITH DEFAULT KEY. * Städte DATA(it_city) = VALUE ty_it_adr( ( id = 100 city = 'Berlin' ) ( id = 101 city = 'Hamburg' ) ( id = 102 city = 'M?nchen' ) ). * Tabelle mit Personen DATA(it_persons) = VALUE ty_it_persons( ( city_id = 100 forename = 'Udo' surename = 'Lehmann' age = 35 ) ( city_id = 101 forename = 'Erika' surename = 'Müller' age = 63 ) ( city_id = 102 forename = 'Heinz' surename = 'Schulze' age = 65 ) ). DATA(it_csv) = VALUE stringtab( * alle Namen durchgehen FOR <p> IN it_persons INDEX INTO idx * Hilfsvariablen zusammensetzen LET name = |{ <p>-surename }, { <p>-forename }| city = it_city[ id = <p>-city_id ]-city age_string = COND string( WHEN <p>-age > 63 THEN 'Rentner' ELSE 'kein Rentner' ) output = |{ idx };{ name };{ city };{ age_string }| * Hilfsvariablen verwenden IN * neue Zeile zu Tabelle hinzufügen ( output ) ). * Anzeige cl_demo_output=>display( it_csv ).
Variante 4 (CONV)
DATA(lv_i) = CONV i( LET x = 1 IN x ). WRITE: / lv_i.
Variante 5 (NEW)
DATA(lv_i) = NEW i( LET x = 1 IN x ). WRITE: / lv_i->*.