Trying to modify the type of a field with .WithDefaultValue() - fluent-migrator

I have a table with a column that has a default value:
this.Create.Table("msgqueue")
.WithColumn("id")
.AsInt32()
.Identity()
.PrimaryKey()
.WithColumn("queueddt")
.AsDateTime()
.Nullable()
.WithDefaultValue(SystemMethods.CurrentDateTime)
;
I want to change this from datetime to datetime2:
this.Alter.Table("msgqueue")
.AlterColumn("queueddt")
.AsCustom("datetime2")
.Nullable()
.WithDefaultValue(SystemMethods.CurrentDateTime)
;
This gives me errors:
The error was The object 'DF_msgqueue_queueddt' is dependent on column 'queueddt'.
I did some googling around, and discovered Delete.DefaultConstraint(), so I tried that, first:
this.Delete.DefaultConstraint()
.OnTable("msgqueue")
.OnColumn("msgqueue")
;
And I still see the same problem.

Before your Alter Table statement try dropping the default constraint using Execute.Sql:
Execute.Sql(#"ALTER TABLE msgqueue DROP CONSTRAINT DF_msgqueue_queueddt")
Also, your column name is wrong in your last statement. It should be:
this.Delete.DefaultConstraint()
.OnTable("msgqueue")
.OnColumn("queueddt");

Related

How to access controls?

I have just created a window, containing a fill-in field (TestField) and a checkbox (chk_TestField):
DEFINE VARIABLE TestField AS INTEGER VIEW-AS FILL-IN.
DEFINE VARIABLE chk_TestField AS LOGICAL VIEW_AS TOGGLE-BOX.
It is very simple to change the value of the fill-in field, based on the checking of the checkbox, something like:
ON VALUE-CHANGED OF chk_TestField IN FRAME DEFAULT-FRAME
DO:
TestField = 5.
END.
However, I'm interested in changing an attribute of the Fill-in field itself, not the integer it represents (I would like to make the fill-in field read-only), how to I do this?
I've tried:
ON VALUE-CHANGED OF chk_TestField IN FRAME DEFAULT-FRAME
DO:
TestField.Read-Only = NOT(chk_TestField).
END.
This, obviously, does not work.
ASSIGN TestField:READ-ONLY IN FRAME {&FRAME-NAME} = TRUE.
or
ASSIGN Table.TestField:READ-ONLY IN FRAME {&FRAME-NAME} = TRUE.

Show table by button click

TABLES: mara, marc.
"marc is N
"mara is 1
SELECTION-SCREEN PUSHBUTTON 15(10) text-001 USER-COMMAND press.
DATA: lt_mara TYPE TABLE OF mara WITH HEADER LINE,
ls_mara TYPE mara.
DATA: lt_marc TYPE TABLE OF marc WITH HEADER LINE,
ls_marc TYPE marc,
Sum type P length 8 DECIMALS 2.
PARAMETERS: p_mtart TYPE mara-mtart.
SELECT-OPTIONS: so_werks FOR marc-werks.
SELECT * FROM mara INTO TABLE lt_mara
WHERE mtart = p_mtart.
IF sy-subrc = 0.
SELECT * FROM marc INTO TABLE lt_marc
FOR ALL ENTRIES IN lt_mara
WHERE matnr = lt_mara-matnr
AND werks IN so_werks.
LOOP AT lt_marc INTO ls_marc.
READ TABLE lt_mara INTO ls_mara
WITH KEY matnr = ls_marc-matnr.
sum = ls_mara-brgew + ls_mara-ntgew .
WRITE:/ ls_mara-mtart, ls_marc-matnr , ls_marc-werks , ls_mara-brgew, ls_mara-ntgew,sum.
ENDLOOP.
ELSE.
MESSAGE TEXT-e02 TYPE 'E' .
ENDIF.
How Can make this happen:I want that on click of the button to show the table.Please the code to be as simple as possible and as easy to understand as possible.if you can't make it with a button make it with a radiobutton or smth else.
Thanks in advance!
If you want to keep it simple, you can use "sy-ucomm" which stores your last triggered action. With your button, it'd look like this:
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'PRESS'.
*code for displaying your table via ALV or WRITE goes here*
ENDCASE.
The most common way to display internal tables like this is with an ALV, a simple example of how to build up an ALV can be found here:
https://archive.sap.com/discussions/thread/873601
If you'd like it to do the WRITE: to screen under one circumstance, and display the ALV Grid in another, you should use Select Options and parameters.
Your code needs the addition of EVENTS, please take a look here on what they are and how to use them:
http://www.erpworkbench.com/abap/abap-events.htm

Birt Crosstab Date Issue

I have a crosstab where one of the groups contains a date. When the date is NULL, i want to display a space, anything I've tried including the code below on the expression for the binding name of the field. Yet it still displays Jan 1, 0001. How can I get it to display a space instead when the value is NULL?
if (["Group5"]["CP_EXPIRATION_DATE"] == null ) {
" ";
} else {
dimension["Group5"]["CP_EXPIRATION_DATE"];
}
I am not sure you can do this in the binding expression because the datatype is a Date, therefore a blank space can't be set as value. You could always use a script for this, although there might be a more elegant way:
Click your expiration date field onto the crosstab-> Script tab -> onRender -> Enter a script such
if (dimension["Group5"]["CP_EXPIRATION_DATE"]==null){
this.setDisplayValue(" ")
}

GRID COLUMNS atk4 agiletoolkit

Hi I am trying to get some referenced data from another table,
Data structure:
Table PartDetail
-id
-OperationTypeID(foreign key)
-DateAdded
Table OperationType
-id
-Description
I am trying something like this:
$crud = $this->add('MVCGrid', array('allow_edit'=>false));
$crud->setModel('Model_PartDetail',array('DateAdded'));
But then I want to see the "description" from table OperationType, because on my PartDetail model I declare my relationship like this:
$this->hasOne('OperationType','OperationTypeID','Description')
->mandatory(true)
->caption('Operation Type');
for example in this case I want to see the description from the table OperationType
I tried:
$crud->setModel('Model_PartDetail',array('DateAdded','OperationType'));
but is not working, only works with:
$crud->setModel('Model_PartDetail',array('DateAdded','OperationTypeID'));
but I get only the ID number, not the description.
How this works?
I was able to solved it.
on the model you need to redefine it as
$ref = $this->add('Field_Reference', 'OperationTypeID');
$ref->dereferenced_field='OperationTypeDescription';
$m = $this->add('Model_OperationType');
$m->addField('D'); // <-- actually seems that this line is not working
$ref->setModel($m, 'Description');
And then in the page you can actually added as OperationTypeDescription:
$crud->setModel('Model_PartDetail', array('DateAdded', 'OperationTypeDescription'));

SelectedValue which is invalid because it does not exist in the list of items

I encounter this problem repeatedly, and haven't a clue what is causing it. I get an exception in the DataBind: SelectedValue which is invalid because it does not exist in the list of items.
Here are some important pieces of information:
I reload listOrgs periodically when the underlying data has changed.
The Organization.DTListAll call returns 2 Int, String pairs.
There are no duplicate or null values in the returned data
After the first two lines below, listOrgs.Items.Count is 0, and the Selected Value is 0
The selected value after the DataBind operation executes is the ID value from the first row in the data
This exception happens the very first time this code is executed after a fresh page load
listOrgs.Items.Clear();
listOrgs.SelectedValue = "0";
listOrgs.DataSource = new Organization().DTListAll(SiteID);
listOrgs.DataTextField = "OrganizationName";
listOrgs.DataValueField = "OrganizationID";
listOrgs.DataBind();
Apparently the solution I posted wasn't entirely effective... Eventually in my application I changed to this:
listOrgs.Items.Clear();
listOrgs.SelectedIndex = -1;
listOrgs.SelectedValue = null;
listOrgs.ClearSelection(); // Clears the selection to avoid the exception (only one of these should be enough but in my application I needed all..)
listOrgs.DataSource = new Organization().DTListAll(SiteID);
listOrgs.DataTextField = "OrganizationName";
listOrgs.DataValueField = "OrganizationID";
listOrgs.DataBind();
I kept getting this error.
Weird thing is that before I set the datasource and rebind after deleting an item the selected index = -1.
If I explicitly set the selectedIndex = -1; then it works and doesn't throw an error.
So even though it was already -1 setting it to -1 stops it from erroring.
Weird eh?
Try setting listOrgs.SelectedValue = "0" after you refresh the DataSource
At the moment you are trying to select the first item in an empty list.
Change the first two line with this :
listOrgs.SelectedItem.Selected = false;
listOrgs.Items.Clear();
In case you still have this problem this is how i resolved it:
listOrgs.SelectedIndex = -1; // Clears the SelectedIndex to avoid the exception
listOrgs.DataSource = new Organization().DTListAll(SiteID);
listOrgs.DataTextField = "OrganizationName";
listOrgs.DataValueField = "OrganizationID";
listOrgs.DataBind(); //Unless you have "listOrgs.AppendDataBoundItems = true" you don't need to clear the list
#PMarques answer helped me out and did solve my problem.
However whilst experimenting, it clicked in my head why I was gettign the error in the first place.
I was setting the "Text" attribute thinking that it might create an encompassing label or fieldset + legend, for me (which it doesn't).
The Text property for a list is infact the SelectedValue property for a ListControl.
So my mistake in misinterpreting what the text property did.
Not sure it is your case, but I had the same problem and apparently there was no explanation, then I realized doing a copy and paste on notepad of a field of database that at the beginning of the value there was a NULL.
Curious thing was that a select joining tables was working. I deleted the row and reinserted, after was working fine.
I was getting the same error repeatedly and try ending up by not setting the default selected value to Index -1.
I commented my code ddlDRIBidAmt.SelectedValue = -1
This value was set at the time where my Page Controls were reset to default values.
I know its too late to answer, but what I tried is an dirty solution but it worked.
After databinding, I am insert a item at index 0
ddl.Items.Insert(0, new ListItem("---Select---","-1"));
And on setting,
I am placing try catch, In catch i am setting Value to -1

Resources