View previous topic :: View next topic
|
Author |
Message |
Help-Me-Out
New User
Joined: 09 Dec 2006 Posts: 56 Location: Pune
|
|
|
|
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 |
|
|
tosaurabh20
New User
Joined: 08 Jun 2007 Posts: 26 Location: Noida
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
If it is left justified can't you just refer to it like ACCT-NO PIC(1:8) |
|
Back to top |
|
|
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
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 |
|
|
Help-Me-Out
New User
Joined: 09 Dec 2006 Posts: 56 Location: Pune
|
|
|
|
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 |
|
|
marvs13th
New User
Joined: 22 Jun 2007 Posts: 5 Location: philippines
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
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 |
|
|
krishnakumarramaraj
New User
Joined: 15 Nov 2005 Posts: 15 Location: chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
ok. i get it. Thanks. Lets hear from OP now. |
|
Back to top |
|
|
krishnakumarramaraj
New User
Joined: 15 Nov 2005 Posts: 15 Location: chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Ashwin_mudikon
New User
Joined: 03 Apr 2007 Posts: 32 Location: Chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Yes, that will move the correct 8 bytes, but it will not ensure they are numeric. . . |
|
Back to top |
|
|
Ashwin_mudikon
New User
Joined: 03 Apr 2007 Posts: 32 Location: Chennai
|
|
|
|
The variable ACC-No is a group variable. So I think it will be considered as alphanumeric and will allow spaces. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Dick,
I used to work w/a guy named Gene. It was kinda funny when we passed in the hallway. |
|
Back to top |
|
|
krishnakumarramaraj
New User
Joined: 15 Nov 2005 Posts: 15 Location: chennai
|
|
|
|
hello,
sorry for late reply.i didnt understand what u said |
|
Back to top |
|
|
nagasri83
New User
Joined: 20 May 2005 Posts: 15 Location: chennai
|
|
|
|
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 |
|
|
|