How to fix DB2 sqlcode=-805 in a REXX mainframe script with execsql prepare - db2

When I run the REXX script :
/* REXX */
CALL CONNIN /* CONNECTION */
ADDRESS DSNREXX "EXECSQL DECLARE C1 CURSOR FOR S1"
IF SQLCODE \= 0 THEN DO
ERRMSG = "EXECSQL DECLARE"
CALL SQLCA
END
TTABLE = "ibmuser.dept"
SQLSMT = "SELECT * FROM :TTABLE"
ADDRESS DSNREXX "EXECSQL PREPARE S1 FROM :SQLSMT"
IF SQLCODE \= 0 THEN DO
ERRMSG = "EXECSQL PREPARE"
CALL SQLCA
END
CALL CLOSING /*CLOSING ALL*/
EXIT 0
/*ROUTINES CALLED*/
/*INITIAL CONNECTION*/
CONNIN:
SSID = "DBCG"
ADDRESS TSO "SUBCOM DSNREXX"
IF RC THEN S_RC = RXSUBCOM("ADD","DSNREXX","DSNREXX")
ADDRESS DSNREXX "CONNECT" SSID
IF SQLCODE \= 0 THEN DO
ERRMSG = "CONNECT TO" SSID "FAILED."
CALL SQLCA
END
RETURN
/* ERROR HANDLING ROUTINE */
SQLCA:
SAY " ERROR MSG= >"ERRMSG"<"
SAY " SQLCODE = >"SQLCODE"<"
SAY " SQLSTATE = >"SQLSTATE"<"
SAY " SQLERRMC = >"SQLERRMC"<"
SAY " SQLERRP = >"SQLERRP"<"
SAY " SQLERRD.1= >"SQLERRD.1"<"
SAY " SQLERRD.2= >"SQLERRD.2"<"
SAY " SQLERRD.3= >"SQLERRD.3"<"
SAY " SQLERRD.4= >"SQLERRD.4"<"
SAY " SQLERRD.5= >"SQLERRD.5"<"
SAY " SQLERRD.6= >"SQLERRD.6"<"
EXIT 8
RETURN
/* CLOSING */
CLOSING:
ADDRESS DSNREXX "DISCONNECT"
S_RC = RXSUBCOM("DELETE","DSNREXX","DSNREXX")
RETURN
After running I receive the error messages :
ERROR MSG= >EXECSQL PREPARE<
SQLCODE = >-805<
SQLSTATE = >51002<
SQLERRMC = >DALLASC..DSNREXX.1AB2405808DB7F29:DSNREXX:03<
SQLERRP = >DSNXEPM <
SQLERRD.1= >-251<
SQLERRD.2= >0<
SQLERRD.3= >0<
SQLERRD.4= >-1<
SQLERRD.5= >0<
SQLERRD.6= >0<
The error comes from : ADDRESS DSNREXX "EXECSQL PREPARE S1 FROM :SQLSMT"
With SPUFI (db2 utility) I can list the table IBMUSER.DEPT with select * from ibmuser.dept;
How I can fix this issue?
Thanks

I would try
TTABLE = "ibmuser.dept"
SQLSMT = "SELECT * FROM" TTABLE
Error -805 is
-805 DBRM OR PACKAGE NAME location-name.collection-id.dbrm-name.consistency-token NOT FOUND IN PLAN plan-name. REASON
The full message will tell you what DB2 can not find. If you can not find it, try looking in your TSO job output

Thanks to #piet.t and #bruce-martin for the suggestions. The issue was because the DSNREXX was not enabled for public usage.

Related

Save job output from SDSF into a PDS and using ISPF functions in REXX

We periodically runs jobs and we need to save the output into a PDS and then parse the output to extract parts of it to save into another member. It needs to be done by issuing a REXX command using the percent sign and the REXX member name as an SDSF command line. I've attempted to code a REXX to do this, but it is getting an error when trying to invoke an ISPF service, saying the ISPF environment has not been established. But, this is SDSF running under ISPF.
My code has this in it (copied from several sources and modified):
parse arg PSDSFPARMS "(" PUSERPARMS
parse var PSDSFPARMS PCURRPNL PPRIMPNL PROWTOKEN PPRIMCMD .
PRIMCMD=x2c(PPRIMCMD)
RC = isfquery()
if RC <> 0 then
do
Say "** SDSF environment does not exist, exec ending."
exit 20
end
RC = isfcalls("ON")
Address SDSF "ISFGET" PPRIMPNL "TOKEN('"PROWTOKEN"')" ,
" (" VERBOSE ")"
LRC = RC
if LRC > 0 then
call msgrtn "ISFGET"
if LRC <> 0 then
Exit 20
JOBNAME = value(JNAME.1)
JOBNBR = value(JOBID.1)
SMPDSN = "SMPE.*.OUTPUT.LISTINGS"
LISTC. = ''
SMPODSNS. = ''
SMPODSNS.0 = 0
$ = outtrap('LISTC.')
MSGVAL = msg('ON')
address TSO "LISTC LVL('"SMPDSN"') ALL"
MSGVAL = msg(MSGVAL)
$ = outtrap('OFF')
do LISTCi = 1 to LISTC.0
if word(LISTC.LISTCi,1) = 'NONVSAM' then
do
parse var LISTC.LISTCi . . DSN
SMPODSNS.0 = SMPODSNS.0 + 1
i = SMPODSNS.0
SMPODSNS.i = DSN
end
IX = pos('ENTRY',LISTC.LISTCi)
if IX <> 0 then
do
IX = pos('NOT FOUND',LISTC.LISTCi,IX + 8)
if IX <> 0 then
do
address ISPEXEC "SETMSG MSG(IPLL403E)"
EXITRC = 16
leave
end
end
end
LISTC. = ''
if EXITRC = 16 then
exit 0
address ISPEXEC "TBCREATE SMPDSNS NOWRITE" ,
"NAMES(TSEL TSMPDSN)"
I execute this code by typing %SMPSAVE next to the spool output line on the "H" SDSF panel and it runs fine until it gets to this point in the REXX:
114 *-* address ISPEXEC "TBCREATE SMPDSNS NOWRITE" ,
"NAMES(TSEL TSMPDSN)"
>>> "TBCREATE SMPDSNS NOWRITE NAMES(TSEL TSMPDSN)"
ISPS118S SERVICE NOT INVOKED. A VALID ISPF ENVIRONMENT DOES NOT EXIST.
+++ RC(20) +++
Does anyone know why it says I don't have a valid ISPF environment and how I can get around this?
I've done quite a bit in the past with REXX, including writing REXX code to handle line commands, but this is the first time I've tried to use ISPEXEC commands within this code.
Thank you,
Alan

Acces ODBC passthru query fails with error 3146 giving different error description texts

I create a passthru query SELECTINg rows of a Postgres v.11 database table.
Running currentDb.execute generates ODBC error 3146 and "invalid argument" mentioned in DBEngine.errors.
Opening same query in the database explorer generates ODBC error 3146 and a message box with "permission denied ..." which actually reflects the source of error.
My questions is how can I programmatically get hold of latter more informative error message ?
I think the following will provide what you are looking for:
Public Function DbEngineErrors() As String
Dim intErr As Integer
Dim strRet As String
Dim strErr As String
If DBEngine.Errors.Count > 0 Then
strRet = "DbEngineErrors:"
For intErr = 0 To DBEngine.Errors.Count - 1
strErr = DBEngine.Errors(intErr).Number & " / " & DBEngine.Errors(intErr).Description & " / " & DBEngine.Errors(intErr).Source
strRet = strRet & vbCrLf & strErr
Next
End If
DbEngineErrors = strRet
End Function

How to get the details of the 500 error with Overbyte ICS

I'm working with the TSslHttpCli component of ICS OverByte, at times I get the error 500 "Internal Server Error" I get the error code in the "OnRequestDone" event as shown below:
procedure TFFormCot.SslHttpCotRequestDone(Sender: TObject;
RqType: THttpRequest; ErrCode: Word);
var
SslHttpCli : TSslHttpCli;
begin
try
SslHttpCli := Sender as TSslHttpCli;
if ErrCode <> 0 then
begin
Memo1.lines.add('ICS:Erro:CT-01: Falha na solicitação ao servidor - ErrCode:[' + IntToStr(ErrCode) + '][' + SslHttpCli.ReasonPhrase + ']');
end;
if SslHttpCli.StatusCode <> 200 then
begin
Memo1.lines.add('ICS:Erro:CT-01.A: ' + IntToStr(SslHttpCli.StatusCode) + ' ' + SslHttpCli.ReasonPhrase);
end;
end;
But I can not get the details of error 500.
the html is not available, you may have some message stating the reason for the error, such as a wrong sent parameter. How do I get the html in this case, or the header received?

Rexx, Parse a file for a single line

I'm trying to find a way to parse a file in Rexx. Each line has two words and an IP address.
Example
Location Name 10.0.0.1
I have looked over a lot of documentation and i can get it to print all the lines in the file but i cannot figure out how to search an entire file and print a specific line by using a match operator.
For Regina Rexx this is a program should be close to what you want:
Call A000_init
Call R000_ReadFile
do while MoreData
parse var line pt1 pt2
if (pt1 == whatever) then do
/* Do some thing */
end
Call R000_ReadFile
end
A000_init:
Yes = 1
No = 0
MoreData = yes
filename = .....
return
R000_ReadFile:
if lines(filename,'N') then do
Line= LineIn(filename)
end; else do
line = ''
MoreData = no
end
Return
This is a pretty easy task for a Rexx program.
ExpectedLocation = 'Living Room' /* What location are we searching for? */
Signal on NotReady /* Jump to "NotReady:" at end-of-file. */
Do Forever /* ... or at least until EOF or Exit! */
Parse LineIn Word1 Word2 IPAddress . /* Pull apart the three tokens on the line */
Location = Word1 Word2 /* Put the two words of the location back together. */
If Location = ExpectedLocation then Do /* Did we find it? */
Say "Found it :-)" /* Yay! */
Exit /* We're done, stop the program. */
End
End
NotReady: /* We come here at end-of-file. */
Say "Didn't find it :-(" /* Darn! */
Regina is Open Source, the project is on SourceForge at http://regina-rexx.sourceforge.net, and the documentation for the version you're using can be downloaded from http://sourceforge.net/projects/regina-rexx/files/regina-documentation/3.4/
Input file : XXXXXX.XXXX.XXXX
***************************** Top of Data
Location1 Name1 11.11.11.11
Location2 Name2 22.22.22.22
Location3 Name3 33.33.33.33
**************************** Bottom of Data
Code:
/* REXX */
/* Author : Ebin Paulose */
/*=============================================================================*/
YourWord = Location2 /*Word which we need to find, here i m giving "Location2"*/
Your_PS = 'XXXXXX.XXXX.XXXX' /*File name where we need to search */
"ALLOC DA('"Your_PS"') F(FILEDD) SHR REUSE" /* Allocate the file */
DO FOREVER
"EXECIO 1 DISKR FILEDD"
IF RC>0 THEN LEAVE
PULL Record /* pull one record from file */
PARSE VAR Record Location " " Name " " IPAddress
/* parse record into 3 parts Location, Name and IPAddress */
IF Location = YourWord THEN do /* check for matching */
SAY 'Found : ' Location
Found = 'Y'
END
END
IF Found ¬= 'Y' THEN DO
SAY 'Sorry Search item Not found'
END
"EXECIO 0 DISKR FILEDD (FINIS"
"FREE F(FILEDD)"
Output 1 (item found) :
Found : LOCATION2
Output 2 (item not found) :
Sorry Search item Not found
filename = 'MY.DATA.SET'
if sysdsn(''''filename'''') <> 'OK' then exit
address 'TSO'
"ALLOCATE FILE(INDD) DATASET('"filename"') SHR REUSE"
"EXECIO DISKR * INDD(STEM file. FINIS)"
"CLOSE FILE(INDD)"
target = 'My Location'
found = 1==0 /* false */
do i = 1 to file.0
card = file.i
parse var card loc1 loc2 ip_address .
found = loc1' 'loc2 == target
if found then leave
end i
if found then
say 'IP address of 'target' is 'ip_address
else
say 'No IP address found for 'target
exit

Text Emailing using VBscript

I have tried the following code, No errors thrown. and no emails have been sent either.
Dim i, objEmail
' Use custom error handling
On Error Resume Next
Set objEmail = CreateObject( "CDO.Message" )
' Fill in the field values
With objEmail
.From = "xyz#abc.com"
.To = "pqr#abc.com"
.Subject = "Test"
.TextBody = "Email from VB Script"
If mySMTPPort = "" Then
mySMTPPort = 25
End If
With .Configuration.Fields
.Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "HostNameHere"
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 25
.Update
End With
.Send
End With
' Return status message
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
EMail = "Message sent ok"
End If
' Release the e-mail message object
Set objEmail = Nothing
When I execute this VBS file, It just does nothing at all. Please help me out. I have to send simple text emails from my domain to another domain. Or is there a work around for the task i want to perform?
You're probably getting an error when trying to send mail. However, you have error handling enabled (On Error Resume Next), but your error handler just puts the error information in a variable without actually doing anything with that variable. Adding a line that echoes the variable should provide you with more information about what's going on:
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
EMail = "Message sent ok"
End If
WScript.Echo EMail
should provide you with more information about what's going on.
Edit: Apparently you're getting a connection error. There are several possible causes for that. First check that your name resolution works correctly:
nslookup HostNameHere
If the name doesn't resolve either use the IP address in your script or get the name resolution fixed.
Next check if you can connect to port 25 on the remote host, both via name and IP address:
telnet HostNameHere 25
telnet a.b.c.d 25
If you get a result like this:
C:\>telnet HostNameHere 25
Connecting To HostNameHere...Could not open connection to the host, on port 25:
Connect failed
something is blocking your connection. Could be a network firewall, a host-based firewall on the remote host, or the service not listening on port 25 in the first place. Check with your network admins and/or the admin(s) of the mail server.
Your code hides errors. err default property is number. So You say if err.number = 0 (same as false) then error, if err.number not 0 (ie error) everything fine.