메뉴 건너뛰기

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
번호 제목 글쓴이 날짜 조회 수
187 프로그램 내에서 문자열 찾기 [3] sapjoy 2007.03.06 6237
186 NATIVE SQL의 INSERT 문 [4] sapjoy 2007.11.13 6259
185 Access predicates and Filter predicates sapjoy 2012.03.14 6289
184 SAP 테이블 구조도 [8] file 죽돌이 2009.01.28 6305
183 BAPI_MATERIAL_AVAILABILITY 가용성체크시에 사용하세요. [1] 노름마치 2007.12.10 6317
182 Automated Note Search & Customer Code Detection 소주와 막걸리 2011.04.27 6352
181 TRANSPORTING [9] ecbase 2006.12.02 6375
180 업로드할 엑셀 파일을 TXT 파일(탭으로 분리된)로 내리지 않고 엑셀파일로 꿀단지 2011.10.11 6380
» add 구문 [3] sapjoy 2006.12.02 6431
178 Internal Table Read performance [4] file sapjoy 2012.03.12 6431
177 특정프로그램 내에서 프린터로 직접 프린트하는 함수 [8] 미쓰조 2010.03.17 6450
176 SAP의 On-line Program에서 Double Click Event 잡는 법 [8] Delight 2008.04.30 6470
175 (-) 부호 값 앞에 붙이기 [6] 권장원 2009.11.06 6473
174 Nested loops Tunning [3] sapjoy 2012.03.13 6515
173 SAP Icon 출력 [3] 홍성현 2007.08.09 6543
172 [Function]금액(숫자)를 영문철자로 바꿔보자 [3] file 양키 2010.09.28 6551
171 테이블 구조 다운로드 DD03L 테이블 조회 [1] sapjoy 2006.12.12 6552
170 <img src=d.gif>[Function]Edit 팝업창을 뛰워보자[추천:e-abap] [19] file 양키 2010.09.28 6603
169 [Tip] Explorer 8.0 & SAP GUI 7.2 fancky 2011.05.19 6603
168 Buffer Bypass 방법 [4] sapjoy 2010.05.20 6623