FIELD CONVERSIONS:
The following programs gives the clarifications on conversions ( dates, fields , characters and numbers ).
PROGRAM:
*&---------------------------------------------------------------------*
*& Report Z_FIELD_CONVERSIONS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_field_conversions.
* Converting to numbers during computations
DATA: number_1(4) VALUE '1771',
number_2(3),
result TYPE i.
WRITE : 'Converting to numbers during computations' color 1.
number_2 = '005'.
result = number_1 + number_2.
WRITE :/ 'When number_2 = "005"', result.
number_2 = ' 5'.
result = number_1 + number_2.
WRITE :/ 'When number_2 = " 5"', result.
SKIP.
uline.
WRITE : 'Padding character fields with blanks' color 7.
* Padding character fields with blanks
DATA: old_customer_name(10) VALUE 'Edison',
new_customer_name(25).
MOVE old_customer_name TO new_customer_name.
WRITE / new_customer_name.
SKIP.
uline.
WRITE : 'Calculating dates for leap year and non leap year' color 3.
* Calculating dates
DATA: any_date TYPE d,
same_day_of_next_week TYPE d.
any_date = '19991231'.
same_day_of_next_week = any_date + 7.
WRITE / same_day_of_next_week.
* When leap year
any_date = '20000228'.
same_day_of_next_week = any_date + 7.
WRITE :/ 'when leap year', same_day_of_next_week.
* Non leap year
any_date = '21000228'.
same_day_of_next_week = any_date + 7.
WRITE :/ 'When non leap year', same_day_of_next_week.
SKIP.
ULINE.
WRITE 'Truncating fields or padding with blanks' color 4.
* Truncating fields or padding with blanks
DATA: short_name(8),
long_name(16).
MOVE 'Washington' TO: short_name, long_name.
WRITE : / short_name color 5 , long_name COLOR 6.
SKIP.
* Take care of intermediate steps
long_name = short_name = 'Washington'.
WRITE : / 'Take care of intermediate steps', short_name color 5, long_name COLOR 6.
SKIP.
ULINE.
* Converting number fields
* Using numeric texts and packed numbers
DATA: no_employees(4) TYPE n,
no_rooms TYPE p,
employees_per_room TYPE p DECIMALS 2.
employees_per_room = no_employees / no_rooms.
* Rounding with integers and packed numbers
DATA: income TYPE i VALUE '10000',
tax TYPE p DECIMALS 2 VALUE '0.2',
net_income TYPE p DECIMALS 2,
rounded_net_income TYPE i.
write / 'Converting number fields' color 5.
net_income = income * ( 1 - tax ).
rounded_net_income = income * ( 1 - tax ).
WRITE: / 'When income = 10000', net_income, rounded_net_income.
income = '10002'.
net_income = income * ( 1 - tax ).
rounded_net_income = income * ( 1 - tax ).
WRITE: / 'When income = 10002', net_income, rounded_net_income.
skip.
uline.
* Converting date fields
* Using the built-in calendar
DATA: RECEIVING_DATE TYPE D,
LAST_ADMISSIBLE_DATE TYPE D.
write / 'Converting date fields' color 6.
RECEIVING_DATE = '19980223'.
LAST_ADMISSIBLE_DATE = RECEIVING_DATE + 10.
WRITE / : 'When non leap year', LAST_ADMISSIBLE_DATE.
RECEIVING_DATE = '19980305'.
LAST_ADMISSIBLE_DATE = RECEIVING_DATE + 10.
WRITE / LAST_ADMISSIBLE_DATE.
RECEIVING_DATE = '20000223'.
LAST_ADMISSIBLE_DATE = RECEIVING_DATE + 10.
WRITE / : 'When leap year', LAST_ADMISSIBLE_DATE.
OUTPUT:
The following programs gives the clarifications on conversions ( dates, fields , characters and numbers ).
PROGRAM:
*&---------------------------------------------------------------------*
*& Report Z_FIELD_CONVERSIONS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_field_conversions.
* Converting to numbers during computations
DATA: number_1(4) VALUE '1771',
number_2(3),
result TYPE i.
WRITE : 'Converting to numbers during computations' color 1.
number_2 = '005'.
result = number_1 + number_2.
WRITE :/ 'When number_2 = "005"', result.
number_2 = ' 5'.
result = number_1 + number_2.
WRITE :/ 'When number_2 = " 5"', result.
SKIP.
uline.
WRITE : 'Padding character fields with blanks' color 7.
* Padding character fields with blanks
DATA: old_customer_name(10) VALUE 'Edison',
new_customer_name(25).
MOVE old_customer_name TO new_customer_name.
WRITE / new_customer_name.
SKIP.
uline.
WRITE : 'Calculating dates for leap year and non leap year' color 3.
* Calculating dates
DATA: any_date TYPE d,
same_day_of_next_week TYPE d.
any_date = '19991231'.
same_day_of_next_week = any_date + 7.
WRITE / same_day_of_next_week.
* When leap year
any_date = '20000228'.
same_day_of_next_week = any_date + 7.
WRITE :/ 'when leap year', same_day_of_next_week.
* Non leap year
any_date = '21000228'.
same_day_of_next_week = any_date + 7.
WRITE :/ 'When non leap year', same_day_of_next_week.
SKIP.
ULINE.
WRITE 'Truncating fields or padding with blanks' color 4.
* Truncating fields or padding with blanks
DATA: short_name(8),
long_name(16).
MOVE 'Washington' TO: short_name, long_name.
WRITE : / short_name color 5 , long_name COLOR 6.
SKIP.
* Take care of intermediate steps
long_name = short_name = 'Washington'.
WRITE : / 'Take care of intermediate steps', short_name color 5, long_name COLOR 6.
SKIP.
ULINE.
* Converting number fields
* Using numeric texts and packed numbers
DATA: no_employees(4) TYPE n,
no_rooms TYPE p,
employees_per_room TYPE p DECIMALS 2.
employees_per_room = no_employees / no_rooms.
* Rounding with integers and packed numbers
DATA: income TYPE i VALUE '10000',
tax TYPE p DECIMALS 2 VALUE '0.2',
net_income TYPE p DECIMALS 2,
rounded_net_income TYPE i.
write / 'Converting number fields' color 5.
net_income = income * ( 1 - tax ).
rounded_net_income = income * ( 1 - tax ).
WRITE: / 'When income = 10000', net_income, rounded_net_income.
income = '10002'.
net_income = income * ( 1 - tax ).
rounded_net_income = income * ( 1 - tax ).
WRITE: / 'When income = 10002', net_income, rounded_net_income.
skip.
uline.
* Converting date fields
* Using the built-in calendar
DATA: RECEIVING_DATE TYPE D,
LAST_ADMISSIBLE_DATE TYPE D.
write / 'Converting date fields' color 6.
RECEIVING_DATE = '19980223'.
LAST_ADMISSIBLE_DATE = RECEIVING_DATE + 10.
WRITE / : 'When non leap year', LAST_ADMISSIBLE_DATE.
RECEIVING_DATE = '19980305'.
LAST_ADMISSIBLE_DATE = RECEIVING_DATE + 10.
WRITE / LAST_ADMISSIBLE_DATE.
RECEIVING_DATE = '20000223'.
LAST_ADMISSIBLE_DATE = RECEIVING_DATE + 10.
WRITE / : 'When leap year', LAST_ADMISSIBLE_DATE.
OUTPUT: