have in 100 records in a flat file i want to move records
like 1,3,5,7,9,11,.. to Output file1 and
2,4,6,8,10,12,14 .. records moved to Output file2..Pls
Provide real time answer..

Answers were Sorted based on User's Feedback



have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and..

Answer / xxx

Since I assume this is a COBOL question (and not JCL), I have tried below code.
-------------------------------------------------------

OPEN INPUT DASA
OPEN OUTPUT DASB DASC

INITIALIZE WS-NUM.
MOVE 'N' TO WS-EOF-SW.
READ DASA INTO WS-NUM
AT END MOVE 'Y' TO WS-EOF-SW
END-READ

PERFORM UNTIL WS-EOF-SW = 'Y'
DIVIDE WS-NUM BY 2 GIVING WS-Q REMAINDER WS-R
IF WS-R = 1
WRITE DASB-RCD FROM WS-NUM
ELSE
WRITE DASC-RCD FROM WS-NUM
END-IF
READ DASA INTO WS-NUM
AT END MOVE 'Y' TO WS-EOF-SW
END-READ
END-PERFORM


CLOSE DASA DASB DASC

STOP RUN
.

Is This Answer Correct ?    4 Yes 0 No

have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and..

Answer / ranjith kumar

//JOBNAME
//STEP1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT DSN,DISP=SHR
//OUT1 DD DSN=OUTPUT DSN1,DISP=(NEW,CATLG),
// SPACE=(CYL,(5,5)),UNIT=SYSDA
//OUT2 DD DSN=OUTPUT DSN2,DISP=(NEW,CATLG),
// SPACE=(CYL,(5,5)),UNIT=SYSDA
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(OUT1,OUT2),SPLIT
/*
//

Is This Answer Correct ?    6 Yes 6 No

have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and..

Answer / harsha

For ODD records
//JOBNAME
//STEP1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT DSN,DISP=SHR
//OUT1 DD DSN=OUTPUT DSN1,DISP=(NEW,CATLG),
// SPACE=(CYL,(5,5)),UNIT=SYSDA
//OUT2 DD DSN=OUTPUT DSN2,DISP=(NEW,CATLG),
// SPACE=(CYL,(5,5)),UNIT=SYSDA
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=OUT1,STARTREC=1,SAMPLE=2
/*
//

For EVEN records
OUTFIL FNAMES=OUT2,STARTREC=2,SAMPLE=2

Is This Answer Correct ?    2 Yes 3 No

have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and..

Answer / dimpy19

FILE-CONTROL.
SELECT INP ASSIGN TO INF
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INP
RECORDING MODE IS F.
01 INP-REC.
10 STUDENT-ID PIC 9(3).
10 STUDENT-NAME PIC X(20).
FILE-CONTROL.
SELECT INP ASSIGN TO INF
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INP
RECORDING MODE IS F.
01 INP-REC.
10 STUDENT-ID PIC 9(3).
10 STUDENT-NAME PIC X(20).
WORKING-STORAGE SECTION.
01 C PIC 99 VALUE ZEROS.
01 D PIC 99V99 VALUE ZEROS.
01 E PIC 99.99.
01 I PIC 99 VALUE ZEROS.
01 WS-INP-REC.
10 WS-STUDENT-ID PIC 9(3).
10 WS-STUDENT-NAME PIC X(20).
05 EOF PIC X VALUE 'N'.
01 PRINT-CHAR PIC X(20).
PROCEDURE DIVISION.
OPEN INPUT INP.
READ INP INTO WS-INP-REC.
PERFORM UNTIL EOF = 'Y'
ADD 1 TO I
DISPLAY I
DIVIDE 2 INTO I GIVING C REMAINDER D
MOVE D TO E
DISPLAY E
IF (D IS ZERO)THEN
DISPLAY WS-STUDENT-NAME
END-IF
READ INP INTO WS-INP-REC AT END MOVE 'Y' TO EOF
END-READ
END-PERFORM.
CLOSE INP.
GOBACK.

output :
01
01.00
02
00.00
BRPITA
03
01.00
04
00.00
DRPITA
05
01.00
06
00.00
FRPITA

input :
000001 070 ARPITA
000002 080 BRPITA
000003 090 CRPITA
000004 100 DRPITA
000005 110 ERPITA
000006 120 FRPITA

Is This Answer Correct ?    0 Yes 1 No

have in 100 records in a flat file i want to move records like 1,3,5,7,9,11,.. to Output file1 and..

Answer / rajeev darla

The solutions provided are not real time . They are batch
solutions. If you need to do it real time then use program

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More COBOL Interview Questions

how you read control card into array?

3 Answers   HCL,


How to resolve the soc4 and soc7 errors?

5 Answers   IBM, RBS,


How many bytes S(8) comp field occupy and its maximum value?

0 Answers  


What is the usage of comp fields in cobol?

0 Answers  


can we use go to statement inline-perform?

7 Answers   IBM,






HOW TO MOVE REDEFINES CLAUSE FROM INPUT TO OUTPUT ?

1 Answers  


if a dataset is already created with fixed length but after that i want to change fixed length to variable length then how is it possible

3 Answers   IBM,


if a pic 9(3) value 354,b pic x(2) value '46' then a)a>b 2)a<b 3)error

8 Answers   Cap Gemini,


How do you set a return code to the JCL from a COBOL program?

4 Answers  


What will happen if we move SPACES to numeric field and ZEROES to alphabetic field?

2 Answers  


Hi All, how is sign is stored in S9(17) comp-3 variable. Answer with an Example will be of great help.

5 Answers   EDS,


What is an index for tables?

2 Answers  


Categories