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
 

 

String usage in cobol

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

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Mon Feb 02, 2009 10:23 am    Post subject: String usage in cobol
Reply with quote

Hi,

in my cobol program i am have 3 variables as below

10 IN-PAT-LNAME PIC X(15).
10 IN-PAT-FNAME PIC X(10).
10 IN-PAT-MI PIC X(1).

01 WS-PATIENT PIC X(26) VALUE SPACES.

05 RPT-PATIENT PIC X(26).

I am sending the input from the in variables to WS-PATIENT and string it and sent to the RPT-PATIENT

the string statement goes like this

STRING IN-PAT-LNAME,WS-SPACE,IN-PAT-FNAME,
WS-SPACE,IN-PAT-MI
DELIMITED BY " "
INTO WS-PATIENT
END-STRING
MOVE WS-PATIENT TO RPT-PATIENT

for some names i am getting the out put correctly

but for some records i am getting an extra space in between the first name and middle name.

Code:
for example
             AMBRY CATHERINE M for this record
i am getting AMBRY CATHERINE  M an extra space


can any one help me in this regard
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Feb 02, 2009 10:35 am    Post subject:
Reply with quote

Hello,

Check the names that appear to have one or more extra spaces to make sure there are no "unprintable" characters at the end of a name. Suggest you look at some of the values for some of the names that generate the incorrect result in hex to do this.

FWIW - You should also move spaces to ws-patient before the string. Unless there is some other use for ws-patient later in the code, you could string directly into rpt-patient.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1238
Location: Richfield, MN, USA

PostPosted: Mon Feb 02, 2009 11:23 am    Post subject:
Reply with quote

I don't have access to a mainframe, but try this untested code:
Code:
string in-pat-lname delimited by space
       ' '
       in-pat-fname delimited by space
       ' '
       in-pat-mi    delimited by size
       into ws-patient
end-string
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Feb 02, 2009 11:28 am    Post subject: Reply to: String usage in cobol
Reply with quote

Hi Terry,

Yup. Personally, i prefer your code style for this.

d
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Mon Feb 02, 2009 11:40 am    Post subject:
Reply with quote

hi terry...

i tried ur code but i m not getting the out put correctly for fname and lname the data is coming to gether and for middle name the 2 spaces are commig
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1238
Location: Richfield, MN, USA

PostPosted: Mon Feb 02, 2009 12:11 pm    Post subject:
Reply with quote

Are you saying that your result is
Code:
AMBRYCATHERINE  M
instead of
Code:
AMBRY CATHERINE M
? Did you code it exactly as I did with the
Code:
' '
between the lname and fname and between the fname and mi? As I said, without mainframe access all I can do is check the Language Reference Manual. Have you reviewed the syntax and example of the STRING statement there?
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Mon Feb 02, 2009 12:18 pm    Post subject:
Reply with quote

Yes what code u have given i have given the same.
i am getting one space between the lname and mname but i am not getting a aingle space between the fname and laname.

i have tried vice versa also .... but still the problem is comming.

i have refered to the manul before i posted the query in the forum... but i could not get it.....
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Mon Feb 02, 2009 12:47 pm    Post subject:
Reply with quote

Hi Veena,

Can you please provide the screen shot of the syntax you are using in your code. Also please provide the output you are getting.

While providing the screen shot please do the HEX ON or you can confirm the HEX value of the position.

The code provided by Terry should work correctly.

string in-pat-lname delimited by ' '
' ' delimited by size
in-pat-fname delimited by ' '
' ' delimited by size
in-pat-mi delimited by size
into ws-patient
end-string

For the below example the above code should work perfectly.
10 IN-PAT-LNAME PIC X(15). Smith
10 IN-PAT-FNAME PIC X(10). John
10 IN-PAT-MI PIC X(1). M

Output => Smith John M

Thanks & Regards,
Shashank Kapoor
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Feb 02, 2009 1:03 pm    Post subject:
Reply with quote

Hello,

As i mentioned earlier, your data may contain some unprintable characters. You need to post some of the problem name data (in hex) so we can se what is the matter.

Did you change the code to move spaces to the target field before the string? The value could also be leftover from the prior string.
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Mon Feb 02, 2009 1:36 pm    Post subject: Reply to: String usage in cobol
Reply with quote

hi , please find the attachment of the screen shot.


AMBRYDENNIS L
AMBRYCATHERINE M
AMBRYDANIELLE A

this is the output i got when i tried terry's code
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Feb 02, 2009 1:41 pm    Post subject:
Reply with quote

Hello,

It appears that the "extra" space has been resolved. To resolve the last and first name running together, try this slight modification:
Code:
string in-pat-lname delimited by space
       ' '          delimited by '\'
       in-pat-fname delimited by space
       ' '          delimited by '\'
       in-pat-mi    delimited by size
       into ws-patient
end-string
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Mon Feb 02, 2009 2:42 pm    Post subject:
Reply with quote

hi dick ...

i tried the syntax u have given...... but in the first name for example the name is

PAAPE JR JOHN H

JR in first name is not populating in the report
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Mon Feb 02, 2009 3:09 pm    Post subject: Reply to: String usage in cobol
Reply with quote

Hi Veena,

Just Curious regarding few things:
1) Did you check the HEX value of the particular position?
2) Did you initialize both your output variable?

As per your last post it seems that you are expecting space in input first name for eg.
10 IN-PAT-LNAME PIC X(15) value 'PAAPE JR'

If this is the case then definitely the below statement
' ' delimited by size
will remove the JR from output

Thanks & Regards,
Shashank
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Mon Feb 02, 2009 3:22 pm    Post subject:
Reply with quote

hi ...

i have initialised all the output variables before moving the data....

i have checked all the values before moving also....

icon_confused.gif
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Mon Feb 02, 2009 6:36 pm    Post subject:
Reply with quote

Hi,

Please find below statements, it is working fine:
Code:
01 WS-VALUES.                                                 
     05 WS-LAST-NAME            PIC X(15)   VALUE   'SMITH     '.
     05 WS-FIRST-NAME           PIC X(10)   VALUE   'JOHN      '.
     05 WS-MIDDLE-NAME          PIC X(01)   VALUE   'M'.         
     05 WS-PATIENT              PIC X(26)   VALUE   SPACES.     
     05 WS-RPT-PATIENT          PIC X(26)   VALUE   SPACES.     



Code:
STRING WS-LAST-NAME    DELIMITED BY ' '   
       ' '             DELIMITED BY SIZE   
       WS-FIRST-NAME   DELIMITED BY ' '   
       ' '             DELIMITED BY SIZE   
       WS-MIDDLE-NAME  DELIMITED BY ' '   
INTO WS-PATIENT.               
           
DISPLAY 'WS-PATIENT : ' WS-PATIENT         
                                           
MOVE WS-PATIENT TO WS-RPT-PATIENT.         
DISPLAY 'WS-RPT-PATIENT : ' WS-RPT-PATIENT.


Output =>
Code:
WS-PATIENT : SMITH JOHN M   
WS-RPT-PATIENT : SMITH JOHN M


I have displayed the value in spool.
If your input can also have a space in input variable then you can use ' ' i.e. double spaces in the string function.

Hope this will help you.

-------------------
Shashank
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Feb 03, 2009 12:16 am    Post subject:
Reply with quote

Hello,

Quote:
i tried the syntax u have given...... but in the first name for example the name is
PAAPE JR JOHN H
JR in first name is not populating in the report
The syntax i posted will work - for your original requirement. . . The name that does not work does not match the format of the name you posted.

Before implementing some code, you need to completely define all of the name conditions that might arise and how they should be "strung". To work the code one discovery at a time is just a waste of time.
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Tue Feb 03, 2009 9:52 am    Post subject: Reply to: String usage in cobol
Reply with quote

hello dick.....

the program i m working .... its a very big input file and i cant put displays in my program when i am running a big file in my work place....

the string logic is working for some conditions and for some it is not working....

is there any other option for the program.

for example by taking the
PAPPE JR JOHN H and when implementing JR is not populating
if we are taking AMBRY CATHERINE M i am getting double space....

please help me in this regard
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Feb 03, 2009 10:03 am    Post subject:
Reply with quote

Hi Veenaq,

As i mentioned earlier, i believe a complete definition of the "rules" is needed befoer code is written. Suggest you gather a list of a few "standard" names (a first name a last name and an initial. To this list, add names that present a more complex rule - like PAPPE JR JOHN H, or VAN DER SCHOETTEN DR WILLIEM J, or others.

A study needs to be made to make sure that the same name components are stored in the same input fields. If the input arrives differently between records, this may cause inconsistencies.

Quote:
the string logic is working for some conditions and for some it is not working....
This needs to be completely understood.

Your solution may be a combination of reference modification, data manipulation to remove unwanted components, and some string or move instructions to build the final output name field.
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Tue Feb 03, 2009 12:21 pm    Post subject:
Reply with quote

hi ...

my problem got resolved .... firstly i have moved the length of the variables to another variable and i have printed according to that length......

one of my collegue has helped me in this regard....

thnks every one ... who has given me suggestions....

I have experimented a lot on string function
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Tue Feb 03, 2009 12:57 pm    Post subject:
Reply with quote

Good to see this that your problem got resolved.
Request you to share the logic you have used for this.

Just Curious, did you use the function reverse in your code?


------------
Shashank
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. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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