Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need help on STRING Logic.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Mar 15, 2012 6:10 pm    Post subject: Need help on STRING Logic.
Reply with quote

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
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Mar 15, 2012 6:23 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Thu Mar 15, 2012 6:45 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Thu Mar 15, 2012 8:08 pm    Post subject: Reply to: Need help on STRING Logic.
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Mar 15, 2012 8:42 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Thu Mar 15, 2012 9:04 pm    Post subject: Reply to: Need help on STRING Logic.
Reply with quote

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
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Fri Mar 16, 2012 2:01 pm    Post subject:
Reply with quote

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. icon_sad.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Fri Mar 16, 2012 2:22 pm    Post subject: Reply to: Need help on STRING Logic.
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Mar 16, 2012 2:28 pm    Post subject:
Reply with quote

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
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Fri Mar 16, 2012 3:49 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Fri Mar 16, 2012 3:57 pm    Post subject: Reply to: Need help on STRING Logic.
Reply with quote

Dbz reminding me of the King Kong remake, with a famous line about crystal balls.

Try this, from searching this forum.
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Fri Mar 16, 2012 8:56 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Fri Mar 16, 2012 9:03 pm    Post subject: Reply to: Need help on STRING Logic.
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Fri Mar 16, 2012 9:05 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Mar 16, 2012 9:30 pm    Post subject:
Reply with quote

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
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Mon Mar 19, 2012 11:44 am    Post subject:
Reply with quote

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.... icon_sad.gif

My job spool got deleted. so let me run again, with new sysout...! Will post after some time.
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Mon Mar 19, 2012 12:27 pm    Post subject:
Reply with quote

Hi Bill, Dick, Robert... thnx everyone.. It worked. icon_smile.gif

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Mon Mar 19, 2012 1:01 pm    Post subject: Reply to: Need help on STRING Logic.
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Mar 19, 2012 1:26 pm    Post subject:
Reply with quote

how to use bbcode
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us