| Code: |
|
insertstmt = "INSERT INTO xxxx.xxxxxxxx ", "(", " ARIDFR", ",PDARIDFR", ",SRCESOFTWAREIDFR", ",PDARSECID", ",PDARSECIDTP", ",PDARLCSTATUS", ",PDARLCSTATUSDT", ",PRODUCTNUMBER", ",PDIDFR", ",PDSECID", ",PDSECIDTP", ",PDARTP", ",TCNLDBKEY", ",MOID", ",TMSTPUPDTROW", ") ", "VALUES", "(", " ?", ",?", ",'1001'", ",?", ",'1'", ",'7'", ",?", ",'10'", ",'20'", ",'30'", ",'3'", ",'23'", ",?", ",?", ",?", ")" address dsnrexx "EXECSQL PREPARE S2 FROM :insertstmt" |
| Code: |
|
"EXECSQL EXECUTE S2 USING :aridfr ,:pdaridfr", ",:pdarsecid ,:today ", ",:tcnldbkey ,:moid ,:ts" |
| Code: |
|
insertstmt = "INSERT INTO xxxx.xxxxxxxx ", "(", " ARIDFR", ",PDARIDFR", ",SRCESOFTWAREIDFR", ",PDARSECID", ",PDARSECIDTP", ",PDARLCSTATUS", ",PDARLCSTATUSDT", ",PRODUCTNUMBER", ",PDIDFR", ",PDSECID", ",PDSECIDTP", ",PDARTP", ",TCNLDBKEY", ",MOID", ",TMSTPUPDTROW", ") ", "VALUES", "(", " '"strip(aridfr,'T')"'", ",'"strip(pdaridfr,'T')"'", ",'1001'", ",'"strip(pdarsecid,'T')"'", ",'1'", ",'7'", ",'"today"'", ",'10'", ",'20'", ",'30'", ",'3'", ",'23'", ",'"tcnldbkey"'", ",'"moid"'", ",'"ts"'", ")" address dsnrexx "execsql prepare s1 from :insertstmt" if sqlcode <> 0 then do rc = db2err_rpt() rc = disconnect_from_db2t() exit 1 end address dsnrexx "execsql execute s1 " |
| Code: |
|
right(pdarifdr,N,'0') N = length of the column |
| misi01 wrote: |
| Don't think that's what I'm after. In this case, the column is 32 characters, so your suggestion would fill it with loads of leading zeros, NOT what I want.
The value in PDARIDFR already contains what I want in the final DB2 column. It's just that REXX (?) sees it as a numeric value and automatically chops the leading zero, not what I want either. |
| Code: |
|
RIGHT(PDARIFDR,LENGTH(PDARIFDR),'0') |
| Code: |
|
"EXECSQL EXECUTE S2 USING :aridfr ,:'"pdaridfr"'", ",:pdarsecid ,:today ", ",:tcnldbkey ,:moid ,:ts" |
| misi01 wrote: |
| Assume the value in pdaridfr is 123 and I want it to be 4 characters with leading zeroes. I could do what you suggest above and get 0123. Only trouble with that is that I already have a value of 0123 in pdaridfr, so I'm not sure why I would need to use right and pad with zeroes.
|
| Code: |
|
pdarsecid = pdarsecid + 1 pdarsecid = right(pdarsecid,9,'0') address dsnrexx , "EXECSQL EXECUTE S2 USING :aridfr ,:pdaridfr", ",:pdarsecid ,:today ", ",:tcnldbkey ,:moid ,:ts" |
| Code: |
|
pdarsecid = pdarsecid + 1 pdarsecid = right(pdarsecid,9,'0') address dsnrexx , "EXECSQL EXECUTE S2 USING :aridfr ,:pdaridfr", pdarsecid",:today ", ",:tcnldbkey ,:moid ,:ts" |
| Quote: |
|
SQLSTATE = 42601 SQLERRD = 0,0,0,0,0,0 SQLERRP = DSNTZEXE SQLERRMC = 000000001.<HOST-VARIABLE> .° DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL "". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: DSNT415I SQLERRP = SQL PROCEDURE DETECTING ERROR |
| Code: |
| /* REXX - test inserting a number with a leading zero into a char field */
/*------------------------------------------------------------------- * Ensure the DB2 interface is active. *-----------------------------------------------------------------*/ ADDRESS TSO "SUBCOM DSNREXX" s_rc = rc if s_rc <> 0 then do s_rc = RXSUBCOM('ADD','DSNREXX','DSNREXX') if s_rc <> 0 then do say '==> Error 1: Activating REXX/DB2 Interface RXSUBCOM, rc='s_ exit 16 end end address dsnrexx "CONNECT DB2U" s_rc = rc if s_rc <> 0 then do say '==> Error 2: Connecting REXX to DB2 Subsystem DB2U, rc='s_rc exit 16 end /*------------------------------------------------------------------- * Insert a row *-----------------------------------------------------------------*/ s_key = '01234568' s_key = s_key + 1 s_key = right(s_key,8,'0') s_sql = "INSERT INTO DB2ROYU.BIL_ACT_INQUIRY", " (BIL_ACCOUNT_ID", " ,BIL_ACY_TYPE_CD", " ,BIL_NXT_ACY_DT", " )", " VALUES('"s_key"'", " ,'X'", " ,'01/01/2014'", " )" ADDRESS DSNREXX "EXECSQL " s_sql say 'rc = 'rc say 'sqlcode = 'sqlcode exit 0 |
| Code: |
| COLUMN NAME DATATYPE LENGTH
------------------ -------- ------ BIL_ACCOUNT_ID CHAR 8 BIL_ACY_TYPE_CD CHAR 3 BIL_NXT_ACY_DT DATE 4 |
| Code: |
| SELECT * FROM DB2ROYU.BIL_ACT_INQUIRY
WHERE BIL_ACCOUNT_ID LIKE '0123456%' WITH UR; ---------+---------+---------+---------+------- BIL_ACCOUNT_ID BIL_ACY_TYPE_CD BIL_NXT_ACY_DT ---------+---------+---------+---------+------- 01234567 X 01/01/2014 01234568 X 01/01/2014 01234569 X 01/01/2014 |
| Code: |
|
insertstmt = "INSERT INTO DB2ROYU.BIL_ACT_INQUIRY ", "(", "BIL_ACCOUNT_ID", " ,BIL_ACY_TYPE_CD", " ,BIL_NXT_ACY_DT", ") ", "VALUES", "(", " ?", ",?", ",?", ")" address dsnrexx "EXECSQL PREPARE S2 FROM :insertstmt" |
| Code: |
|
"EXECSQL EXECUTE S2 USING :s_key ,:BIL_ACY_TYPE_CD", ",:BIL_NXT_ACY_DT " |
| Quote: |
| The statement can also be prepared by calling the DB2 ODBC SQLPrepare function and then executed by calling the DB2 ODBC SQLExecute function. In both cases, the application does not contain an embedded PREPARE or EXECUTE statement. You can execute the statement, without preparation, by passing the statement to the DB2 ODBC SQLExecDirect function. DB2 ODBC Guide and Reference describes the APIs supported with this interface. |
| Code: |
| /* REXX - test inserting a number with a leading zero into a char field */
/*------------------------------------------------------------------- * Ensure the DB2 interface is active. *-----------------------------------------------------------------*/ ADDRESS TSO "SUBCOM DSNREXX" s_rc = rc if s_rc <> 0 then do s_rc = RXSUBCOM('ADD','DSNREXX','DSNREXX') if s_rc <> 0 then do say '==> Error 1: Activating REXX/DB2 Interface RXSUBCOM, rc='s_rc exit 16 end end address dsnrexx "CONNECT DB2U" s_rc = rc if s_rc <> 0 then do say '==> Error 2: Connecting REXX to DB2 Subsystem DB2U, rc='s_rc exit 16 end /*------------------------------------------------------------------- * Insert a row *-----------------------------------------------------------------*/ s_key = '01234571' s_key = s_key + 1 s_key = right(s_key,8,'0') s_cd = 'X' s_dt = '01/01/2014' INSQLDA.SQLD = 3 INSQLDA.1.SQLTYPE = 453 INSQLDA.1.SQLLEN = 8 INSQLDA.1.SQLDATA = s_key INSQLDA.1.SQLIND = 0 INSQLDA.2.SQLTYPE = 453 INSQLDA.2.SQLLEN = 3 INSQLDA.2.SQLDATA = s_cd INSQLDA.2.SQLIND = 0 INSQLDA.3.SQLTYPE = 385 INSQLDA.3.SQLLEN = 10 INSQLDA.3.SQLDATA = s_dt INSQLDA.3.SQLIND = 0 s_sql = "INSERT INTO DB2ROYU.BIL_ACT_INQUIRY", " (BIL_ACCOUNT_ID", " ,BIL_ACY_TYPE_CD", " ,BIL_NXT_ACY_DT", " )", " VALUES(?", " ,?", " ,?", " )" ADDRESS DSNREXX "EXECSQL PREPARE S2 FROM :s_sql" say 'rc = 'rc say 'sqlcode = 'sqlcode ADDRESS DSNREXX "EXECSQL EXECUTE S2 USING DESCRIPTOR :INSQLDA" say 'rc = 'rc say 'sqlcode = 'sqlcode exit 0 |
output generated using printer-friendly topic mod. All times are GMT - 5 Hours