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

How to add % towards the end of my field value


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

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 2:51 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 22, 2016 3:07 pm
Reply with quote

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

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 3:25 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 22, 2016 3:50 pm
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Fri Apr 22, 2016 11:28 pm
Reply with quote

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

Global Moderator


Joined: 10 May 2007
Posts: 2454
Location: Hampshire, UK

PostPosted: Sun Apr 24, 2016 9:28 pm
Reply with quote

Why waste DB2 resources when you can do it so much quicker within the program?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Sun Apr 24, 2016 10:00 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 25, 2016 12:34 pm
Reply with quote

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

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Mon Apr 25, 2016 1:07 pm
Reply with quote

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

Global Moderator


Joined: 10 May 2007
Posts: 2454
Location: Hampshire, UK

PostPosted: Mon Apr 25, 2016 7:42 pm
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Mon Apr 25, 2016 8:52 pm
Reply with quote

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

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Fri Apr 29, 2016 11:46 am
Reply with quote

You can use this code:
Code:
INSPECT MY-STRING REPLACING FIRST SPACE BY '%'.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 29, 2016 2:08 pm
Reply with quote

Well, I suppose that will be quicker than using DB2...
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Tue May 03, 2016 10:05 pm
Reply with quote

I wouldn't disagree anymore icon_smile.gif
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Wed May 04, 2016 12:16 am
Reply with quote

Trailing blanks in the host variable can be significant if LIKE is used with wildcards.

There is a complete discussion in:

www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.sqlref/src/tpc/db2z_likepredicate.dita

Especially see the section that discusses the the LIKE_BLANK_INSIGNIFICANT subsystem parameter.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Tue May 10, 2016 4:20 pm
Reply with quote

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
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

 


Similar Topics
Topic Forum Replies
No new posts Help required to reset decimal points... DFSORT/ICETOOL 8
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top