|
View previous topic :: View next topic
|
| Author |
Message |
mohamedmubee
New User
Joined: 17 Oct 2012 Posts: 2 Location: India
|
|
|
|
Hi Everyone,
I am new to this forum, so if there is any mistake teach me...
I would like to know how can we able to write a cobol program or logic to read a record from input file and write to a output file of length 80 bytes.
the input file has many records each 4 bytes of data.
input file:
ADAM
BASU
DAVE
JOHN
MARY
NICK
RAJA
SARA
......
.......
the output file should look like below...
INCLUDE COND=(1,4,EQ,C'ADAM,BASU,DAVE',
OR,1,4,EQ,C'JOHN,MARY,NICK',
OR,1,4,EQ,C'RAJA,SARA'),FORMAT=SS
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE |
|
| Back to top |
|
 |
Akatsukami
Global Moderator

Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
| Create an internal table with 16 entries. Let the last byte of each entry be set to comma. As records are read, let them be placed in the four-byte portion of the entry. When the table is full, write it out. Be sure to include logic to handle the case where the input data set does not contain a multiple of sixteen records. |
|
| Back to top |
|
 |
pramitdas
New User
Joined: 27 Aug 2016 Posts: 3 Location: India
|
|
|
|
Okay. Thanks for asking.
Please follow the below steps.
1. First define one control card or PDS member ABC or a PS file: ABC.XYZ.XYZ of 80 LRECL having the job card and below input.
ABC.XYZ.XYZ or ABC
__________________________________________________
Your job card
---------------------------------------------------
//STEPNAME --------------
//INCLUDE COND=(1,4,EQ,C'XXX1,YYY2,ZZZ1',
OR,1,4,EQ,C'XXX2,YYY2,ZZZ2',
OR,1,4,EQ,C'XXX3,YYY3'),FORMAT=SS
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE
/*
__________________________________________________
2. Now read this static control card or PS file into an array IN-JCL[18] assuming that total no of lines in the control card ABC is 18.
3. Now Read the original input file of yours with an internal array of max 100 records. Say your file can contain max of 100 records. and note your array ARR [I] value.
3. Now in your logic of Cobol program , replace the value of XXX1, YYY2 etc with exact ARR [I] value. for that you need to put the column no and starting position and length.
For e.g. XXX1 resides at your control card or PS file at column 20 and row 16 , then logic should be:
MOVE ARR(1) to IN-JCL(16) (20:04 ) ------> 4 is the length of the name ( ADAM, BASU etc).
MOVE ARR(2) to IN-JCL(16) (26:04 )
and So on
4. Then write the value of IN-JCL(I) to OUT-JCL(I) which you are looking for.
This way you can dynamically prepare the exact job. Any doubt please let me know.
Thanks,
Pramit
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2283 Location: USA
|
|
|
|
I guess it makes no sense to convert this to neither COBOL nor anything else.
Since you have your selection list in the file, and finally you need to use SORT facility based on this selection, the better way is to do it straightforward:
| Code: |
//SORT EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SELECT DD *
ADAM
BASU
DAVE
JOHN
MARY
NICK
RAJA
SARA
//INPUT DD DSN=input file
//SORTOUT DD DSN=output file
//SYSIN DD *
JOINKEYS F1=SELECT,
FIELDS=(1,4,A)
JOINKEYS F2=INPUT,
FIELDS=(1,4,A)
REFORMAT FIELDS=(F2:1,length)
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE
END
//*
|
|
|
| Back to top |
|
 |
pramitdas
New User
Joined: 27 Aug 2016 Posts: 3 Location: India
|
|
|
|
It is all based on the requirements as agreed.
It apparently needs a Cobol program due to the below reason.
A dynamic JCL should be populated which can be submitted automatically by CLIST from the same job. Means SAY job A has two steps. First step to prepare the desired output thru Cobol program and 2nd step to submit the output ( in this case SORT JCL ) JCL thru some CLIST. Means, if I have submitted JCL A, it will submit JCL B as well. I believe that is the requirement.
Thanks!! |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| Quote: |
| I believe that is the requirement |
No - that is not the requirement. The requirement is to format the data. The most efficient mens of doing that should be chosen.
Other points:
1 - the cobol program could directly submit the next job
2 - using CLIST is outmoded - using Rexx is the better option
3 - use code tags when presenting JCL, control cards, data and anything else that you see on your screen - as shown you have control cards starting in column 1 which is WRONG
4 - INCLUDE is a sort control card not a JCL card so should not have // in columns 1 and 2:
//STEPNAME --------------
//INCLUDE COND=(1,4,EQ,C'XXX1,YYY2,ZZZ1',
OR,1,4,EQ,C'XXX2,YYY2,ZZZ2',
OR,1,4,EQ,C'XXX3,YYY3'),FORMAT=SS
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE
/*
should be
| Code: |
//STEPNAME -----------
INCLUDE COND=(1,4,EQ,C'XXX1,YYY2,ZZZ1',
OR,1,4,EQ,C'XXX2,YYY2,ZZZ2',
OR,1,4,EQ,C'XXX3,YYY3'),FORMAT=SS
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE
/*
|
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2283 Location: USA
|
|
|
|
Note 1
SORT statement semantics is wrong for SS (SubString) format/function. The syntax is correct, but it doesn't work as expected by author.
The correct statement would be either (using SS,EQ):
| Code: |
INCLUDE COND=(C'XXX1,YYY2,ZZZ1',EQ,1,4,
OR,C'XXX2,YYY2,ZZZ2',EQ,1,4,
OR,C'XXX3,YYY3',EQ,1,4),FORMAT=SS |
or (using CH,EQ):
| Code: |
INCLUDE COND=(1,4,EQ,L(C'XXX1',C'YYY2',C'ZZZ1'),
OR,1,4,EQ,L(C'XXX2',C'YYY2',C'ZZZ2'),
OR,1,4,EQ,L(C'XXX3',C'YYY3')),FORMAT=CH |
Note 2
String manipulation in COBOL is possible, but extremly inconvenient. The easier way is using REXX or some other tools.
REXX option:
| Code: |
. . .
"execio * diskr SELECTDD (stem ListSel. finis" /* read into stem variable */
Step = 3
Do i = 1 by Step to ListSel.0
StrWords = ''
Do j = i to (i + Step - 1)
StrWords = StrWords || ListSel.j
If j >= ListSel.0 Then Leave j
StrWords = StrWords || ','
End j
If i = 1 Then
StrStmt = " INCLUDE COND=(C'"
Else
StrStmt = " OR,C'"
StrStmt = StrStmt || StrWords
If (i + Step - 1) < ListSel.0 Then
StrStmt = StrStmt || "',"
Else
StrStmt = StrStmt || "'),FORMAT=SS"
Queue StrStmt
End i
"execio * diskw OUTDD (finis" /* write all lines from program stack */
|
|
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
| Code: |
INCLUDE COND=(1,4,EQ,C'ADAM,BASU,DAVE',
OR,1,4,EQ,C'JOHN,MARY,NICK',
OR,1,4,EQ,C'RAJA,SARA'),FORMAT=SS
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE |
Why even bother formulating such control cards or file? Join this file with the final file where you want to use this card? |
|
| Back to top |
|
 |
mohamedmubee
New User
Joined: 17 Oct 2012 Posts: 2 Location: India
|
|
|
|
these are the things i missed to include in the requirement...
first, the input file will get the records based on some other files that will be written to the file.
second, the record may be 5 records, or 10 or 13 it will be varying....
third, the ouput sort card then will be taken as a control card and to be used in further steps to begin processing of other files based on the sort card selection of data.
so
@ Akatsukami, the count will vary so its hard to code how many table entries needed.
@ pramitdas,
yes it is a cobol program i am trying to write these output. i think i can't put these in ps file as i didn't know how many records will come from the input file ??
ABC.XYZ.XYZ or ABC
__________________________________________________
Your job card
---------------------------------------------------
//STEPNAME --------------
//INCLUDE COND=(1,4,EQ,C'XXX1,YYY2,ZZZ1',
OR,1,4,EQ,C'XXX2,YYY2,ZZZ2',
OR,1,4,EQ,C'XXX3,YYY3'),FORMAT=SS
SORT FIELDS=(1,4,CH,A)
SUM FIELDS=NONE
/*
@ sergeyken
i need to use the output file record as a control card and need to process the further steps in the JCL. and I am using MicroFocus COBOL not sure whether REXX can be used. also I didn't know REXX I will check this one on how your code works for this requirement.....
let me know if any quesitons....  |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| If you are on a mainframe then you do not have files - you have data sets and if you are not on a mainframe then you are in the wrong forum. |
|
| Back to top |
|
 |
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
I don't understand what is stopping you to achieve this.
1. Do a perform 3 times or end of file
2. Inside this perform, read file and string the values as ADAM,BASU,DAVE
3. If it is the first time you are performing this loop then string the values you got (i.e. ADAM,BASU,DAVE) to 'INCLUDE COND=(1.4,EQ,C' and Write to output
4. If it is Not the first time you are doing this perform then string the values with OR,1,4,EQ,C' and write to output
5. When it is end of file condition then add OR condition accordingly to close the bracket and add FORMAT=SS and write to output
6. Other statements can be added after this
Is this what you want ?
.
P.S. you made me laugh with this:
| Quote: |
| let me know if any quesitons.... |
Somebody, who is asking others for help, is asking others if they have any question. Really? I know what you meant but it's just the words that we have to choose carefully.
. |
|
| Back to top |
|
 |
Akatsukami
Global Moderator

Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
| mohamedmubee wrote: |
these are the things i missed to include in the requirement...
first, the input file will get the records based on some other files that will be written to the file.
second, the record may be 5 records, or 10 or 13 it will be varying....
third, the ouput sort card then will be taken as a control card and to be used in further steps to begin processing of other files based on the sort card selection of data.
so
@ Akatsukami, the count will vary so its hard to code how many table entries needed. |
I fail to understand your objection. Do you mean that the number of input records to be concatentated into a single output record will vary (something that is easily parameterized) or that the total number of input records will vary (which is the point of writing any sort of code in the first place)? |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2283 Location: USA
|
|
|
|
In my humble opinion, the Team Leader who suggested to create SORT statements from sequential file instead of doing JOIN in SORT step - he or she must be fired immediately.
The TL who insisted to create those SORT statements via COBOL code additionally must be sentenced to death. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
| Haha.. 😊That's what I thought about the approach. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|