View previous topic :: View next topic |
Author |
Message |
waves Beginner
Joined: 09 Nov 2006 Posts: 35 Topics: 12
|
Posted: Wed Mar 11, 2009 11:13 am Post subject: COBOL sort |
|
|
Hi,
I have a input file A. I need to extract 7 strings from the input file based on the position say @position 5,30,40,55,60,75,90 etc.
after extracting the seven strings, i need to put all the strings in the output file. i want to achieve this using COBOL.
I know this can be achieved using JCL. But i need a COBOL solution.
Please help me.
Thanks in advance. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Wed Mar 11, 2009 11:19 am Post subject: |
|
|
waves,
Do you need to sort the extracted strings? If you just need to extract strings isn't it a simple case of using a MOVE statement of input to output?
You need to do a better job of explaining as to what you are trying to do. Show us the input layout and desired output layout with a sample data along with the DCB properties of the input and output files.
Kolusu |
|
Back to top |
|
|
waves Beginner
Joined: 09 Nov 2006 Posts: 35 Topics: 12
|
Posted: Wed Mar 11, 2009 11:41 am Post subject: |
|
|
Hi Kolusu,
I dont need to sort the extracted strings.
first i will sort the input file and then i will extract the 7 strings based on the poistions from input file and put it in the output file.
Input file:
Code: |
20001345679asddpioqewwr34499000qkmkppl
20001223499asddsslkldwwr34558000qkmkppl
20001444455asddsdsjjwwr344991230qkmkppl
|
Output file:
Code: |
55sd91
79pi99
99ss58
|
The above string is extracted based on position 10,16,27 respectively.
Thanks a lot |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Wed Mar 11, 2009 1:30 pm Post subject: |
|
|
You cannot do it in JCL. JCL is Job Control Langage and is used for definng the programs and datasets to be used by your job. It does not process data.
That said, why can you not just define a record structure for your input records and another for your output records and, as Kolusu suggested, move the appropriate fields from the input structure to the output structure? _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
waves Beginner
Joined: 09 Nov 2006 Posts: 35 Topics: 12
|
Posted: Thu Mar 12, 2009 8:32 am Post subject: |
|
|
Can somebody pls help with COBOL code.
It will be very helpful to me.
Thanks in advance. |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Thu Mar 12, 2009 10:57 am Post subject: |
|
|
Show us what you've coded, and I'll be happy to review it to see if I can help. |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Thu Mar 12, 2009 12:40 pm Post subject: |
|
|
If you are not a COBOL programmer then why are you doing this task? If you want to learn then try COBOL for Dummies or similar books. _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
kalatur Beginner
Joined: 09 Apr 2007 Posts: 2 Topics: 0 Location: Bay Area
|
Posted: Sat Mar 21, 2009 10:36 pm Post subject: Re: COBOL sort |
|
|
waves wrote: | Hi,
I know this can be achieved using JCL. But i need a COBOL solution.
|
What are you saying can be done using JCL? Changing data? |
|
Back to top |
|
|
hari_uss Beginner
Joined: 19 Dec 2002 Posts: 78 Topics: 6 Location: Trivandrum, India
|
Posted: Mon Mar 23, 2009 2:21 am Post subject: |
|
|
I think waves meant SORT or similar utilities which can be executed in JCL. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Mar 23, 2009 6:52 pm Post subject: |
|
|
Waves,
Here is an untested cobol program which I just cloned it from one of my existing programs.
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. COBSORT
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE
ASSIGN TO INFILE
ORGANIZATION IS SEQUENTIAL.
SELECT OUTFILE
ASSIGN TO OUTFILE
ORGANIZATION IS SEQUENTIAL.
SELECT SORT-FILE
ASSIGN TO TEMPFILE.
DATA DIVISION.
FILE SECTION.
FD INFILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS IN-REC.
01 IN-REC PIC X(80).
FD OUTFILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS OUT-REC.
01 OUT-REC.
05 OUT-KEY1 PIC X(02).
05 OUT-KEY2 PIC X(02).
05 OUT-KEY3 PIC X(02).
SD SORT-FILE
RECORD CONTAINS 80 CHARACTERS
DATA RECORD SORT-RECORD.
01 SORT-RECORD.
05 FILLER PIC X(09).
05 SD-KEY1 PIC X(02).
05 FILLER PIC X(04).
05 SD-KEY2 PIC X(02).
05 FILLER PIC X(09).
05 SD-KEY3 PIC X(02).
05 FILLER PIC X(52).
WORKING-STORAGE SECTION.
01 S-EOF-INPUT PIC X VALUE 'N'.
PROCEDURE DIVISION.
OPEN OUTPUT OUTFILE
SORT SORT-FILE
ON ASCENDING KEY SD-KEY1
ON ASCENDING KEY SD-KEY2
ON ASCENDING KEY SD-KEY3
USING INFILE
OUTPUT PROCEDURE 1000-WRITE-REC
GOBACK
.
1000-WRITE-REC.
*************************************************************
* THIS PARAGRAPH WRITES OUTPUT RECORDS *
*************************************************************
PERFORM 2000-CHECK-EOF
PERFORM UNTIL S-EOF-INPUT = 'Y'
IF SORT-RETURN = 0
MOVE SD-KEY1 TO OUT-KEY1
MOVE SD-KEY2 TO OUT-KEY2
MOVE SD-KEY3 TO OUT-KEY3
WRITE OUT-REC
PERFORM 2000-CHECK-EOF
END-IF
END-PERFORM
.
2000-CHECK-EOF.
*************************************************************
* THIS PARAGRAPH CHECKS FOR END-OF-FILE CONDITION *
*************************************************************
RETURN SORT-FILE AT END
MOVE 'Y' TO S-EOF-INPUT
CLOSE OUTFILE
END-RETURN
.
|
Hope this helps...
Kolusu |
|
Back to top |
|
|
|
|