View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi,
I have a field like,
PART-NO=123456
Actually this field is of 15 bytes. But if I give partial value to this field I need to pad a % towards the end and search it in the DB2 table.
Could you please help me on how can I pad it.
Expected value=123456% |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You mean you want to use LIKE for find all 15-digit numbers which start with those six numbers?
You will need to pad with % to the end of your field, not just have one.
INSPECT changing space to % is probably common. There's setting the field to ALL % and then STRING or reference-modification. Other ways. Depends on what you actually want, local standards, etc. |
|
Back to top |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
What you said is correct. I need to pad a single % only to 123456 and look like 123456%.
Can I achieve it via INSPECT to pad it towards the end ?. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If all your data is six digits and you want to put one % at the end, just do it with the data-defintion.
01 a-nice-name.
05 the-six-digit-part-nicely-named PIC X(6).
05 the-trailing-percent-for-like PIC X value "%".
You put your six-digit field in the obvious place, and use a-nice-name for the seven-byte field with the trailing percent.
If doing something which does not allow group items, just use REDEFINES as well. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Now, You confirmed that you have a DB2 then what stops you using a DB2 functions? like e.g.
Code: |
select CONCAT('123456','%')
FROM sysibm.sysdummy1 |
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
Why waste DB2 resources when you can do it so much quicker within the program? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
I don't see a waste you when you query on sysibm.sysdummy1 in a cobol-db2 program and in my shop such formatting is easy and quick to expand in future changes than making some fancy cobol code. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You mean you don't see that there would be any difference between a VALUE statement (set once, when the program is loaded) and a DB2 statement per program use? Even if done only once, the DB2 solution is "longer" and "hides" the fact that a "%" is wanted at position seven. Nothing else. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
I second what Bill said having just one '%' might not be working as expected. You need to pad '%' for the rest of the string |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
The DB2 solution incurs the overhead of leaving your program, getting DB2 to do something that is easy within your program whilst it could be doing some more useful DB2 stuff, and then returning to your program. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Unless I misunderstand the situation of the original post of the starter , 123456 is just an example and the values may vary between 1-15 and if this is true then he needs to be handling it dynamically than a static. But id that is always a 6 bytes then Bill's way of handling can be chosen.
Regarding the overhead, I would consider that to be very minimal but either way TS now has a choice based on sites standards.
DB2 Solution
Code: |
select replace(CONCAT('123456 ','%'),' ','') from sysibm.sysdummy1 |
would me more accurate to the situation.
Cobol Solution
1. find the actual value , see here
2. string '%' to the obtained value from step1 |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
You can use this code:
Code: |
INSPECT MY-STRING REPLACING FIRST SPACE BY '%'. |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, I suppose that will be quicker than using DB2... |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
I wouldn't disagree anymore |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
I would say you can try this approach and see if works.
>> In working storage set a literal lit1 x(1) to a value of %
>>move the value 123456 or whatever into a alphanumeric variable
var1 x(15) . Instead of 123456 it could be 123456789 also.
If the length of Var1 < 15 do below operation
>>String Var1 delimited by space with lit1 delimited by size into a new output variable which is also x(15)
Else
Continue
Endif |
|
Back to top |
|
|
|