메뉴 건너뛰기

SAP 한국 커뮤니티

add 구문

sapjoy 2006.12.02 17:59 조회 수 : 6431 추천:36

ADD

Variants


1. ADD n TO m.
2. ADD n1 THEN n2 UNTIL nz GIVING m.
3. ADD n1 THEN n2 UNTIL nz TO m.
4. ADD n1 THEN n2 UNTIL nz
...ACCORDING TO sel ...GIVING m.
5. ADD n1 FROM m1 TO mz GIVING m.

Variant 1
ADD n TO m.

Effect
Adds the contents of n to the contents of M and stores the result in m .
This is equivalent to: m = m + n.

Example

DATA: NUMBER TYPE I VALUE 3,
      SUM    TYPE I VALUE 5.
ADD NUMBER TO SUM.

The field SUM now contains 8, whilst the contents of the field NUMBER remains unchanged at 3.

Note
The details about conversions and performance described under COMPUTE are identical for ADD .

Note
Runtime errors

BCD_BADDATA : P field contains incorrect BCD format.
BCD_FIELD_OVERFLOW : Result field too small (type P ).
BCD_OVERFLOW : Overflow with arithmetic operation (type P .
COMPUTE_INT_PLUS_OVERFLOW : Integer overflow when adding.

Related COMPUTE , ADD-CORRESPONDING .

Variant 2
ADD n1 THEN n2 UNTIL nz GIVING m.

Effect
Adds the contents of the fields n1, n2, ..., nz together and stores the result in m , where n1 is the first, n2 the second and nz the last of a sequence of fields the same distance apart. They can be either database fields or internal fields, but they must all have the same type and length.
This is equivalent to: m = n1 + n2 + ... + nz.

Example

DATA: BEGIN OF NUMBERS,
        ONE   TYPE P VALUE 10,
        TWO   TYPE P VALUE 20,
        THREE TYPE P VALUE 30,
        FOUR  TYPE P VALUE 40,
        FIVE  TYPE P VALUE 50,
        SIX   TYPE P VALUE 60,
      END   OF NUMBERS,
      SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN  NUMBERS-TWO
                UNTIL NUMBERS-FIVE GIVING SUM.

The field SUM now contains 150 but its initial value is unimportant. The fields within the field string NUMBERS remain unchanged.

Variant 3
ADD n1 THEN n2 UNTIL nz TO m.

Effect
Calculates the total as in variant 2 but then adds it to the contents of the field m .
This is equivalent to: m = m + n1 + n2 + ... + nz

Example

DATA: BEGIN OF NUMBERS,
        ONE   TYPE P VALUE 10,
        TWO   TYPE P VALUE 20,
        THREE TYPE P VALUE 30,
        FOUR  TYPE P VALUE 40,
        FIVE  TYPE P VALUE 50,
      END   OF NUMBERS,
      SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN  NUMBERS-TWO
                UNTIL NUMBERS-FIVE TO SUM.

The field SUM now contains 1150.

Variant 4
ADD n1 THEN n2 UNTIL nz
...ACCORDING TO sel ...GIVING m.

Effect
Calculates the total as in variants 2 and 3. In this case, however, the operands from a sequence of fields of the same type are restricted to a partial sequence by the selection specification sel generated by SELECT-OPTIONS or RANGES . The partial sequence results from the indexes that satisfy the condition IN sel (see IF ).

Example

DATA: BEGIN OF NUMBERS,
        ONE   TYPE P VALUE 10,
        TWO   TYPE P VALUE 20,
        THREE TYPE P VALUE 30,
        FOUR  TYPE P VALUE 40,
        FIVE  TYPE P VALUE 50,
      END   OF NUMBERS,
      SUM   TYPE I VALUE 1000,
      INDEX TYPE I.
RANGES SELECTION FOR INDEX.

SELECTION-SIGN   = 'I'.
SELECTION-OPTION = 'BT'.
SELECTION-LOW    = 2.
SELECTION-HIGH   = 4.
APPEND SELECTION.

ADD NUMBERS-ONE THEN NUMBERS-TWO
                UNTIL NUMBERS-FIVE
                ACCORDING TO SELECTION
                GIVING SUM.

SUM now contains 90. Only the component fields TWO to FOUR were selected from the field string NUMBERS and added together.

Variant 5
ADD n1 FROM m1 TO mz GIVING m.

Effect
The field n1 must be the first in a sequence of consecutive fields of the same type. m1 and mz should contain the numbers of the first and last fields in this sequence to be added together (whether fixed or variable). The total is stored in m .

Example

DATA: BEGIN OF NUMBERS,
        ONE   TYPE P VALUE 10,
        TWO   TYPE P VALUE 20,
        THREE TYPE P VALUE 30,
        FOUR  TYPE P VALUE 40,
        FIVE  TYPE P VALUE 50,
      END   OF NUMBERS,
      START TYPE I VALUE 2,
      SUM   TYPE I VALUE 1000.
ADD NUMBERS-ONE FROM START TO 4 GIVING SUM.

The field SUM now contains 90.

Note
Performance The details for conversion and performance specified for COMPUTE are equally valid for ADD .
The runtime required for adding two numbers of type I or F is about 2 (standardized microseconds), for type P it is roughly 8 msn.

Note
Runtime errors

Besides the runtime errors listed in variant 1, the error ADDF_INT_OVERFLOW can occur instead of COMPUTE_INT_PLUS_OVERFLOW in other variants.

Index
?SAP AG 1996
번호 제목 글쓴이 날짜 조회 수
387 System field 정리한 내용이에요 [4] 김창훈 2007.08.21 5487
386 테이블 update 프로그램 [4] sapjoy 2007.08.29 4746
385 Image를 화면에 보여주는 방법 [1] 정두영 2007.08.30 6000
384 OK Code Values... 흠,,, [1] 김창훈 2007.08.31 4652
383 제가 모은 팁들입니다. [62] file 풍운사랑 2007.09.07 5541
382 미니 SAP 설치 메뉴얼 입니다. [5] 신종철™ 2007.09.17 4574
381 너무도 당연해서 가끔 잊곤하는 공기와 같은 존재 'F1' key [5] 백혜정 2007.09.19 4034
380 ABAP TIP [4] file 둘리67 2007.10.03 5952
379 ICON ascii code [3] file sapjoy 2007.10.05 5004
378 SAP 어플리케이션의 구성 [3] file 노름마치 2007.10.10 3897
377 간단팁1 : 텍스트 금액에서 천단위 구분자 ',' 삭제(개수 상관없음) [12] 윤훈태 2007.10.15 5432
376 간단팁2 : 특정 값으로 구분된 텍스트, 한방에 분리 및 각각의 변수에 저장 [2] 윤훈태 2007.10.15 4138
375 새로운 Print format 추가하기 [5] file 이명환 2007.10.18 3679
374 그룹을 이용하여 SAP PRD 시스템 접속하기 [2] file 이명환 2007.10.18 4531
373 Tip : 전표 라인 아이템 Direct 조회 [5] 2007.10.23 10166
372 주민번호 체크 [3] 임선미 2007.10.23 4795
371 widget을 이용한 Job monitor 데모 [1] 해처리 2007.10.24 3603
370 BAPI_DELIVERYPROCESSING_EXEC 납품문서 만들때 사용하세요 노름마치 2007.10.29 7494
369 NATIVE SQL의 INSERT 문 [4] sapjoy 2007.11.13 6258
368 Internal table 사용시 속도개선을 위한 구문 [16] 노름마치 2007.11.14 10013