Set Categories on DateNavigator - abap

My friend seems to be having some trouble with ABAP. Here's a copy of his question - posted on the SAP community forums.
Hey Everyone,
I am trying to mark the DateNavigator with two categories. I made a context called Marking, with attributes Date, Category and Tooltip.
Node: Marking
Date:
Category:
Tooltip:
I filled category attribute with two categories : e_category-three and e_category-four. I filled the Date attribute with dates. I want some of these dates to be category-three and others category-four.
Currently, all dates are set to the first category (e_category-three) and the code looks like this.
if ls_host_name-host_name <> host_msg and ls_vm_name-vm_name = vm_msg.
loop at lt_machine_booking into wa.
if ls_host_name-host_name = wa-host_name.
date = wa-reserved_from.
while date <= wa-reserved_till.
ls_dates_shared-dates = date. > i want these dates to be e_category-three
append ls_dates_shared to lt_dates_shared.
add 1 to date.
ENDWHILE.
endif.
ENDLOOP.
elseif ls_host_name-host_name <> host_msg and ls_vm_name-vm_name <> vm_msg.
loop at lt_machine_booking into wa.
if ls_host_name-host_name = wa-host_name and ls_vm_name-vm_name = wa-vm_name.
date = wa-reserved_from.
while date <= wa-reserved_till.
ls_dates_shared = date. > i want these dates to be e_category-four
append ls_dates_shared to lt_dates_shared.
add 1 to date.
ENDWHILE.
endif.
" ...

I'm assuming that ls_dates_shared is of type marking?
If this is the case you have to fill the fields ls_dates_shared-category and ls_dates_shared-tooltip explicitly.
Currently this may be filled prior to the code snippet that you give us. Try something like this:
if ls_host_name-host_name <> host_msg and ls_vm_name-vm_name = vm_msg.
loop at lt_machine_booking into wa.
if ls_host_name-host_name = wa-host_name.
date = wa-reserved_from.
while date <= wa-reserved_till.
ls_dates_shared-dates = date. "i want these dates to be e_category-three"
ls_dates_shared-category = e_category-three.
"ls_dates-tooltip = appropriate_tooltip for e_category-three"
append ls_dates_shared to lt_dates_shared.
add 1 to date.
ENDWHILE.
endif.
ENDLOOP.
elseif ls_host_name-host_name <> host_msg and ls_vm_name-vm_name <> vm_msg.
loop at lt_machine_booking into wa.
if ls_host_name-host_name = wa-host_name and ls_vm_name-vm_name = wa-vm_name.
date = wa-reserved_from.
while date <= wa-reserved_till.
ls_dates_shared = date. "i want these dates to be e_category-four"
ls_dates_shared-category = e_category-four.
"ls_dates-tooltip = appropriate_tooltip for e_category-four"
append ls_dates_shared to lt_dates_shared.
add 1 to date.
ENDWHILE.
endif.
...

Related

How to change status based on date in another text box on form - Access

Im making a training database.
Im looking to change a textbox value on a form based on a date in another textbox.
I have the following:
Refresher Period - TxtRef
Participation Date - TxtPart
Refresher Date - TxtRefDate
Status - TxtStatus
I want status to update to either - In Date, Expired or Expiring based on the following rules applying to the date in TxtRefDate.
Value < Now() + 60 "Expiring"
Value < Now() "Expired"
Value > Now() + 60 "In Date"
Create a small helper function:
Public Function Status(ByVal RefDate As Date) As String
Dim Description As String
Select Case DateDiff("d", Date, RefDate)
Case > 60
Description = "In date"
Case > 0
Description = "Expiring"
Case Else
Description = "Expired"
End Select
Status = Description
End Function
Now, set the ControlSource of txtStatus to:
=Status([TxtRefDate])
I think you're looking for something like that ?
If TxtRefDate.Value < Now() Then
TxtStatus.Value = "Expired"
Else:
If TxtRefDate.Value < Now() + 60 Then
TxtStatus.Value = "Expiring"
Else:
TxtStatus.Value = "In Date"
End If
End If

Find monday of after a certain date

I have 2 tables, Table 1 and Table 2. Both the tables have one date column each. I am inserting the first Monday of the month on top of the table 1 and Table 2, both. I will fetch date value from each row of the table 2, and if it is more than the value on top of the table, I will insert 0. If the date value in the table 2 is "16/02/2018", and it is not a Monday, I will insert the Monday after it, and the value 1 for that record.How can I proceed with it? Please help.
Dim col_tab2_dat as Date
first_day = DateSerial(Year(Date), Month(Date), 1)
last_day = DateSerial(Year(Date), Month(Date) + 1, 1)
curr_month= Format(first_day, "mmm")
w = Weekday(first_day , vbMonday)
FirstMonday = first_day + IIf(w <> 1, 8 - w, 0)
tab1_last_lin = ws.Columns(2).Find("Total(T1)").Row
tab2_last_lin = ws.Columns(2).Find("Total(T2)").Row
find_tab2 = ws.Columns(1).Find("Table 2").Row
last_lin = Range("B" & Rows.Count).End(xlUp).Row
last_col_tab1 = ws.Cells(tab1_last_lin, ws.Columns.Count).End(xlToLeft).Column
last_col_tab2 = ws.Cells(tab2_last_lin, ws.Columns.Count).End(xlToLeft).Column
last_dat = ws.Cells(2, last_col_tab1 - 1).Value
new_date = last_dat + 7
For i = find_tab2 + 3 to tab2_last_lin
ws.Cells(find_tab2 + 3, 1).Value = col_tab2_dat
If col_tab2_dat > last_dat Then
I am stuck here. What to do next?
End If
Next i
Here is a function that will return the next Monday:
Public Function GetNextMonday(dt As Date) As Date
Do Until Weekday(dt, vbSunday) = 2
dt = DateAdd("d", 1, dt)
Loop
GetNextMonday = dt
End Function
Here's a function that will work for any day of the week.
NextWeekday Function:
Function NextWeekday(FromDate As Date, vbWeekday As VbDayOfWeek) As Date
If Weekday(FromDate) < vbWeekday Then
NextWeekday = FromDate + vbWeekday - Weekday(FromDate)
Else
NextWeekday = FromDate + 7 + vbWeekday - Weekday(FromDate)
End If
End Function
It takes two arguments:
FromDate: The Date of which you are wanting to find the next weekday of. You can simply use "Date" as the argument for today's Date.
vbWeekday: The upcoming day of the week you are wanting the date for.
VBA Example:
Once you've added the above function to your code module, it's easy to get its value:
Sub Main()
Dim NextThursday As Date
NextThursday = NextWeekday(Date, vbThursday)
End Sub
Worksheet Formula Example:
Or you can use it as a worksheet function:
=NextWeekday(Today(), 5)
Worksheet Formula Considerations:
Notice in the worksheet formula we had to remove the vbThursday constant as worksheet functions doesn't have this functionality built-in. However, if you want to still use these constant values in your worksheet, you can create them yourself by using the Name Manager.
Click on the Formulas Tab, then on Define Name
Start creating your constants starting at vbSunday = 1 through vbSaturday = 7 by placing the Constant Name in the Name: field, and the value in the Refers to: field:
And there you have it! You can now refer to them using your named values:
Additional Example Usage:
Comments:
The benefit of using the VbDayOfWeek Type is that you will now gain IntelliSense when using the function:

Assign values to dynamic structure

Need idea on the below codes, on how to simplify. Codes below works good but is there a way I could enhance or shorten the codes making it dynamic?
TYPES: BEGIN OF lty_dates,
yesterday TYPE string,
today TYPE string,
tomorrow TYPE string,
END OF lty_dates.
DATA: it_table TYPE TABLE OF lty_dates.
DO 3 TIMES.
CASE lv_count.
WHEN 1.
it_table[ 1 ]-zyesterday = 'Result Yesterday'.
it_table[ 2 ]-zyesterday = 'Result Yesterday'.
it_table[ 3 ]-zyesterday = 'Result Yesterday'.
WHEN 2.
it_table[ 1 ]-ztoday = 'Result Today'.
it_table[ 2 ]-ztoday = 'Result today'.
it_table[ 3 ]-ztoday = 'Result Today'.
WHEN 3.
it_table[ 1 ]-ztommorrow = 'Result Tomorrow'.
it_table[ 2 ]-ztommorrow = 'Result Tomorrow'.
it_table[ 3 ]-ztommorrow = 'Result Tomorrow'.
ENDCASE.
lv_count = lv_count + 1.
ENDDO.
My idea is something like the below pseudocodes. I would not want to perform CASE multiple times specially instances if fields for it_table would reach 100 (fields).
DO 3 TIMES.
ASSIGN 'ZTODAY' TO <dynamic_fieldname>.
it_table[ 1 ]-<dynamic_fieldname> = <dynamic_result>.
it_table[ 2 ]-<dynamic_fieldname> = <dynamic_result>.
it_table[ 3 ]-<dynamic_fieldname> = <dynamic_result>.
ENDDO.
Please help or light me up on this.
You could use the command ASSIGN COMPONENT compname OF STRUCTURE structure TO <field_symbol>.
TYPES: BEGIN OF lty_dates,
yesterday TYPE string,
today TYPE string,
tomorrow TYPE string,
END OF lty_dates.
TYPES: BEGIN OF lty_result ,
fieldname TYPE fieldname,
result TYPE string,
END OF lty_result .
FIELD-SYMBOLS <data> TYPE any .
DATA: lt_table TYPE TABLE OF lty_dates,
lt_result TYPE TABLE OF lty_result.
lt_result = VALUE #( ( fieldname = 'yesterday'
result = 'Result Yesterday' )
( fieldname = 'today'
result = 'Result Today' )
( fieldname = 'tomorrow'
result = 'Result Tomorrow' ) ).
lt_table = VALUE #( ( ) ( ) ( ) ). " 3 empty lines
LOOP AT lt_table ASSIGNING FIELD-SYMBOL(<table>) .
LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<result>) .
ASSIGN COMPONENT <result>-fieldname OF STRUCTURE <table> TO <data> .
<data> = <result>-result.
ENDLOOP .
ENDLOOP .
Actually, your code creates this result table:
YESTERDAY TODAY TOMORROW
Result Yesterday Result Today Result Tomorrow
Result Yesterday Result today Result Tomorrow
Result Yesterday Result Today Result Tomorrow
Why not to use macro for this? Macro can perfectly fulfill your needs:
FIELD-SYMBOLS: <fvalue> TYPE ANY.
DEFINE put_values.
ASSIGN COMPONENT &1 OF STRUCTURE &2 TO <fvalue>.
<fvalue> = &3.
END-OF-DEFINITION.
it_table = VALUE #( ( ) ( ) ( ) ).
LOOP AT it_table ASSIGNING FIELD-SYMBOL(<fs_tab>).
put_values 'yesterday' <fs_tab> 'Result Yesterday'.
put_values 'today' <fs_tab> 'Result Today'.
put_values 'tomorrow' <fs_tab> 'Result Tomorrow'.
ENDLOOP.
This will work if the number if the loop iterations are equal to lines of itab (as in your code).

how to compare 2 datetimepicker vb.net

I'd like to compare 2 DateTimePicker's value
Dim dd1 As Date, dd2 As Date
Dim diff As Integer
dd1 = DateTimePicker1.Value
dd2 = DateTimePicker2.Value
diff = DateDiff("d", dd1, dd2)
If diff > 0 Then
MsgBox("datetimpicker1datetimepicker2")
End If
but it doesn't work could you help me please
Another way to compare would be to use the DateTime.Compare function. For a simple "Are they the same?" you could try:
If Not DateTime.Compare(dd1,dd2) = 0 then
'they are diffent
End If
Or if you want to be more specific then you might go with something like this:
If Not DateTime.Compare(dd1,dd2) = 0 then
'they are same
ElseIf DateTime.Compare(dd1,dd2) > 0 then
'dd1 is later than dd2
Else
'dd1 is prior to dd2
End If
You can see more about DateTime.Comare here on MSDN
If You are using DateDiff() then there are three case can be possible:-
1) DatePicker1 date is bigger than DatePicker2
2) DatePicker1 date is lower than DatePicker2
3) DatePicker1 date is equal to DatePicker2
To handle this, You have to use this
diff = DateDiff("d", dd1, dd2)
If diff > 0 Then
MsgBox("datetimpicker1 is greater than datetimepicker2")
Else If diff < 0 Then
MsgBox("datetimpicker1 is lesser than datetimepicker2")
Else
MsgBox("datetimpicker1 is equal to datetimepicker2")
End If

Count of days that have at least 1 job open using SQL

I have a MS Access table that has a list of jobs that were executed (Job ID, StartDate, EndDate) I need to find the count of days in a specified date range (e.g. between 1st Jan and 30 Jun) that a user selects using textboxes that have at least 1 job open ie between StartDate and EndDate. I have some experience with VBA and with SQL (not very good with grouping).
Could anyone assist me with a suggestion of how I could get this count?
JobID| StartDate| EndDate
1142| 03-Jan-14| 04-Feb-14|
1143| 13-Mar-14| 18-May-14|
1144| 03-Jan-14| 29-Jan-14|
1145| 20-Jan-14| 13-Apr-14|
1146| 03-Jan-14| 07-Jan-14|
You could create a calendar table as suggested in the comments and add a button called cmdCountJobDays to your form.
The below code will check all possible dates in the selected date range against the job dates. A bit clunky but it will get you there :-)
Private Sub cmdCountJobDays_Click()
Dim StartDate as Date
Dim EndDate as Date
StartDate = me.txtYourStartDateTextBox
EndDate = me.txtYourEndDateTextBox
SQLGetJobCountPeriod = SQLGetJobCountPeriod & "Select CalendarDate from tblCalendarDates where CalendarDate >=" & cdbl(StartDate)
SQLGetJobCountPeriod = SQLGetJobCountPeriod & " and CalendarDate <= " & cdbl(EndDate)
Set dateschecked = CurrentDb.OpenRecordset(SQLGetJobCountPeriod)
If dateschecked.EOF = False Then
dateschecked.MoveFirst
CountOpenJobDays = 0
CountAllDays = 0
Do While dateschecked.EOF = False
CurrentCheckDate = CDbl(dateschecked.Fields("CalendarDate"))
SQLJobDates = "Select StartDate, EndDateDate from jobdetails "
Set Jobdates = CurrentDb.OpenRecordset(SQLJobDates)
If Jobdates.EOF = False Then
Jobdates.MoveFirst
Do While Jobdates.EOF = False
Jobstartdate = CDbl(Jobdates.Fields("StartDate"))
Jobenddate = CDbl(Jobdates.Fields("EndDate"))
If (CurrentCheckDate > Jobstartdate - 1) And (CurrentCheckDate < Jobenddate + 1) Then
CountJobOpen = CountJobOpen + 1
Exit Do
End If
Jobdates.MoveNext
Loop
End If
CountAllDays = CountAllDays + 1
dateschecked.MoveNext
Loop
End If
msgbox CountJobOpen
End Sub
The count is using a datediff function.
datediff(dd,startdate, enddate)
"dd" tells it to find days, start date would be 1/03/2014, and end date would be 2/04/2014 as an example for your first line