2.3K views

Uploaded by sxdasgu

save

- php8Hghij
- A Normal to the Graph of y =
- Lateral MCA Scheme and Syllabus 2013 Onwards 28-10-2013
- DB2 File Aid – A Step By Step Manual for Beginners
- JAVA Project
- mc-ty-introfns-2009-1
- IntroToArena.4
- Statements in C
- Comp-3 To Comp - Decimal Conversions
- COBOL.pdf
- ch05
- IntroP Curs 4 Eng
- COBOL_CDC[1]
- Cobol_Part2
- Limit Proof Technique
- 16479_ArrayMCQ.doc
- Relations
- Squareroot Functions
- Fault Analyser
- c Unit 6 Array Last Print
- Arrays c++ Print
- Arrays
- Ch 7 Arrays & Collections
- samathaR[1]
- Introduction to Programming
- ARRAYA OF XII.doc
- 2-espres
- Array
- Array 280910 - A
- Inverse Function
- Abend Codes
- Michael Learns to Rock Lyrics
- AMODE & RMODE
- Bryan Adams Lyrics
- IBM SORT for Beginners
- 24 Genesee Sangertown
- File Status Keys in Mainframes
- Condor Training Basics
- ITJOBSHUB DB2 Interview Questions
- 28981105-Abend-Codes
- Visual Age Pacbase
- ITJOBSHUB JCL Interview Questions
- List of SQLCODES for DB2
- Geocities VSAM Interview Questions
- Different Utilities
- Geocities JCL Interview Questions
- An Introduction to Trigger in DB2 for OS
- Sort - Examples
- SQLCODES for DB2
- Cobol FAQs
- Mainframe Utilities
- Handling Variable Length Sequential Files
- Comp-3 To Comp - Decimal Conversions
- Geocities COBOL Interview Questions
- Geocities DB2 Interview Questions

You are on page 1of 3

An Alphanumeric to numeric move is not a valid move in COBOL. There is an exceptional case where this move is permissible which will be discussed in the text. The Moves in Cobol are always guided by the 'Receiving field' in Cobol. If the receiving field is declared as numeric then the move is called a numeric move. Let us take an example and analyze each case along with their solutions. Let us consider the following fields: WS-INPUT WS-OUTPUT PIC X(10). PIC 9(10).

The following Table shows the Input records and the Expected Output Case 1. 2. 3. INPUT RECORD 1234567890 10107 101006 OUTPUT RECORD 1234567890 0000010107 0000101006

CASE 1: (Exceptional case) COBOL statements: MOVE WS-INPUT TO WS-OUTPUT. DISPLAY “ OUTPUT IS : “ WS-OUTPUT. Result: OUTPUT IS : 1234567890 Here even tough the Input field is Alphanumeric but as the Data in the field is numeric and has no spaces. Thus the simple MOVE statement will work.

CASE 2 & 3: COBOL statements: MOVE WS-INPUT TO WS-OUTPUT. DISPLAY “ OUTPUT IS : “ WS-OUTPUT.

ERROR!

The reason being there are spaces in the input data, which are Characters. And we cannot move characters into a numeric field. The simple MOVE statement will not work. Now the Question arises what to do if we need the numeric values of an alphanumeric variable? The above result can be achieved in 3 ways: 1. Using an array. 2. Using INSPECT statement. 3. NUMVAL () Function.

1. Using an array:

01 WS-ARR. 05 WS-INPUT-ARR 01 WS-IDX OCCURS 10 TIMES PIC X (1). PIC 9(02) VALUE ZEROES.

MOVE WS-INPUT TO WS-ARR. PERFORM VARYING WS-IDX FROM 1 BY 1 UNTIL WS-INOUT-ARR (WS-IDX) IS NOT NUMERIC. MOVE WS-INPUT (1:WS-IDX) TO WS-OUTPUT. DISPLAY “ OUTPUT IS : “ WS-OUTPUT. Result for INPUT RECORD 2: OUTPUT IS : 0000010107 Result for INPUT RECORD 3: OUTPUT IS : 0000101006 This particular method is not considered a good programming practice.

**2. Using INSPECT Statement:
**

* ************************************************************** IT COUNTS THE NUMBER CHARACTERS BEFORE THE FIRST SPACE * * IS ENCOUNTERED AND MOVES THE VALUE OF THAT COUNT TO WS-IDX * **************************************************************

INSPECT WS-INPUT TALLYING WS-IDX FOR CHARACTERS BEFORE INITIAL SPACES. MOVE WS-INPUT (1:WS-IDX) TO WS-OUTPUT. DISPLAY “ OUTPUT IS : “ WS-OUTPUT. Result for INPUT RECORD 2: OUTPUT IS : 0000010107 Result for INPUT RECORD 3: OUTPUT IS : 0000101006

**WAIT THERE IS A CATCH HERE!!
**

The INSPECT may FAIL if WS-INPUT is “ 123 “. Here the value of the WS-IDX = 0. Thus you will get an error, as you will be moving spaces. (By now we know that spaces cannot be moved in a numeric variable) The above case is handled by the next function.

**3. Using NUMVAL () Function:
**

The NUMVAL function returns the numeric value represented by the character string specified by parameter-1. Leading and trailing spaces are ignored. Syntax FUNCTION NUMVAL (parameter-1) The total number of digits in parameter-1 must not exceed 18. COMPUTE WS-OUTPUT = FUNCTION NUMVAL (WS-INPUT). DISPLAY “ OUTPUT IS : “ WS-OUTPUT. Result for INPUT RECORD 2: OUTPUT IS : 0000010107 Result for INPUT RECORD 3: OUTPUT IS : 0000101006 Considering the case which failed in the INSPECT statement If WS-INPUT is “ 123 “ OUTPUT IS : 0000000123

- php8HghijUploaded byContinuing Education at the University of Vermont
- A Normal to the Graph of y =Uploaded byluxvis
- Lateral MCA Scheme and Syllabus 2013 Onwards 28-10-2013Uploaded byjebin
- DB2 File Aid – A Step By Step Manual for BeginnersUploaded bysxdasgu
- JAVA ProjectUploaded byapi-3738474
- mc-ty-introfns-2009-1Uploaded byapi-324766399
- IntroToArena.4Uploaded byBabu Subramaniam
- Statements in CUploaded bySerban Petrescu
- Comp-3 To Comp - Decimal ConversionsUploaded bysxdasgu
- COBOL.pdfUploaded bylakshmi
- ch05Uploaded byNeneFI
- IntroP Curs 4 EngUploaded byBogdanPăvăloaia
- COBOL_CDC[1]Uploaded byLalith Kumar
- Cobol_Part2Uploaded byShanurenu
- Limit Proof TechniqueUploaded bylsdumayac_742856
- 16479_ArrayMCQ.docUploaded byVinay Prakash
- RelationsUploaded byLiciaMc
- Squareroot FunctionsUploaded bypaolo furio
- Fault AnalyserUploaded byNagaveni Siddappa
- c Unit 6 Array Last PrintUploaded bykamalshrish
- Arrays c++ PrintUploaded byMargarett Geronimo
- ArraysUploaded byThajid Ibna Rouf Uday
- Ch 7 Arrays & CollectionsUploaded byAnamika Raj
- samathaR[1]Uploaded bySaran Kumar
- Introduction to ProgrammingUploaded byEj Estrella
- ARRAYA OF XII.docUploaded byhar4sg
- 2-espresUploaded bySu'ud Kemal
- ArrayUploaded byPheng Gabriel
- Array 280910 - AUploaded byJeten C Rika
- Inverse FunctionUploaded bycircleteam123

- Abend CodesUploaded bysxdasgu
- Michael Learns to Rock LyricsUploaded bysxdasgu
- AMODE & RMODEUploaded bysxdasgu
- Bryan Adams LyricsUploaded bysxdasgu
- IBM SORT for BeginnersUploaded bysxdasgu
- 24 Genesee SangertownUploaded bysxdasgu
- File Status Keys in MainframesUploaded bysxdasgu
- Condor Training BasicsUploaded bysxdasgu
- ITJOBSHUB DB2 Interview QuestionsUploaded bysxdasgu
- 28981105-Abend-CodesUploaded bysxdasgu
- Visual Age PacbaseUploaded bysxdasgu
- ITJOBSHUB JCL Interview QuestionsUploaded bysxdasgu
- List of SQLCODES for DB2Uploaded bysxdasgu
- Geocities VSAM Interview QuestionsUploaded bysxdasgu
- Different UtilitiesUploaded bysxdasgu
- Geocities JCL Interview QuestionsUploaded bysxdasgu
- An Introduction to Trigger in DB2 for OSUploaded bysxdasgu
- Sort - ExamplesUploaded bysxdasgu
- SQLCODES for DB2Uploaded bysxdasgu
- Cobol FAQsUploaded bysxdasgu
- Mainframe UtilitiesUploaded bysxdasgu
- Handling Variable Length Sequential FilesUploaded bysxdasgu
- Comp-3 To Comp - Decimal ConversionsUploaded bysxdasgu
- Geocities COBOL Interview QuestionsUploaded bysxdasgu
- Geocities DB2 Interview QuestionsUploaded bysxdasgu