Code Comments
Programming Forum and web based access to our favorite programming groups.Hello all, I had this small cobol routine dropped on my desk and need to convert it into a vb app, but I am not all that familiar with most of cobol. I can read most of it and decipher what is going on, but having trouble with this move. var1 pic 9 comp. var2 pic 9(10) If var2 had the value of 138755482 and MOVE VAR2 TO VAR1 is executed, what is actually stored in var1. I apologize if this is a no brainer. Thanks in advance. Peace.
Post Follow-up to this messageOn 31 May 2006 08:27:26 -0700, the_tragic_hip@yahoo.com wrote: >I had this small cobol routine dropped on my desk and need to convert >it into a vb app, but I am not all that familiar with most of cobol. I >can read most of it and decipher what is going on, but having trouble >with this move. > >var1 pic 9 comp. >var2 pic 9(10) > >If var2 had the value of 138755482 and > >MOVE VAR2 TO VAR1 is executed, what is actually stored in var1. > >I apologize if this is a no brainer. > >Thanks in advance. What is stored is 2, but it is stored in binary. This seems like a weird thing to do, truncated a value but stored as binary. How is VAR1 used? What version of CoBOL are you using? Compiler and OS.
Post Follow-up to this message> What is stored is 2, but it is stored in binary. This seems like a > weird thing to do, truncated a value but stored as binary. How is > VAR1 used? > > What version of CoBOL are you using? Compiler and OS. I thought that that was what was stored there, but I couldn't make sense of it. This routine is a check to make sure an account number is valid. It goes through a whole bunch of multipys and divides and such, and then the outcome of all this must match var2. Unfortunately, all I was handed was a piece of paper with the code, no clue what version of CoBOL was being used or compiler. I do have an exe of the routine that I can run on XP. Let me see if I have this part correct. 01 JB-WORK 03 VAR1 PIC 9(10) 03 VAR1-R REDEFINES VAR1 05 VAR9 PIC9(9). 05 VARLST PIC 9. I am assuming that if 138755482 is moved to var1 then var9 would be 138755482 ... is that correct? Thanks so much for the quick reply. Peace.
Post Follow-up to this messageOn 31 May 2006 08:27:26 -0700 the_tragic_hip@yahoo.com wrote: :>I had this small cobol routine dropped on my desk and need to convert :>it into a vb app, but I am not all that familiar with most of cobol. I :>can read most of it and decipher what is going on, but having trouble :>with this move. :>var1 pic 9 comp. :>var2 pic 9(10) :>If var2 had the value of 138755482 and :>MOVE VAR2 TO VAR1 is executed, what is actually stored in var1. Probably depends on your COBOL and various compiler options. A PIC 9 comp will probably be stored in a halfword (I don't know how much th e COBOL standard allows the size of a COMP to be implementer defined). It may take the last digit and store it as binary. It may take the whole number, convert it to binary, truncate to halfword and store that (IBM TRUNC option). The best thing is too look at the generated code or try it out with the same compiler options and see what happens. :>I apologize if this is a no brainer. Not at all. -- Binyamin Dissen <bdissen@dissensoftware.com> http://www.dissensoftware.com Director, Dissen Software, Bar & Grill - Israel Should you use the mailblocks package and expect a response from me, you should preauthorize the dissensoftware.com domain. I very rarely bother responding to challenge/response systems, especially those from irresponsible companies.
Post Follow-up to this messagetheHip wrote: > > > I thought that that was what was stored there, but I couldn't make > sense of it. This routine is a check to make sure an account number is > valid. It goes through a whole bunch of multipys and divides and such, > and then the outcome of all this must match var2. > > Unfortunately, all I was handed was a piece of paper with the code, no > clue what version of CoBOL was being used or compiler. I do have an > exe of the routine that I can run on XP. > > Let me see if I have this part correct. > > 01 JB-WORK > 03 VAR1 PIC 9(10) > 03 VAR1-R REDEFINES VAR1 > 05 VAR9 PIC9(9). > 05 VARLST PIC 9. > > I am assuming that if 138755482 is moved to var1 then var9 would be > 138755482 ... is that correct? > > Thanks so much for the quick reply. > > Peace. > No. Var1 is a ten (decimal)digit number. Var9 redefines the first 9 digits as a 9 digit number, and Varlst redfines the low order digit as a single digit number. So moving 138775842 to var1 moves 1387784 to var9, and 2 to varlst. I would suspect that the routine uses the low order digit in some sort of checksum routine. Donald
Post Follow-up to this messageOn 31 May 2006 08:52:52 -0700, "theHip" <the_tragic_hip@yahoo.com> wrote: >I thought that that was what was stored there, but I couldn't make >sense of it. This routine is a check to make sure an account number is >valid. It goes through a whole bunch of multipys and divides and such, >and then the outcome of all this must match var2. I've come across that kind of validation code. The last digit of the account was created by a bank or somebody using the same calculation and is used like a parity bit. If you don't get the same result, the number is corrupt. So don't try to make sense of it quite yet, just translate it. The number doesn't have to be COMP though, all you're doing is arithmetic and truncating until you get a digit to match with the digit they got. Test it with supplied numbers and with hand-made corrupt numbers.
Post Follow-up to this messageOn 31 May 2006 08:52:52 -0700 "theHip" <the_tragic_hip@yahoo.com> wrote: :>Let me see if I have this part correct. :>01 JB-WORK :> 03 VAR1 PIC 9(10) :> 03 VAR1-R REDEFINES VAR1 :> 05 VAR9 PIC9(9). :> 05 VARLST PIC 9. :>I am assuming that if 138755482 is moved to var1 then var9 would be :>138755482 ... is that correct? A completely different story. You are now using an overlay and you aren't using COMP. VAR9 = 013875548 VARLST = 2 -- Binyamin Dissen <bdissen@dissensoftware.com> http://www.dissensoftware.com Director, Dissen Software, Bar & Grill - Israel Should you use the mailblocks package and expect a response from me, you should preauthorize the dissensoftware.com domain. I very rarely bother responding to challenge/response systems, especially those from irresponsible companies.
Post Follow-up to this message> I had this small cobol routine dropped on my desk and need to convert > it into a vb app, but I am not all that familiar with most of cobol. I > can read most of it and decipher what is going on, but having trouble > with this move. > > var1 pic 9 comp. > var2 pic 9(10) > > If var2 had the value of 138755482 and > > MOVE VAR2 TO VAR1 is executed, what is actually stored in var1. > > I apologize if this is a no brainer. MOVE= assignment MOVE A TO B (cobol) ===> [ LET] B = A (BASIC) DIM VAR1 AS LONG, VAR2 AS LONG VAR1 = VAR2 WARNING: a long integer will not hold Var2, where PIC 9(10) specifies a numeric data item with ten digits before the decimal. You may need to go to a SINGLE or DOUBLE here. I say "may" because....... WARNING 2: the MOVE statement shown is also invalid, since a PIC 9 COMP (1 digit integer) won't hold it either. If this is the actual code and not just an example you made up for posting purposes, it looks as though someone has done something "cute" and if you don't know COBOL you are in for a VERY long day. BUT.... if you want to learn about COBOL datatypes, download my free text and graphics tutorial at http://www.flexus.com/download.html, get file COBDATA.ZIP If you want to learn more specifically about using COBOL-created data in non-COBOL programs, read the free tutorial on my web site at http://www.talsystems.com, click on "Tech Corner" and then select file "C2IEEE.HTML" Of course, there's always the option to engage outside assistance from someone who knows both BASIC and COBOL.... -- Michael Mattias Tal Systems, Inc. Racine WI mmattias@talsystems.com
Post Follow-up to this messageIn article <1149090772.312634.210890@g10g2000cwb.googlegroups.com>, theHip <the_tragic_hip@yahoo.com> wrote: > >I thought that that was what was stored there, but I couldn't make >sense of it. This routine is a check to make sure an account number is >valid. It goes through a whole bunch of multipys and divides and such, >and then the outcome of all this must match var2. > >Unfortunately, all I was handed was a piece of paper with the code, no >clue what version of CoBOL was being used or compiler. So let me get this straight... you don't know COBOL, you don't have a compiler so you cannot test your results... and someone expects a valid answer out of you? Based on the amount of attention and resources being paid to this problem there is no money involved in it... good thing, too! DD
Post Follow-up to this message"Michael Mattias" <michael.mattias@gte.net> wrote in message news:qPjfg.2694$VE1.1338@newssvr14.news.prodigy.com... > > MOVE= assignment > > MOVE A TO B (cobol) ===> [ LET] B = A (BASIC) > > DIM VAR1 AS LONG, VAR2 AS LONG > > VAR1 = VAR2 > > WARNING: a long integer will not hold Var2, where PIC 9(10) specifies a > numeric data item with ten digits before the decimal. You may need to go > to > a SINGLE or DOUBLE here. It takes 34 bits to store an unsigned 10 digit number, and 35 bits to store a signed 10 digit number, so you're right that LONG INTEGER (32 bit signed) won't be enough to store all values of the PIC 9(10). However, if you move to floating point numbers (e.g. SINGLE or DOUBLE), you're opening yourself up to problems with rounding, which may also yield big headaches. In such a case, you'll want to use a "Big Integer" package, such as the one which can be downloaded from http://www.codeproject.com/com/BigInteger.asp - Oliver
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.