Step 1 Create Time Employed Reusable Part

VLF Windows Application Development

Step 1. Create Time Employed Reusable Part

VFW070 – Create Time Employed Reusable Part

 

1.  Create a new Reusable Part  / type Object:

     Name: iiiVFW12

     Description: Time Employed Calculator

2.  Note that your reusable part has an ancestor of PRIM_OBJT.

3.  iiiVFW12 should have one method routine, uEmployTime, which has one input parameter and three output parameters, defined as follows.

For

Name

Class

*input

i_strdter

STARTDTER

*output

o_year

PRIM_NMBR

*output

o_month

PRIM_NMBR

*output

o_days

PRIM_NMBR

 

     Note: STARTDTER will be passed to this component, which is a 6 long date in the form YYMMDD. This will provide a solution which works for regions using both DDMMYY and MMDDYY date formats.    

     Your uEmployTime method routine should initially look like the following:

Mthroutine Name(uEmployTime)
Define_Map For(*input) Class(#startdter) Name(#i_strdter)
Define_Map For(*output) Class(#PRIM_NMBR) Name(#o_year)
Define_Map For(*output) Class(#prim_nmbr) Name(#o_month)
Define_Map For(*output) Class(#prim_nmbr) Name(#o_days)

Endroutine

 

4.  Define_Map Statements:

This step reviews the Define_Map statement, there is no code for you to write here.

     The Define_Map statement defines input and output parameters to a routine. For example:

Define_Map For(*input) Class(#startdter) Name(#i_strdte)

 

  • The method routine will reference this variable as #i_strdte.
  • This method will be invoked by another components, passing the required parameters and values:

Invoke #iiiVFW10.uEmployTime i_strdte(#startdter) . . .

 

  • The invoking component refers to this parameter as i_strdte().
  • Input parameters are mandatory unless they are defined with a default value, for example, this is an optional input parameter:

Define_Map For(*input) Class(#prim_nmbr) Name(#i_num) Mandatory(1)

 

     Note: Start Date is a signed 6.0 field. Designing this component to accept only this form of input is obviously a limitation. In a real example, you would probably add another input parameter which defines the format of the passed date, and also change the input date definitions so that a number of date formats of such as Signed 6,0 and Signed 8,0 and Date or Datetime can be handled.

5.  Define the following work fields (following the Begin_Com) which are required during the calculation routine:

Define Field(#i_date) Reffld(#std_datex) Desc('Input Date')
Define Field(#c_date) Reffld(#std_datex) Desc('Current Date')
Define Field(#i_year) Reffld(#yyyy) Desc('Input Year number')
Define Field(#c_year) Reffld(#yyyy) Desc('Current Year number')
Define Field(#i_month) Reffld(#month) Desc('Input Month number')
Define Field(#c_month) Reffld(#month) Desc('Current Month number')
Define Field(#i_day) Reffld(#day) Desc('Input Day Number')
Define Field(#c_day) Reffld(#day) Desc('Output day number')

 

6.  In the uEmployTime method, start to build the logic to calculate years, months and days since the employee start date:

7.  Setup current and input year, month and day values:

* Setup current and input year, month and day values.
#c_date := *date
#c_year := #c_date.year
#i_date := #i_strdter.asdate( yymmdd )
#i_year := #i_date.year
#i_month := #i_date.month
#i_day := #i_date.day

 

     These calculations make use of intrinsic functions. Use F2 Features help on a field to discover the intrinsic functions which it supports.

8.  Calculate number of years

     Current year must be greater than or equal to the input year

* Calculate number of years, months and days
If (#c_year >= #i_year)
#o_year := #C_year - #I_year 
Else
#o_year #o_month #o_days := 0
Endif

 

9.  Extend the logic to calculate number of months. New code is highlighted in red

If (#c_year >= #i_year)
#o_year := #C_year - #I_year – 1
* Calculate number of months
* When input month is less than current month

If (#i_month < #c_month)

#o_month := #c_month - #i_month - 1

Else

#o_month := (12 - #i_month) + #c_month – 1

#o_year -= 1

Endif

If (#i_month = #c_month)

#o_month := *zeroes

Endif

Else
#o_year #o_month #o_days := 0
Endif

 

10. Extend logic to calculate number of days. New code is highlighted in red.

If (#c_year >= #i_year)
#o_year := #C_year - #I_year – 1
* Calculate number of months
* When input month is less than current month
If (#i_month < #c_month)
#o_month := #c_month - #i_month - 1
Else
#o_month := (12 - #i_month) + #c_month – 1
#o_year -= 1
Endif
If (#i_month = #c_month)
#o_month := *zeroes
Endif
* Calculate number of days
* when input day number is less than current day

If (#i_day < #c_day)

#o_days := #c_day - #i_day

#o_month += 1

Else

If (#i_month = 2)

#o_days := (28 - #i_day) + #c_day

Endif

If ((#i_month = 4) *Or (#i_month = 6) *Or (#i_month = 9) *Or (#i_month = 11))

#o_days := (30 - #i_day) + #c_day

Else

#o_days := (31 - #i_day) + #c_day

Endif

Endif

Else
#o_year #o_month #o_days := 0
Endif

 

11. Compile your Time Employed reusable part.