Pass array has object property from foxpro (to c#) - com

I'm trying to have a class that hold a array and use that class in some COM calls (I makes using C#).
So, I've got my classes like this:
DEFINE CLASS Logistics_Columns AS Session OLEPUBLIC
DIMENSION COLUMNS_ARRAY[1]
DIMENSION COLUMNS_ARRAY_COMATTRIB(4)
COLUMNS_ARRAY_COMATTRIB(1) = 0
COLUMNS_ARRAY_COMATTRIB(2) = "COLUMNS_ARRAY"
COLUMNS_ARRAY_COMATTRIB(3) = "COLUMNS_ARRAY"
COLUMNS_ARRAY_COMATTRIB(4) = "Array"
ENDDEFINE
DEFINE CLASS Logistics_Column AS Session OLEPUBLIC
COLUMN_NAME = .NULL.
DIMENSION COLUMN_NAME_COMATTRIB(4)
COLUMN_NAME_COMATTRIB(1) = 0
COLUMN_NAME_COMATTRIB(2) = "COLUMN_NAME"
COLUMN_NAME_COMATTRIB(3) = "COLUMN_NAME"
COLUMN_NAME_COMATTRIB(4) = "Character"
COLUMN_TYPE = .NULL.
DIMENSION COLUMN_TYPE_COMATTRIB(4)
COLUMN_TYPE_COMATTRIB(1) = 0
COLUMN_TYPE_COMATTRIB(2) = "COLUMN_TYPE"
COLUMN_TYPE_COMATTRIB(3) = "COLUMN_TYPE"
COLUMN_TYPE_COMATTRIB(4) = "Character"
COLUMN_WIDTH = .NULL.
DIMENSION COLUMN_WIDTH_COMATTRIB(4)
COLUMN_WIDTH_COMATTRIB(1) = 0
COLUMN_WIDTH_COMATTRIB(2) = "COLUMN_WIDTH"
COLUMN_WIDTH_COMATTRIB(3) = "COLUMN_WIDTH"
COLUMN_WIDTH_COMATTRIB(4) = "Integer"
COLUMN_PRECISION = .NULL.
DIMENSION COLUMN_PRECISION_COMATTRIB(4)
COLUMN_PRECISION_COMATTRIB(1) = 0
COLUMN_PRECISION_COMATTRIB(2) = "COLUMN_PRECISION"
COLUMN_PRECISION_COMATTRIB(3) = "COLUMN_PRECISION"
COLUMN_PRECISION_COMATTRIB(4) = "Integer"
ENDDEFINE
In C# for the Logistics_Columns class, COLUMNS_ARRAY is not seen as an array.
Yet or the Logistics_Column class all 4 properties are correctly seen as string or integer.
I guess "Array" (COLUMNS_ARRAY_COMATTRIB(4) = "Array")isn't the right literal value to indicate an array.
But then, what is?

As planned I created a custom collection wrapper.
It's basically a foxpro class of type Session OLEPUBLIC which store a Collection and wraps its methods.
Regarding the performance I think it adds some noticeable overhead, but it's the best method I could eventually come with.

Related

adding/removing objects to a list in vb.net

i have a list of objects called gobletinv that i want to add and remove objects from
right now to add a new object I've just done this
gobletinv(gobletpointer).mainstattype = MST.Text
gobletinv(gobletpointer).mainstatvalue = MSV.Text
gobletinv(gobletpointer).substat1type = ST1.Text
gobletinv(gobletpointer).substat1value = SV1.Text
gobletinv(gobletpointer).substat2type = ST2.Text
gobletinv(gobletpointer).substat2value = SV2.Text
gobletinv(gobletpointer).substat3type = ST3.Text
gobletinv(gobletpointer).substat3value = SV3.Text
gobletinv(gobletpointer).substat4type = ST4.Text
gobletinv(gobletpointer).substat4value = SV4.Text
gobletpointer += 1
i currently have no idea how i would remove an object from this list
Let's assume that the type your collection holds is called Stat. Let's also assume that gobletpointer is an Integer with an initial value of 0.
Each line where you are referencing the collection, you start it off with:
gobletinv(gobletpointer)
What this does is get the item from the collection at a given index.
So right now when you set the various property values to their respective TextBox value, you are overwriting the existing item in the collection.
If you wanted to add a new item to the collection, you would use the Add method (documentation). For example:
gobletinv.Add(New Stat() With {
mainstattype = MST.Text,
mainstatvalue = MSV.Text
substat1type = ST1.Text,
substat1value = SV1.Text,
substat2type = ST2.Text,
substat2value = SV2.Text,
substat3type = ST3.Text,
substat3value = SV3.Text,
substat4type = ST4.Text,
substat4value = SV4.Text
})
Now if you wanted to remove the object from the collection, it depends on how you want to remove it. But here is an example of leveraging the RemoveAt method (documentation) to remove the first record from the collection:
gobletinv.RemoveAt(0)
Update: This is a fiddle demonstrating how to add/remove items to the collection. https://dotnetfiddle.net/c0W6yS

Add business objects to contacts

I've successfully created a contact in the SAP IS-U (Release 618) system using the function: BCONTACT_CREATE
EDIT:
Since this question was voted "close" for being "too broad" - here's some very specific code:
DATA:
ls_contact TYPE bpc01_bcontact_auto,
ls_contact_properties TYPE bcont,
lv_contact_text TYPE string,
lv_bp TYPE bu_partner,
lv_bpcontact_id TYPE ct_contact,
lv_no_dialog TYPE flag VALUE abap_true,
lv_repid TYPE syst-repid.
* Main logic
lv_contact_text = 'Test'.
lv_bp = '0010000062'.
ls_contact_properties-cclass = '0003'.
ls_contact_properties-activity = '0001'.
ls_contact_properties-f_coming = '3'.
* Mapping
*--------------------------------------------------------------------*
ls_contact-notice-line = lv_contact_text.
ls_contact-bcontd = ls_contact_properties.
* set flag to use auto data
ls_contact-bcontd_use = abap_true.
lv_repid = sy-repid.
CALL FUNCTION 'BCONTACT_CREATE'
EXPORTING
x_no_dialog = lv_no_dialog
x_auto = ls_contact
x_prgcontext = lv_repid
x_partner = lv_bp
IMPORTING
y_new_bpcontact = lv_bpcontact_id
EXCEPTIONS
existing = 1
foreign_lock = 2
number_error = 3
general_fault = 4
input_error = 5
not_authorized = 6
OTHERS = 7.
When I open the created contact in the BCT2 transaction I see the nothing under Business-Objects:
How can I programmatically add a business object to a contact, so that it is displayed here like this?
I found it a solution!
First create variables (a table and a structure for filling the table) for your business objects that you want to add (I saw some code that had a limit of 5 so I just set that too to be safe):
lt_business_objs TYPE TABLE OF bpc_obj INITIAL SIZE 5,
ls_business_obj TYPE bpc_obj,
Next append your object, in this example I'm just appending one:
* Append business objects
*--------------------------------------------------------------------*
ls_business_obj-objkey = 'The value here may be your business object input value'.
ls_business_obj-objrole = 'DEFAULT'. "Don't know what this is for...
ls_business_obj-objtype = 'OBJECT_NAME'. "Name of your business object - seen in table TOJTB
APPEND ls_business_obj TO lt_business_objs.
And lastly put the object list into the contact structure:
ls_contact-iobjects = lt_business_objs.

Add table rows to a TR programmatically?

I have a problem with adding rows of table to the transport request in programming way.
When i wrote down the transport request number i get the error:
You cannot use request EAMK913244
the code I use is
data lt_variable_changed type table of ztable_task2.
data: l_request type trkorr,
lt_e071 type tr_objects,
lt_e071k type tr_keys,
lv_tabkey type trobj_name,
ls_e071 type e071,
ls_e071k type e071k.
ls_e071-pgmid = 'R3TR'.
ls_e071-object = 'TABU'. "for table
ls_e071-obj_name = 'ZTABLE_TASK2'.
ls_e071-objfunc = 'K'.
append ls_e071 to lt_e071.
loop at lt_variable_changed into ls_variable.
lv_tabkey = ls_variable-num.
ls_e071k-pgmid = 'R3TR'.
ls_e071k-object = 'TABU'.
ls_e071k-objname = 'ZTABLE_TASK2'.
ls_e071k-mastertype = 'TABU'.
ls_e071k-mastername = 'ZTABLE_TASK2'.
ls_e071k-tabkey = lv_tabkey.
append ls_e071k to lt_e071k.
endloop.
call function 'TR_REQUEST_CHOICE'
exporting
iv_suppress_dialog = 'X'
iv_request = var_query
it_e071 = lt_e071
it_e071k = lt_e071k.
message 'Ok' type 'I'.
Screen from se01:
Thanks for help and good luck!
three function modules shall be used to transport changes
call function 'TR_ORDER_CHOICE_CORRECTION'
exporting
iv_category = 'CUST'
importing
ev_order = ev_request
ev_task = ev_task
exceptions
invalid_category = 1
no_correction_selected = 2
others = 3.
call function 'TR_OBJECTS_CHECK'
exporting
iv_no_show_option = abap_true
tables
wt_ko200 = lt_ko200_customizing
wt_e071k = lt_e071k_customizing
exceptions
cancel_edit_other_error = 1
show_only_other_error = 2
others = 3.
call function 'TR_OBJECTS_INSERT'
exporting
wi_order = lv_request
iv_no_show_option = abap_true
tables
wt_ko200 = lt_ko200_customizing
wt_e071k = lt_e071k_customizing
exceptions
cancel_edit_other_error = 1
show_only_other_error = 2
others = 3.
You can also use object-oriented approach for transporting tables.
This piece creates a customizing request and puts contents of a table in it:
DATA(instance) = cl_adt_cts_management=>create_instance( ).
TRY.
instance->insert_objects_in_wb_request( EXPORTING pgmid = 'R3TR'
object = 'TABU'
obj_name = CONV trobj_name( 'Z_TABLE' )
CHANGING trkorr = l_trkorr ).
CATCH cx_adt_cts_insert_error.
RETURN.
ENDTRY.
This piece uses ADT CTS classes and is very flexible. Despite the name wb_request this method is adaptive and will create workbench or customizing request depending on the objects passed.

Unable to compare 2 objects of same type

Dim obj As New CMS_Page
Dim comparisonObj As New CMS_Page
The assignment
obj = db.CMS_Pages.First(Function(s) s.PageID = pageID)
comparisonObj = db.CMS_Pages.First(Function(s) s.PageID = pageID)
Somwhere in the middle of my code
obj.property = sometextfield.text 'Apparently this also changes the comparisonObj
Basically what I'm doing in the end would be
if (obj.property = comparisonObj.property) then
//...
end if
Why can't i change obj.Property without it changing the same property in comparisonObj.Property?
You are probably setting "comparisonObj = obj". You probably want "comparisonObj = obj.Clone()". You will have to implement the "Clone" method yourself.
If CMS_Page is not under your control, then you can create an extension method to clone it.
obj = db.CMS_Pages.First(Function(s) s.PageID = pageID)
comparisonObj = db.CMS_Pages.First(Function(s) s.PageID = pageID)
These two lines result in two references to the same object. Hence, when you do this: obj.property = sometextfield.text then comparisonObj will also reflect that change.
What is the result of
obj.ReferenceEquals(comparisonObj)
if that is True then obj is comparisonObj. You can do the same check more concisely like this,
obj Is comparisonObj
If you have a VB background, both variables are references to the same object.
If you have a C background, both variables are pointers to the same object.
essentially, the variable holds an integer value that addresses the object in memory.

Matlab Object Oriented Programming: Setting and getting properties for multiple objects

I have a class like so:
classdef Vehicle < handle
%Vehicle
% Vehicle superclass
properties
Is_Active % Does the vehicle exist in the simualtion world?
Speed % [Km/Hour]
end
methods
function this = Vehicle(varargin)
this.Speed = varargin{1}; % The speed of the car
this.Is_Active = true;
end
end
end
I create my Vehicle-class objects in a cell form (don't ask me why - it's a laymen's workaround for global setting):
Vehicles{1} = Vehicle(100);
Vehicles{2} = Vehicle(200);
Vehicles{3} = Vehicle(50);
Vehicles{1}.Is_Active = true;
Vehicles{2}.Is_Active = true;
Vehicles{3}.Is_Active = true;
My questions:
1. Is there a way to set all three objects' active in a single command?
2. Is there a way to get all three objects' Speed in a single command?
3. Is there a way to query which vehicles are faster than X in a single command?
Thanks
Gabriel
For the members of the same class you can use round brackets (regular array):
Vehicles(1) = Vehicle(100);
Vehicles(2) = Vehicle(200);
Vehicles(3) = Vehicle(50);
To set all objects use deal:
[Vehicles(:).Is_Active] = deal( true );
You could also initialize an array of objects in the first place.
For your questions (2) and (3) the syntax is equivalent to those of MATLAB structures:
speedArray = [Vehicles.Speed];
fasterThanX = Vehicles( speedArray > X );
Such vectorization notation is a strong point of MATLAB and is used extensively.