안녕하세요!
오늘은 ABAP에서 변수에 데이터를 입력할 수 있는 VALUE 구문과 BASE 옵션에 대해 알아보겠습니다.
OLD-SYNTAX


New-Syntax : VALUE


VALUE 구문은 Old 구문과 같은 결과를 나타내지만 가독성 차원에서 뛰어난 효과를 보여줍니다.
하지만 VALUE구문에는 주의해야 할 내용이 있습니다.


위처럼 무턱대고 VALUE 구문을 사용 시 기존의 데이터를 지워버릴 수 있습니다.
구조체의 데이터를 입력할 때는 기존의 데이터를 유의하여 사용해야 하는데요, 구조체에서는 BASE 구문을 통해 데이터를 유지하며 새로운 데이터를 입력할 수 있습니다.
VALUE(BASE) 구문


기존의 데이터를 유지하고 VALUE 구문을 사용하는 것은 생각보다 간단합니다.
VALUE #( BASE <유지할 구조체> <Field> = '값' ).
위와 같은 형식으로 사용할 수 있습니다.
VALUE 구문은 Table구조에도 데이터를 입력할 수 있습니다.


이때도 구조체와 마찬가지로 기존에 데이터가 있다면 기존의 데이터는 지워지며 새로 데이터가 들어갑니다.
역시 BASE구문으로 기존의 데이터를 유지할 수 있으며 아래와 같이 개발할 수도 있습니다.

lt_base와 lt_table이라는 두 개의 인터널 테이블을 만들었습니다.
1) lt_base에는 가, 나, 다, A, B, C라는 데이터를 입력했고
2) lt_table에는 라, 마, 바, D, E, F라는 데이터를 입력했습니다.
3) lt_table에 1,2,3이라는 데이터를 넣으려고 합니다.
VALUE 구문을 사용하면 lt_table의 데이터 라, 마, 바, D, E, F가 사라지게 되니 BASE 구문을 사용하였습니다.
이때 BASE의 구조를 lt_table이 아닌 lt_base를 사용하면 어떻게 될까요?
.
.
.
.
.
.
.
.
.

결과는 lt_table의 기존 데이터는 사라지고 lt_base의 값에 새로운 1,2,3이 추가되어 lt_table에 입력되었습니다.
BASE는 이처럼 구조를 지정해 주는 것이 아니라 실제 값을 가지고 오기 때문에 적절하게 사용한다면, 효율적으로 개발할 수 있을 것이라 생각합니다!!
그럼 좋은 하루 보내세요 :D
'SAP > New Syntax' 카테고리의 다른 글
ABAP New Syntax - Read Table (2) | 2023.04.17 |
---|---|
ABAP 문자열 합치기( CONCATENATE New-Syntax ) (0) | 2023.02.27 |