SUBTRACT-CORRESPONDING

SUBTRACT-CORRESPONDING

Syntax diagram

Effect

Interprets struc1 and struc2 as field strings. If, for example, struc1 and struc2 are tables, executes the statement for their header lines.

Searches for all sub-fields which occur both in struc1 and struc2 and then generates, for all relevant field pairs corresponding to the component fields ni, statements of the form

SUBTRACT struc1-ni FROM struc2-ni.

The other fields remain unchanged.

With complex structures, the full names of the field pairs must be identical.

Example

DATA: BEGIN OF PERSON, 
		NAME(20)	 VALUE 'Paul', 
		MONEY TYPE I VALUE 5000, 
	END   OF PERSON, 
	BEGIN OF PURCHASES OCCURS 10, 
		PRODUCT(10), 
		MONEY TYPE I, 
	END   OF PURCHASES. 
PURCHASES-PRODUCT = 'Table'. 
PURCHASES-MONEY = 100. 
APPEND PURCHASES. 
 
PURCHASES-PRODUCT = 'Chair'. 
PURCHASES-MONEY =  70. 
APPEND PURCHASES. 
 
LOOP AT PURCHASES. 
  SUBTRACT-CORRESPONDING PURCHASES FROM PERSON. 
ENDLOOP.

The value of PERSON-MONEY is now 4830. The above SUBTRACT-CORRESPONDING statement (executed twice here) is equivalent to:

SUBTRACT PURCHASES-MONEY FROM PERSON-MONEY.

Note

All fields of the same name are subtracted, whether they are numeric or not. Here, the conversions performed are the same as with SUBTRACT and the same runtime errors can occur.

Related

SUBTRACT
MOVE-CORRESPONDING
ADD-CORRESPONDING
MULTIPLY-CORRESPONDING
DIVIDE-CORRESPONDING