GoodleAds

EXAMPLES ON CONVERSIONS ( DATE, FIELD, NUMBER, CHARACTER )

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
DATAnumber_1(4VALUE '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
DATAold_customer_name(10VALUE '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
DATAany_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
DATAshort_name(8),
      long_name
(16).
MOVE 'Washington' TOshort_namelong_name.
WRITE : short_name color long_name COLOR 6.
SKIP.
* Take care of intermediate steps
long_name 
short_name 'Washington'.
WRITE : 'Take care of intermediate steps'short_name color 5long_name COLOR 6.
SKIP.
ULINE.


* Converting number fields
* Using numeric texts and packed numbers
DATAno_employees(4TYPE n,
      no_rooms 
TYPE p,
      employees_per_room 
TYPE DECIMALS 2.
      employees_per_room 
no_employees / no_rooms.
* Rounding with integers and packed numbers
DATAincome TYPE i VALUE '10000',
      tax 
TYPE DECIMALS VALUE '0.2',
      net_income 
TYPE 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_incomerounded_net_income.
income 
'10002'.
net_income 
income * 1 tax ).
rounded_net_income 
income * 1 tax ).
WRITE'When income = 10002'net_incomerounded_net_income.
skip.
uline.


* Converting date fields
* Using the built-in calendar
DATARECEIVING_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:




No comments:

Post a Comment