here is my requirement
A1 is alphanumeric with value 'A1B2C3D4' as defined below

05 A1 PIC X(8) VALUE IS 'A1B2C3D4'

but i need to have A2,A3 as ABCD & 1234 repectively......
A2 = ABCD
A3 = 1234

Can you please explain me what are the different ways to do it?

Answers were Sorted based on User's Feedback



here is my requirement A1 is alphanumeric with value 'A1B2C3D4' as defined below 05 A1..

Answer / rajkanya

DATA DIVISION.
WORKING-STORAGE SECTION.
01 GROUP1.
05 A1 PIC X(08)
VALUE 'A1B2C3D4'.
05 ARRAY1 REDEFINES A1 OCCURS 8 TIMES
PIC X(01).
01 ARRAY2.
05 A2 OCCURS 4 TIMES PIC X(01).
01 ARRAY3.
05 A3 OCCURS 4 TIMES PIC X(01).
01 WS-COUNT PIC 9(02)
VALUE 01.


PROCEDURE DIVISION.

PERFORM MOVE-LETTERS-PARA VARYING ODD FROM 1 BY 2
UNTIL ODD > 8
* INITIALIZE THE COUNTER FOR SECOND LOOP
MOVE 01 TO WS-COUNT
*
PERFORM MOVE-NUMBERS-PARA VARYING EVEN FROM 2 BY 2
UNTIL EVEN > 8
.
.
.
MOVE-LETTERS-PARA.
MOVE ARRAY (ODD) TO ARRAY2 (WS-COUNT)
ADD 1 TO WS-COUNT
.
.
MOVE-NUMBERS-PARA.
MOVE ARRAY (EVEN) TO ARRAY3 (WS-COUNT)
ADD 1 TO WS-COUNT
.
.
.

Is This Answer Correct ?    2 Yes 0 No

here is my requirement A1 is alphanumeric with value 'A1B2C3D4' as defined below 05 A1..

Answer / mainframe guy

You can also do it this way:

DATA DIVISION
01 A1 VALUE 'A1B2C3D4'
05 A1-CHAR PIC X(01) OCCURS 8.
01 A2 PIC X(04) VALUE SPACES.
01 A3 PIC X(04) VALUE SPACES.
01 I PIC 9(02) VALUE ZEROS.
01 J PIC 9(02) VALUE ZER0S.
01 K PIC 9(02) VALUE ZEROS.

PROCEDURE DIVISION.
MOVE 1 TO I J K
PERFORM VARYING I FROM 1 BY 1 UNTIL WS-I > 8
IF A-CHAR(I) IS NUMERIC
MOVE A-CHAR(I) TO A3(K:1)
ADD 1 TO K
ELSE
MOVE A-CHAR(I) TO A2(J:1)
ADD 1 TO J
END-IF
END-PERFORM

Now you will have A2 = ABCD and A3 = 1234
This method can be used only if you want to seperate numbers
from alphabets. Otherwise, the previous solution has to be used.

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More COBOL Interview Questions

which certifications r 4 cobol,jcl,db2,cics what is format of xam n what is importance of these certifications... plz post answer only if u r sure... thanks

1 Answers  


What is the difference between Structured COBOL Programming and Object Oriented COBOL ?

1 Answers  


consider the following progrm statements MOVE 0 TO SW.NO.OF.REC PERFORM PRI-OUT UNTIL SW=1 DISPALY NO.OF.REC STOP RUN PRE-OUT READ IN-FILE AT END MOVE 1 TO SW WRITE OUO-REC FROM IN-REC ADD 1 TO NO.OF REC if the IN-FILE contains 1000 records what value will be displayedafter the PERFORM is over?assume that N0.OF.REC has PIC 9(4) a.1000 b.1001 c.1 d.none of the above since there is a syntex error

4 Answers   TCS,


what is lrec=f,what is difference between f,fb,v,vb?what is default value?how do we came to know that records are in f,fb,v,vb?

2 Answers   IBM, Wipro,


level number 77 is used to define a)group data b)elementary data c)redefine d)none

8 Answers   TCS,






how the control comes back from subprogram to mainprogram

3 Answers   IBM,


What happens in the background of spool when we submit a job for compilation and execution... This is a recent question in ibm...Kindly help me.....

3 Answers   IBM,


)what is retrieve?

1 Answers   IBM,


How do you reference the following file formats from cobol programs?

0 Answers  


Which of the following paragraphs is compulsory in every COBOL program? (a) SPECIAL-NAMES (b) PROGRAM-ID (c) FILE-CONTROL (d) OBJECT-COMPUTER

4 Answers  


I have File 1 occurs 5 times with Employee-ID,Employee-Name,Employee-Dept (EEE and MECH). I have File 2 occurs 10 times with Employee-ID,Employee-Name,Employee-Dept (EEE,CIVIL,CHEMICAL and MECH). In FIle 1 and FIle 2 , for matching Employee-DEPT (Only MECH) , we need to move entire records from file1 to file 2. We should not use 2D array. Your help is needed here.

0 Answers   Steria,


what is meant by binary search?

4 Answers  


Categories