View previous topic :: View next topic
|
Author |
Message |
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
I am in a requirement to convert value
(1 appended with 3 spaces) to
in efficient way in CICS SCREEN.
This means all trailing spaces should get converted into leading zeros for entered value by user....
e.g.
Code: |
'5 ' --> '0005'
'68 ' --> '0068'
|
I have logic of reference modification but it seems complicated and redundant as i have to develop it for so many input flags.
I am trying to search some easy mechanism to do this. |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Am guessing defining your field as ZZZ9 should do the trick... Maybe you might have to REDEFINE the field to write your code effectively... |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Use the "PICIN" and "PICOUT" BMS Keywords at the DFHMDF level. Your Map Copybook will then be generated with fields defined as PIC 9 as opposed to PIC X.
Your attribute must still be "NUM" (you're probably using "UNPROT" as well), because Users can still enter non-numeric special-characters, even with "NUM".
Never underestimate the ability of a User to mess things up.... |
|
Back to top |
|
|
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
Absolutely Bill, i am using NUM UNPROT attributes.
PICIN and PICOUT.. i dont think so we can use in our shop...
I tried to send the input value to X(4) JUSTIFIED RIGHT and redefined same by 9(4) but it didnt workk.. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
PICIN/PICOUT is the easiest method to deal with this "opportunity" and their use shouldn't warrant their restriction.
Management decision?
Frightening....
Take a look at the CICS Builtin Function DEEDIT. I think that will work for you.... |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Why not NUMVAL? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
EXEC CICS BIF DEEDIT will do what you want; in COBOL you can use FUNCTION NUMVAL to achieve amost the same result (the CICS code handles non-numeric characters but FUNCTION NUMVAL expects the data to be spaces / digits). |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
FUNCTION NUMVAL is another method, but requires COBOL/370 and above and has its limitations.
Wasn't sure what version of COBOL was being used. Many times in overseas shops, VS/COBOL II (the predecessor to COBOL/370) as well as OS/VS COBOL are still quite popular.
BIF DEEDIT has been around for 30+ years and will work on any version of COBOL. |
|
Back to top |
|
|
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
I will try both options n let our forum know...
Very very thankful to all of you.. Hope BIF DEEDIT will work for me.. |
|
Back to top |
|
|
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
But there is doubt...
I have to convert it to '0001' only if user enters '1 ' not '1@@@' and not '1###'..
Let me give a hand on this ... But your valuable suggestions gave me track to sail thru...
thanks |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If you have access to transid CECI (CICS Command Level Interpreter) then you can experiment (using BIF DEEDIT) to ensure you've covered all data-scenarios.
CECI comes in very handy and is a good way to learn command level CICS.
Ask your CICS System Programmer whether you already have or request to have access (non-Production region(s) only).
HTH.... |
|
Back to top |
|
|
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
Thanks a lot Bill...
I tried both NUMVAL and DEEDIT options...
both gave me almost right results.
Now i am just waiting for approval on usage of either of them so that i can go ahead !!!
I think NUMVAL has some issues of compiler versions so lets see if i can go ahead with DEEDIT cics command...
I passed control to above options by using IF condition construct for checking only numeric and spaces... !! |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
rohanthengal wrote: |
I think NUMVAL has some issues of compiler versions so lets see if i can go ahead with DEEDIT cics command... |
What version of COBOL are you using? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
01 The-field.
88 blank-field value space.
05 FILLER PIC 9.
05 last-three-bytes.
88 three-trailing-spaces value space.
10 second-byte PIC X.
10 last-two-bytes.
88 two-trailing-spaces value space.
15 third-byte PIC X.
15 fourth-byte PIC X.
88 one-trailing-space value space.
01 FILLER REDEFINES The-field.
05 first-three-bytes PIC 999.
05 FILLER REDEFINES first-three-bytes.
10 first-two-bytes PIC 99.
10 FILLER REDEFINES first-two-bytes.
15 first-byte PIC 9.
15 FILLER PIC X.
10 FILLER PIC X.
01 FILLER REDEFINES The-field.
05 The-field-as-numeric PIC 9(4). |
Code: |
EVALUATE TRUE
WHEN blank-field
do something for a blank field
WHEN three-trailing-spaces
MOVE first-byte TO somewhere-numeric
WHEN two-trailing-spaces
MOVE first-two-bytes TO somewhere-numeric
WHEN one-trailing-space
MOVE first-three-bytes TO somewhere-numeric
WHEN OTHER
IF The-field NUMERIC
MOVE The-field-as-numeric TO somewhere-numeric
ELSE
do something for invalid numeric data
END-IF
END-EVALUATE |
If you want to "code less" but have the CPU do more work, you could use UNSTRING .... DELIMITED BY SPACE into two output fields, the first a JUSTIFIED RIGHT PIC X(4), setting both the space before the UNSTRING. If the second field is not space afterwards, you have an embedded blank.
INSPECT the JUST RIGHT REPLACING LEADING SPACE BY ZERO, test the field for NUMERIC, and, if it is, MOVE a 9(4) definition of that field to where you desire.
Code: |
" 111"
"1 "
"11 "
"111 "
"1 11"
"1111"
"1@11"
"1.11"
|
Whichever you go with, include the above test data alongside your own. |
|
Back to top |
|
|
rohanthengal
Active User
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
Finally, we have decided to go with NUMVAL...
Its working nicely in all above test cases.
I have placed NUMVAL function under IF construct after checking for valid combination of numerics and spaces in INPUT.
so only when input has:
numerics prefixed/suffixed with zeros or spaces
any other combination will through an error as per requirement.. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
After receiving the map, issue the following, which will ensure that SPACES will replace any other character except numerics 0-9, which will be retained. In the example below, WS-MAP-FIELD contains a '1' in the first-position and special-characters in positions 2-4. After the INSPECT, WS-MAP-FIELD will contain '1bbb' with 'bbb' representing blanks/spaces. NUMVAL should operate much cleaner, based upon the fact that WS-MAP-FIELD now only contains numerics and/or spaces.
Code: |
03 WS-XLATE-FROM-TBL PIC X(256).
03 WS-XLATE-TO-TBL PIC X(256).
03 WS-SUB PIC 9(008) BINARY.
03 WS-SUB-X REDEFINES WS-SUB
PIC X(004).
03 WS-MAP-FIELD PIC X(004).
*
PERFORM VARYING TALLY FROM 1 BY 1
UNTIL TALLY > LENGTH OF WS-XLATE-FROM-TBL
COMPUTE WS-SUB = (TALLY - 1)
MOVE WS-SUB-X (4:1) TO WS-XLATE-FROM-TBL (TALLY:1)
END-PERFORM.
*
MOVE SPACES TO WS-XLATE-TO-TBL.
MOVE WS-XLATE-FROM-TBL (241:)
TO WS-XLATE-TO-TBL (241:10).
MOVE '1#^!' TO WS-MAP-FIELD.
*
INSPECT WS-MAP-FIELD CONVERTING WS-XLATE-FROM-TBL
TO WS-XLATE-TO-TBL.
|
The following code eliminates the need to issue FUNCTION NUMVAL and/or BIF DEEDIT as it right justifies the map field, padding it with high-order zeros. For example, if WS-MAP-FIELD is populated with '1bb1', after the PERFORM, it would equal '0011'.
Code: |
03 WS-MAP-FIELD PIC X(04).
03 WS-WORK-FIELD PIC X(04).
03 WS-SUB PIC 9(08) BINARY.
*
MOVE LENGTH OF WS-MAP-FIELD TO TALLY.
MOVE LENGTH OF WS-MAP-FIELD TO WS-SUB.
MOVE ZERO TO WS-WORK-FIELD.
MOVE '1 1' TO WS-MAP-FIELD.
*
PERFORM UNTIL TALLY < 1
IF (WS-MAP-FIELD (TALLY:1) NOT < '1'
AND WS-MAP-FIELD (TALLY:1) NOT > '9')
MOVE WS-MAP-FIELD (TALLY:1)
TO WS-WORK-FIELD (WS-SUB:1)
SUBTRACT 1 FROM WS-SUB
END-IF
SUBTRACT 1 FROM TALLY
END-PERFORM.
*
MOVE WS-WORK-FIELD TO WS-MAP-FIELD.
|
HTH.... |
|
Back to top |
|
|
|