Function modules to update table bsid (field: cession_kz) - function

For a certain program I need to update table bsid. The field cession_kz needs to be updated. I've looked for many function modules but none of them fit my needs. Does someone know a best practice to solve this problem?

BSID is a secondary index for BSEG customer items, so updating it directly will lead to database inconsistencies and any update must go via BSEG.
You can use a function module like FI_ITEMS_MASS_CHANGE. This FM updates BSEG by running a BDC for transaction FB02 (Change Document). When a relevant (customer) item is changed in BSEG, the corresponding BSID record is changed as well.
See example code below:
DATA: ls_bseg TYPE bseg,
lt_errdoc TYPE tpit_t_errdoc,
lt_fname TYPE tpit_t_fname,
lt_buztab TYPE tpit_t_buztab.
* Field name to be changed
APPEND 'CESSION_KZ' TO lt_fname.
* New field value
ls_bseg-cession_kz = 'AB'.
* Selection of items to be changed
* Only select customer items to avoid problems in batch input
SELECT bukrs belnr gjahr buzei koart umskz bschl mwart mwskz
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE lt_buztab
WHERE belnr = '1400000000' AND
bukrs = '1000' AND
koart = 'D'. "Customers
CALL FUNCTION 'FI_ITEMS_MASS_CHANGE'
EXPORTING
s_bseg = ls_bseg
IMPORTING
errtab = lt_errdoc[]
TABLES
it_buztab = lt_buztab
it_fldtab = lt_fname
EXCEPTIONS
bdc_errors = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Make sure you allow changes in maintenance view V_TBAER with transaction SM30 or through customizing:
Financial Accounting → Financial Accounting Global Settings → Document → Line Item → Document Change Rules, Line Item.
Note:
Pledging indicators should be defined for all company codes passed to the FM:
Financial Accounting → Accouts Receivable and Accounts Payable → Customer Account → Master Data → Preperation for creating master data → Define Accounts Receivable Pledging Indicator.
If not, the field will not be available for the batch input and the FM will result in an error.

Related

implementing users notification on the same table or on a seperated relationed table (laravel)

i have a user and invoice table which i want to make notifications for them that they will be able to turn them on/off .
now my question is that should i add 5 columns for example on users table and 3 on invoice table to make it on or off or make 2 tables as below :
notification_list and : notification_user to make user to be able to turn the notification from user model and invoice on or off .
the problem here is that notification_user will be a massive table as soon as the users table growth . for every user i need to add 5 records at least .
i am using laravel and the tables and relations of it .so i can use morph relations but i still dont know which one is better to implement it inside the table or on a seperated table . thanks
If this can be toggled globally for all invoices all at once
You definitely need notification_list, but instead of notification_user I'd add extra column to users table or create something like users_preferences to store multiple user preferences. Creating separate table for each of preferences doesn't seem like a good solution
If this should be done for each invoice separately
You actually can't add extra columns to invoices and users table as you would be required to have one column for each user.
You have to use your solution Nr 2. But bare in mind that you don't need to create any records in table unless they differ from default behavior. That means you only add record to table when user toggles button. Also you can delete these records once invoice is no longer active. So this new table doesn't really grow as fast.
You can also use only one field for your user notification preferences. but this solution require good structuring.
It's base on the fact that what you need to track is just the state of the preference (on or off).
so save it as an integer containing the prefrence of the user. here is an example:
$preference1 = 1;
$preference2 = 0;
$preference3 = 0;
$preference4 = 1;
$preference5 = 0;
//the value to save is the integer result of the binary 01001
$preference = 1 * $preference1 + 2 * $preference2 + 4 * $preference3 + 8 * $preference4 + 16 * $preference5;
//or simply
$preference = bindec($pref5.$pref4.$pref3.$pref2.$pref1);
Now to check if a specific preference is enabled, use the bitwise comparison
if ($preference & 4) { //preference 3 has value 4
//preference 3 is on.
}
//you can also check multiple prefrences at the same time
if ($preference & 5 == 5) { //this is preference 3 and preference 1
//user has both preference enabled
}
You can also use it in your database request
$users = User::whereRaw("BIT_COUNT('prefrence' & 4)")->get();
//this will give you all the users having preference 3 enabled
To add more structure to this solution, you should declare constants in your user model
class User extends Authenticatable
{
const PREFRENCE1 = 1;
const PREFRENCE2 = 2;
const PREFRENCE3 = 4;
const PREFRENCE4 = 8;
const PREFRENCE5 = 16;
//...
}
//This way everything will make more sense like:
$users = User::whereRaw("BIT_COUNT('prefrence' & ".User::PREFERENCE3.")")->get();
if ($preference & User::PREFERENCE3) {
//preference 3 is on.
}
PS: Make sure that the integer size in the database in not under your number of preference to save.

Update planned order - two committed modifications, only one saved

I need to update two information on one object: the quantity (PLAF-gsmng) and refresh the planned order via the module function 'MD_SET_ACTION_PLAF'.
I successfully find a way to update each data separately. But when I execute the both solutions the second modification is not saved on the database.
Do you know how I can change the quantity & set the action on PLAF (Planned order) table ?
Do you know other module function to update only the quantity ?
Maybe a parameter missing ?
It's like if the second object is locked (sm12 empty, no sy-subrc = locked) ... and the modification is not committed.
I tried to:
change the order of the algorithm (refresh and after, change PLAF)
add, remove, move the COMMIT WORK & COMMIT WORK AND WAIT
add DEQUEUE_ALL or DEQUEUE_EMPLAFE
This is the current code:
1) Read the data
lv_plannedorder = '00000000001'
"Read PLAF data
SELECT SINGLE * FROM PLAF INTO ls_plaf WHERE plnum = lv_plannedorder.
2) Update Quantity data
" Standard configuration for FM MD_PLANNED_ORDER_CHANGE
CLEAR ls_610.
ls_610-nodia = 'X'. " No dialog display
ls_610-bapco = space. " BAPI type. Do not use mode 2 -> Action PLAF-MDACC will be autmatically set up to APCH by the FM
ls_610-bapix = 'X'. " Run BAPI
ls_610-unlox = 'X'. " Update PLAF
" Customize values
MOVE p_gsmng TO ls_plaf-gsmng. " Change quantity value
MOVE sy-datlo TO ls_plaf-mdacd. " Change by/datetime, because ls_610-bapco <> 2.
MOVE sy-uzeit TO ls_plaf-mdact.
CALL FUNCTION 'MD_PLANNED_ORDER_CHANGE'
EXPORTING
ecm61o = ls_610
eplaf = ls_plaf
EXCEPTIONS
locked = 1
locking_error = 2
OTHERS = 3.
" Already committed on the module function
" sy-subrc = 0
If I go on the PLAF table, I can see that the quantity is edited. It's working :)
3) Refresh BOM & change Action (MDACC) and others fields
CLEAR ls_imdcd.
ls_imdcd-pafxl = 'X'.
CALL FUNCTION 'MD_SET_ACTION_PLAF'
EXPORTING
iplnum = lv_plannedorder
iaccto = 'BOME'
iaenkz = 'X'
imdcd = ls_imdcd
EXCEPTIONS
illegal_interface = 1
system_failure = 2
error_message = 3
OTHERS = 4.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
If I go on the table, no modification (only the modif. of the part 2. can be found on it).
Any idea ?
Maybe because the ls_610-bapco = space ?
It should be possible to update planned order quantity with MD_SET_ACTION_PLAF too, at least SAP Help tells us so. Why don't you use it like that?
Its call for changing the quantity should possibly look like this:
DATA: lt_acct LIKE TABLE OF MDACCTO,
ls_acct LIKE LINE OF lt_acct.
ls_acct-accto = 'BOME'.
APPEND lt_acct.
ls_acct-accto = 'CPOD'.
APPEND lt_acct.
is_mdcd-GSMNG = 'value' "updated quantity value
CALL FUNCTION 'MD_SET_ACTION_PLAF'
EXPORTING
iplnum = iv_plnum
iaenkz = 'X'
IVBKZ = 'X'
imdcd = is_mdcd "filled with your BOME-related data + new quantity
TABLES
TMDACCTO = lt_accto
EXCEPTIONS
illegal_interface = 1
system_failure = 2
error_message = 3.
So there is no more need for separate call of MD_PLANNED_ORDER_CHANGE anymore and no more problems with update.
I used word possibly because I didn't find any example of this FM call in the Web (and SAP docu is quite ambiguous), so I propose this solution just as is, without verification.
P.S. Possible actions are listed in T46AS table, and possible impact of imdcd fields on order can be checked in MDAC transaction. It is somewhat GUI equivalent of this FM for single order.

VBA code to analyze a HTML table based off certain conditions

So I need to screen scrape data off a website and return it to a spreadsheet based off if a charge amount matched as well the date was the most recent in the table. If there was simply one line in the table, the macro pulls that accordingly. So most of the code is good, I am connected to the website, pulling everything effectively. Where I am struggling is getting the logic to work where the two amounts match as well as the date being the most recent in the HTML table.
I guess what my question is how do I loop through Item(5) the column of that table and specify it to choose the most recent date, also setting the value so that it only finds the one equal to the charge amount. I only want a one to one match. I am new to this so if anyone wants to help me I would greatly appreciate it.
Set IHEC = iHTMLDoc.getElementsByTagName("TR")
If IHEC.Length > 2 Then
For index = 0 to IHEC.Length - 1
Set IHEC_TD = IHEC.Item(index).getElementsByTagName("TD")
Do Until IHEC.Length <2 Or index = IHEC.Length - 1
If IHEC.TD.Item(3).innerText = myBilledAmount Then
myItem1 = IHEC_TDItem(0).innerText
myItem2 = IHEC_TDItem(1).innerText
myItem3 = IHEC_TDItem(2).innerText
myItem4 = IHEC_TDItem(3).innerText
myItem5 = IHEC_TDItem(4).innerText
myItem6 = IHEC_TDItem(5).innerText
myItem7 = IHEC_TDItem(6).innerText
myItem8 = IHEC_TDItem(7).innerText
myItem9 = IHEC_TDItem(8).innerText
End If
End If
Loop
Next Index

BigCommerce Stencil - Product Variant Stock Levels

A client wants to set up A/B testing on the Product Detail Page related to the stock_level of a product's variants. Once the user selects their options, if the quantity is less than 5, I'd show something like "Hurry, only 3 more in stock"...
I believe I have the correct Inventory settings enabled, because I can retrieve the stock_level of a product without options.
Has anyone had success pulling variant SKU stock_levels in stencil?
Thanks
This can be done using javascript in the assets/js/theme/common/product-details.js file. On initial page load and each time a product option is changed, there is a function updateView(data) that is called. The data parameter contains all the info you need for the selected variation.
Starting on line 285, replace this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
this.showMessageBox(data.stock_message || data.purchasing_message);
with this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
if(data.stock < "5") {
data.stock_message = "Hurry, only " + data.stock + " left!";
}
this.showMessageBox(data.stock_message || data.purchasing_message);

Deleting record from database based on an action in a page

I am making an application for a car dealership. I have a page for stocks and a page for sales. Whenever I make a new entry in sales, I want the corresponding entry to be deleted from the stocks page.
My db for sales is
db.define_table('sales',
Field('customer_name','string'),
Field('village','string'),
Field('mobile_number','integer'),
Field('model','string',required=True,requires=IS_IN_SET(['1035DI','241DI','241DI(P.S.)','245DI','245DI(P.S.)','9000DI','9000DI(P.S)','5245DI','9500DI'])),
Field('engine_number','string'),
Field('chassis_number','string'),
Field('date_of_sale','date'),
Field('sale_price','integer'),
Field('bill_number','integer'),
Field('mode_of_payment','string',requires=IS_IN_SET(['Cash','Cheque']))
)
My db for stock is
db.define_table('stock',
Field('model','string',required=True,requires=IS_IN_SET(['1035DI','241DI','241DI(P.S.)','245DI','245DI(P.S.)','9000DI','9000DI(P.S)','5245DI','9500DI'])),
Field('engine_number','string',required=True),
Field('chassis_number','string',required=True),
Field('invoice_number','integer',required=True),
)
Engine number and chassis number is unique for each entry.
You didn't post any controller code, so I'm just making a simple untested example. I'm assuming you're using SQLFORM, and your sales controller function is just named "sales"
#controller, i.e. default.py
def sales():
form = SQLFORM(db.sales)
if form.process().accepted:
engine_number = form.vars.engine_number
chassis_number = form.vars.chassis_number
db((db.stock.engine_number == engine_number) & (db.stock.chassis_number == chassis_number)).delete()
return dict(form=form)