View previous topic :: View next topic |
Author |
Message |
sakreg Beginner
Joined: 28 Feb 2005 Posts: 80 Topics: 26
|
Posted: Fri Aug 12, 2005 5:36 am Post subject: String Handling Help |
|
|
Hi,
I have some variables defined in the Working Storage as:
Quote: |
WS-A PICX(1)
WS-B PICX(1)
WS-C PICX(1)
WS-D PICX(1)
WS-OUTPUT PIC X(7)
|
Based on a SQL, WS-A,WS-B, WS-C, WS-D variables MAY or MAY NOT get populated.
What I want to do is, Say WS-A, WS-C are populated with A and C respectively. Now this has to formatted and moved to a WS-OUTPUT variable as A,C. If it is WS-A,WS-C and WS-D, then WS-OUTPUT should be populated with A,C,D
Can someone here help me with the Procedure Division Statements to achieve this using Cobol String Functions |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Fri Aug 12, 2005 7:18 am Post subject: |
|
|
What have you attempted alaready? Let us know the errors that you are facing in your attempt. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
SureshKumar Intermediate
Joined: 23 Jan 2003 Posts: 211 Topics: 21
|
Posted: Fri Aug 12, 2005 7:33 am Post subject: |
|
|
sakreq,
String all the variables into a WS field(STRING ?? DELIMITED BY SPACE)
. Then reverse to remove the trailing blanks and move them to your output one by one, adding a ','. |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Fri Aug 12, 2005 7:40 am Post subject: |
|
|
Suresh,
What sakreg wants can be acheived by declaring WS-OUTPUT as a group variable and using only MOVE statements. STRING, INSPECT REVERSE are not needed. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
shivashunmugam Muthu Beginner
Joined: 11 Aug 2005 Posts: 5 Topics: 0 Location: Chennai, India
|
Posted: Fri Aug 12, 2005 7:44 am Post subject: |
|
|
Yes,..with group variable & some simple validation for inputs 2 check spaces is enough! |
|
Back to top |
|
|
sakreg Beginner
Joined: 28 Feb 2005 Posts: 80 Topics: 26
|
Posted: Fri Aug 12, 2005 9:10 pm Post subject: |
|
|
I was thinking to approach this using STRING and INSPECT verbs. I could not find a way how to use those.
But anyway to concat ',' with the DB values I have to use STRING I believe.
Can you guys please make it a bit more clear.
Thank You for having a look. |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Sun Aug 14, 2005 6:10 am Post subject: |
|
|
Like this,
Code: |
01 WS-OUTPUT.
05 WS-A-1 PIC X.
05 FIL-1 PIC X.
05 WS-B-1 PIC X.
05 FIL-2 PIC X.
05 WS-C-1 PIC X.
05 FIL-3 PIC X.
05 WS-D-1 PIC X.
|
Move commas to the FIL-x and the values to WS-A-1 or WS-B-1 as the need maybe. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
sakreg Beginner
Joined: 28 Feb 2005 Posts: 80 Topics: 26
|
Posted: Mon Aug 15, 2005 11:41 am Post subject: |
|
|
Thanks Cogito-Ergo-Sum
Say IF WS-A-1 and WS-D-1 are Populated with A and D respectively, What I expect in WS-OUTPUT is A,D. As of now WS-OUTPUT would be A, , ,D.
Can this be done? |
|
Back to top |
|
|
dtf Beginner
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
|
Posted: Mon Aug 15, 2005 4:27 pm Post subject: |
|
|
I think this code would do what you want. It accepts a 4 byte field as a JCL parm, so you can experiment with all kinds of combinations.
Code: |
WORKING-STORAGE SECTION.
01 WORK-LINE.
03 F1W.
05 F1 PIC X.
05 PIC X VALUE ','.
03 F2W.
05 F2 PIC X.
05 PIC X VALUE ','.
03 F3W.
05 F3 PIC X.
05 PIC X VALUE ','.
03 F4W.
05 F4 PIC X.
05 PIC X VALUE SPACE.
01 WS-DISPLAY-LINE PIC X(7) VALUE SPACES.
LINKAGE SECTION.
01 FIELDS.
05 FIELDS-LENGTH PIC 9(4) COMP.
03 F1W.
05 F1 PIC X.
03 F2W.
05 F2 PIC X.
03 F3W.
05 F3 PIC X.
03 F4W.
05 F4 PIC X.
EJECT
PROCEDURE DIVISION USING FIELDS.
MOVE CORR FIELDS TO WORK-LINE
STRING F1W IN WORK-LINE DELIMITED BY SPACE
F2W IN WORK-LINE DELIMITED BY SPACE
F3W IN WORK-LINE DELIMITED BY SPACE
F4W IN WORK-LINE DELIMITED BY SPACE
INTO WS-DISPLAY-LINE.
INSPECT WS-DISPLAY-LINE REPLACING ALL ', ' BY ' '.
DISPLAY 'DL=' WS-DISPLAY-LINE.
GOBACK.
|
________
Mazda AZ-Wagon picture
Last edited by dtf on Tue Feb 01, 2011 2:00 pm; edited 1 time in total |
|
Back to top |
|
|
sakreg Beginner
Joined: 28 Feb 2005 Posts: 80 Topics: 26
|
Posted: Fri Aug 19, 2005 2:58 am Post subject: |
|
|
That complies my expectations.
Thank You So Much, dtf |
|
Back to top |
|
|
|
|