Why does unused file fields are having blank value? - eval

I have a table named
EQRECORDS
as below-
A R REQ
A FNAME 10A
A LNAME 10A
A K FNAME
and program as below-
fEQRECORDS if e k disk
d uwvar2 s 10a inz('ANKUR')
/free
setll *loval req;
reade uwvar2 req;
dow not %eof(eqrecords) and not %error;
dsply lname;
reade uwvar2 req;
enddo;
*inlr = *on;
/end-free
When first time READE executes, if I want to see the value of Fname using Eval. Why is it shown Blank?
Data in the table is as below-
**FNAME LNAME**
VIKASH SHUKLA
VIKASH SHUKLA
ANKUR VERMA
ANKUR MEHTA
VIKASH MISHRA
VIKASH GUPTA
ANKUR GUPTA
BHASKAR MISHRA
CHINTU
BHUVI GUPTA

I assume you are using 'eval' in the debugger. If you have OPTION(*NOUNREF) on an H-spec or the compile command then unreferenced fields are not available in the debugger. Put OPTION(*UNREF) in your H-spec to have them be included.

Post the exact code that is giving you the problem. This should work:
fEQRECORDS if e k disk
d uwvar2 s 10a inz('ANKUR')
d message s 50a inz
/free
setll *loval req;
reade uwvar2 req;
dow not %eof(eqrecords) and not %error;
message = %trimr(fname) + ' ' + lname;
dsply message;
reade uwvar2 req;
enddo;
*inlr = *on;
/end-free

I got the solution of this problem. I used debug(*input) in H-spec and got the result.
Try this link...
Descreption about debug(*input)

Related

Append User List to Database Atoms

what I am trying to accomplish is using a database of disease facts
symptom(shingles,headache).
symptom(shingles,fever).
symptom(shingles,malaise).
symptom(shingles,headache).
symptom(smallpox,fever).
symptom(smallpox,rash).
and compare it with a list of symptoms from the user. I can currently get the symptoms from the user and add the disease to a list, however, I cant figure out how to loop through the entier database to add all the possible diseases it could be.
start:-
consult(diseases1),
getSymptoms(Symptoms),
write(Symptoms).
welcome:-
write('Welcome to the Disease Diagnostic Center'),nl,nl.
getSymptoms(Symptoms) :-
write('Please enter symptoms now, enter "Done" when finished: ' ),
read_string(user, "\n", "\r", _, Response),
(
Response == "Done"
->
Symptoms = []
;
atom_string(Symptom,Response),
valid_symptom(Symptom,Symptoms)
).
valid_symptom(Symptom,Symptoms) :-
(
symptom(_,Symptom)
->
getSymptoms(Symptoms0),
foreach(symptom(Y,Symptom),write(Y))
;
format('Invalid symptom: `~w''~n',[Symptom]),
getSymptoms(Symptoms0),
Symptoms = Symptoms0
).
So for example, the user enters fever as one of the symptoms, then the list should have in it shingles and smallpox. Currently I am able to write each possible disease to the screen, but I am not sure what to replace write with to be able to add each to a list.
If you have a list with all you diseases, you can filter it by requiring a specific symptom.
All diseases:
all_diseases(Diseases) :-
setof(Disease, Symptom^symptom(Disease, Symptom), Diseases).
?- all_diseases(D).
D = [shingles, smallpox].
Then filter it:
require_symptom(Symptom, Diseases0, Diseases) :-
setof(Disease,
( member(Disease, Diseases0),
symptom(Disease, Symptom)),
Diseases)
*-> true
; Diseases = [].
?- all_diseases(Ds), require_symptom(headache, Ds, D1).
Ds = [shingles, smallpox],
D1 = [shingles].
?- all_diseases(Ds), require_symptom(fever, Ds, D1).
Ds = D1, D1 = [shingles, smallpox].
?- all_diseases(Ds), require_symptom(vomiting, Ds, D1).
Ds = [shingles, smallpox],
D1 = [].
Output the list before and after filtering it.

Incrementing over a URL variable

import urllib2
import pandas as pd
from bs4 import BeautifulSoup
x = 0
i = 1
data = []
while (i < 13):
soup = BeautifulSoup(urllib2.urlopen(
'http://games.espn.com/ffl/tools/projections?&slotCategoryId=4&scoringPeriodId=%d&seasonId=2018&startIndex=' % i, +str(x)).read(), 'html')
tableStats = soup.find("table", ("class", "playerTableTable tableBody"))
for row in tableStats.findAll('tr')[2:]:
col = row.findAll('td')
try:
name = col[0].a.string.strip()
opp = col[1].a.string.strip()
rec = col[10].string.strip()
yds = col[11].string.strip()
dt = col[12].string.strip()
pts = col[13].string.strip()
data.append([name, opp, rec, yds, dt, pts])
except Exception as e:
pass
df = pd.DataFrame(data=data, columns=[
'PLAYER', 'OPP', 'REC', 'YDS', 'TD', 'PTS'])
df
i += 1
I have been working with a fantasy football program and I am trying to increment data over all weeks so I can create a dataframe for the top 40 players for each week.
I have been able to get it for any week of my choice by manually entering the week number in the PeriodId part of the url, but I am trying to programmatically increment it over each week to make it easier. I have tried using PeriodId='+ I +' and PeriodId=%d but I keep getting various errors about str and int concatenate and bad operands. Any suggestions or tips?
Try removing the comma between %i and str(x) to concatenate the strings and see if that helps.
soup = BeautifulSoup(urllib2.urlopen('http://games.espn.com/ffl/tools/projections?&slotCategoryId=4&scoringPeriodId=%d&seasonId=2018&startIndex='%i, +str(x)).read(), 'html')
should be:
soup = BeautifulSoup(urllib2.urlopen('http://games.espn.com/ffl/tools/projections?&slotCategoryId=4&scoringPeriodId=%d&seasonId=2018&startIndex='%i +str(x)).read(), 'html')
if you have problem concatenating or formatting URL please create variable instead write it one line with BeautifulSoup and urllib2.urlopen.
Use parenthesis to format with multiple value like "before %s is %s" % (1, 0)
url = 'http://games.espn.com/ffl/tools/projections?&slotCategoryId=4&scoringPeriodId=%s&seasonId=2018&startIndex=%s' % (i, x)
# or
#url = 'http://games.espn.com/ffl/tools/projections?&slotCategoryId=4&scoringPeriodId=%s&seasonId=2018&startIndex=0' % i
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')
Make the code sorter will not effect the performance.

How to display messages from a message file on a display screen using RPGLE?

I have designed a screen using SDA in AS/400 that takes an ID number as input and searches in two PFs for that ID and displays corresponding values fetched from those PFs in the respective fields on screen. Below is the DSPF code:
A*%%TS SD 20180813 084626 PATELDH REL-V7R1M0 5770-WDS
A*%%EC
A DSPSIZ(24 80 *DS3)
A R HEADER
A*%%TS SD 20180802 075026 PATELDH REL-V7R1M0 5770-WDS
A 2 2USER
A 2 30'PRODUCT INQUIRY SCREEN'
A COLOR(WHT)
A 2 63DATE
A EDTCDE(Y)
A 3 63TIME
A R FOOTER
A*%%TS SD 20180802 074433 PATELDH REL-V7R1M0 5770-WDS
A OVERLAY
A 22 4'F3=EXIT'
A R DETAIL
A*%%TS SD 20180813 073420 PATELDH REL-V7R1M0 5770-WDS
A CA03(03 'EXIT')
A CA12(12 'PREVIOUS')
A OVERLAY
A 7 16'ID:'
A 10 16'NAME:'
A 12 16'CATEGORY:'
A #ID R I 7 20REFFLD(CATEGORIES/ID AS400KT2/RCATE-
A GORY)
A #NAME R O 10 22REFFLD(PRODUCTS/NAME AS400KT2/RPROD-
A UCTS)
A #CATEGORY R O 12 26REFFLD(CATEGORIES/CATEGORY AS400KT2-
A /RCATEGORY)
A R MSGSFL SFL
A*%%TS SD 20180803 054959 PATELDH REL-V7R1M0 5770-WDS
A SFLMSGRCD(24)
A MSGKEY SFLMSGKEY
A MSGQ SFLPGMQ(10)
A R MSGCTL SFLCTL(MSGSFL)
A*%%TS SD 20180813 084626 PATELDH REL-V7R1M0 5770-WDS
A OVERLAY
A SFLDSP
A SFLDSPCTL
A SFLINZ
A 01 SFLEND
A SFLSIZ(0002)
A SFLPAG(0001)
A MSGQ SFLPGMQ(10)
I have written a free format RPGLE code that makes this screen work. Below is the RPGLE code:
FDSPPRD CF E WorkStn
FRPRODUCTS IF E K DISK
FRCATEGORY IF E K DISK
FRPRODCATEGO A E K DISK
DtempID S LIKE(ID)
DmsgID S 7A
DmsgF S 10A
D getMsg PR EXTPGM('MSGSFLCL')
D msgID 7A
D msgF 10A
/Free
DoW *In03 = *Off;
Write HEADER;
Write FOOTER;
ExFmt DETAIL;
If #ID = *Zeros;
msgID = 'MSG0001';
msgF = 'ASGNMSGF';
getMsg(msgID:msgF);
Else;
Chain #ID RPRODUCTS;
If %Found(RPRODUCTS);
#NAME = NAME;
Chain ID RCATEGORY;
If %Found(RCATEGORY);
#CATEGORY = CATEGORY;
EndIf;
EndIf;
EndIf;
EndDo;
*InLR = *On;
/End-Free
Below is the CL program called by RPGLE program to get the message text from the msgfile:
PGM PARM(&MSGID &MSGF)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)
SNDPGMMSG MSGID(&MSGID) MSGF(&MSGF)
ENDPGM
Below are the two PFs from which the records are read:
RPRODUCTS-
A R PRODUCTS
A ID 2P 0
A NAME 16A
A K ID
RCATEGORY-
A R CATEGORIES
A ID 2P 0
A CATEGORY 15A
A K ID
All the above codes compile successfully. But the problem is that the msg from the msgf does not appear on the screen. Rest all works. Just the msg from msgf is not being displayed when I press 'Enter' key with a blank ID on screen. Can someone please suggest an information source from where I can learn the concepts of such applications. Also, a help with this one would be appreciated.
You are not writing the MSGCTL record. If you don't write that, then the message subfile will not be displayed. You are also not providing a value for MSGQ.
When using a message subfile, I generally get the program name out of the program status data structure, and put that into MSGQ during program initialization time. It should never change. I also pass that to my procedure that sends the message to the message queue. That way I know that both values will be the same. If they are not the messages will not display.
Here is my message subfile definition:
A* ========================================================================
A* Message Subfile
A* ------------------------------------------------------------------------
A R MSGSFL SFL
A SFLMSGRCD(27)
A MSGKEY SFLMSGKEY
A PGMQ SFLPGMQ(10)
A* ------------------------------------------------------------------------
A* Message Subfile Control
A* ------------------------------------------------------------------------
A R MSGCTL SFLCTL(MSGSFL)
A SFLPAG(1)
A SFLSIZ(2)
A SFLDSP SFLDSPCTL
A SFLINZ
A 53
AON53 SFLEND
A PGMQ SFLPGMQ(10)
There are only a few differences from yours. Lets go through them.
A SFLMSGRCD(27)
This is 27 because I am using the *DS4 screen size. Not an issue.
You are using OVERLAY, I'm not because I write that format first, but as long as you write MSGCTL after you write HEADER you should be good there.
You are using SFLCLR. That is unnecessary, remove it.
A 53
AON53 SFLEND
This is a bit different. I do this because SFLEND requires a conditioning indicator, but I really don't care, I want SFLEND active no matter what that indicator says. (I use *In53 as my SFLEND for regular subfiles too, and I don't want to have to worry whether it is on or off.
I use a sub-procedure to send the message: here is my code for that:
// ----------------------------------------
// SndDspfMsg - sends an *INFO message to the
// message subfile in a display file.
//
// Parameters:
// StackEntry - The program call stack entry to which the message is sent.
// Usually the program name. This must be the same value that
// is placed in the SFLPGMQ variable in the message subfile
// control format.
// MsgId - The Message ID from message file JCMSGF to be sent to the program
// message Queue.
// MsgDta - (optional) Data to be used by the message to provide dynamic
// message content. Defaults to blank.
// MsgDtaLen - (optional) The length of the message data provided above.
// This parameter is required if MsgDta is provided. Defaults
// to zero. If this is not provided or is zero, MsgDta is ignored.
// ----------------------------------------
dcl-proc SndDspfMsg Export;
dcl-pi *n;
StkEnt Char(10) Const;
MsgId Char(7) Const;
MsgDta Char(512) Const Options(*VarSize: *NoPass);
MsgDtaLen Int(10) Const Options(*NoPass);
end-pi;
dcl-s Name_t Char(10) Template Inz('');
// Call Stack Qualifier - used by message handling APIs
dcl-ds CallStackQual_t Qualified Template Inz;
Module Like(Name_t) Inz('*NONE');
Program Like(Name_t) Inz('*NONE');
end-ds;
// Qualified Name
dcl-ds QualName_t Qualified Template Inz;
Name Like(Name_t) Inz('');
User Like(Name_t) Inz('');
end-ds;
// Standard Error Code Format
dcl-ds ErrorCdType1_t Qualified Template Inz;
BytesProv Int(10) Inz(%size(ErrorCdType1_t));
BytesAvail Int(10);
MsgId Char(7);
Data Char(1024) Pos(17);
end-ds;
dcl-ds MsgFile LikeDs(QualName_t) Inz(*LikeDs);
dcl-ds ErrorCd LikeDs(ErrorCdType1_t) Inz(*LikeDs);
dcl-s pmMsgDta Char(512) Inz('');
dcl-s pmMsgDtaLen Int(10) Inz(0);
dcl-s pmMsgTyp Char(10) Inz('*INFO');
dcl-s pmStkCnt Int(10) Inz(0);
dcl-s pmMsgKey Char(4) Inz('');
// Send Program Message
dcl-pr qmhsndpm ExtPgm('QMHSNDPM');
MessageId Char(7) Const;
MessageFile LikeDs(QualName_t) Const;
MessageDta Char(512) Const Options(*Varsize);
MessageLen Int(10) Const;
MessageType Char(10) Const;
StackEntry Char(4102) Const Options(*Varsize);
StackCounter Int(10) Const;
MessageKey Char(4);
Error LikeDs(ErrorCdType1_t);
StackEntryLen Int(10) Const Options(*NoPass);
StackEntryQual LikeDs(CallStackQual_t)
Const Options(*NoPass);
ScreenWaitTime Int(10) Const Options(*NoPass);
StackEntryType Char(10) Const Options(*NoPass);
Ccsid Int(10) Const Options(*NoPass);
end-pr;
// Handle *NoPass Parms
if %parms() >= %parmnum(MsgDtaLen);
pmMsgDtaLen = MsgDtaLen;
endif;
// if Message Data is provided,
if pmMsgDtaLen > 0;
pmMsgDtaLen = min(%size(pmMsgDta): pmMsgDtaLen);
pmMsgDta = %subst(MsgDta: 1: pmMsgDtaLen);
endif;
MsgFile.Name = 'JCMSGF';
qmhsndpm(MsgId: MsgFile: pmMsgDta: pmMsgDtaLen:
pmMsgTyp: StkEnt: pmStkCnt: pmMsgKey:
ErrorCd);
end-proc;
This should get your message subfile working. As for why the other fields are not populating, maybe your product ID and category ID are not found in the file. Note, the product ID and category ID will be the same value when this program runs because ID is mapped to the display file, the product file, and the category file. This doesn't seem to be what you want. If you have trouble dealing with that, ask a new question.

How to create a for loop when the variable is in a sentence?

I want to create a for loop when the variable is in a string format.
my code is:
for i in range(1,32):
DEP_RATE = pd.read_sql_query('select DAYNUM,YYYYMM,sum(DEP_RATE) from ASPM.aspm_qtr where LOCID="ABQ" and DAYNUM = i:"{i}" group by YYYYMM',{i:str(i)},rconn)
the error is:
'dict' object has no attribute 'cursor'
I used this code:
for i in range(1,32):
DEP_RATE = pd.read_sql_query('select DAYNUM,YYYYMM,sum(DEP_RATE) from ASPM.aspm_qtr where LOCID="ABQ" and DAYNUM = "i" group by YYYYMM',rconn, params={i:str(i)})
It hasn't error but doesn't work. the problem is:
("Truncated incorrect DOUBLE value: 'i'")
This appears to be a PANDAS question, yes? I believe it's an argument mismatch with the read_sql_query API. The function signature is:
pandas.read_sql_query(sql, con, index_col=None, coerce_float=True, params=None, parse_dates=None, chunksize=None)
Which roughly says that the first two positional arguments are required, and everything else is defaulted or optional.
To make it more obvious, consider putting your core SQL string on a separate line:
sql = 'SELECT daynum, ... AND daynum = :i'
for i in range(1, 32):
DEP_RATE = pd.read_sql_query(sql, {i: str(i)}, rconn)
With this formulation, it's more obvious that your arguments do not match the API: your second argument is off. Perhaps you want (note the additional keyword argument params):
DEP_RATE = pd.read_sql_query(sql, rconn, params={i: str(i)})
I corrected the code. The correct answer is:
DEP_RATE = list(np.zeros((1,1)))*31
for i in range(1,32):
DEP_RATE[i-1] =np.array(pd.read_sql_query('select DAYNUM,YYYYMM,sum(DEP_RATE) from ASPM.aspm_qtr where LOCID="ABQ" and DAYNUM = '+str(i)+' group by YYYYMM;',rconn, params={i:str(i)}))

Execute Microsoft SQL query on R Shiny

I am writing an R-Shiny app. Can some one tell me how to execute a Microsoft SQL query in R Shiny ?
This is what I have done so far:
data <- reactive({
conn <- reactive ({ databaseOpen(serverName="[serverName]", databaseName=[dbName])})
qr <- reactive ({ SELECT * from myTable })
res <- reactive ({databaseQuery(conn = conn,query = qr)})
close(conn)
View(res)
})
Any help is appreciated !
I was able to call a query by creating a function outside of the server and ui functions (in other words, in a global.r). Then the server function could call that query function using one of the inputs in the function.
Here is my code:
queryfunction <- function(zipper){
odbcChannel <- odbcConnect("myconnection")
querydoc <- paste0("
SELECT distinct *
FROM mydb
where substring(nppes_provider_zip,1,2) = '43'
and [provider_type] = 'General Practice'
")
pricetable <- sqlQuery(odbcChannel, querydoc)
close(odbcChannel)
pricetable[which(substring(pricetable$nppes_provider_zip,1,5)==zipper),]
}
server <- shinyServer(function(input, output) {
output$mytable1 <- renderDataTable(data.table(queryfunction(input$zip)))
})
I figured it out. It can be done as:
server.r
serverfun<-function(input, output){
# Storing values in myData variable
myData <- reactive({
# Opening database connection
conn <- databaseOpen(serverName = "myServer",databaseName = "myDB")
# Sample query which uses some input
qr <- paste( "SELECT name FROM Genes g WHERE Id = ",input$myId," ORDER BY name")
# Storing results
res <- databaseQuery(conn = conn,query = qr)
# closing database
databaseClose(conn)
# Returning results
res
})
output$tbTable <- renderTable({
# Checking if myData is not null
if(is.null(myData())){return ()}
# return myData
myData()
})
ui.r
library("shiny")
shinyUI(
pageWithSidebar(
headerPanel("Hide Side Bar example"),
sidebarPanel(
textInput("Id", "Enter ID below","1234")
),
mainPanel(
tabsetPanel(
tabPanel("Data", tableOutput("tbTable"))
)
)
)
)

Resources