|
|
本帖最后由 Test 于 2011-8-23 14:47 编辑
Usually we can just use DecisionPlus to do it. just as example here:
- !file 1 $MTDAT/certs
- #define certs 1
- !temp txtline,,a160,t
- !temp filename,,a100
- !temp txtfile,,i2
- !temp charct,,i2
- !temp charstr,,a80,t
- !temp onechar,,a1
- !temp threechar,,a3
- !temp startpos,,i2
- !temp endpos,,i2
- !temp hostname,,a3
- !init scroll 4 : filename = arg : gosub INIT
- END\
- end
- INIT\
- fopen txtfile filename "r"
- ... fopen txtfile "/tmp/transfers_certs_rcp.out" "r"
- hostname=$HOSTNAME
- NEWLINE\
- fgets txtfile txtline eof = RETURN
- charct = 10
- NEXTCHAR\
- onechar = getstr(txtline,charct,1)
- if onechar = " " then goto CHK_HOST
- charct = charct + 1: goto NEXTCHAR
- CHK_HOST\
- threechar = getstr(txtline,charct+8,3)
- if threechar = hostname then goto GET_HEAT
- goto NEWLINE
- GET_HEAT\
- charct = charct + 27
- cert_num = getstr(txtline,charct,24)
- read certs nsr=CONT
- goto NEWLINE
- CONT\
- cert_num = getstr(txtline,charct,24)
- insert certs
- print cert_num
- goto NEWLINE
- RETURN\
- return
复制代码 But Linux already has very strong capability on text processing, so I tried to use script to get data and only pass the data been read out to the DecisionPlus program.
like we have a csv file for grouping id with just customer id and master id, like.
MasterID Cust_ID
V 1375 S 829
K 2121
V 1375
R 1561
R 551
E 1693
S 348
R 430
E 4926
S 884 R 388
S 884
V 5162 K 3628
K 4009
V 5162
E 4204
S 2430
R 1768
V 486 E 6613
V 486
K 1050 csv file like:
- dev]$ cat supplier_list_2.csv
- V 1375,S 829
- ,K 2121
- ,V 1375
- ,R 1561
- ,R 551
- ,E 1693
- ,S 348
- ,R 430
- ,E 4926
- S 884,R 388
- ,S 884
- V 5162,K 3628
- ,K 4009
- ,V 5162
- ,E 4204
- ,S 2430
- ,R 1768
- V 486,E 6613
- ,V 486
- ,K 1050
复制代码 we have bash script file getcsv.jcl as:
- #!/bin/bash
- #INPUT=supplier_list.csv
- function pause(){
- print '...'
- read -p "$*"
- }
- INPUT=$1
- if [ "$1" == "" ]; then
- INPUT=supplier_list_1.csv
- fi
- echo "Input file: $1"
- OLDIFS=$IFS
- IFS=,
- masterid=""
- [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
- while read master acct
- do
- #echo "Name : " $master "Acct :" $acct
- if [ "$masterid" == "" ]; then masterid="$master"; fi
- if [ "$master" == "" ]; then master="$masterid"; else masterid="$master"; fi
- ./showp.jcl "$master" "$acct"
- #/appl/sagexec/sagerep input_supp_csv nullp "$acct" "$master"
- /appl/sagexec/sagerep input_supp_csv nullp UPDATE "$acct" "$master"
- #echo 'Next to go ...'
- #echo "Name : ${master}| Acct : ${acct}|"
- done < $INPUT
- IFS=$OLDIFS
复制代码 and then, the DecisionPlus only used to update data by the number provided by arguments.
- ... input_supp_csv.r
- ... Append new items to supplier_master
- ... 08-23-11 Johnz: use parameters to update supplier grouping table inside Metaltraq
- !file 1 $MTDAT/supplier_master
- !temp master,,a6,u+
- !temp supplier,,a6,u+
- !temp tmp_key,,a6
- !temp tmpstr,,a60,t
- !temp tmp_count,,i2
- !init scroll 4 : tmp_key = arg
- !init scroll 5 : supplier = arg
- !init scroll 6 : master = arg
- !init gosub INIT
- ...!heading gosub HEAD
- !final gosub TAIL
- ... print "Show Data ..."
- if tmp_key = "UPDATE" then \
- rewind 1 : suppm_master_id = master : suppm_num = supplier : \
- print "Insert "; supplier; " -> ";master;" ..." : \
- insert 1 re = RERROR : \
- print " --- succeed." \
- else \
- print "Supplier:";supplier;" ---> ";master
- print "..."
- rewind 1
- tmp_count = tmp_count + 1
- END\
- exit 0
- RERROR\
- print "Supplier ";master;" existed! insert failed."
- goto END
- ._________________________________________________________________________________
- INIT\
- tmp_count = 0
- . print "Starting ..."
- if tmp_key <> "UPDATE" then \
- master = supplier : supplier = tmp_key
- . print "Supplier:";supplier;" - Master:";master
- return
- .________________________________________________________________
- TAIL\
- return
复制代码
and this code can be easily used to update other data tables.
|
|