IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Want first 8 characters to be moved to the another variable


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

New User


Joined: 09 Dec 2006
Posts: 56
Location: Pune

PostPosted: Mon Jun 25, 2007 10:22 am
Reply with quote

Hi,

Need help to get first 8 characters of account no. I have field ACCT-NO PIC X(19). This field contains numbers only. This fields may contain 19/17/16/14/13 characters, in my case it can be 13/14 characters. Now I want first 8 characters to be moved to the another variable which has def TEMP PIC 9(8).

How can I do? I have used reference modification & inspect for temporary solution.

Please suggest on this.

Thanks,

Sandeep
Back to top
View user's profile Send private message
tosaurabh20

New User


Joined: 08 Jun 2007
Posts: 26
Location: Noida

PostPosted: Mon Jun 25, 2007 10:31 am
Reply with quote

Help-Me-Out wrote:
Hi,

Need help to get first 8 characters of account no. I have field ACCT-NO PIC X(19). This field contains numbers only. This fields may contain 19/17/16/14/13 characters, in my case it can be 13/14 characters. Now I want first 8 characters to be moved to the another variable which has def TEMP PIC 9(8).

How can I do? I have used reference modification & inspect for temporary solution.

Please suggest on this.

Thanks,

Sandeep


Hi Sandeep,

With reference to your question, i would like to request you to use Reference modification. Hope you have heard about it, if not then it is a technique through which you can move a substring to another varaible.

Refer some manuals you will definitely find it out. Its very common in COBOL programming. still if you are not able to find it then let me know i will help you out further.

Thanks
Saurabh
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Jun 25, 2007 12:47 pm
Reply with quote

If the value is normally left justified with trailing blank padding, just grab the left-most eight characters through RM or redefinition.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jun 25, 2007 6:40 pm
Reply with quote

If it is left justified can't you just refer to it like ACCT-NO PIC(1:8)
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Mon Jun 25, 2007 8:33 pm
Reply with quote

Hi All,
Since he mention the account Number is ACCT-NO PIC X(19) and has value of 13/14 character.then we move only 8 character better we can use ACCT-NO PIC(1:8)...
Back to top
View user's profile Send private message
Help-Me-Out

New User


Joined: 09 Dec 2006
Posts: 56
Location: Pune

PostPosted: Wed Jun 27, 2007 9:45 am
Reply with quote

Hi,

In my req acct no contains the spaces b4 actual acct no starts.
e.g. ' 1234567890123'

In this first 6 characters ar spaces. I need only 12345678. It might happen the spaces will be less or more according to the acct no.

Thanks,
Back to top
View user's profile Send private message
marvs13th

New User


Joined: 22 Jun 2007
Posts: 5
Location: philippines

PostPosted: Wed Jun 27, 2007 1:01 pm
Reply with quote

my code is

01 ACCT-NO PIC X(19).
01 NEW-ACCTNO REDEFINES ACCT-NO
03 TEMP-NUMERIC PIC 9(8).
03 TEMP-ALPHA PIC X(8).


think this may work........ : )
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Jun 27, 2007 2:02 pm
Reply with quote

Hello,

How does
Quote:
01 ACCT-NO PIC X(19).
01 NEW-ACCTNO REDEFINES ACCT-NO
03 TEMP-NUMERIC PIC 9(8).
03 TEMP-ALPHA PIC X(8).

that code deal with the "leading spaces" mentioned previously?
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Thu Jun 28, 2007 8:56 am
Reply with quote

Could you guys tell me if this would work in the case mentioned above??

put a perform loop for i varying from 1 to 19 times(as big as the variable size). and in each turn check if that particular value of the variable i.e x(i) in the loop is a 'space'. If it is not 'space' then use reference modification from there on.

e.g

01 i pic 99 value 1.


perform varying i from 1 by 1 until i>19

if x(i:1) not= space
move x(i:8) to y
else
continue.


where x is original variable
Back to top
View user's profile Send private message
krishnakumarramaraj

New User


Joined: 15 Nov 2005
Posts: 15
Location: chennai

PostPosted: Thu Jun 28, 2007 11:34 am
Reply with quote

HI,
You can do it by using UNSTRING and DELIMITED BY phrase.But the receiving field should be defined such that it can contain only 8 charcters.B'coz u need only 8 characters.Hope this may work.
Regards
Krishnakumar
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jun 28, 2007 11:35 am
Reply with quote

Hello,

I believe that will be close if the value is alpha-numeric, but you will have problems if it is supposed to be numeric and does not contain 8 consecutive numeric digits (a test for numeric would be needed). Also, you would not want to go thru "19" as that would go beyond the end of the field.

Once you handle any case where the value is not numeric and change the "high-water" mark, that should work.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jun 28, 2007 12:00 pm
Reply with quote

Hello,

UNSTRING may not give the desired result. Please post the code you would suggest to accomplish removing some variable number of possible leading spaces and retaining the 8 digit numeric value.
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Thu Jun 28, 2007 3:00 pm
Reply with quote

but dick, is it not right that as long as the value is not SPACES in those fields the logic would work.

We just dont want the "spaces" to be there. The problem says that there could be any number of spaces and only then does the account number start. Even if the acc number is alpha or numeric the logic should work, shouldn't it?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jun 28, 2007 6:27 pm
Reply with quote

Hello,

Please look at the target field definition - 03 TEMP-NUMERIC PIC 9(8).

If anything other than valid numbers are moved into the field, later problems are likely. It is better to make sure the 8 bytes after the leading space(s) really contain numbers.
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Thu Jun 28, 2007 9:50 pm
Reply with quote

ok. i get it. Thanks. Lets hear from OP now.
Back to top
View user's profile Send private message
krishnakumarramaraj

New User


Joined: 15 Nov 2005
Posts: 15
Location: chennai

PostPosted: Fri Jun 29, 2007 11:10 am
Reply with quote

Hi sandeep ,
i sent you some suggesstion related to ur problem.Here is the exact thing u try this out.

UNSTRING identifier-1(WhICH HAS 12/34/56/78/93/98...)
DELIMITED BY identifier-2(this should contain'/')
INTO ident-3 [which is an x(2)],ident-4[is an X(2)],ident-5[is an X(2)],ident-6[is an X(2)]
now this will store the first 6 characters in four identfiers from 3 to 6.
Next you have to use STRING statement to brought all the 8 characters together in to a single field.its syntax is...

STRING ident-3 DELIMITED BY SIZE
ident-4 DELIMITED BY SIZE
ident-5 DELIMITED BY SIZE
ident-6 DELIMITED BY SIZE
INTO ident-7(this should acommodate 8 characters,either x(8) or 9(8))
if ident-7 is x(8) then you can use MOVE to convert it in to neumeric i.e 9(8)

Refer cobol programming M.K.Roy (Page no ;348,349 also the example given in 351)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jun 29, 2007 11:23 am
Reply with quote

Hello,

What you have posted is nothing like the requirement posted. Please re-read the entire topic and see that the requirement is to skip zero-to-n blanks before an 8 digit number.

Your example with nn/nn/nn/nn introduces the slashes which were not mentioned in the requirement and ignores leading spaces which was the main focus of the requirement.

If anyone were to try this, how would it remove leading spaces and capture an 8-digit numeric value?
Back to top
View user's profile Send private message
Ashwin_mudikon

New User


Joined: 03 Apr 2007
Posts: 32
Location: Chennai

PostPosted: Fri Jun 29, 2007 3:40 pm
Reply with quote

hi,

I think this may work out.


Code:
INSPECT ACC-NO TALLYING SPC-COUNT FOR LEADING SPACES.
ADD 1 TO SPC-COUNT.
MOVE ACC-NO(SPC-COUNT:8)  TO OUT-FLD.


Regards,
Ashwin
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jun 29, 2007 6:19 pm
Reply with quote

Hello,

Yes, that will move the correct 8 bytes, but it will not ensure they are numeric. . .
Back to top
View user's profile Send private message
Ashwin_mudikon

New User


Joined: 03 Apr 2007
Posts: 32
Location: Chennai

PostPosted: Fri Jun 29, 2007 6:46 pm
Reply with quote

The variable ACC-No is a group variable. So I think it will be considered as alphanumeric and will allow spaces.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jun 29, 2007 6:59 pm
Reply with quote

Hi HMO,

You could try something like this:
Code:

1     /                                                                 
      ******************************************************************
       WORKING-STORAGE SECTION.                                         
      ******************************************************************
                                                                       
      ******************************************************************
       01  WS-WORK-FLDS.                                               
      ******************************************************************
      *===>                                                             
           05  COMP-INFO                   PIC  X(021) VALUE SPACES.   
                                                                       
           05  WS-ACCT                     PIC  X(019) VALUE           
               '      1234567890123'.                                   
***********05  WS-ACCT                     PIC  X(019) VALUE           
***************'     12345678901234'.                                   
           05  WS-ACCT-9                   PIC  9(008) VALUE 0.         
1     /                                                                 
       PROCEDURE DIVISION.                                             
      ******************************************************************
       000-MAINLINE.                                                   
      ******************************************************************
      *===>                                                             
      *===>                                                             
      *===>                                                             
      *-----------------------------------------------------------------
           DISPLAY 'TESTPGM STARTED'                                   
           MOVE FUNCTION WHEN-COMPILED  TO COMP-INFO                   
           DISPLAY 'TESTPGM COMPILED ON '                               
                   COMP-INFO(5:2) '/'                                   
                   COMP-INFO(7:2) '/'                                   
                   COMP-INFO(1:4)                                       
                   ' AT '                                               
                   COMP-INFO(9:2)                                       
                   ':'                                                 
                   COMP-INFO(11:2)                                     
           DISPLAY ' '                                           
           EVALUATE TRUE            ALSO TRUE                   
           WHEN WS-ACCT(5:1) = ' '  ALSO WS-ACCT(6:1) NUMERIC   
                MOVE WS-ACCT(6:8)     TO WS-ACCT-9               
                DISPLAY 'ACCT-9 >'  WS-ACCT-9 '< '               
           WHEN WS-ACCT(6:1) = ' '  ALSO WS-ACCT(7:1) NUMERIC   
                MOVE WS-ACCT(7:8)     TO WS-ACCT-9               
                DISPLAY 'ACCT-9 >'  WS-ACCT-9 '< '               
           END-EVALUATE                                         
           GOBACK 
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jun 29, 2007 8:42 pm
Reply with quote

Hello,

This
Quote:
The variable ACC-No is a group variable. So I think it will be considered as alphanumeric and will allow spaces.
does not deal with ensuring the value of the 8 bytes is a valid numeric. I'm not sure why the "group" matters.

Hi Jack (bet i shouldn't yell that at the airport),
Yup, that looks like it will do what is needed - might need a few more cases for inputs with less spaces icon_smile.gif
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jun 29, 2007 11:09 pm
Reply with quote

Hi Dick,

I used to work w/a guy named Gene. It was kinda funny when we passed in the hallway. icon_smile.gif
Back to top
View user's profile Send private message
krishnakumarramaraj

New User


Joined: 15 Nov 2005
Posts: 15
Location: chennai

PostPosted: Fri Jul 06, 2007 10:14 am
Reply with quote

hello,
sorry for late reply.i didnt understand what u said
Back to top
View user's profile Send private message
nagasri83

New User


Joined: 20 May 2005
Posts: 15
Location: chennai

PostPosted: Thu Jul 12, 2007 6:33 am
Reply with quote

Why don't you use INSPECT & referrence modification concepts to meet this requirement.

Inspect the variable for leading SPACES and then use RM.

INSPECT ACCT-NO TALLYING CNTR FOR LEADING SPACES.
COMPUTE CNTR = CNTR + 1.
MOVE ACCT-NO(CNTR:8) TO WS-ACCT-NO-8.

Hope this works and provides the solution.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Reading dataset in Python - New Line ... All Other Mainframe Topics 22
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top