View previous topic :: View next topic
|
Author |
Message |
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
Hi,
suppose I have a string of 40 length, and I have some occurences of 'LOCO' and I just want to get the substring of 5 digits( only numeric) next to 'LOCO' for all occurences of the string... If next to LOCO does not have numeric of 5 occurences then its not needed...
suppose I have string:
WS-DATA -- ABCDLOCO40000kakakLOCO98abcLOCO500009898
my result would be 40000+50000=90000
can it be possible ?
What will be the approach to solve this ?
1. to get the position of LOCO.
2. check whether next 5 characters are numeric
3. use referential integrity to get the next 5 numeric data
Please post if you have any good approach to resolve this...
Thanks |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You need to proofread your posts before you hit Submit.
Quote: |
3. use referential integrity to get the next 5 numeric data |
Referential integrity is a database term related to the consistency of data between tables. I assume you actually meant reference modification, which actually is a COBOL term. If you actually didn't know the difference, you need to stop posting on this forum (which is for experts) and start posting on Beginners and Students Forum instead. |
|
Back to top |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
Hi, I know it's a expert forum and it's not a homework question.
sorry, it's referential modification... it's typo.
I post this in expert forum, because It's not a easy one.
Anyway thanks...
I think I too wasted my time like you... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I post this in expert forum, because It's not a easy one. |
Well, you might THINK it's not an easy one … I figure about half a day of COBOL coding should get a good solution, compiled and tested. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I post this in expert forum, because It's not a easy one. |
I consider myself a competent COBOL programmer. I just coded a solution, using your sample data, in one hour -- so half a day is probably more than is needed. Code:
Code: |
000800 WORKING-STORAGE SECTION.
000900 01 WS-VARS.
001000 05 WS-SOURCE PIC X(80) VALUE
001100 'ABCDLOCO40000KAKAKLOCO98ABCLOCO500009898'.
001200 05 WS-WORK PIC X(80).
001300 05 WS-TEMP PIC X(80).
001400 05 WS-CUR-LOC PIC S9(09) COMP-5 VALUE 1.
001500 05 WS-LOCO-LOC PIC S9(09) COMP-5 VALUE 1.
001600 05 WS-NUM-LOC PIC S9(09) COMP-5.
001700 05 WS-NUM-FLAG PIC X(01).
001800 PROCEDURE DIVISION.
001900 DISPLAY 'SOURCE: ' WS-SOURCE.
002000 MOVE WS-SOURCE TO WS-WORK.
002100 PERFORM 1000-PROCESS
002200 UNTIL WS-LOCO-LOC = ZERO.
002300
002400 STOP RUN.
002500
002600 1000-PROCESS.
002700 MOVE ZERO TO WS-LOCO-LOC.
002800 INSPECT WS-WORK
002900 TALLYING WS-LOCO-LOC
003000 FOR CHARACTERS BEFORE 'LOCO' .
003100 COMPUTE WS-CUR-LOC = WS-LOCO-LOC + 5.
003200 MOVE 'Y' TO WS-NUM-FLAG.
003300 PERFORM
003400 VARYING WS-NUM-LOC
003500 FROM WS-CUR-LOC BY 1
003600 UNTIL WS-NUM-LOC > WS-CUR-LOC + 4
003700 IF WS-WORK (WS-NUM-LOC : 1) >= 0
003800 AND WS-WORK (WS-NUM-LOC : 1) <= 9
003900 CONTINUE
004000 ELSE
004100 MOVE 'N' TO WS-NUM-FLAG
004200 END-IF
004300 END-PERFORM.
004400 DISPLAY 'STRING: ' WS-WORK (1 : WS-NUM-LOC).
004500 DISPLAY 'NUMERIC: ' WS-NUM-FLAG.
004600 MOVE WS-WORK (WS-NUM-LOC : ) TO WS-TEMP.
004700 MOVE WS-TEMP TO WS-WORK.
|
yields results of
Code: |
SOURCE: ABCDLOCO40000KAKAKLOCO98ABCLOCO500009898
STRING: ABCDLOCO40000K
NUMERIC: Y
STRING: KAKAKLOCO98ABCL
NUMERIC: N
STRING: LOCO500009
NUMERIC: Y |
Perhaps you need a better understanding of what "an easy one" actually is? Based on what you've shown on this thread, you really should be posting on Beginners and Students Forumn because it doesn't matter how many "years" of industry experience you claim, you're still a beginner. |
|
Back to top |
|
|
|