View previous topic :: View next topic
|
Author |
Message |
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Hi All,
I have my input file format as below
FD INPUT-FILE.
01 INPUT-REC.
05 EMAIL-ID1 PIC X(20).
05 EMAIL-ID2 PIC X(20).
05 SUBJECT PIC X(30).
05 TEXT PIC X(30).
FD OUTPUT-FILE PIC
01 OUTPUT-REC PIC X(104) - Maximum value this file can contain.
Now The above fields of input file may contain the data of whole length or may contain less than their actual length.
Like EMAIL-ID1 is of 20 bytes. It can either contains 20 bytes of data or less than 20 bytes.
Now I want to write output file as below in below format.
value in EMAIL-ID1|value in EMAIL-ID2|value in SUBJECT|value in TEXT|
Ex. If EMAIL-ID1 = 'abc.xyz@gmail.com'
EMAIL-ID2 = 'abcdxyz@in.com'
SUBJECT = 'GOOD MORNING'
TEXT = 'THIS IS COBOL PROGRAM'
Then my output file will be as below:
abc.xyz@gmail.com|abcdxyz@in.com|GOOD MORNING|THIS IS COBOL PROGRAM|
Here output file's length will be changed if fields will contain less data as compared to their length.
Is it Possible to concatenate thru STRING, or how can we do thru MOVE statement (reference modification) |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
concatenating thru STRING is no problem.
Code: |
MOVE 1 TO ptr-field
STRING EMAIL-ID1
DELIMITED BY SPACE
'|'
DELIMITED BY SIZE
EMAIL-ID2
DELIMITED BY SPACE
'|'
DELIMITED BY SIZE
SUBJECT
DELIMITED BY SPACE
'|'
DELIMITED BY SIZE
TEXT
DELIMITED BY SPACE
INTO WS-OUTPUT-RECORD
WITH POINTER ptr-field
END-STRING
|
ptr-field - 1 will be the length of your variable length record
as an aside, always use the WORK-AREA Option with READs and WRITEs.
do not deal directly in FD 01 level. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
FD OUTPUT-FILE PIC
01 OUTPUT-REC PIC X(104) - Maximum value this file can contain. |
How are you going to make it variable? As coded, you're looking at a fixed-length 104-byte file record. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Plus if the 104 is including the RDW, you don't need to allow for that in a Cobol program. You need to be able to tell Cobol how much to write, to your max of 100 bytes of data, Cobol and its routines will do the RDW for you. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
although I failed to show it in my example,
(the last field also is bounded by |)
the maximum length record is 104, 30+30+20+20+1+1+1+1.
we possibly will have another thread by the TS on the variable length record question,
but this thread is concerned with the building of the record
(concatenation of the fields.)
and the TS has not returned,
probably off for the day and expects his answer waiting for him tomorrow. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, silly me...
Just to say, then, 20 bytes is a bit short for an e-mail address. Mine doesn't fit :-)
@gmail.com is already nine. @yahoo.com is more. @microsoft.com is... and I have plenty of mail in by inbox with longer than 20 after the @.
If you are going to allow for non-specific e-mail addresses (where you know the maxima) then you're going to have to dig up some RFC or other to find out the rules, which I'd imagine would be pretty horrible for your 20 byteses. Somewhere reasonable in between, then, if you're not using specific addresses (and if this doesn't suddenly become some "oh, that is just an example.."). |
|
Back to top |
|
|
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Rober t and Dick thanks for replying.
Here its a learning for me. I hv 2 doubts here.
1)
Dick I was aware of STRING function, only doubt in my mind i was having regd 'DELIMITED BY SPACE'.
For Ex. SUBJECT field contains value GOOD MORNING.
So wont it take only 'GOOD' coz after tht it contains Spaces and append into WS-OUTPUT-RECORD.
2) Robert, Yes the length i hv specified is just to show tht it is a maximum length i.e. output can be written till that length only if all fields will contain data based on actual length.
Yes, If all fields will contain less data then ofcourse output files size will be reduced. So my doubt here is how to declare the variable block output file in FD section and in JCL.
Both the things i am trying for 1st time. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, you have a point.
I suppose you could FUNCTION REVERSE, INSPECT REPLACING LEADING SPACE BY unused non-character. FUNCTION REVERSE again and then do the STRING with the unused non-character as the delimeter.
For the reference-modification, you have to go from the "back" of earch field to count the trailing spaces. Calculate your length. Bob's your uncle.
Could be done byte-by-byte. Or with Occurs Depending On. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
possibly not the most efficient, but nevertheless an effective way would be:
for each of your four fields
work-area pic x(40).
MOVE REVERSE(field) TO WORK-AREA
INSPECT WORK-AREA REPLACING LEADING SPACES BY X'FF'
MOVE REVERSE(WORK-AREA) TO field
then change your DELIMITED BY SPACES
to DELIMITED BY X'FF' |
|
Back to top |
|
|
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Thanks Again Dick and Bill.
But I am still not able to code FD section for output file.
How it will be declared in cobol code and in JCL, since its will a variable block file. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Dbz reminding me of the King Kong remake, with a famous line about crystal balls.
Try this, from searching this forum. |
|
Back to top |
|
|
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Hi Dick,
Above logic didnt work out.
Below is code:
2000-PROCESS-LR950.
DISPLAY '2000-PROCESS-LR950'
DISPLAY 'LR-TO-FIELD-TEXT : ' LR-TO-FIELD-TEXT
MOVE FUNCTION REVERSE(LR-TO-FIELD-TEXT)
TO WS-LR-TO-FIELD
DISPLAY 'WS-LR-TO-FIELD: ' WS-LR-TO-FIELD
INSPECT WS-LR-TO-FIELD REPLACING LEADING SPACES BY X'FF'
DISPLAY 'WS-LR-TO-FIELD: ' WS-LR-TO-FIELD
MOVE FUNCTION REVERSE(WS-LR-TO-FIELD)
TO LR-TO-FIELD-TEXT
DISPLAY 'LR-TO-FIELD-TEXT: ' LR-TO-FIELD-TEXT
Below is SYSOUT:
2000-PROCESS-LR950
LR-TO-FIELD-TEXT : ABCD@GMAIL.COM
WS-LR-TO-FIELD:
MOC.LIAMG@DCBA
WS-LR-TO-FIELD: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::MOC.LIAMG@DCBA
LR-TO-FIELD-TEXT: ABCD@GMAIL.COM::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::: |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The idea was to preserve the spaces and use the high-values as the delimeter for the UNSTRING. I don't see any UNSTRING in your code, so don't know what you were expecting.
ALSO PLEASE USE THE CODE TAGS! To make any sense of the garble you posted, we have to CODE it ourselves, so instead of you spending a few seconds doing it, everyone who has any enthusiasm to look at it has to do it for themselves. Thus greatly reducing people's enthusiasm. Even the enthusiastic are cursing you while wasting their own time... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Ashutosh, since you only implemented PART of Dick's suggestions, why are you posting that they didn't work? Where is your post of this code that Dick posted:
Code: |
MOVE 1 TO ptr-field
STRING EMAIL-ID1
DELIMITED BY X'FF'
'|'
DELIMITED BY SIZE
EMAIL-ID2
DELIMITED BY X'FF'
'|'
DELIMITED BY SIZE
SUBJECT
DELIMITED BY X'FF'
'|'
DELIMITED BY SIZE
TEXT
DELIMITED BY X'FF'
INTO WS-OUTPUT-RECORD
WITH POINTER ptr-field
END-STRING |
and then modified? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
i worked with a guy a few years ago,
who would insert a comment in his code, sorta like:
'per brenholtz, field a should be first inspected and then moved'
after a while I just stopped answering his questions,
and then he started this kind of silliness:
attempted to obtain clarification, but brenholtz would not respond |
|
Back to top |
|
|
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Sorry Dick, Robert .. I posted only half of the things On friday...When I left for the day on friday, while travelling i remember tht i hv done big mistake....
My job spool got deleted. so let me run again, with new sysout...! Will post after some time. |
|
Back to top |
|
|
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Hi Bill, Dick, Robert... thnx everyone.. It worked.
Sorry Bill, I dont know how to use Code tags. Cud u pls let me know.
Also I use mainframe thru Remote desktop connection. So dont know whther it will work or not. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you click on the Quote button to the right of each post, you will be able to see the BBCODE which is used in a post. Find one which has the green-screen stuff and click.
You'll then notice the buttons above the box (unless using the quick-posting box, so I disabled that option for me, experiment for yourself). Highlight the text, click the button.
Use the Preview button below the box and you will see how the post will look. Arrange the formatting until you are happy, using Preview as many times as necessary.
Click Submit. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
Back to top |
|
|
|