RPG SETLL Usage with Partial Key - rpgle

I have a task to read a header and detail tables.
Header get the ordernumber
Detail.
Key is ordernumber, orderline.
c Keyordnum Setll detail
c Iffound
c Keyordnum reade detail
c* read for each orderline update the warehouse field
c xxxxxxx update detailformat
Problem I am having is error for writing a duplicate record.
Question 1. Is the xxxxxx above where I can make a composite key of ordernumber and orderline and updaten this way? the issue is how to update each line.
If not this way how do you solve the issue of reading partial key and updating each line?

UPDATE doesn't have a factor 1. You don't use a key when using UPDATE. The record updated is the last record you read.
Your code doesn't appear to be complete. I'd expect something like so: (written in free-format as I've not written fixed format in 10 years)
setll keyordno detail;
if %found(detail);
reade keyordno detail;
dow not %eof(detail);
//set warehouse field
update detailformat;
reade keyordno detaill;
enddo;
endif;
You shouldn't be seeing duplicate records unless there is a unique key involving the warehouse field.

xxxxxx above as factor with update cannot have a composite key, if there is a duplicate, it is already read before the update.
so if you are not sure whether duplicate ordernumber is read from the header itself, have an additional check with a work variable (wk_ordernum) for value is changed to read again. something like this..
if wk_ordernum <> ordernumber; //check duplicate ordernumber
wk_ordernum = ordernumber;
setll keyordno detail;
if %equal(detail);
reade keyordno detail;
dow not %eof(detail);
//set warehouse field
update detailformat;
reade keyordno detaill;
enddo;
endif;
endif; // end check duplicate ordernumber

Related

Contradicting information on CQL counter type in docs

I have been looking for some information on counters and it seems like there is some rather contradicting info regarding to what you can do with them.
According to the official DataStax Documentation (https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/counter_type.html) "You cannot set the value of a counter, which supports two operations: increment and decrement.".
However, if we look into the BATCH CQL documentation (https://docs.datastax.com/en/dse/6.0/cql/cql/cql_reference/cql_commands/cqlBatch.html#cqlBatch__batch-updates), the bottom page example includes setting, adding, and subtracting a counter variable within a batch.
This example is likely also breaking the rule that having a counter in a table should only have counters for the rest of the table.
So what really are the limitations / usability for counters in cassandra DataStax? There does not seem to be a clear definition.
I think it's just a misunderstanding. Those pages do not contradict each other.
The CQL Counter type page correctly states that it is not possible to set the value of a counter column. For example, this is NOT valid:
UPDATE ks.counter_table
SET count = 10
WHERE pk = ?
The only valid operations on a counter column are increment and decrement. Here are some examples:
UPDATE ks.counter_table
SET count = count + 1
WHERE pk = ?
UPDATE ks.counter_table
SET count = count - 1
WHERE pk = ?
In the BATCH command page, the first 2 examples are increment operations:
UPDATE cycling.popular_count
SET popularity = popularity + 1
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
UPDATE cycling.popular_count
SET popularity = popularity + 125
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
The last example is a decrement operation:
UPDATE cycling.popular_count
SET popularity = popularity - 64
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
I can't see how the examples would break the rule about only having counters in a counter table. From the examples, I would infer that the table schema is:
CREATE TABLE cycling.popular_count
id uuid,
popularity counter,
PRIMARY KEY(id)
)
You can have as many non-counter columns in the table as long as they are part of the PRIMARY KEY.
As a side note, it is not correct to refer to the software as either "Cassandra DataStax" or "DataStax Cassandra" so I've updated the title accordingly. DataStax (the company) does not own Cassandra. The more appropriate reference is "Apache Cassandra" or just plain "Cassandra". Cheers!

Netsuite Suitescript: How to retrieve records based on last modified date?

I am trying to retrieve records in Netsuite via SuiteScript. I would like to use the lastmodifieddate column to fetch record after a certain timestamp.
I am currently doing:
var filters = [new nlobjSearchFilter('lastmodifieddate', null, 'notbefore', time)];
var columns = [new nlobjSearchColumn('lastmodifieddate')];
var newSearch = nlapiCreateSearch(table, filters, columns);
var searchResultSet = newSearch.runSearch();
var back = nextEndIndex - 1000
var results = searchResultSet.getResults(back, nextEndIndex);
Where time is a datetime JS, nextEndIndex index counter for results.
This works for some objects but majority of Netsuite objects do not have the lastmodifieddate column in the record browser. Is there a built in variable for the lastmodifieddate? And if there is, how can I use it in nlapiCreateSearch? If you have better ways to do it, I would be grateful for the info.
Here is a simple example for SuiteScript 2.0.
define(['N/search'],function(search){
function test(chkDate){
log.debug(chkDate);
var empSearch=search.create({
type:search.Type.EMPLOYEE,
columns:['internalid','firstname','lastmodifieddate'],
filters:['lastmodifieddate','after',chkDate]
}).run().each(function(result){
log.debug(JSON.stringify(result));
return true;
});
}
test('05/30/2017');
});
This example is searching for employees, since I was not sure which record type you were looking at. Below are links to the information you can use to build out your searches:
Records Browser (look at the bottom of each section in the filters and columns):
Search Operators (shows which ones to use for which field types)
API Docs
Transactions are slightly different than entities. Transactions have lines. If you are trying to determine the true last modified date of a transaction, you may need to consider using the "Line Last Modified" field in place of "Last Modified Date." Try writing a simple search to pull Sales orders. Include "Last Modified Date" and "Line Last Modified." Then write a simple formula to show those that don't match. When I did this, there were a number of mismatches, with instances of "Line Last Modified" being more than 1 month later than "Last Modified Date." So if you are looking for the true last modified date, you may need to use the max "Line Last Modified."
You could use a 'Max' Summary Filter on {systemnotes.date} - you will of course need to Group by record (document number or internal id for example) for this to show correct results.

How can I view the reference number of SOOrder that I already copy from Quotation in QT Type?

I mean I copy SOOrder #SO001 from the Quotation #QT001. Anyways, I see the reference of Quotation that SOOrder copy from so I want the same result in Quotation. I created trigger when I inserted new SO and then update to QT. By Manually, insert one by one it works well. Yet it got message error when I save SO that already converted from quotation: 'Error #91: Another process has updated 'SOOrder' record. Your changes will be lost.'. For sure, I think I will miss any steps.
CREATE TRIGGER tgg_SOOrder
ON dbo.SOOrder
FOR INSERT
AS
--Update QT record with SO record's order info
UPDATE SOOrder
SET OrigOrderType = 'SO',
OrigOrderNbr = i.OrderNbr
FROM SOOrder so
JOIN inserted i
ON so.OrderNbr = i.OrigOrderNbr
WHERE so.OrderType = 'QT'
AND i.OrderType = 'SO'
AND so.CompanyID = 2--Business logic constraint
AND so.OrigOrderNbr IS NULL
AND so.OrigOrderType IS NULL

How do you add elements to a set with DataStax QueryBuilder?

I have a table whose column types are
text, bigint, set<text>
I'm trying to update a single row and add an element to the set using QueryBuilder.
The code that overwrites the existing set looks like this (note this is scala):
val query = QueryBuilder.update("twitter", "tweets")
.`with`(QueryBuilder.set("sinceid", update.sinceID))
.and(QueryBuilder.set("tweets", setAsJavaSet(update.tweets)))
.where(QueryBuilder.eq("handle", update.handle))
I was able to find the actual CQL for adding an element to a set which is:
UPDATE users
SET emails = emails + {'fb#friendsofmordor.org'} WHERE user_id = 'frodo';
But could not find an example using QueryBuilder.
Based off of the CQL I also tried:
.and(QueryBuilder.set("tweets", "tweets"+{setAsJavaSet(update.tweets)}))
But it did not work. Thanks in advance
Use add (add one element at a time) or addAll (more than one any number of element at a time) method to add to a set.
To extend Ananth's answer:
QueryBuilder.add does not support BindMarker. To use BindMarker while adding in set, it is required to use QueryBuilder.addAll only.*
*Just a note, Collections.singleton may come in handy in this regard.
Using #Ananth and #sazzad answers, the code below works:
Session cassandraSession;
UUID uuid;
Long value;
Statement queryAddToSet = QueryBuilder
.update("tableName")
.with(QueryBuilder.addAll("setFieldName", QueryBuilder.bindMarker()))
.where(QueryBuilder.eq("whereFieldName", QueryBuilder.bindMarker()));
PreparedStatement preparedQuery = cassandraSession.prepare(queryAddToSet);
BoundStatement boundQuery = preparedQuery.bind();
boundQuery
.setUUID("whereFieldName", uuid)
.setSet("setFieldName", Collections.singleton(value));
session.execute(boundQuery);

SQL Azure Database / Can't Insert Record into a Table / ID not getting set during SubmitChanges

In the following instance, I have tried to simplify an issue to root components.
I've got a very simple SQL Azure database where I created a test table called Table1. Azure creates an ID field with Is Required, Is Primary Key checked. It will NOT allow to check the box Is Identity. There are a couple of other fields which are simply required.
In my VS2012 Project, I have created an LinqToSql Class which created a ProductionDataClasses1.dbml object.
I simply want to add a record to this table thru the method shown below. From what I am reading, ID would be set during the SubmitChanges() after InsertOnSubmit(NewRecord) is specified.
It does work the first time but value is set to zero. On subsequent save, I get an exception (basically it a duplicate record because ID=0 already exists).
To put this into context, I have included some sample code below. The idea is to first check if the record exists and update. If not, I want to add a record.
My question is... Do I need to manually set ID? If so, how do I set the value to an int and how to a retrieve the next value. I tried changing to a Guid but not allowed.
Here is my code sample:
public bool AddTestRecord(string someValue)
{
ProductionDataClasses1DataContext context = new ProductionDataClasses1DataContext();
try
{
var ExistingRecord = context.Table1s.SingleOrDefault(c => c.TextKey == someValue);
if (ExistingRecord == null)
{
var NewRecord = new Table1();
// NewRecord.ID = ???? ; How Do I Manually Set. It is getting set to 0 causing a duplicate value exception
NewRecord.TextKey = someValue;
NewRecord.AnotherValue = DateTime.Now.ToShortTimeString();
context.Table1s.InsertOnSubmit(NewRecord);
}
else
{
ExistingRecord.AnotherValue = DateTime.Now.TimeOfDay.ToString();
}
context.SubmitChanges();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
context.SubmitChanges();
}
}
I would suggest manually running a SQL script to alter the table and make the column an identity. Look at this answer
Adding an identity to an existing column
Thanks for your reply.
I just was finally able to make this work on a new table and will try to follow along your instructions to make modifications to my real table. My code (as written above) was OK so the issue is in the SQL Azure table definition.
I found the issue is that when you create a new table in SQL Azure, it creates a table with three fields, ID, Column1, Column2. By default, ID is set as the Primary Key but none are checked as Is Identity.
To make this work, I made ID the Is Identity and unchecked PrimaryKey and Column1 the In Primary Key. Thus when a new record is saved, the ID is set and Column1 is checked to make sure it is not already in the system. I had to do this when the table was first created. Once saved, it would not allow me to change.
Afterwards, I updated my Linq To SQL class and dropped the new table in. I noted that now the AutoGenerated Value on ID and PrimaryKey on Column1 was set and my code worked.

Resources