IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Get next 5 numeric from a string of 'LOCO' of all occurences


 
IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 108
Location: india

PostPosted: Fri Apr 24, 2020 2:30 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8566
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 24, 2020 6:42 pm
Reply with quote

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

Active User


Joined: 27 Feb 2008
Posts: 108
Location: india

PostPosted: Fri Apr 24, 2020 6:56 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8566
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 24, 2020 7:34 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8566
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 24, 2020 8:42 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> COBOL Programming
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts Need to split single line into two li... DFSORT/ICETOOL 7
No new posts how to get total count from numeric d... SYNCSORT 9
No new posts XML-GENERATE to render edited numeric COBOL Programming 0
No new posts To convert numeric to Packed Decimal DFSORT/ICETOOL 9
No new posts how to convert Hex String t char hex PL/I & Assembler 6

Back to Top