SAP ABAP Code Shrikant Naidu

Home
Site Map
What is SAP ?
SAP LSMW Explained with example
User Exits & Enhancements
Best Of SAP Links
BDC Code
SAP SmartForms Step by Step
SAP ABAP ALV Grid Explained with Example
Useful Tips
ABAP System Fields
SAP Script
SAP Script Graphics
SAPScript Print Program
ABAP ListViewer
Dialog Programming
SAP Tables
SAP ALE and IDOC
Recommended SAP ABAP Coding guidelines
SAP General ABAP
SAP Books For consultants
About Me
Contact Me
My Resume
SAP General ABAP

General SAP ABAP Concepts Explained:

 
FIELD-GROUPS fg
  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
EXTRACT 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.
 
EXTRACT fg
  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 
                                                              *group order
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.
EXTRACT mat.
 
customer = 'rahul'
order       = '100002'
EXTRACT order.
material = '1006.'
quantity  = 200.
EXTRACT mat.
 
SORT BY order.          * sorting of sequential dataset by field group order
LOOP .
   AT order .
   WRITE: customer, order.
   ENDAT.
   AT mat.
   WRITE: material,quantity.
   ENDAT.
ENDLOOP.
 

FIELD-SYMBOL <fs>
 The field symbols work similarly to pointers in C. They are used in conjunction with statement
ASSIGN f TO <fs> .
 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:
 
 FIELD-SYMBOL <fs>.
 Declares a field symbol <fs> which can be assigned any single field.
 FIELD-SYMBOL <fs> TYPE /LIKE type.
 Declares a field symbol <fs> which can be assigned any single field 
 which is of particular type.
 FIELD-SYMBOL <fs> STRUCTURE s DEFAULT wa.
 Declares a field symbol <fs> which will point to a structure(table) and the 
 default work area will be wa.
 FIELD-SYMBOL <fs> TYPE LINE OF  /LIKE LINE OF type.
  Declares a field symbol <fs> which will have line type .
 
e.g. FIELD-SYMBOLS <fs>
       TABLES kna1.               * Customer master
        SELECT .....
         ...
        ASSIGN kna1-kunnr TO <fs>.
        WRITE <fs>.
 
ASSIGN f TO <fs>
  This will assign the field f to field symbol <fs>,now we can work with the field symbol instead of the field.

TYPE-POOLS tp
  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 tp
  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
TYPE-POOLS .
 e.g. TYPE-POOLS owntypes.
         DATA customer TYPE owntypes_num.
         DATA name       TYPE  owntypes_name.

 

Enter supporting content here

Shrikant Naidu SAP ABAP Developer (INDIA)