Friday 19 July 2013

JULY 19


Structured Types:Studied about structured types , type pools and their creation  and its implementation in programs.
A user-defined type can be based on the definition of a field string. This is known as a structured type. The following example shows how we can shorten a program using a structured type.

Example:

  Using Structured Types can Reduce Redundancy and Make Maintenance Easier
 1 report ztx0813.
 2 types: begin of address,
 3            street(25),
 4            city(20),
 5            region(7),
 6            country(15),
 7            postal_code(9),
 8            end of address.
 9
10  data: customer_addr type address,
11        vendor_addr   type address,
12        employee_addr type address,
13        shipto_addr   type address.
14
15 customer_addr-street  = '101 Memory Lane'.
16 employee_addr-country = 'Transylvania'.
17
18 write: / customer_addr-street,
19          employee_addr-country.
Description:
Lines 2 through 8 define a data type named address that contains five fields. On lines 10 through 13, four field strings are defined using the new type. Without the new type, these definitions would have used an additional 24 lines of code. Maintenance is also made easier: If a change to the definitions of the address field strings is needed, only the definition of the type needs to be changed. 

Type Groups

types statement can be stored in a type group. A type group (also known as a type pool) is a Data Dictionary object that exists merely to contain one or more types or constants statements. Using the type-poolsstatement in our program, we access types or constants from a type group and use them in our program. Multiple programs can share a type group, giving us the ability to create centralized definitions. 

The following figure illustrates the concept:

Example:
A type-pool Statement Containing Types and Constants 
1 type-pool ztx1.
2 types:     ztx1_dollars(16)         type p decimals 2,
3            ztx1_lira(16)            type p decimals 0.
4 constants: ztx1_warning_threshold   type i value 5000,
5            ztx1_amalgamation_date   like sy-datum value '19970305'.

Description:
Line 1 indicates the beginning of the type group and gives it a name. Lines 2 through 5 define types and constants that can be used in any program.

Using Type Group Reduces Duplication of Code for Easier Maintenance

Program making the use of above created "type-pool" -
 1 report ztx0815.
 2 type-pools ztx1.
 3 data: begin of american_sums,
 4           petty_cash type ztx1_dollars,
 5           pay_outs   type ztx1_dollars,
 6           lump_sums  type ztx1_dollars,
 7           end of american_sums.
 8
 9 american_sums-pay_outs = '9500.03'.
10
11 if american_sums-pay_outs > ztx1_warning_threshold.
12     write: / 'Warning', american_sums-pay_outs,
13              'exceeds threshold', ztx1_warning_threshold.
14     endif.
 Description:
Line 2 includes the definitions from type group ztx1 in the program. Lines 3 through 7 define a field string using type ztx1_dollars from the type group. Line 9 assigns a value to pay_outs, and it is compared with constant ztx1_warning_threshold from the type group on line 11.
If the type group has already been included, subsequent attempts to include it are ignored and they do not cause an error.

NOTE: Type group names can be one to five characters long, and must begin with y or z. Types and constants included in a program using the type-pools statement always have global visibility.


Creating a Type Group

To create a type group:
  1. Begin at the Dictionary: Initial Screen (menu path Tools->ABAP/4 Workbench, Development->ABAP/4 Dictionary).
  2. Type the name of your type group in the Object Name field.
  3. Select the Type Groups radio button.
  4. Press the Create pushbutton. The Type Group xxxx: Create Text screen is displayed.
  5. Type a description of your type group in the Short Text field.
  6. Press the Save button. The Create Object Catalog Entry screen is displayed.
  7. Press the Local Object button. The ABAP/4 Editor: Edit Type Group screen is 
  8. displayed. On the first line, the statement type-pool t. appears, where t is the name of your type group. If it does not appear, you should type it now.
  9. On subsequent lines, type constants and types statements. All names must begin with t_, where t is the name of your type pool.
  10. Press the Save button on the Application toolbar. At the bottom of the window, the message Type group saved is displayed.
  11. Press the Back button on the Application toolbar to return to the Dictionary: Initial Screen.



    To delete a type group, follow steps 1 through 3 of the preceding procedure and then press the Delete button on the Application toolbar.

    Here also we can use T-code se11 ,hence replacing the step 1 and directly moving to the Dictionary: Initial screen.