Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to add % towards the end of my field value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 2:51 pm    Post subject: How to add % towards the end of my field value
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri Apr 22, 2016 3:07 pm    Post subject: Reply to: How to add % towards the end of my field value
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: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 3:25 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri Apr 22, 2016 3:50 pm    Post subject: Reply to: How to add % towards the end of my field value
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Fri Apr 22, 2016 11:28 pm    Post subject:
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: 1715
Location: UK

PostPosted: Sun Apr 24, 2016 9:28 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Sun Apr 24, 2016 10:00 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Apr 25, 2016 12:34 pm    Post subject: Reply to: How to add % towards the end of my field value
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

Moderator


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

PostPosted: Mon Apr 25, 2016 1:07 pm    Post subject:
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: 1715
Location: UK

PostPosted: Mon Apr 25, 2016 7:42 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Mon Apr 25, 2016 8:52 pm    Post subject:
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    Post subject: Reply to: How to add % towards the end of my field value
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri Apr 29, 2016 2:08 pm    Post subject: Reply to: How to add % towards the end of my field value
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Tue May 03, 2016 10:05 pm    Post subject:
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: 641
Location: Whitby, ON, Canada

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

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

There is a complete discussion in:

https://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    Post subject: Reply to: How to add % towards the end of my field value
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 20 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us