Definition not found for symbol 'QMHSNDPM' - rpgle

I am following Scott Klement's tutorials on IFS programming with RPGLE. I am facing the below issues. I have added the code snippets as well. Please assist.
Ownership of object WITHERRH in QTEMP type *MODULE changed.
*SRVPGM object QZDMMDTA in library QSOC not found.
Definition not found for symbol 'QMHSNDPM'.
Definition not found for symbol 'QMHSNDPM'.
Program WITHERRH in library ABCLIBL not created.
The PR were defined inside this copy source.
/if not defined(ERRNO_H)
D strerror PR * extproc('strerror')
D errnum 10I 0 value
/define ERRNO_H
/endif
/if defined(ERRNO_LOAD_PROCEDURE)
P die B
D die PI N
D msg 256A const
D QMHSNDPM PR extproc('QMHSNDPM')
D messageId 7A const
D qualMsgF 20A const
D msgData 256A const
D msgDataLen 10I 0 const
D msgType 10A const
D callSktEnt 10A const
D callSktCnt 10I 0 const
D messageKey 4A
D errorCode 256A
D dsEC DS
D dsECBytesP 1 4I 0 inz(%size(dsEC))
D dsECBytesA 5 8I 0 inz(0)
D dsECMsgId 9 15
D dsECReserv 16 16
D dsECMsgData 17 256
D msgLen S 10I 0
D theKey S 4A
msgLen = %checkr(msg:' ');
if msgLen < 1;
return *off;
endif;
callP QMHSNDPM('CPF9897':'QCPFMSG *LIBL':msg:msgLen:
'*ESCAPE':'*':3:theKey:dsEC);
return *off;
P E
The main program has QC2LE binding directory added; the 'die' procedure is invoked as below,
H dftactgrp(*no) actgrp(*new) bnddir('QC2LE')
D/copy ABCLIBL/QIFSSRC,IFSIO_H
D/copy ABCLIBL/QIFSSRC,ERRNO_H
.....
if write(fd:%addr(wrdata):%size(wrdata)) < 1;
errMsg = %str(strerror(errno));
callP close(fd);
callP die('open(): ' + errMsg);
endif;

As #user2338816 said QMHSNDPM is a external program not a procedure:
D QMHSNDPM PR extpgm('QMHSNDPM')
Most APIs are external programs and not procedures. And when they aren't external programs it's easy to see from the documentation.
For example: Dump Module Variables
With this API you would bind your program to the QTEDMPV service program and then use extproc to reference the procedure.
D DumpVariables PR extproc('QteDumpModuleVariables')

Related

RPGLE code to RPG - Count number of Digits

I am having an issue with coding this, I need some similar code with this but written in RPG to count the digits in a number.
NumField (15, 0) packed decimal
EVAL numDig = %len(%trim(%char(NumField)))
the %editc built in function dates back to the begin of time. So does %len, %trim and varying fields.
** ---------------------- test0003r ---------------------------
dtest0003r pi
d errmsg s 256a
d packNum s 15p 0
d lx s 10i 0
d v20 s 20a varying
d ch50 s 50a
/free
packNum = 32553;
v20 = %trim(%editc(packNum:'Z')) ;
lx = %len(v20) ;
ch50 = %trim(%editc(lx:'Z')) + ' ' + v20 ;
dsply ch50 ;
*inlr = '1' ;
return ;
/end-free
A fun challenge.
#zen, I agree with others. I would not try to code this in RPG III. I would either convert the RPG III program to RPG IV, or I would call an RPG IV program to do this calculation.
But here is some RPG III code that gets the number of digits. It is horrible code, and almost completely untested. I would never use this code or recommend that anyone else use this code.
C Z-ADD1.2 NUM 52
C EXSR SUB1
C Z-ADD-123.45 NUM 52
C EXSR SUB1
C Z-ADD0 NUM 52
C EXSR SUB1
C RETRN
C SUB1 BEGSR
C MOVELNUM STR 30 P
C '0':' ' XLATESTR STR2 30 P
C ' ' CHECKSTR2 P 50
C P IFGT 0
C SUBSTSTR2:P STR3 30 P
C ' ' CHEKRSTR3 P 50
C ENDIF
C P DSPLY
C ENDSR
It displays 2, 5, 0.

Difference between values and how the code reads the values in CS50

Here's my main code:
// Update vote totals given a new vote
bool vote(string name, int candidatecount, candidate candidates1[MAX])
{
// TODO
for (int a = 0; a < candidatecount; a++)
{
if (candidatecount == a)
{
printf("a\n");
return false;
}
if (name == candidates1[a].names)
{
printf("b\n");
candidates[a].votes = candidates[a].votes + 1;
}
printf("%s, %s\n", candidates1[a].names, name);
}
printf("1\n");
return(name);
}
This was my command line:
./plurality R D
The output (with my responses) was this:
Number of voters: 3
Vote: R
R, R
D, R
1
Vote: D
R, D
D, D
1
Vote: R
R, R
D, R
1
vote candidate 0 go around 0
b 0 e (null)
vote candidate 0 go around 1
b 0 e (null)
(null) won with 0 votes.
It makes it seem like this:
if (name == candidates1[a].names)
should work, but it doesn't, because the printf I have after it doesn't work.
Does anyone know why?
Review the Week 3 video, starting around the 40 minute mark. The prof says
It turns out that in C, you can't use equals equals to compare two strings.
He introduces strcmp at that time, and will give further explanation about why in the next lesson. The simple explanation is that strings are pointers and == will compare the addresses of the operands, not the values.

Problem with GCC compiler

I am using Arch Linux and when I am compiling and running the following C code,
#include <stdio.h>
#include<string.h>
int main(void) {
char s1[]="Hello";
char s2[]="World";
strcat(s1,s2);
int s2_len=strlen(s2);
printf("s1 = %s, s2 = %s and length of s2 = %d.\n", s1, s2, s2_len);
return 0;
}
I am getting the output:
s1 = HelloWorld, s2 = orld and length of s2 = 4.
Although the output shoud be s1 = HelloWorld, s2 = World and length of s2 = 5. and it is the output when I am using some online IDE.
Can somebody explain me why is this happening?
char s1[]="Hello";
char s2[]="World";
strcat(s1,s2);
The variable declarations allocate memory for 5 characters each, plus the terminating NUL byte. Your strcat call writes past that space, which produces undefined results.
In this case, the memory layout is probably something like this
0 1 2 3 4 5 6 7 8 9 10 11
H e l l o \0 W o r l d \0
^ ^
s1 s2
After the strcat, the result is:
0 1 2 3 4 5 6 7 8 9 10 11
H e l l o W o r l d \0 \0
^ ^
s1 s2
Which gives the result you see. Note that there could be other possible results, the program could e.g. crash at the strcat call.

Urlencode/decode, different representation of the same string

I am a bit out of my comfort zone here, so I'm not even sure I'm aproaching the problem appropriately. Anyhow, here goes:
So I have a problem where I shall hash some info with sha1 that will work as that info's id.
when a client wants to signal what current info is being used, it sends a percent-encoded sha1-string.
So one example is, my server hashes some info and gets a hex representation like so:
44 c1 b1 0d 6a de ce 01 09 fd 27 bc 81 7f 0e 90 e3 b7 93 08
and the client sends me
D%c1%b1%0dj%de%ce%01%09%fd%27%bc%81%7f%0e%90%e3%b7%93%08
Removing the % we get
D c1 b1 0dj de ce 01 09 fd 27 bc 81 7f 0e 90 e3 b7 93 08
which matches my hash except for the beginning D and the j after the 0d, but replacing those with their ascii hex no, we have identical hash.
So, as I have read and understood the urlencoding, the standard would allow a client to send the D as either D or %44? So different clients would be able to send different representations off the same hash, and I will not be able to just compare them for equality?
I would prefer to be able to compare the urlencoded strings as they are when they are sent, but one way to do it would be to decode them, removing all '%' and get the ascii hex value for whatever mismatch I get, much like the D and the j in my above example.
This all seems to be a very annoying way to do things, am I missing something, please tell me I am? :)
I am doing this in node.js but I suppose the solution would be language/platform agnostic.
I made this crude solution for now:
var unreserved = 'A B C D E F G H I J S O N K L M N O P Q R S T U V W X Y Za b c d e f g h i j s o n k l m n o p q r s t u v w x y z + 1 2 3 4 5 6 7 8 9 0 - _ . ~';
function hexToPercent(hex){
var index = 0,
end = hex.length,
delimiter = '%',
step = 2,
result = '',
tmp = '';
if(end % step !== 0){
console.log('\'' + hex + '\' must be dividable by ' + step + '.');
return result;
}
while(index < end){
tmp = hex.slice(index, index + step);
if(unreserved.indexOf(String.fromCharCode('0x' + tmp)) !== -1){
result = result + String.fromCharCode('0x' + tmp);
}
else{
result = result + delimiter + tmp;
}
index = index + step;
}
return result;
}

AS2: How to iterate X times through a percentage calculation (containing a circular reference)?

Here is a question for the Excel / math-wizards.
I'm having trouble doing a calculation which is based on a formula with a circular reference. The calculation has been done in an Excel worksheet.
I've deducted the following equations from an Excel file:
a = 240000
b = 1400 + c + 850 + 2995
c = CEIL( ( a + b ) * 0.015, 100 )
After the iterations the total of A+B is supposed to be 249045 (where b = 9045).
In the Excel file this gives a circular reference, which is set to be allowed to iterate 4 times.
My problem: Recreate the calculation in AS2, going through 4 iterations.
I am not good enough at math to break this problem down.
Can anyone out there help me?
Edit: I've changed the formatting of the number in variable a. Sorry, I'm from DK and we use period as a thousand separator. I've removed it to avoid confusion :-)
2nd edit: The third equation, C uses Excels CEIL() function to round the number to nearest hundredth.
I don't know action script, but I think you want:
a = 240000
c = 0
for (i = 0; i < 4; i++){
b = 1400 + c + 850 + 2995
c = (a + b) * 0.015
}
But you need to determine what to use for the initial value of c. I assume that Excel uses 0, since I get the same value when running the above as I get in Excel with iterations = 4, c = 3734.69...
Where do you get the "A + B is supposed to be 249045" value? In Excel and in the above AS, b only reaches 8979 with those values.
function calcRegistrationTax( amount, iterations ) {
function roundToWhole( n, to ) {
if( n > 0 )
return Math.ceil( n/ to ) * to;
else if( n < 0)
return Math.floor( n/ to ) * to;
else
return to;
}
var a = amount;
var b = 0;
var c = 0
for (var i = 0; i < iterations; i++){
b = basicCost + ( c ) + financeDeclaration + handlingFee;
c = ( a + b ) * basicFeeRatio;
c = roundToWhole( c, 100 );
}
return b;
}
totalAmount = 240000 + calcRegistrationTax( 240000, 4 ); // This gives 249045
This did it, thanks to Benjamin for the help.

Resources