ABAP New Syntax 정리(After 7.40)

SAP ABAP 7.40 이후로 New Syntax를 사용할 수 있음

1. ABAP 7.40 Quick Reference

https://blogs.sap.com/2015/10/25/abap-740-quick-reference

2. Data Statement
  • Before 7.40
    DATA text TYPE string.
    text = ABC.
  • With 7.40
    DATA(text1) = 'ABC'.
3. Loop at into work area
  • Before 7.40
    DATA: ls_0001 TYPE pa0001.
    DATA: lt_0001 TYPE TABLE OF pa0001.
    LOOP AT lt_0001 INTO ls_0001.
    ENDLOOP.
  • With 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001.
    LOOP AT lt_0001 INTO DATA(ls_pa0001).
    ENDLOOP.
4. Loop at assigning
  • Before 7.40
    FIELD-SYMBOLS: TYPE any.
    DATA: lt_0001 TYPE TABLE OF pa0001.
    LOOP AT lt_0001 ASSIGNING .
    ENDLOOP.
  • With 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001.
    LOOP AT lt_0001 ASSIGNING FIELD-SYMBOL().
    ENDLOOP.
5. Read assigning
  • Before 7.40
    FIELD-SYMBOLS: TYPE any.
    DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
    READ TABLE lt_0001 ASSIGNING .
  • With 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
    READ TABLE lt_0001 ASSIGNING FIELD-SYMBOL().
6. Read Table index
  • Before 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001.
    DATA: ls_0001 TYPE pa0001.
    DATA: lv_index TYPE i.
    READ TABLE lt_0001 INDEX lv_index INTO ls_0001.
  • With 7.40
    lv_index = 1.
    ls_0001 = lt_0001[ lv_index ].
7. Read Table with key
  • Before 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001.
    DATA: ls_0001 TYPE pa0001.
    DATA: lv_pernr TYPE persno.
    DATA: lv_begda TYPE d.
    READ TABLE lt_0001 WITH KEY pernr = lv_pernr
    begda = lv_begda
    INTO ls_0001.
  • With 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001.
    DATA: ls_0001 TYPE pa0001.
    DATA: lv_pernr TYPE persno.
    DATA: lv_begda TYPE d.
    ls_0001 = lt_0001[ pernr = lv_pernr begda = lv_begda ].
8. Does record exist?
  • Befire 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
    DATA: lv_pernr TYPE persno.
    READ TABLE lt_0001 INDEX 1 TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
    ENDIF.
  • With 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
    DATA: lv_pernr TYPE persno.
    IF line_exists( lt_0001[ pernr = lv_pernr ] ).
    ENDIF.
9. Get table index
  • Before 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
    DATA: lv_tabix TYPE sy-tabix.
    DATA: lv_pernr TYPE persno.
    READ TABLE lt_0001 TRANSPORTING NO FIELDS.
    lv_tabix = sy-tabix.
  • With 7.40
    DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
    DATA: lv_pernr TYPE persno.
    DATA(lv_tabix) = line_index( lt_0001[ pernr = lv_pernr ] ).
10. Conversion Operator
  • Before 7.40
    DATA: text TYPE c LENGTH 255 VALUE '반짝이'.
    DATA: helper TYPE string.
    DATA: xstr TYPE xstring.
    helper = text.
    xstr = cl_abap_codepage=>convert_to( source = helper ).
    WRITE:/ xstr.
  • With 7.40
    DATA text TYPE c LENGTH 255.
    DATA(xstr) = cl_abap_codepage=>convert_to( source = CONV #( text ) ).
11. For Operator1
  • Before 7.40
    TYPES: BEGIN OF ty_ship,
    tknum TYPE tknum, "shipment NUMBER
    name TYPE ernam, "name OF PERSON who created the OBJECT
    city TYPE ort01, "starting city
    route TYPE route, "shipment route
    END OF ty_ship.
    TYPES: ty_ships TYPE SORTED TABLE OF ty_ship WITH UNIQUE KEY tknum.
    TYPES: ty_citys TYPE STANDARD TABLE OF ort01 WITH EMPTY KEY.
    DATA: gt_ships TYPE ty_ships.
    DATA: gt_citys TYPE ty_citys,
    gs_ship TYPE ty_ship,
    gs_city TYPE ort01.
    LOOP AT gt_ships INTO gs_ship.
    gs_city = gs_ship-city.
    APPEND gs_city TO gt_citys.
    ENDLOOP.
  • With 7.40
    TYPES: BEGIN OF ty_ship,
    tknum TYPE tknum, "shipment NUMBER
    name TYPE ernam, "name OF PERSON who created the OBJECT
    city TYPE ort01, "starting city
    route TYPE route, "shipment route
    END OF ty_ship.
    TYPES: ty_ships TYPE SORTED TABLE OF ty_ship WITH UNIQUE KEY tknum.
    TYPES: ty_citys TYPE STANDARD TABLE OF ort01 WITH EMPTY KEY.
    DATA: ls_ships TYPE ty_ships.
    DATA(gt_citys) = VALUE ty_citys( FOR ls_ship IN gt_ships ( ls_ship-city ) ).
12. For Operator2
  • Before 7.40
    TYPES: BEGIN OF ty_ship,
    tknum TYPE tknum, "shipment NUMBER
    name TYPE ernam, "name OF PERSON who created the OBJECT
    city TYPE ort01, "starting city
    route TYPE route, "shipment route
    END OF ty_ship.
    TYPES: ty_citys TYPE STANDARD TABLE OF ort01 WITH EMPTY KEY.
    TYPES: ty_ships TYPE SORTED TABLE OF ty_ship WITH UNIQUE KEY tknum.
    DATA: gt_citys TYPE ty_citys,
    gs_ship TYPE ty_ship,
    gs_city TYPE ort01.
    DATA: gt_ships TYPE ty_ships.
    LOOP AT gt_ships INTO gs_ship WHERE route = 'R0001'.
    gs_city = gs_ship-city.
    APPEND gs_city TO gt_citys.
    ENDLOOP.
  • With 7.40
    TYPES: BEGIN OF ty_ship,
    tknum TYPE tknum, "shipment NUMBER
    name TYPE ernam, "name OF PERSON who created the OBJECT
    city TYPE ort01, "starting city
    route TYPE route, "shipment route
    END OF ty_ship.
    TYPES: ty_citys TYPE STANDARD TABLE OF ort01 WITH EMPTY KEY.
    TYPES: ty_ships TYPE SORTED TABLE OF ty_ship WITH UNIQUE KEY tknum.
    DATA: gt_ships TYPE ty_ships.
    DATA: ls_ship TYPE ty_ship.
    DATA(gt_citys) = VALUE ty_citys( FOR ls_ship IN gt_ships
    WHERE ( route = 'R0001' ) ( ls_ship-city ) ).
13. FOR with THEN and UNTIL|WHILE
  • Before 7.40
    TYPES:
    BEGIN OF ty_line,
    col1 TYPE i,
    col2 TYPE i,
    col3 TYPE i,
    END OF ty_line,
    ty_tab TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
    DATA: gt_itab TYPE ty_tab,
    j TYPE i.
    FIELD-SYMBOLS TYPE ty_line.
    j = 1.
    DO.
    j = j + 10.
    IF j > 40. EXIT. ENDIF.
    APPEND INITIAL LINE TO gt_itab ASSIGNING .
    -col1 = j.
    -col2 = j + 1.
    -col3 = j + 2.
    ENDDO.
  • With 7.40
    TYPES:
    BEGIN OF ty_line,
    col1 TYPE i,
    col2 TYPE i,
    col3 TYPE i,
    END OF ty_line,
    ty_tab TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
    DATA(gt_itab) = VALUE ty_tab( FOR j = 11 THEN j + 10 UNTIL j > 40
    ( col1 = j col2 = j + 1 col3 = j + 2 ) ).
14. Example for COND

DATA(time) =
COND string(
WHEN sy-timlo < '120000' THEN
|{ sy-timlo TIME = ISO } AM|
WHEN sy-timlo > '120000' THEN
|{ CONV t( sy-timlo - 12 * 3600 ) TIME = ISO } PM|
WHEN sy-timlo = '120000' THEN
|High Noon|
ELSE
| | ).

15. Concatenate
  • Before 7.40
    DATA lv_output TYPE string.
    CONCATENATE 'Hello' 'world' INTO lv_output SEPARATED BY space.
  • With 7.40
    DATA lv_output TYPE string.
    lv_output = |Hello| & | | & |world|.