Code Comments
Programming Forum and web based access to our favorite programming groups.I am using NetCOBOL for .NET version V2.0L10. When I run this program IDENTIFICATION DIVISION. PROGRAM-ID. TST-TEMP. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. 01 DATA-GROUP. 05 DG-ALPHA PIC X(10). 05 DG-NUM PIC S9(9) COMP-3. 05 DG-NUM2 PIC 9(3). PROCEDURE DIVISION. START-IT-ALL. DISPLAY "TESTING MOVE SPACES". MOVE SPACES TO DATA-GROUP. IF DG-NUM = 0 DISPLAY "NUM IS 0" ELSE DISPLAY "NUM IS NOT 0" END-IF. IF DG-NUM2 = 0 DISPLAY "NUM2 IS 0" ELSE DISPLAY "NUM2 IS NOT 0" END-IF. IF DG-ALPHA = SPACES DISPLAY "ALPHA IS SPACES " ELSE DISPLAY "ALPHA IS NOT SPACES" END-IF. DISPLAY "TESTING INITIALIZE". INITIALIZE DATA-GROUP. IF DG-NUM = 0 DISPLAY "NUM IS 0" ELSE DISPLAY "NUM IS NOT 0" END-IF. IF DG-NUM2 = 0 DISPLAY "NUM2 IS 0" ELSE DISPLAY "NUM2 IS NOT 0" END-IF. IF DG-ALPHA = SPACES DISPLAY "ALPHA IS SPACES " ELSE DISPLAY "ALPHA IS NOT SPACES" END-IF. PROG-END. STOP RUN. I get this output TESTING MOVE SPACES NUM IS NOT 0 NUM2 IS NOT 0 ALPHA IS SPACES TESTING INITIALIZE NUM IS 0 NUM2 IS 0 ALPHA IS SPACES Here is my problem. When I move spaces to a group level item I would expect that the numeric display item to test as zero, and the numeric comp item not to test as zero. This is the result that I would expect. NUM IS NOT 0 NUM2 IS 0 ALPHA IS SPACES Is there a control setting / flag that I missed in the documentation? Thanks in advance for your help. Tom
Post Follow-up to this messageIn article <1192112346.309248.85020@r29g2000hsg.googlegroups.com>, "tleaders ..gmail.com" <tleaders@gmail.com> wrote: >I get this output > >TESTING MOVE SPACES >NUM IS NOT 0 >NUM2 IS NOT 0 >ALPHA IS SPACES >TESTING INITIALIZE >NUM IS 0 >NUM2 IS 0 >ALPHA IS SPACES Which of course is *exactly* what is expected. >Here is my problem. When I move spaces to a group level item I would >expect that the numeric display item to test as zero, and the numeric >comp item not to test as zero. Indeed, that is your problem: that you are expecting things to happen, that the Cobol standard explicitly says will *not* happen. What you *should* expe ct is that the program will do exactly what you told it to do: MOVE SPACES to t he group item. Which, of course, is just what it did. > This is the result that I would expect. >NUM IS NOT 0 >NUM2 IS 0 >ALPHA IS SPACES Why would you expect that? You told it to move spaces. It moved spaces. Spac es and zeros are not the same. If you want spaces in the alphanumeric items, an d zeros in the numeric ones, use INITIALIZE. That's what it's for. And your testing shows, unsurprisingly, that it works for that purpose just as expected. > >Is there a control setting / flag that I missed in the documentation? What you missed in the documentation is the description of the way a MOVE to a group item behaves -- and, possibly, the description of INITIALIZE, too: I'l l bet that under that heading, your documentation explains exactly how the behavior of INITIALIZE differs from the behavior of a group MOVE. -- Regards, Doug Miller (alphagat milmac dot com) It's time to throw all their damned tea in the harbor again.
Post Follow-up to this messageOn Thu, 11 Oct 2007 14:19:06 -0000, "tleaders...gmail.com" <tleaders@gmail.c om> wrote: >I am using NetCOBOL for .NET version V2.0L10. > > 01 DATA-GROUP. > 05 DG-ALPHA PIC X(10). > 05 DG-NUM PIC S9(9) COMP-3. > 05 DG-NUM2 PIC 9(3). > > PROCEDURE DIVISION. > START-IT-ALL. > DISPLAY "TESTING MOVE SPACES". > MOVE SPACES TO DATA-GROUP. > > DISPLAY "TESTING INITIALIZE". > INITIALIZE DATA-GROUP. > >I get this output > >TESTING MOVE SPACES >NUM IS NOT 0 >NUM2 IS NOT 0 >ALPHA IS SPACES >TESTING INITIALIZE >NUM IS 0 >NUM2 IS 0 >ALPHA IS SPACES > > >Here is my problem. When I move spaces to a group level item I would >expect that the numeric display item to test as zero, and the numeric >comp item not to test as zero. This is the result that I would expect. >NUM IS NOT 0 >NUM2 IS 0 >ALPHA IS SPACES > >Is there a control setting / flag that I missed in the documentation? The option you're looking for is SPZERO and run-time switch -F. If you want a fast way to initialize DATA-GROUP, create another structure ju st like it (perhaps using typedef for both), INITIALIZE the second structure once, do a group move to initialize DATA-GROUP.
Post Follow-up to this message"Robert" <no@e.mail> wrote: > > The option you're looking for is SPZERO and run-time switch -F. > > If you want a fast way to initialize DATA-GROUP, create another structure just like it > (perhaps using typedef for both), INITIALIZE the second structure once, do a group move to > initialize DATA-GROUP. When he says "just like it," he doesn't mean that the actual data names need to be the same. Only the number, type, size and sequence of the fields must to be the same, for this purpose. You may want to make the data names similar for clarity, but if they are identical, you will have to qualify every reference to any of the data names. Personally, I like to assign a unique prefix (usually an acronym derived from the record name) to every field within a given record (01 data item). Then the two records Robert described above would be identical, except for the prefixes of the data names. -- Judson McClendon judmc@sunvaley0.com (remove zero) Sun Valley Systems http://sunvaley.com "For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
Post Follow-up to this messagetleaders...gmail.com wrote: > I am using NetCOBOL for .NET version V2.0L10. > > When I run this program > IDENTIFICATION DIVISION. > PROGRAM-ID. TST-TEMP. > ENVIRONMENT DIVISION. > CONFIGURATION SECTION. > INPUT-OUTPUT SECTION. > FILE-CONTROL. > DATA DIVISION. > FILE SECTION. > WORKING-STORAGE SECTION. > > 01 DATA-GROUP. > 05 DG-ALPHA PIC X(10). > 05 DG-NUM PIC S9(9) COMP-3. > 05 DG-NUM2 PIC 9(3). > > PROCEDURE DIVISION. > START-IT-ALL. > DISPLAY "TESTING MOVE SPACES". > MOVE SPACES TO DATA-GROUP. > IF DG-NUM = 0 > DISPLAY "NUM IS 0" > ELSE > DISPLAY "NUM IS NOT 0" > END-IF. > IF DG-NUM2 = 0 > DISPLAY "NUM2 IS 0" > ELSE > DISPLAY "NUM2 IS NOT 0" > END-IF. > IF DG-ALPHA = SPACES > DISPLAY "ALPHA IS SPACES " > ELSE > DISPLAY "ALPHA IS NOT SPACES" > END-IF. > > > DISPLAY "TESTING INITIALIZE". > INITIALIZE DATA-GROUP. > IF DG-NUM = 0 > DISPLAY "NUM IS 0" > ELSE > DISPLAY "NUM IS NOT 0" > END-IF. > IF DG-NUM2 = 0 > DISPLAY "NUM2 IS 0" > ELSE > DISPLAY "NUM2 IS NOT 0" > END-IF. > IF DG-ALPHA = SPACES > DISPLAY "ALPHA IS SPACES " > ELSE > DISPLAY "ALPHA IS NOT SPACES" > END-IF. > > PROG-END. > STOP RUN. > > > > > I get this output > > TESTING MOVE SPACES > NUM IS NOT 0 > NUM2 IS NOT 0 > ALPHA IS SPACES > TESTING INITIALIZE > NUM IS 0 > NUM2 IS 0 > ALPHA IS SPACES > > > Here is my problem. When I move spaces to a group level item I would > expect that the numeric display item to test as zero, and the numeric > comp item not to test as zero. This is the result that I would expect. > NUM IS NOT 0 > NUM2 IS 0 > ALPHA IS SPACES > > Is there a control setting / flag that I missed in the documentation? > > Thanks in advance for your help. > > Tom > You may be confusing what happens when you move DG-NUM2 to an edited field PIC Z(3) -- if DG-NUM2 is 0, then you get three spaces -- with what is actually stored in DG-NUM2 if you set it to zero. For ASCII machines (i.e., something other than an IBM mainframe or Unisys MCP system), a '0' character is hex 30, and a space is hex 20. If you test DG-NUM2 to see if it was numeric after you moved spaces to DATA-GROUP, I wouldn't be surprised if the result turns out to be false. Louis
Post Follow-up to this messageRobert - thanks I will read up on the SPZERO and run-time switch -F and try to test it this wend. For the rest. This was a sample program that I wrote to show the issue. I should mention that I am maintaining Unisys A-Series Cobol 74 code but I port the code and do all the initial testing on my notebook in cobol.net. This allows me to build/update/destroy the data in sql server, and the debugging tools are a lot better. The initialize verb is not available on A-Series Cobol74 at least not with the settings that I am running. And Yes I could change to Cobol85 but at this time I see no ROI for that effort. Also the code on the A-series (Clearpath) behaves exactly as I described. By the way Doug that was a rather verbose way of saying NO I don't have a clue. Tom
Post Follow-up to this messageIn article <1192127701.497708.78990@k79g2000hse.googlegroups.com>, "tleaders ..gmail.com" <tleaders@gmail.com> wrote: >By the way Doug that was a rather verbose way of saying NO I don't >have a clue. <snort> It wasn't *me* who was expecting MOVE SPACES to produce zeros. -- Regards, Doug Miller (alphagat milmac dot com) It's time to throw all their damned tea in the harbor again.
Post Follow-up to this messageOn Oct 11, 3:23 pm, spamb...@milmac.com (Doug Miller) wrote: > In article <1192127701.497708.78...@k79g2000hse.googlegroups.com>, "tleade rs...gmail.com" <tlead...@gmail.com> wrote: > > > <snort> > > It wasn't *me* who was expecting MOVE SPACES to produce zeros. > > -- > Regards, > Doug Miller (alphagat milmac dot com) > > It's time to throw all their damned tea in the harbor again. http://supportline.microfocus.com/d...1sp1/cyswit.htm SPZERO - causes space characters in numeric data items of USAGE DISPLAY to be treated as zeros.
Post Follow-up to this messagetleaders...gmail.com wrote: <snip> > Also the code on the A-series (Clearpath) behaves exactly as I > described. Quoting from the B5900 System Reference Manual: The numeric field (low-order four bits) of each character in an EBCDIC sequence is interpreted as a decimal digit. The corresponding digit sequence is the sequence of numeric fields with the zone fields (high-order four bits) removed. ... Sounds like the A-Series box is also doing it in hardware (or firmware or whatever) and is masking out the zone fields, so an EBCDIC space (hex 40, if I recall correctly) conveniently comes out 0 just like an EBCDIC '0' (hex F0). netcobol *could* have done the same thing, but, by default, didn't. Most of the decimal to binary conversion code I've seen computes the decimal value by subtracting '0' from the character. This assumes only that the characters '0' through '9' are represented by continuous values. Louis
Post Follow-up to this message"Robert Jones" <rjones0@hotmail.com> wrote: > "Judson McClendon" <ju...@sunvaley0.com> wrote: > > I like the idea, but it would be less code to INITIALIZE the original > group data item, store it in an elementary data item of the same > length and move that back into the original group data item whenever > required. It might even be the case that an optimising compiler would > do this automatically where INITIALIZE is used repetitively for the > same group data item. I agree, that would be better. What would be *really* nice is if you could do this: 01 the-record. 03 the-field-a pic ... 03 the-field-b pic ... .. 01 the-record-initialize pic x(SizeOf(the-record)). :-) -- Judson McClendon judmc@sunvaley0.com (remove zero) Sun Valley Systems http://sunvaley.com "For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.