How to encounter error UPDATE and DELETE without prior input WHEN want to update to SUBFILE in RPGLE - rpgle

I'm having an error shown as in the picture below :
If I enter blank option or wrong option, I will get the error as above
When this error occur, I cant Update, Delete and Refresh.
It happens when I want to update existing record and also when I put wrong option and blank option. When I debug, I realize that the error comes when want to UPDATE SUBFILE.
OSR Begsr
ReadC SFL01
DOW *IN91 = *OFF
Select
OPT WhenEQ 2
Exsr UPDSR
OPT WhenEQ 4
Exsr DLTSR
OPT WhenEQ 5
Exsr DSPSR
Other
Exsr ERRSR
EndSL
Clear OPT
UPDATE SFL01
READC SFL01
Enddo
Endsr
What should I do? Do I need to chain from logical file before UPDATE SUBFILE?
Please help me. Thanks in advance

You should show the error as text, not include a link to a picture.
Also give the error ID, CPFxxxx not just the description.
The message is pretty self-explanatory, and you can find out even more details in the second level message text. (Hit F1 on the message if an active job or look at the joblog if the job has ended.)
Your UPDSR or DLTSR is doing an UPDATE or DELETE op-code without first reading the record via CHAIN.

the indicator *in91 has to be specified as the EQ result indicator of the READC statement. Both READC statements. Or, replace the test for *in91 with a test of the built in %eof variable.
c OSR Begsr
c ReadC SFL01 91
c DOW *IN91 = *OFF
** ------------------------- osr_eof -----------------------
c OSR_eof Begsr
c ReadC SFL01
c DOW %eof = '0'
c Select
c OPT WhenEQ 2
c Exsr UPDSR
c OPT WhenEQ 4
c Exsr DLTSR
c OPT WhenEQ 5
c Exsr DSPSR
c Other
c Exsr ERRSR
c EndSL
c Clear optn
c UPDATE SFL01
c READC SFL01
c Enddo

Related

PySpark: Check if value from one column matches another on next row

So I have a data frame listed as follows:
StartTime StartName StopTime StopName
10.00 A 11.00 B
11.00 B 13.00 C
14.00 D 17.00 A
And I would like to filter out where the StartName column on one row equals the StopName column on the next row. I'm hoping to create a new data frame as follows:
StartTime StartName StopTime StopName
13.00 C 14.00 D
I'm a bit lost, I've tried using window but couldn't figure it out. Any help would be greatly appreciated.
Using a Window works: you can add the StopName of the prevoius row as new column to each row and then filter out according to your requirement:
w = Window.orderBy("StartTime").rowsBetween(-1,-1)
df = ...
df = df.withColumn("PrevStopName", F.lag("StopName").over(w))
df = df.filter("StartName <> PrevStopName").drop("PrevStopName")
As the window definition does not include a partition, the warning
WARN WindowExec: No Partition Defined for Window operation! Moving all data to a single partition, this can cause serious performance degradation.
will appear.
To prevent the performance problem, the input data should also contain a grouping column that groups together all rows that should be considered together in the window operation. This column should then be used as parameter of Window.partitionBy.

for given data i need to find the count of "a" in the column Key

Key
----------
0 a
1 a
2 b
3 b
4 a
5 c
so far i tried this:
df.groupby(["key1"],).count()
However it is also showing the counts of b and c, i want only for a.
Create mask and count by sum:
df["Key"].eq('a').sum()

How to apply template in Automatic Recode in SPSS?

I have saved template (`.sat) file, but cannot apply it. When I apply it, the OK button is still disabled. Please see the image:
Could this be because of the trial version?
Thanks.
If you're within the 14-day trial period, you have everything available to you, so it isn't the license.
1). A common mistake is to forget to fill in the "New Name" field. Make sure you have done that and clicked 'Add New Name'. Until you do, OK is disabled.
2). Apart from that, if you haven't tried in syntax, then could you please start the program and try something like this:
DATA LIST FREE /x (F1) a (A1).
BEGIN DATA.
1 a 2 b 3 c 4 d 5 e
END DATA.
DATASET NAME data1.
AUTORECODE VARIABLES=a /INTO na
/SAVE TEMPLATE='<your path>/template.sat'
/PRINT.
DATA LIST FREE /y (F1) a (A1).
BEGIN DATA.
1 a 2 e 3 d 4 a 5 c 6 b 7 c 8 e 9 g 10 z
END DATA.
DATASET NAME data2.
DATASET ACTIVATE data2.
AUTORECODE VARIABLES=a /INTO na
/APPLY TEMPLATE='<your path>/template.sat'
/PRINT.
If you get an error with AUTORECODE then there is a problem with your installation; please reply with whatever the error message is.

Formula to determine latest ordered entry of unique table values

I'm looking for some help in creating a column populated with 1's for the (in this example) 'latest' revision of each unique entry (in another column).
Project # Rev Flag
=========================
FCA1 A
FCA1 D 1
FCA1 B
FCA1 B
FCA1 C
FCA1 C
BRS1 A
BRS1 B 1
BRS2 A 1
FCA2 A
FCA2 A
FCA2 B
FCA2 B
FCA2 C 1
FCA2 C 1
BRS3 A 1
FCA1 D 1
FCA1 D 1
FCA1 A
My desired output is in the 'Flag' column in the above example. For example, all Rev D's for project number FCA1 and all Rev C's for FCA2. Same thing for the other values under Project #. Note that I'd like this done independent of the order or sorting of the entries. The example just happens to show them in some sort of order for clarity.
I'm working with Excel 2010.
Thank you!
The formula you want is:
=IF(MAX(INDEX(($A$2:$A$20=$A2)*CODE($B$2:$B$20),0))=CODE($B2),1,"")
E.g.:
EDIT
Re the question how can I error handle when there is a blank entry in the Rev column? It's not possible if you are using A, B, C and D as revision codes because the CODE function won't handle an empty string in the formula I presented. If you switch to number-based revisions then it will work with this formula:
=IF(MAX(INDEX(($A$2:$A$20=$A2)*$B$2:$B$20,0))=$B2,1,"")
Noting that this is the same formula as above but without the CODE function usage. E.g. if A=1, B=2, C=3 and D=4 then:

How to count every word occurence in a string in a ORACLE loop?

I've got a problem which seems simple at first, but really isn't. I'm storing words in a table in such way that pair of strings "A B C D E" and "D E F" becomes:
id value
-- -----
1 A
1 B
1 C
1 D
1 E
2 D
2 E
2 F
And i pass to my ORACLE procedure string which looks like this: "A B C D G". And now I want to check percentage of similarity between strings in the database and string passed as a parameter.
I presume that I have to use one of split functions and use an array. Later check if every word in passed string occurs in the table and then count ids. But there`s a twist: I need precise percentage value.
So, result from example above should look like this:
id percentage
-- ----------
1 80 -- 4 out of 5 letters exists in query string (A B C D)
2 33 -- 1 out of 3 (D)
So, my questions are:
what is most effective way to split query string and then iterate on it (table?)
how to store partial results and then count them?
how to count final percentage value?
Every help would be greatly appreciated.
The following query would give you what you want without the need to bother with procedures.
select id
, sum(case when value in ('A', 'B', 'C', 'D', G') then 1 else 0 ) / count(*)
from my_table
group by id
Alternatively if you have to pass the string "A B C D G" and get a result back you could do:
select id
, sum(case when instr('A B C D G', value) <> 0 then 1 else 0 ) / count(*)
from my_table
group by id
These do involve full scanning the table or an index full scan if you use the suggested index below, so you might want to add the following where clause if you only want to find ids that have a percentage > 0.
select id
, sum(case when instr('A B C D G', value) <> 0 then 1 else 0 ) / count(*)
from my_table
where exists ( select 1
from my_table
where id = mt.id
and instr('A B C D G', value) <> 0 )
group by id
For all the queries your table should be indexed on my_table, id in that order.
Have you had a look at UTL_MATCH? It doesn't do exactly what you're trying to achieve, but you may find it useful if the definition of your percentage agreement isn't set in stone.

Resources