ERP Database - The Unofficial ERP Knowledge Base

Facebook Twitter del.icio.us Digg it
ERP Database contains a huge collection of articles related to ERP System and Software. Many of the articles are specifically related to SAP. All these ERP/SAP articles are freely available to everyone.

If you would like to submit an article or share any document related to ERP or any specific ERP software. Please mail it to support@erpdb.info. Please make sure that the documents are not copyrighted.
Social Bookmarks:

ABAP Keyword a day : ADD

Print This Post Email This Post Written by admin on Oct 29th, 2007 | Filed under: ABAP, ABAP Keywords

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.

Parts marked with ” …” are interchangeable
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 msn (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.
ADD-CONDITIONAL is not an ABAP/4 key word (in R/3).

Regards,
ABAPer
———————
ABAPer, mail: abap.community@gmail.com http://www.erpdb.info

Share

If you like this post, you may as well like these too:

  1. ADD-CORRESPONDING : ABAP Keyword a day ADD-CORRESPONDING Basic form ADD-CORRESPONDING rec1 TO rec2. Effect Interprets rec1 and rec2 as field strings. If, for example, rec1 and rec2 are tables, executes the statement for their header lines....
  2. GET: ABAP Keyword a day GET: Event keyword for defining event blocks for reporting events. GET <node> [FIELDS <fi> <f 2>...]. GET node LATE [FIELDS f1 f2 ...]. Only occurs in executable programs. When the...
  3. AT : ABAP Keyword a day AT Events in lists- AT LINE-SELECTION.- AT USER-COMMAND.- AT PFn.Events on selection screens- AT SELECTION-SCREEN.Control break with extracts- AT NEW f.- AT END OF f.- AT FIRST.- AT LAST.- AT...
  4. DO : ABAP Keyword a day DO Variants 1. DO. 2. DO n TIMES. Variant 1 DO. Addition … VARYING f FROM f1 NEXT f2 Effect Repeats the processing enclosed by the DO and ENDDO statements...
  5. FORM: ABAP Keyword a day FORM: Defines a subroutine. Syntax FORM [USING ... [VALUE(][)] [TYPE |LIKE ]„. ] [CHANGING... [VALUE(][)] [TYPE |LIKE ]„. ]. Introduces a subroutine. The USING and CHANGING additions define the subroutine’s...
  6. FETCH : ABAP Keyword a day FETCH Basic form FETCH NEXT CURSOR c target. Effect Uses the cursor c to read the next line or lines from the dataset of a database table determined by OPEN...
  7. DIVIDE : ABAP Keyword a day DIVIDE Basic form DIVIDE n1 BY n2. Effect Divides the contents of n1 by n2 and places the result in n1 . This is equivalent to: n1 = n1 /...
  8. DESCRIBE : ABAP Keyword a day DESCRIBE Return attributes of a field - DESCRIBE FIELD f. Return attributes of an internal table - DESCRIBE TABLE itab. Determine distance between two fields - DESCRIBE DISTANCE BETWEEN f1...
  9. DATA : ABAP Keyword a day DATA Variants1. DATA f.2. DATA f(len).3. DATA: BEGIN OF rec,…END OF rec.4. DATA: BEGIN OF itab OCCURS n,…END OF itab.5. DATA: BEGIN OF COMMON PART c,…END OF COMMON PART.EffectDefines global...
  10. CONTINUE: ABAP Keyword a day CONTINUE Basic formCONTINUE.EffectWithin loop structures like * DO … ENDDO* WHILE … ENDWHILE* LOOP … ENDLOOP* SELECT … ENDSELECTCONTINUE terminates the current loop pass, returns the processing to the beginning...
  11. CONCATENATE : ABAP Keyword a day CONCATENATE Basic form CONCATENATE f1 … fn INTO g. Addition … SEPARATED BY h Effect Places the fields f1 to fn after g . With the fields fi (1 <=...
  12. COMPUTE: ABAP Keyword a day COMPUTEBasic formCOMPUTE n = arithexp.EffectEvaluates the arithmetic expression arithexp and places the result in the field n .Allows use of the four basic calculation types + , – , *...
  13. CHECK : ABAP Keyword a day CHECK Within loops and events- CHECK logexp.Special for reports with logical databases- CHECK sel.- CHECK SELECT-OPTIONS. CHECK – within loops Basic formCHECK logexp.EffectCHECK evaluates the subsequent logical expression . If...
  14. ASSIGN: ABAP Keyword a day ASSIGN Variants:1. ASSIGN f TO .2. ASSIGN (f) TO .3. ASSIGN TABLE FIELD (f) TO .4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .5. ASSIGN COMPONENT idx OF...
  15. GET PARAMETER: ABAP Keyword a day GET PARAMETER Gets an SPA/GPA parameters. Syntax GET PARAMETER ID <pid> FIELD <field_name>. Writes the value of the SPA/GPA parameter <pid> from the user-specific SAP memory into the variable <f>....



One Response to “ABAP Keyword a day : ADD”

  1. ,

Leave a Reply