Tibco spotfire; Refresh tables under conditions using ironpython - properties

I wrote the following script in order to refresh tables under specific conditions.
I have created a document property under the name "lob".
Some tables will be refreshed according to lob's value, while othes will be refreshed despite lob's value.
Please note that some tables may not be refreshed at all. That's the reason for begging my script with data's deletion from every single table and then refreshing.
Moreover, i have created a document property under the name "PIAreadyToDisplay". This property equals "No" while tables are being refreshed. When the table's refresh is finished, the document property equals to "Yes".
It seems that tables are refreshing according my needs but the document property "PIAreadyToDisplay" does not work as it should.
Do you find any mistake in my script?
Thank you in advance for your reply.
**Script**
Document.Properties["PIAreadyToDisplay"] = "No"
import clr
from Spotfire.Dxp.Data import RowSelection, IndexSet
MyTable = Document.Data.Tables["In Force"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["ACP_IF"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["NAYO_IF"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["In Force"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["pol_start_dt"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["Policy_Info_Fire_append_non_fire"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["policy_info_covers_mani"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["Intermediaries"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["Policy_Info_HH _with_Descriptions"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["Policy_info_Companies_with_descriptions"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
MyTable = Document.Data.Tables["policy_multiple_Usages"]
MyTable.RemoveRows(RowSelection(IndexSet(MyTable.RowCount,True)))
import clr
from System.Collections.Generic import List, Dictionary
from Spotfire.Dxp.Data import DataTable
from Spotfire.Dxp.Framework.ApplicationModel import NotificationService
--- Empty list to hold DataTables
Tbls = List[DataTable]()
str1 = Document.Properties["lob"] ;
str2 = "5049242";
if (str2 in str1)==True:
Tbls.Add(ACP)
str3 = "5049234";
if (str3 in str1)==True:
Tbls.Add(NAYO_IF)
str4 = "Πυρός";
if (str4 in str1)==True:
Tbls.Add(house)
Tbls.Add(companies)
Tbls.Add(use)
Tbls.Add(polstart)
Tbls.Add(interm)
Tbls.Add(covers)
--- Notification service
notify = Application.GetService[NotificationService]();
--- Execute something after tables are loaded
def afterLoad(exception, Document=Document, notify=notify):
if not exception:
Document.Properties["PIAreadyToDisplay"] = "Yes"
else:
notify.AddErrorNotification("Error refreshing table(s)","Error details",str(exception))
--- Refresh table(s)
Document.Data.Tables.RefreshAsync(Tbls, afterLoad)

Solved
In order to show the value of document property "PIAreadyToDisplay":
I inserted an text area I inserted a label - property control.
In order to do that, i selected a table in the "Data" field and i
selected my document property in the "Values" field. When the table
(of step 2) was not refreshed, document property's value was not
changed.
In step 2, i selected a table which will always have been refreshed.

Related

Update SD condition records using FM/BAPI

I am trying to update DATBI field of A* pricing condition tables using the data coming from excel file.I have tried below approaches but unable to update the entry as DATBI is key field. It creates new record instead of updating the existing one. Approaches:
FM: RV_CONDITION_COPY(with mai tain_ mode as B)
FM: RV_CONDITION_MAINTENANCE(using maintain_mode as B)
BAPI_PRICES_CONDITIONS(It changes KONH table but not A* table.Also, as per note#1135984,we shouldn't be using it)
FM:RV_KONDITION_SICHERN_V13A in update mode(This gives sy-subrc 4 in this FM post update A* from table__ syntax as the datbi is new coming from my excel file)
Idoc COND_A04(This also creates new entry instead of updating existing one)
BDC is the only approach that I can think of but looking at VK12 screen, it has been observed that based on key combination and its underlying A* tables, it should be dynamic.
Can you please help in this regard?Is there any dynamic BDC for VK12?
Undoubtedly we shouldn't use BAPI_PRICES_CONDITIONS, and note 94443 describes the problems it can cause when you push incorrect conditions into system, but sometime there is no way to avoid it. I tried this FM and it definitely worked on my system.
Here is the code for updating A009 table:
* header table
APPEND INITIAL LINE TO lt_head ASSIGNING <fs_head>.
<fs_head>-operation = '009'.
<fs_head>-cond_usage = 'A'.
<fs_head>-table_no = '007'.
<fs_head>-applicatio = 'V'.
<fs_head>-cond_type = 'ZP15'.
<fs_head>-valid_from = '20210103'.
<fs_head>-valid_to = '99991231'.
<fs_head>-cond_no = '$000000001'.
<fs_head>-varkey = 'BE110101001000635199993112'.
** items
APPEND INITIAL LINE TO lt_konh ASSIGNING <fs_konh>.
<fs_konh>-operation = '009'.
<fs_konh>-cond_no = '$000000001'.
<fs_konh>-cond_usage = 'A'.
<fs_konh>-table_no = '007'.
<fs_konh>-applicatio = 'V'.
<fs_konh>-cond_type = 'ZP15'.
<fs_konh>-valid_from = '20210103'.
<fs_konh>-valid_to = '99991231'.
<fs_konh>-created_by = sy-uname.
<fs_konh>-creat_date = sy-datum.
APPEND INITIAL LINE TO lt_konp ASSIGNING <fs_konp>.
<fs_konp>-operation = '009'.
<fs_konp>-cond_no = '$000000001'.
<fs_konp>-cond_count = '01'.
<fs_konp>-applicatio = 'V'.
<fs_konp>-cond_type = 'ZP15'.
<fs_konp>-scaletype = 'A'.
<fs_konp>-scalebasin = space.
<fs_konp>-scale_qty = '0'.
<fs_konp>-cond_p_unt = '1'.
<fs_konp>-cond_unit = 'Т'.
<fs_konp>-calctypcon = 'C'.
<fs_konp>-cond_value = '160'.
<fs_konp>-condcurr = 'EUR'.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
pi_initialmode = abap_true
TABLES
ti_bapicondct = lt_head
ti_bapicondhd = lt_konh
ti_bapicondit = lt_konp
ti_bapicondqs = lt_konm
ti_bapicondvs = lt_konw
to_bapiret2 = lt_return
to_bapiknumhs = lt_knumh
to_mem_initial = lt_buffer
EXCEPTIONS
update_error = 1
OTHERS = 2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = abap_true.
I tried the above code and record with the specified key was properly updated with new valid to field (DATAB). Updating DATBI is a bit more complicated since it is included in the primary key and cannot be updated in one step. You must delete the record with the old DATBI and the create the new one. In this blog you can read more about how to use this BAPI:
https://blogs.sap.com/2019/07/22/how-to-use-bapi_prices_conditions-to-mass-upload-price-conditions/

How do I create a service ticket using CRM_ORDER_MAINTAIN?

I'm trying to learn the Function Module CRM_ORDER_MAINTAIN and so far I managed to create a standard order with partners and their roles, however now I'm having trouble creating a service ticket with its required fields.
I tried debugging the FM when calling it from WEBUI to see what structures and tables are to be filled but I'm having a bit of trouble figuring out which ones to fill and which ones are generated and don't know if I'm missing something small somewhere that's causing it not to save.
I think the error lies in this part of the code that handles Categorization, because the other code that handles adding partners worked for the standard order.
I'm not filling any GUIDS and only filling HANDLES because that's what I did for the standard order.
*****categorization: motive+submotive******
clear ls_input_fields.
clear ls_fieldsname.
ls_fieldsname-fieldname = 'CONC_KEY'.
INSERT ls_fieldsname INTO TABLE ls_input_fields-field_names.
ls_input_fields-ref_handle = 1."
ls_input_fields-ref_kind = gc_object_kind-orderadm_h.
ls_input_fields-objectname = 'SERVICE_OS'.
ls_subject-ref_handle = ls_orderadm_h-handle.
ls_subject-ref_handle_h = ls_orderadm_h-handle.
ls_subject-katalogart = 'Z1'.
ls_subject-codegruppe = 'ZCA00001'.
ls_subject-code = 'Z044'.
append ls_subject TO ls_osset-subject.
ls_osset-ref_handle = ls_orderadm_h-handle.
ls_osset-profile_type = 'A'.
ls_osset-subject_profile = 'ZCCCAST'.
append ls_osset to ls_service_os-osset.
ls_service_os-ref_handle = ls_orderadm_h-handle.
append ls_service_os to it_service_os.
INSERT ls_input_fields INTO TABLE lt_input_fields.
ls_subject-ref_handle = ls_orderadm_h-handle.
ls_subject-ref_handle_h = ls_orderadm_h-handle.
ls_subject-katalogart = 'Z1'.
ls_subject-codegruppe = 'ZCA00002'.
ls_subject-code = 'Z009'.
append ls_subject TO ls_osset-subject.
ls_osset-ref_handle = ls_orderadm_h-handle.
ls_osset-profile_type = 'A'.
ls_osset-subject_profile = 'ZCCCAST'.
append ls_osset to ls_service_os-osset.
ls_service_os-ref_handle = ls_orderadm_h-handle.
append ls_service_os to it_service_os.
INSERT ls_input_fields INTO TABLE lt_input_fields.
Any help is appreciated
For Service OS there is a multilevel categorization up to four levels. You can check the hierarchy via CRM_ORDER_READ FM in parameter ET_SERVICE_OS.
Also, you can check the hierarchy in the below structure CRMT_SRV_OSSET_WRK
To maintain the data for more than 2 levels of hierarchy you have to create a new ref GUID. You have to prepare and fill data to Create OS as below
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_16 = lv_ref_guid.
ls_subject-ref_handle = '0000000000'.
ls_subject-ref_guid = lv_ref_guid. " newly created ref GUID
ls_subject-cat_id = 'As per your req.'.
ls_subject-katalog_type = ''.
ls_subject-mode = 'A'. "For creation A, for update B
" maintain other Subject parameter as per your requirement
APPEND ls_subject TO lt_subject.
" you can skip preparing Ref-Object structure if you don't want to update
ls_refobj-ref_guid = lv_ref_guid. " newly created ref GUID
ls_refobj-product_id = "Product ID". " optional
ls_refobj-ref_handle = '0000000000'.
ls_refobj-main_object = abap_true.
ls_refobj-mode = 'A'. " mode A for creating, B for update
INSERT ls_refobj INTO TABLE lt_refobj.
ls_osset-ref_handle = '0000000000'.
ls_osset-ref_guid = "Header or Item GUID of Service".
ls_osset-subject_profile = 'SERVICE'.
ls_osset-profile_type = 'A'. " service profile type
ls_osset-refobject = lt_refobj.
ls_osset-subject = lt_subject.
INSERT ls_osset INTO TABLE lt_osset.
ls_service_os-ref_guid = "Header or Item GUID of Service".
ls_service_os-ref_kind = "A or B". " A for Header and B for Item
ls_service_os-osset = lt_osset.
INSERT ls_service_os INTO TABLE lt_service_os.

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.

Update BSEG-ZUONR with Function Module

I successfully change BKPF-BKTXT with FM CHANGE_DOCUMENT but why can't I change BSEG-ZUONR with FM CHANGE_DOCUMENT too?
Here's the FM CHANGE_DOCUMENT:
CALL FUNCTION 'CHANGE_DOCUMENT'
TABLES
T_BKDF = t_bkdf
T_BKPF = t_bkpf
T_BSEC = t_bsec
T_BSED = t_bsed
T_BSEG = t_bseg
T_BSET = t_bset
* T_BSEG_ADD =
.
Here's the code to change BKPF-BKTXT (succeeded):
wa_t_bkpf-mandt = sy-mandt.
wa_t_bkpf-bukrs = '1000'.
wa_t_bkpf-gjahr = gjahr_import.
wa_t_bkpf-belnr = belnr_import.
wa_t_bkpf-bktxt = zuonr_import.
APPEND wa_t_bkpf TO t_bkpf.
Here's the code to change BSEG-ZUONR (failed):
wa_t_bseg-mandt = sy-mandt.
wa_t_bseg-bukrs = '1000'.
wa_t_bseg-gjahr = gjahr_import.
wa_t_bseg-belnr = belnr_import.
wa_t_bseg-buzei = '1'.
wa_t_bseg-zuonr = zuonr_import.
APPEND wa_t_bseg TO t_bseg.
As author has no time to confirm, I can do this for him as I just tested this case.
If we pass to FM all parameters from its signature the update runs smoothly. For example, like this:
DATA: lt_bkdf TYPE TABLE OF bkdf,
lt_bkpf TYPE TABLE OF bkpf,
wa_bkpf TYPE bkpf,
lt_bsec TYPE TABLE OF bsec,
wa_bseg TYPE bseg,
lt_bsed TYPE TABLE OF bsed,
lt_bseg TYPE TABLE OF bseg,
lt_bset TYPE TABLE OF bset.
wa_bkpf-mandt = sy-mandt.
wa_bkpf-bukrs = '5900'.
wa_bkpf-gjahr = gjahr_import.
wa_bkpf-belnr = belnr_import.
wa_bkpf-bktxt = 'Batch'.
APPEND wa_bkpf TO lt_bkpf.
wa_bseg-mandt = sy-mandt.
wa_bseg-bukrs = '5900'.
wa_bseg-gjahr = gjahr_import.
wa_bseg-belnr = belnr_import.
wa_bseg-buzei = '1'.
wa_bseg-zuonr = '20151131'.
APPEND wa_bseg TO lt_bseg.
CALL FUNCTION 'CHANGE_DOCUMENT'
TABLES
t_bkdf = lt_bkdf
t_bkpf = lt_bkpf
t_bsec = lt_bsec
t_bsed = lt_bsed
t_bseg = lt_bseg
t_bset = lt_bset
.
COMMIT WORK.
All FM table parameters except the last one are mandatory.
Do not use this FM
CALL FUNCTION 'CHANGE_DOCUMENT'
This FM is changing all other fields to initial if not provided.
CALL FUNCTION 'FI_DOCUMENT_CHANGE'
It seems that this FM cannot be used to change line item which has account type (BSEG-KOART) - 'S' (GL Account).
Try this FM:
'FI_ITEMS_MASS_CHANGE'
The field zuonr references to an object it belongs to.
For example a purchase order.
Lets asume you pay a position of a purchase order.
A document in bkpf/bseg is created (and more).
Bseg-Zuonr contains the number of this purchase order position.
If you were allowed to change this field, you would destroy the referential integrity of the data. It would point to a purchase order position it was not created from or one that doesn't exist at all.
So from a business standpoint it makes no sense to ever change this field after it is created, therefore SAP will never allow to change it.

How to disable validating row when it loses focus in Datagridview

I have a datagridview, and I would like to allow the end user to type whateever he wants in the rows and the validation will be done later programmatically.
For example
Column1 : AllowDBNull = true
The user will still be able skip the cell related to Column1 and move to another row (may be to fill it later)
And the validation will be performed once he clicks ValidateButton.
I have been looking to :
DataGridView.CausesValidation = False
But that was unsuccessful.
I was trying also
DataSourceUpdateMode = DataSourceUpdateMode.Never
but couldn't apply this property to DataGridView.Datasource
Here is a bit of my code
'CreateMasterDataTable and CreateDetailDataTable are two functions that return two datatables
Master_DT = CreateMasterDataTable()
Detail_DT = CreateDetailDataTable()
DataSet.Tables.Add(Master_DT)
DataSet.Tables.Add(Detail_DT)
DataSet.Relations.Add("Relation", Master_DT.Columns("City"), Detail_DT.Columns("City"))
Master_BindingSource.DataSource = DataSet
Master_BindingSource.DataMember = Master_DT.TableName
Details_BindingSource.DataSource = Master_BindingSource
Details_BindingSource.DataMember = "Relation"
DataGridView.DataSource = Details_BindingSource
Does anyone have an idea on how to disable the row validation once it loses focus please ?
Thanks