tag:blogger.com,1999:blog-26543220228391092242024-03-13T00:05:45.495-07:00Tips on CobolRihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-2654322022839109224.post-5954982540357361912008-12-06T03:09:00.000-08:002008-12-06T04:10:36.158-08:00Handling an empty input fileWhen reading a sequential file, I always use the AT END clause. For example:<br /><br />READ STUDENT-FILE<br /> AT END MOVE 1 TO END-OF-FILE<br />END READ<br /><br />So that if an end of file is reached, END-OF-FILE data field will have a value of '1' and I will use this value to check if an end of file is reached. It also can be used to check for an empty file. It looks like this:<br /><br />IF END-OF-FILE = 1<br /> CLOSE STUDENT-FILE<br /> STOP RUN<br />END-IF<br /><br />After the READ statement, before processing the records in the file, I always check if I'm reading an empty file so as to avoid errors and also to save time by ending the program immediately after it satisfies the condition 'IF END-OF-FILE = 1'.Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com1tag:blogger.com,1999:blog-2654322022839109224.post-14355322939571451852008-10-19T00:25:00.000-07:002008-10-19T02:57:16.296-07:00Initialize statement<span style="font-family:verdana;"><span style="font-size:100%;">I find it very important to initialize first data fields that are to be used in the program to make certain that it will not contain any trash. INITIALIZE statement is like MOVE statement. It is like you are moving spaces to alphanumeric data fields and zeroes to numeric data fields. Consider the following example:</span><br /><span style="font-size:100%;"></span><br /><span style="font-size:100%;">01 WS-EMPLOYEE-RECORD.</span><br /><span style="font-size:100%;"> 05 WS-NAME PIC X(20).</span><br /><span style="font-size:100%;"> 05 WS-BIRTHDAY PIC 9(8).</span><br /><span style="font-size:100%;"> 05 WS-ADDRESS PIC X(30).</span><br /><span style="font-size:100%;"> 05 WS-RATE   PIC 9(4)V99.</span><br /><span style="font-size:100%;"> 05 WS-HOURS PIC 9(4)99.</span><br /><span style="font-size:100%;"></span><br /><span style="font-size:100%;">INITIALIZE WS-EMPLOYEE-RECORD.<BR></span><br /><span style="font-family:verdana;font-size:100%;">The above statement will move spaces to WS-NAME and WS-ADDRESS while zeroes will be moved to WS-BIRTHDAY, WS-RATE and WS-HOURS.</span><br /><span style="font-size:100%;"></span><br /><span style="font-family:verdana;font-size:100%;">Aside from INITIALIZE statement, VALUE clause and MOVE statement can also be used to initialize a data field. </span><br /><span style="font-size:100%;"></span><br /><span style="font-family:verdana;font-size:100%;">If the value of a data field will not change until the end of the program, use the VALUE clause to lessen the execution time.</span><br /><span style="font-size:100%;"></span><br /><span style="font-size:100%;">01 WS-RATE PIC 9(4)V99 VALUE 0100.50.</span><br /><span style="font-size:100%;"></span><br /><span style="font-family:verdana;font-size:100%;">Use MOVE statement if a data field will continually change.</span><br /><span style="font-size:100%;"></span><br /><span style="font-size:100%;">MOVE 12251979 TO WS-BIRTHDAY.</span><br /><span style="font-size:100%;"></span><br /><span style="font-family:verdana;font-size:100%;">According to the book 'Structured COBOL First Course' by M. B. Khan, less execution time for VALUE clause for it assigns the value during compilation whereas the MOVE statement assigns it during execution time.</span><br /><span style="font-size:100%;"></span><br /><span style="font-family:verdana;font-size:100%;">By experience, if I'm not moving anything to a data field using MOVE statement, VALUE clause and INITIALIZE statement it will contain LOW-VALUES. </span><br /><span style="font-size:100%;"></span>Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com0tag:blogger.com,1999:blog-2654322022839109224.post-73723879492445642552008-10-17T20:49:00.000-07:002008-10-19T03:27:27.737-07:00Data field with PIC 9(18) PICTURE clause<span style="font-family:verdana;font-size:100%;">I was about to turnover in production the COBOL program that I've revised due to some discrepancies. It's quite a habit for me to check first the output of the program before passing it for implementation. And this is what I've learned...<br /><br /></span><div><div><span style="font-family:verdana;font-size:100%;">Consider the following example:</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;">01 EMPLOYEE-RECORD. </span></div><div><span style="font-family:georgia;font-size:100%;"> 10 EMP-ID-CODE PIC 9(02).</span></div><div><span style="font-family:georgia;font-size:100%;"> 10 EMP-BDAY PIC 9(08).</span></div><div><span style="font-family:georgia;font-size:100%;"> 10 EMPLOYEE-NO PIC 9(10).</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;">01 WS-EMP-NBR PIC 9(18). <p></span></p></div><div><span style="font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;">01 WS-EMP-RECORD PIC X(20).</span></div><div><span style="font-size:100%;"></span><span style="font-family:georgia;"><br /></div></span><div><span style="font-family:georgia;"><span style="font-size:100%;"><span style="font-family:verdana;">I don't need the</span> EMP-ID-CODE. <span style="font-family:verdana;">Just their birthday and employee number. So I</span></span></span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;">MOVE EMPLOYEE-RECORD TO WS-EMP-NBR.</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;"><span style="font-size:100%;"><span style="font-family:verdana;">Thinking that it will eliminate</span> EMP-ID-CODE since WS-EMP-NBR <span style="font-family:verdana;">is shorter than the value being moved and should cut off the value from the left since the receiving data field is defined as numeric.</span></span></span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;"><span style="font-size:100%;"><span style="font-family:verdana;">If</span> EMPLOYEE-RECORD <span style="font-family:verdana;">contains</span></span></span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixfCrfB1xwQt_RKEoaJ35sRNdmzaZuLTsHK1q8aHPY-5aFmGMR0WlXb7ddky_ETAieE3pVZRH9JdW8gKqoAPRpbk-bYv8yGyzi0HMyxxHG4KDqcFFEB7RLY4OgNSqBzm-_9N0uYrK5j9dH/s1600-h/pic9(18).bmp"><span style="font-family:georgia;font-size:100%;"><img id="BLOGGER_PHOTO_ID_5258364281202238818" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixfCrfB1xwQt_RKEoaJ35sRNdmzaZuLTsHK1q8aHPY-5aFmGMR0WlXb7ddky_ETAieE3pVZRH9JdW8gKqoAPRpbk-bYv8yGyzi0HMyxxHG4KDqcFFEB7RLY4OgNSqBzm-_9N0uYrK5j9dH/s320/pic9(18).bmp" border="0" /></span></a><span style="font-family:georgia;font-size:100%;">.</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:verdana;font-size:100%;">And I was expecting after the move statement to be</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLCjUDeGdWNfPMOR9KOyaNMJE3NvT-Szr6XzAyvYsOyiTJ9u_D9zl6-oin9T2VJOhrxK22KXvktDKp3xH2q7DW8UbLsHNB_Dis7fvml-4gg4P2SWVSeUb3Pyec2QxdIvaghpbqLBIqK_oY/s1600-h/exp.bmp"><span style="font-family:georgia;font-size:100%;"><img id="BLOGGER_PHOTO_ID_5258366074944140066" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLCjUDeGdWNfPMOR9KOyaNMJE3NvT-Szr6XzAyvYsOyiTJ9u_D9zl6-oin9T2VJOhrxK22KXvktDKp3xH2q7DW8UbLsHNB_Dis7fvml-4gg4P2SWVSeUb3Pyec2QxdIvaghpbqLBIqK_oY/s320/exp.bmp" border="0" /></span></a><span style="font-family:georgia;font-size:100%;">.</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:verdana;font-size:100%;">But instead</span></div><div><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_-GzkMUVgrmJtX4vu6KweSbp98KtUzfwUEPtYXB1yN-TwdQ6oCx52bUiJkuarFPvLG7sZoNWAdz8WlLNUquDjlpLkvpgGKo2qqB7r39TJ5esMzHMHJ7GTOAo8ZIcFQ4PdkmakYmuVDEOY/s1600-h/but.bmp"><span style="font-family:georgia;font-size:100%;"><img id="BLOGGER_PHOTO_ID_5258400586642526354" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_-GzkMUVgrmJtX4vu6KweSbp98KtUzfwUEPtYXB1yN-TwdQ6oCx52bUiJkuarFPvLG7sZoNWAdz8WlLNUquDjlpLkvpgGKo2qqB7r39TJ5esMzHMHJ7GTOAo8ZIcFQ4PdkmakYmuVDEOY/s320/but.bmp" border="0" /></span></a><span style="font-family:georgia;"><span style="font-size:100%;"> <span style="font-family:verdana;">were the contents. <p></span></span></span></p></div><div><span style="font-family:Verdana;font-size:100%;"></span></div><div><span style="font-family:Verdana;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:verdana;font-size:100%;">To sum it all up, avoid moving group data field, like the one above, in numeric data field for it will not truncate the value from the left as I have expected. Move the group data field first into elementary data field, same as the solution that I did which is also shown below, to come up with just the employee's birthday and employee number. Also, always check the output if it's what you really want the outcome to be. So below is what I did; <p></span></p></div><div><span style="font-family:Verdana;font-size:100%;"></span></div><div><span style="font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;font-size:100%;">MOVE EMPLOYEE-RECORD TO WS-EMP-RECORD.</span></div><div><span style="font-family:georgia;font-size:100%;">MOVE WS-EMP-RECORD TO WS-EMP-NBR.</span></div><div><br /><span style="font-family:georgia;font-size:100%;"></span></div><div><span style="font-family:georgia;"><span style="font-size:100%;"><span style="font-family:verdana;">Just also want to add that PIC 9(18) is the maximum allowable size for numeric data field. In excess of this will cause an error.</span></div><div><span style="font-family:georgia;font-size:100%;"></span></div></div></span></span><br /><br /><span style="font-family:georgia;"><span style="font-size:100%;"></span></span>Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com0tag:blogger.com,1999:blog-2654322022839109224.post-63275798923019708232008-10-06T06:56:00.000-07:002008-10-19T03:23:06.044-07:00HIGH-VALUES<span style="font-size:100%;"><span style="font-family:georgia;">While I was in the middle of revising a program, I tried to move HIGH-VALUES to a data field</span><br /><br /><span style="font-family:georgia;">MOVE HIGH-VALUES TO WS-RECEIVING FIELD</span><br /><br /><span style="font-family:georgia;">where</span><br /><br /><span style="font-family:georgia;">01 WS-RECEIVING FIELD PIC X(10) is in the WORKING-STORAGE SECTION. </span><br /><br /><span style="font-family:georgia;">Contents of WS-RECEIVING FIELD after the MOVE</span><br /></span><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgslDBrFoZN_7UZzPYJUqGxtAM-3cY2iT-HYNciyQu3TQrftVw2sBjFDyPLih9fOolFnrsGjQ6I0x3Tz7Upd-Qetdm8WF8aB-gsXeYioQTzC_-H6n-GMpYu-JoC7UwsxO8kMbLUdTFPpjjg/s1600-h/untitled1.bmp"><img id="BLOGGER_PHOTO_ID_5254432232987355762" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgslDBrFoZN_7UZzPYJUqGxtAM-3cY2iT-HYNciyQu3TQrftVw2sBjFDyPLih9fOolFnrsGjQ6I0x3Tz7Upd-Qetdm8WF8aB-gsXeYioQTzC_-H6n-GMpYu-JoC7UwsxO8kMbLUdTFPpjjg/s320/untitled1.bmp" border="0" /></a><br /><br /><div></div><div><span style="font-size:100%;">I have to type "hex on" on the command line to make sure that it is not spaces.</span><br /></span><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5aSa18BuHccx_fVZK9h72SDjepYO4FEgpxk_WYTiiZ3EuF1EBcClKbX1CMi2DNueEPlBc-T9nujnVdI0zCQnqD-At9d_W5fPOwNkQ-MXBh5bimluvsJLf5rQ7baWA0K0GEBhjeCBp_MBp/s1600-h/untitled4.bmp"><img id="BLOGGER_PHOTO_ID_5254441319582174018" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5aSa18BuHccx_fVZK9h72SDjepYO4FEgpxk_WYTiiZ3EuF1EBcClKbX1CMi2DNueEPlBc-T9nujnVdI0zCQnqD-At9d_W5fPOwNkQ-MXBh5bimluvsJLf5rQ7baWA0K0GEBhjeCBp_MBp/s320/untitled4.bmp" border="0" /></a></span><br /><br /></div><div><span style="font-size:100%;"></span> </div><div><span style="font-size:100%;"></span> </div><div></div><div><span style="font-size:100%;"></span></div><div><span style="font-size:100%;">Actually both LOW-VALUES and HIGH-VALUES look like SPACES when "hex off". The difference is that SPACES hex value is: <br /></span></div><br /><div></div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ANt1b6dqOM3CgNiB3ckrR6lJCOdj9at9RZZWnuZPjBLlZy2P0X0dhbC_Vomj6a_XN84mH0P_q1e9D2cFXW_mat8KZJLfonNAnnBRNmvMy6kABZ2NYOmSH5VHUbxmcyelqFVpxch1y5e7/s1600-h/untitled3.bmp"><img id="BLOGGER_PHOTO_ID_5254440282307521730" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ANt1b6dqOM3CgNiB3ckrR6lJCOdj9at9RZZWnuZPjBLlZy2P0X0dhbC_Vomj6a_XN84mH0P_q1e9D2cFXW_mat8KZJLfonNAnnBRNmvMy6kABZ2NYOmSH5VHUbxmcyelqFVpxch1y5e7/s320/untitled3.bmp" border="0" /></a><br /><br /><div></div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguUfJPpeWeML8ape3wHoH9JRMDjLUM9qLZ4nii0MuYt6CofaEuIGvk-69yf6x1OyaVBRpBUKckx_gRjpZvFwpCIWPn-zdb0df-V9yGOxGkvPLEZWBhQGp7_9YY1BrX86-8khGMLODA8yQv/s1600-h/untitled1.bmp"></a>Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com1tag:blogger.com,1999:blog-2654322022839109224.post-13402043701879071102008-10-04T23:44:00.000-07:002008-10-19T03:24:47.641-07:00Dealing with abends - S0C7<span style="font-family:georgia;"><span style="font-size:100%;">I have recently been part of a project. Thank God that it is now implemented and being used by our clients. I have encountered a data exception error (abend code = S0C7) during the pilot implementation. It took me and my teammates 2 hours to correct this error. Because of this experience I should be careful next time not to move </span></span></span></span><a href="http://www.felgall.com/cob1.htm"><span style="font-family:georgia;font-size:100%;">alphabetic character </span></span></a><span style="font-family:georgia;font-size:100%;">or spaces to a data field that is declared </span></span><a href="http://www.3480-3590-data-conversion.com/article-reading-cobol-layouts-4.html"><span style="font-family:georgia;font-size:100%;">numeric</span></span></a><span style="font-family:georgia;font-size:100%;"> for it will cause a data exception error or S0C7.</span>Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com0tag:blogger.com,1999:blog-2654322022839109224.post-43575277125365563422008-10-04T05:24:00.000-07:002008-10-19T03:12:01.476-07:00Meanings of Figurative Constants<span style="font-family:georgia;font-size:100%;"><span style="font-family:verdana;">I constantly use figurative constants in assigning initial values to data fields thus it is helpful to know what are these figurative constants and its meaning.<br /></span><br /></span><span style="font-family:verdana;font-size:100%;"><strong>Figurative Constant Meaning<br /><br />SPACE(S) Fills the field with blank spaces<br />ZERO(S) Fills the field with zeroes<br />HIGH-VALUE(S) Fills the field with the highest binary value the computer system being used is able to represent<br />LOW-VALUE(S) Fills the field with the lowest binary value the computer system being used is able to represent</strong></span><br /><span style="font-family:verdana;"><strong><span style="font-size:100%;"><br /></span></strong><span style="font-family:georgia;"><span style="font-family:verdana;"><span style="font-size:100%;">Figurative contants by the way are reserved words in COBOL. These have predefined meanings to the compiler.<br /></span><span style="font-family:georgia;"><br /><span style="font-family:verdana;font-size:100%;">Reference:<br />(1) Khan, M.B., </span></span><a href="http://www.amazon.com/Structured-Cobol-M-B-Khan/dp/0789500981"><span style="font-size:100%;">Structured COBOL: First Course</span></span></a><span style="font-family:georgia;font-size:100%;">, 1996, boyd & fraser publishing company.</span></span></span><span style="font-size:100%;"><br /><br /></span><br /></span></span></span></span></span>Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com0tag:blogger.com,1999:blog-2654322022839109224.post-68050969603967936852008-10-04T03:12:00.000-07:002008-10-19T03:08:11.612-07:00Moving LOW-VALUES to a data-field<span style="font-family:georgia;font-size:100%;">I am a Cobol Programmer. I have been in this career since 2004. I am a licensed ECE but my heart is really with programming. So I'm writing to give you some pointers that will somehow help you. When I was in my early years in this job, I had so many things that I wanted to know like what will be the contents of the receiving data field when I move <span style="font-family:georgia;font-size:100%;">LOW-VALUE(S) to it.</span><br /><br />For example in my <span style="font-family:verdana;">WORKING-STORAGE SECTION</span>, I will have<br /><br /><span style="font-family:verdana;">01 WS-RECEIVING-FIELD PIC X(10)</span><br /><br />and in PROCEDURE DIVISION, I will code<br /><br /><span style="font-family:verdana;">MOVE LOW-VALUES TO WS-RECEIVING-FIELD</span>.<br /><br />The contents of the data field <span style="font-family:verdana;">WS-RECEIVING-FIELD</span> after executing the previous MOVE statement will be</span><br /><br /><div><div> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkjtg12q8cJT-CiWv7TBDKgK45fFPuzoqpokgG2BUkuI83aqib5RmamjsyoxW2lQJFK0dEw6BhXx2in-dzmmv51SfTRQcKBsTnmeppfeplaCGCb0SnGtekx7jMBWsSN183eQ5XtFAC2Pdg/s1600-h/untitled.bmp"><img id="BLOGGER_PHOTO_ID_5254430673539851458" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkjtg12q8cJT-CiWv7TBDKgK45fFPuzoqpokgG2BUkuI83aqib5RmamjsyoxW2lQJFK0dEw6BhXx2in-dzmmv51SfTRQcKBsTnmeppfeplaCGCb0SnGtekx7jMBWsSN183eQ5XtFAC2Pdg/s320/untitled.bmp" border="0" /></a><br /></div><div><div><span style="font-family:georgia;font-size:100%;"><br />when "hex on" is typed in the command line.</span></div></div></div>Rihannahttp://www.blogger.com/profile/04327836110939617529noreply@blogger.com0