SAP ABAP New Syntax 정리(After 7.40)

SAP ABAP 컴포넌트가 7.40 이상이라면 아래 New Syntax를 사용할 수 있습니다.

0. 버전 보는 방법

  • 시스템  → 상태 → 제품버전내 세부사항
1. ABAP 7.40 Quick Reference
2. Data Statement 예제
Before 7.40With 7.40
DATA text TYPE string.
text = ABC.
DATA(text) = ‘ABC’.
 3. Loop at into work area 예제
Before 7.40With 7.40
DATA: ls_0001 TYPE pa0001.
DATA: lt_0001 TYPE TABLE OF pa0001.
LOOP AT lt_0001 INTO ls_0001.
ENDLOOP.
DATA: lt_0001 TYPE TABLE OF pa0001.
LOOP AT lt_0001 INTO DATA(ls_pa0001).
ENDLOOP.
 4. Loop at assigning 예제
Before 7.40With 7.40
FIELD-SYMBOLS: TYPE any.
DATA: lt_0001 TYPE TABLE OF pa0001.
LOOP AT lt_0001 ASSIGNING .
ENDLOOP
DATA: lt_0001 TYPE TABLE OF pa0001.
LOOP AT lt_0001 ASSIGNING FIELD-SYMBOL().
ENDLOOP.
 5. Read assigning 예제
Before 7.40With 7.40
FIELD-SYMBOLS: TYPE any.
DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
READ TABLE lt_0001 ASSIGNING .
DATA: lt_0001 TYPE TABLE OF pa0001 WITH HEADER LINE.
READ TABLE lt_0001 ASSIGNING FIELD-SYMBOL().
 6. Read Table index 예제
Before 7.40With 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.

lv_index = 1.
ls_0001 = lt_0001[ lv_index ].

 

 7. Read Table with key 예제
Before 7.40With 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.

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? 예제
Before 7.40With 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.
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.40With 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.
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.40With 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.

DATA text TYPE c LENGTH 255.
DATA(xstr) = cl_abap_codepage=>convert_to( source = CONV #( text ) ).

 

 11. For Operator1 예제
Before 7.40With 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.

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.40With 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.
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.40With 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.

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 예제
Before 7.40With 7.40
 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.40With 7.40
DATA lv_output TYPE string.
CONCATENATE ‘Hello’ ‘world’ INTO lv_output SEPARATED BY space.
DATA lv_output TYPE string.
lv_output = |Hello| & | | & |world|.
 16. Select 예제
Before 7.40With 7.40
 Select SINGLE itpct FROM pa0541 INTO @DATA(lv_itpct)
WHERE pernr EQ @i_struc-pernr.
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments