How to UPDATE DIFFERENT RECORD from subfile to physical file in RPGLE? - updates

How to Update value of different record from SUBFILE into Physical file?
The screen are as shown in picture below:
The value I want to update is for USD from 4.12 to 4.13.
This is my physical file :
After I press enter, the value will just updated on the screen only, but when I runqry to check at physical file, there are no any changes happen. What should I do? Please help me. Thanks in advance :)
My concern :
Now, it updated, but it just update the next value or the latest value for latest date. what I mean is, I try to edit value for USD on 31 May, but when I press enter and refresh the screen, I don't know why the USD value for 1 June is the one that change. And, I also try to update the other value at the same time, but only USD is the one that updated. What should I do then?

use the CHGPF command to change the CUREXG file so it has 2 key fields: EXGDAT and EXGCOD
A R CURREC
A EXGDAT L
A EXGCOD 3A
A EXGRAT 5P 2
A K EXGDAT
A K EXGCOD
CHGPF FILE(CUREXG) SRCFILE(QDDSSRC) SRCMBR(CUREXG)
then, in the RPG, chain to the CUREXG file with the EXGDAT key and the 2nd EXGCOD key:
/free
chain ( exgdat: 'USD' ) currec ;
if %found ;
exgrat = usd ;
update currec ;
endif ;
/end-free

There is only one update for multiple records
Try something like this
UPDSR Begsr
MoveL(P) 'UPDATE' Mode
*******Exgdat Chain Curexg 9091
******* If *In91 = *On
******* Leavesr
******* Endif
******* If *In90 = *Off
******* Movel(p) Date Date2
******* Movel(p) USD USD2
******* Movel(p) GBP GBP2
******* Movel(p) EUR EUR2
******* Movel(p) AUD AUD2
******* Movel(p) SGD SGD2
// make a generic 10 alpha field to control your loop
movel *blank ##Change 10A
*like Define Date2 ##DispDate
##change = 'First';
dow ##change <> *blank; //loop to check for date change
clear ##change;
##DispDate = Date2; // what is the date used to display
##gcod = 'USD'
exsr $ForDisplay;
USD2 = ##grat;
##gcod = 'GBP'
exsr $ForDisplay;
GBP2 = ##grat;
##gcod = 'EUR'
exsr $ForDisplay;
EUR2 = ##grat;
##gcod = 'AUD'
exsr $ForDisplay;
AUD2 = ##grat;
##gcod = 'SGD'
exsr $ForDisplay;
SGD2 = ##grat;
Seton 02
N12 Exfmt Screen
if Date2 <> ##DispDate; //the user changed the date!
##change = 'Change';
endif;
enddo;
******* User's answers
Movel(p) Date2 Date
Movel(p) USD2 USD
##gcod = 'USD';
##grat = usd;
exsr $UpdateRec;
Movel(p) GBP2 GBP
##gcod = 'GBP';
##grat = gbp;
exsr $UpdateRec;
Movel(p) EUR2 EUR
##gcod = 'EUR';
##grat = eur;
exsr $UpdateRec;
Movel(p) AUD2 AUD
##gcod = 'AUD';
##grat = aud;
exsr $UpdateRec;
Movel(p) SGD2 SGD
##gcod = 'SGD';
##grat = sgd;
exsr $UpdateRec;
******* select
******* exgcod wheneq 'USD'
******* move usd exgrat
******* exgcod wheneq 'GBP'
******* move gbp exgrat
******* exgcod wheneq 'EUR'
******* move eur exgrat
******* exgcod wheneq 'AUD'
******* move aud exgrat
******* exgcod wheneq 'SGD'
******* move sgd exgrat
******* endsl
*******N12 Update Currec
eval MSG ='Record updated'
******* Endif
Setoff 91
Endsr
**---------------------------------
Begsr $ForDisplay;
*** Using CHAIN(N) to avoid locking the file, this is to load the screen
** Assumption that the fspec for Curexg has a key list of exgdat, exgcod
** if it does not exist, you will need to create a logical that has one
*like Define exgcod ##gcod
*like Define exgrat ##grat
clear ##grat;
chain(n) ( Date : ##gcod ) Curexg;
if %found(Curexg);
##grat = exgrat;
endif;
Endsr;
**---------------------------------
Begsr $UpdatRec;
if *in12 = *off; //allowed to update?
chain ( Date : ##gcod ) Curexg;
exgrat = ##grat;
if %found(Curexg); //exists, update it
update Currec;
else; //record doesn't exist yet, possibly new currency, new rec
Exgdat = Date;
Exgcod = ##gcod;
write Currec;
endif;
endif;
Endsr;
**---------------------------------

Related

Google Script replacing Index/Match - Matching Values Only

I'm trying to modify a function, essentially i need to replicate index/match but with a script.
I'm using some code that works almost perfectly for me, the values that match are updated fine but unfortunately the values on the 'Slave' sheet that do not match the 'Master' sheet are overwritten with null
MASTER SHEET
VESSEL
C/O DATES
WHARF
COUNT
ROLLING
ROLLING
86
SPARE
SPARE
0
TBA
TBA
7
AITOLIKOS 004N
ETD 17.11
DPWORLD
0
ARKADIA 2210N
C/O 07.11 # 1200
TBA
2
ASL BAUHINIA 2201N
ETD 07.11
DPWORLD
16
CMA CGM BELLINI 216N
ETD 20.11
DPWORLD
1
CMA CGM MARLIN 752N
TBA
0
CMA CGM MOLIERE 242N
C/O 04.11 # 1100
DPWORLD
0
CONTI CONQUEST 239N
C/O 03.11 # 2300
PATRICKS
13
COSCO ADEN 106N
C/O 03.11 # 1900
DPWORLD
90
COSCO FELIXSTOWE 177N
C/O 08.11 # 2200
TBA
12
SLAVE SHEET
FULL OR EMPTY
TRAILER TYPE
CUSTOMER DETAILS
TRUCK #
RELEASE NUMBER
Vessel
Cut Off
EMPTY DELIVERY
SIDELOADER
CH&S
On HOLD refer Adam
35803252DA
TBA
TBA
EMPTY DELIVERY
TRAILER
CH&S
TWMBA270922
CMA CGM BELLINI 216N
ETD 20.11
EMPTY DELIVERY
TRAILER
CH&S
TWMBA270922
CMA CGM BELLINI 216N
ETD 20.11
EMPTY DELIVERY
TRAILER
CH&S
TWMBA270922
COSCO ADEN 106N
C/O 03.11 # 1900
EMPTY DELIVERY
TRAILER
CH&S
TWMBA270922
COSCO ADEN 106N
C/O 03.11 # 1900
EMPTY DELIVERY
TRAILER
CH&S
TWMBA270922
COSCO ADEN 106N
C/O 03.11 # 1900
EMPTY DELIVERY
TRAILER
CH&S
TWMBA270922
COSCO ADEN 106N
C/O 03.11 # 1900
Code:
Original Author of the following code: TheMaster
const ss = SpreadsheetApp.getActive();
function cutoffUpdater (
fromSht = ss.getSheetByName('MASTER'),
toSht = ss.getSheetByName('SLAVE'),
fromCompCol = 1,
toCompCol = 6,
fromCol = 2,
toCol = 7
) {
const toShtLr = toSht.getLastRow();
const toCompArr = toSht.getRange(2, toCompCol, toShtLr - 1, 1).getValues();
const fromArr = fromSht.getDataRange().getValues();
fromCompCol--;
fromCol--;
/*Create a hash object of fromSheet*/
const obj1 = fromArr.reduce((obj, row) => {
let el = row[fromCompCol];
el in obj ? null : (obj[el] = row[fromCol]);
return obj;
}, {});
//Paste to column
toSht.getRange(2, toCol, toShtLr - 1, 1)
.setValues(toCompArr.map(row => (
row[0] in obj1 ? [obj1[row[0]]] : [null]
))
);
}
What i Require
In my situation, i need any value on the 'slave' sheet that doesn't match or is not present on the 'Master' sheet to remain untouched.
I have spent 2 days trying to modify the code but to be honest, the "hash object" is above my abilities.
Follow-up question from:
Google Script version of VLookup (More Efficient Method?)
In your script, how about the following modification?
From:
toSht.getRange(2, toCol, toShtLr - 1, 1)
.setValues(toCompArr.map(row => (
row[0] in obj1 ? [obj1[row[0]]] : [null]
))
);
To:
toSht.getRange(2, toCol, toShtLr - 1, 1)
.setValues(toCompArr.map(row => (
row[0] in obj1 ? [obj1[row[0]]] : [row[0]] // Modified
))
);
When this modified script is run, when row[0] in obj1 is false, [row[0]] is used. By this, the original value of "SLAVE" sheet is kept.

Automatically parse selectors with insheetjson in Stata

I am trying to build a program that gets data from Statistics Denmark's API using insheetjson in Stata. However, I have not been able to find a solution for the following problem: I want to get the metadata from a random table (in this case: "FOLK1A" which is a table of demographics). This table has variables of region, age, marital status and time. If we take regions as an example, there are 105 regions, so if I run insheetjson using "https://api.statbank.dk/v1/tableinfo/FOLK1A?lang=en", showresponse flatten, I see a very clear pattern:
variables:1:values:1:id = 000
variables:1:values:1:text = All Denmark
variables:1:values:2:id = 084
variables:1:values:2:text = Region Hovedstaden
variables:1:values:3:id = 101
variables:1:values:3:text = Copenhagen
variables:1:values:4:id = 147
variables:1:values:4:text = Frederiksberg
variables:1:values:5:id = 155
variables:1:values:5:text = Dragør
variables:1:values:6:id = 185
variables:1:values:6:text = Tårnby
variables:1:values:7:id = 165
variables:1:values:7:text = Albertslund
variables:1:values:8:id = 151
variables:1:values:8:text = Ballerup
variables:1:values:9:id = 153
variables:1:values:9:text = Brøndby
variables:1:values:10:id = 157
variables:1:values:10:text = Gentofte
...
variables:1:values:100:text = Mariagerfjord
variables:1:values:101:id = 773
variables:1:values:101:text = Morsø
variables:1:values:102:id = 840
variables:1:values:102:text = Rebild
variables:1:values:103:id = 787
variables:1:values:103:text = Thisted
variables:1:values:104:id = 820
variables:1:values:104:text = Vesthimmerlands
variables:1:values:105:id = 851
variables:1:values:105:text = Aalborg
However, I am not able not parse all these regions in a single call. Is there a way to tell insheetjson to get all of these regions, i.e. "variables:1:values:[1-105]:id" in one call? I don't want to run the command several times, thus pinging the server way too much.
Best regards,
Emil Blicher

Search for a string and return its value in MySQL

I have a text column where the data is being automatically populated from a machine. Below is the data format which is being populated at the database. The format of the data is almost same for all records which I have in this table.
==========================
=== S U P E R S O N Y ===
========================
START AT 12:16:29A
ON 02-18-19
MACHINE COUNT 1051
OPERATOR ______________
SERIAL # 0777218-15
V=inHg
- TIME T=F P=psig
------------------------
D 12:16:31A 104.6 0.0P
D 12:16:41A 104.1 0.0P
D 12:26:41A 167.2 28.7V
D 12:31:41A 108.1 28.5V
MACHINE VALUE IS:
1.5 mg/min
L 12:41:41A 95.1 28.4V
L 12:43:54A 97.2 1.9V
Z 12:45:23A 97.5 0.0P
========================
= CHECK COMPLETE =
========================
I need to find the exact value after the "MACHINE VALUE IS:" and before "mg/min" word. In the above case, the query must return "1.5". The query I have written is failing because of some spaces after "MACHINE VALUE IS:" word.
SELECT REPLACE(REPLACE(SUBSTRING(contents,
LOCATE('IS:', contents), 10),'IS:', ''),'mg','') as value from machine_content
This will get you the number behind IS:<br> of yourse, uin your case you must change, to what ever breaks the line like cr lf
SET #sql := '==========================
=== S U P E R S O N Y ===
========================
START AT 12:16:29A
ON 02-18-19
MACHINE COUNT 1051
OPERATOR ______________
SERIAL # 0777218-15
V=inHg
- TIME T=F P=psig
------------------------
D 12:16:31A 104.6 0.0P
D 12:16:41A 104.1 0.0P
D 12:26:41A 167.2 28.7V
D 12:31:41A 108.1 28.5V
MACHINE VALUE IS:
1.5 mg/min
L 12:41:41A 95.1 28.4V
L 12:43:54A 97.2 1.9V
Z 12:45:23A 97.5 0.0P
========================
= CHECK COMPLETE =
========================
'
SELECT REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(#sql, 'IS:', -1), 'mg', 1),'\n','')
| REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(#sql, 'IS:', -1), 'mg', 1),'\n','') |
| :-------------------------------------------------------------------------- |
| 1.5 |
db<>fiddle here

Read in search strings from text file, search for string in second text file and output to CSV

I have a text file named file1.txt that is formatted like this:
001 , ID , 20000
002 , Name , Brandon
003 , Phone_Number , 616-234-1999
004 , SSNumber , 234-23-234
005 , Model , Toyota
007 , Engine ,V8
008 , GPS , OFF
and I have file2.txt formatted like this:
#==============================================
# 005 : Model
#------------------------------------------------------------------------------
[Model] = Honda
option = 0
length = 232
time = 1000
hp = 75.0
k1 = 0.3
k2 = 0.0
k1 = 0.3
k2 = 0.0
#------------------------------------------------------------------------------
[Model] = Toyota
option = 1
length = 223
time = 5000
speed = 50
CCNA = 1
#--------------------------------------------------------------------------
[Model] = Miata
option = 2
CCNA = 1
#==============================================
# 007 : Engine
#------------------------------------------------------------------------------
[Engine_Type] = V8 #1200HP
option = 0
p = 12.0
pp = 12.0
map = 0.4914
k1mat = 100
k2mat = 600
value =12.00
mep = 79.0
cylinders = 8
#------------------------------------------------------------------------------
[Engine_Type] = v6 #800HP
option = 1
active = 1
cylinders = 6
lim = 500
lim = 340
rpm = 330
start = 350
ul = 190.0
ll = 180.0
ul = 185.0
#==============================================
# 008 : GPS
#------------------------------------------------------------------------------
[GPS] = ON
monitor = 0
#------------------------------------------------------------------------------
[GPS] = OFF
monitor = 1
Enable = 1
#------------------------------------------------------------------------------
[GPS] = Only
monitor = 2
Enable = 1
#==============================================
# 014 :Option
#------------------------------------------------------------------------------
[Option] = Disable
monitor = 0
#------------------------------------------------------------------------------
[Option] = Enable
monitor = 1
#==============================================
# 015 : Weight
#------------------------------------------------------------------------------
[lbs] = &1
weight = &1
#==============================================
The expected output is supposed to look like this:
Since there is only option 005-008 in file1.txt the output would be:
Code:
#==============================================
# 005 : Model
#------------------------------------------------------------------------------
[Model] = Toyota
option = 1
length = 223
time = 5000
speed = 50
CCNA = 1
#==============================================
# 007 : Engine
#------------------------------------------------------------------------------
[Engine_Type] = V8 #1200HP
option = 0
p = 12.0
pp = 12.0
map = 0.4914
k1mat = 100
k2mat = 600
value =12.00
mep = 79.0
cylinders = 8
#==============================================
# 008 : GPS
#------------------------------------------------------------------------------
[GPS] = OFF
monitor = 1
Enable = 1
#-----------------------------------------------------------------
Now, using Awk and the values from the 2nd and 3rd columns in file1, I want to search for those strings in file2 and output everything in that section to a CSV file ie from where the string is found to where there is the #-------------
demarcation.
Could someone please help me with this and explain also? I am new to Awk
Thank you!
I wouldn't really use awk for this job as specified, but here's a little snippet to get started:
awk -F'[ ,]+' 'FNR == NR { section["[" $2 "]"] = $3; next }
/^\[/ && section[$1] == $3, /^#/' file1.txt file2.txt
1) The -F'[ ,]+' sets the field separator to one or more of spaces and/or commas (since file1.txt looks like it's not a proper CSV file).
2) FNR == NR (record number in file equals total record number) is only true when reading file1.txt. So for each line in file1.txt, we record [second_field] as the pattern to look for with the third field as value.
3) Then we look for lines that begin with a [ and where the value stored in section for the first field of that line matches the third field of that line (/^\[/ && section[$1] == $3), and print from that line until the next line that begins with a #.
The output for your example input is:
[Model] = Toyota
option = 1
length = 223
time = 5000
speed = 50
CCNA = 1
#--------------------------------------------------------------------------
[GPS] = OFF
monitor = 1
Enable = 1
#------------------------------------------------------------------------------
The matched lines in step 3 were [Model] = Toyota and [GPS] = OFF. The Engine line is missing because file2.txt had Engine_Type instead. Also, I didn't bother with the section headers; it would be easy to add another condition to print them all but it requires lookahead to print only the ones that are going to have matching content in them (because at the time you read the header you don't know if a match is found inside). For that, I would switch to another language (e.g., Ruby).

mysql join and fetch

I have try to search topic and try all the way I know to settle this problem, but unfortunately I still cannot.
I am now want including some value inside the google maps infowindows.
I found some source from google developer, but now I need to combine 2 table's info and generate a xml for google maps case.
Table1
id | tid | hotelprice | attachment
1 234 100 http://xxx.xxx.xxx
2 345 106 null
3 663 905 null
Table2
name | url | description | lat | lng | type | area
ABC 111 lorumop111 2.12 -109.1 poi us
EFG 234 lorumop234 2.13 -109.2 hotel us
HIJ 345 lorumop345 2.14 -109.2 hotel us
I need to output the value as XML, first I query
$queryprice = mysql_query("SELECT t1.tid, t2.url, t1.hotelprice
FROM t1 INNER JOIN t2 ON t2.url = t1.tid;");
after that I also query
$query = mysql_query("SELECT * FROM t2 WHERE area = '".$area."'");
after that I need to use the source to output as XML,
while (($row = mysql_fetch_array($query)) && ($row2 = mysql_fetch_array($queryprice))){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("type", $row['type']);
$newnode->setAttribute("description", $row['description']);
$newnode->setAttribute("url", $row['url']);
$newnode->setAttribute("area", $row['area']);
$newnode->setAttribute("hotel_bookingprice", $row2['hotelprice']);
}
echo $dom->saveXML();
but when output as XML, the hotelprice is incorrect.
<markers>
<marker name="ABC" lat="2.12" lng="-109.1" type="poi" description="lorumop111" url="111" area="us" hotelprice="NOT correct amount even this amount can't found in this table, this should be 0 or null because t1 don't have tid=111"/>
<marker name="EFG" lat="2.13" lng="-109.2" type="hotel" description="lorumop234" url="234" area="us" hotelprice="NOT correct amount"/>
</markers>
what I need is:
<marker name="ABC" lat="2.12" lng="-109.1" type="poi" description="lorumop111" url="111" area="us" hotelprice="0"/>
<marker name="EFG" lat="2.13" lng="-109.2" type="hotel" description="lorumop234" url="234" area="us" hotelprice="100"/>
<marker name="HIJ" lat="2.14" lng="-109.3" type="hotel" description="lorumop345" url="345" area="us" hotelprice="106"/>
I hope your guy can understand what I say, thank you.
Try this way:
$query = mysql_query("SELECT t2.*, t1.hotelprice FROM t2
LEFT JOIN t1 ON t2.url = t1.tid
WHERE area = '".$area."'");
while ( $row = mysql_fetch_array($query) ){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("type", $row['type']);
$newnode->setAttribute("description", $row['description']);
$newnode->setAttribute("url", $row['url']);
$newnode->setAttribute("area", $row['area']);
$newnode->setAttribute("hotel_bookingprice", $row['hotelprice']);
}