General SAP ABAP Concepts Explained:
Field groups are used to group similar fields together into one name. Filed groups can be used in conjunction with
INSERT f1 f2 INTO fg
SORT BY fg
LOOP … ENDLOOP
INSERT f1 f2 INTO fg
The INSERT statement is used to create a field group dynamically by
inserting the fields into it.Only global data fields can be inserted and not
local data fields e.g. in FORM modules.
This statement will combine all the fields in the fieldgroup and write them to a sequential dataset as a single record.
e.g. DATA: customer(14) TYPE C,
order(20) TYPE C,
quantity(5) TYPE N,
material(20) TYPE C.
FIELD-GROUPS: order , mat .
INSERT customer order INTO order. * insering two fields in the field
INSERT quantity material INTO mat .
customer = ‘niraj visnoi’
order = ‘100001’
EXTRACT order. *writing the contents of field group
*order to dataset
material = ‘1004.’
quantity = 500.
customer = ‘rahul’
order = ‘100002’
material = ‘1006.’
quantity = 200.
SORT BY order. * sorting of sequential dataset by field group order
AT order .
WRITE: customer, order.
The field symbols work similarly to pointers in C. They are used in conjunction with statement
ASSIGN f TO .
At runtime we can assign a field or structure to the field symbol , any changes or work can be done on the field symbol affecting directly the assigned field. The syntax of field symbol declaration is:
Declares a field symbol which can be assigned any single field.
FIELD-SYMBOL TYPE /LIKE type.
Declares a field symbol which can be assigned any single field
which is of particular type.
FIELD-SYMBOL STRUCTURE s DEFAULT wa.
Declares a field symbol which will point to a structure(table) and the
default work area will be wa.
FIELD-SYMBOL TYPE LINE OF /LIKE LINE OF type.
Declares a field symbol which will have line type .
TABLES kna1. * Customer master
ASSIGN kna1-kunnr TO .
ASSIGN f TO
This will assign the field f to field symbol ,now we can work with the field symbol instead of the field.
Type-pools are used to declare a type pool to be used in the program.The specified type pool should already exists in the ABAP DICTONARY(SE11).Once the type pool has been declared we can use any of the constants and types declared in that type pool.
Type-pool statement is used to create a type group in the ABAP dictionary.It is the first statement in the definition.The type group is used to declare constants and types and these must begin with the name of the type pool and underscore.
e.g. TYPE-POOL owntypes.
TYPES num TYPE P DECIMALS 2.
TYPES name(14) TYPE C.
To use these types in the abap program we have to use the statement
e.g. TYPE-POOLS owntypes.
DATA customer TYPE owntypes_num.
DATA name TYPE owntypes_name.