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

Issue in suppressing leading zeros & trailing zeros in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
Vijay_Sirisha

New User


Joined: 06 Jun 2018
Posts: 8
Location: USA

PostPosted: Thu Jun 07, 2018 8:01 pm
Reply with quote

I have a DB2 table field defined as S9(9) USAGE COMP. When I pass a single digit (For Ex: 9) it is receiving as 09000000.

I was able to suppress leading zeros by defining a Working Storage WS-A PIC Z(7)9. But i was failing in controlling the trailing zeros. To some extent I was successful by using below code but when I enter 90, it is still receiving as 9.

05 WS- IDX PIC 9(03) VALUE ZEROS.
05 WS-STRING-FIELD PIC X(08).

PERFORM VARYING WS-IDX FROM 1 BY 1
UNTIL WS-IDX > 8
IF WS-STRING-FIELD(WS-IDX:1) = ZEROES
MOVE SPACE TO WS-STRING-FIELD(WS-IDX:1)
END-IF.

Can someone suggest me, if there is any other option so that the S9(9) USAGE COMP field will the number I enter? (For Ex: When I enter 3, USAGE COMP field should receive 3 only)


Thanks for your help in advance.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jun 07, 2018 8:11 pm
Reply with quote

Quote:
When I pass a single digit (For Ex: 9) it is receiving as 09000000.
I would expect to see such behavior when using ACCEPT (and not very often otherwise) -- what are you doing to get such an odd result? You need to describe more about what you're doing and the precise results you are getting as opposed to what you want to get. For example, if you pass '90', do you expect to get back '90' or '9'?
Back to top
View user's profile Send private message
Vijay_Sirisha

New User


Joined: 06 Jun 2018
Posts: 8
Location: USA

PostPosted: Thu Jun 07, 2018 9:28 pm
Reply with quote

Thanks for you response.

I am building a COBOL-DB2 program which down the line feed the data to an ETL Process, where my input single or multiple digits (For Ex: 3; 30; 24; 250).

After being passed to my program it's leading & trailing with zeros.

This is a count field which was defined in DB2 as INTEGER and the corresponding COBOL variable as S9(9) USAGE COMP.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jun 08, 2018 12:07 am
Reply with quote

You are still making no sense. A COBOL PIC S9(9) COMP variable will have a value of X'0003' for 3 or X'00FA' for 250. Leading or trailing zeroes don't exist with COMP values since they are binary values.

Quote:
After being passed to my program it's leading & trailing with zeros.
I recommend you contact whoever is passing you the data and get it passed to you in the correct format. You should not have to fix somebody else's data.

Since you have not identified how the data is being passed to your program, nor the precise format it comes into your program, nor much of anything really, there's not much we can do to help you. If you want help, you will need to clearly and concisely explain the data coming in (both what you think it should be as well as what your program actually is getting), the format of that data (alphanumeric, zoned decimal, binary, packed decimal, or whatever), and where the issue comes from.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Fri Jun 08, 2018 1:52 am
Reply with quote

Quote:
This is a count field which was defined in DB2 as INTEGER and the corresponding COBOL variable as S9(9) USAGE COMP.
Why don't you use DB2 functions to convert them to whatever format you want, e.g. use STRIP to get rid off trailing zeroes? That's exactly what is needed here.
Back to top
View user's profile Send private message
Vijay_Sirisha

New User


Joined: 06 Jun 2018
Posts: 8
Location: USA

PostPosted: Fri Jun 08, 2018 3:17 am
Reply with quote

I can control the total number of bytes using STRIP?

For EX: When I enter 200, by using STRIP it will get rid of trailing zeroes right? which means my result will be instead of 200.

Correct me if I am wrong.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Fri Jun 08, 2018 3:22 am
Reply with quote

Yes
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Fri Jun 08, 2018 5:30 pm
Reply with quote

I am just trying to understand , did you try FUNCTION NUMVAL
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sun Jun 10, 2018 6:10 pm
Reply with quote

Vijay_Sirisha wrote:
I have a DB2 table field defined as S9(9) USAGE COMP. When I pass a single digit (For Ex: 9) it is receiving as 09000000.

Hello Vijay, welcome to the forum.
When you have a problem, you have to give us as much information as possible, so we don't have to guess what you are doing.
A lot is missing here: how do you "pass a single digit" ? From where ? To where ?

Because of the lack of details, you have not yet received a clear answer.

My guess is that you have a character field PIC X(8) which has a value of '9', left justified (meaning with 7 spaces on the right).
Or maybe it is PIC X(8) redefined as PIC 9(8), or maybe something else.
Somehow, these spaces are mistaken for zeroes.

As Pandora suggested, try using FUNCTION NUMVAL to move your number from character area to numeric area.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Sun Jun 10, 2018 11:04 pm
Reply with quote

Robert Sample wrote:
You are still making no sense. A COBOL PIC S9(9) COMP variable will have a value of X'0003' for 3 or X'00FA' for 250. Leading or trailing zeroes don't exist with COMP values since they are binary values

This sentence is true for PIC S9(4) COMP:
+3 --> X'0003'
+0003 --> X'0003'
+250 --> X'00FA'
+0250 --> X'00FA'

For PIC S9(9) COMP we'll get in memory:
+3 --> X'00000003'
+000000003 --> X'00000003'
+250 --> X'000000FA'
+000000250 --> X'000000FA'

But all said above has no effect on: how the value is displayed in text/print format, as well as leading zeroes.
Back to top
View user's profile Send private message
Vijay_Sirisha

New User


Joined: 06 Jun 2018
Posts: 8
Location: USA

PostPosted: Tue Jun 12, 2018 1:36 am
Reply with quote

Let me explain clearly, because few people asked me to explain clearly.

I have a field in the DB2 table defined as RECORD_COUNT INTEGER, and the corresponding COBOL variable is RECORD-COUNT S9(9) USAGE COMP.

DB2 Variable : RECORD_COUNT INTEGER
COBOL(HOST VARIABLE) : RECORD-COUNT S9(9) USAGE COMP.

When I am inserting any numeric into the table For EX: 45, it is taking as 0000450000.

Question#1: How can I make sure it is right justified? For Ex: 0000000045.
Questoin#2: Is there any I can see the number what i inserted in the DB2 table instead of leading or trailing zeroes.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Tue Jun 12, 2018 1:51 am
Reply with quote

Where are you getting the value for RECORD-COUNT from and its datatype?
Back to top
View user's profile Send private message
Vijay_Sirisha

New User


Joined: 06 Jun 2018
Posts: 8
Location: USA

PostPosted: Tue Jun 12, 2018 1:56 am
Reply with quote

From Front-End Java, and the data type is alphanumeric.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Tue Jun 12, 2018 2:08 am
Reply with quote

Are using a intermediate field in COBOL program before populating it to RECORD-COUNT?

As I already stated I want you make use of FUNCTION NUMVAL

To be double sure

1.Create a temporary Alphanumeric variable equivalent to your JAVA variable
2.Then make use of FUNCTION NUMVAL
which is

Code:
 COMPUTE RECORD-COUNT = FUNCTION NUMVAL (Temp variable)


This temp variable you have created in Step 1
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Tue Jun 12, 2018 2:32 am
Reply with quote

Vijay_Sirisha wrote:
Let me explain clearly, because few people asked me to explain clearly.

I have a field in the DB2 table defined as RECORD_COUNT INTEGER, and the corresponding COBOL variable is RECORD-COUNT S9(9) USAGE COMP.

DB2 Variable : RECORD_COUNT INTEGER
COBOL(HOST VARIABLE) : RECORD-COUNT S9(9) USAGE COMP.

When I am inserting any numeric into the table For EX: 45, it is taking as 0000450000.

Question#1: How can I make sure it is right justified? For Ex: 0000000045.
Questoin#2: Is there any I can see the number what i inserted in the DB2 table instead of leading or trailing zeroes.

Internally used data format INTEGER (in DB2), or COMP (in COBOL) - both have nothing to do with neither leading nor trailing zeroes. Period.

From your unprofessional blah-blah-blah no-one is able to understand: where and how did you get "leading/trailing zeroes"?
Back to top
View user's profile Send private message
Vijay_Sirisha

New User


Joined: 06 Jun 2018
Posts: 8
Location: USA

PostPosted: Tue Jun 12, 2018 3:17 am
Reply with quote

sergeyken wrote:
Vijay_Sirisha wrote:
Let me explain clearly, because few people asked me to explain clearly.

I have a field in the DB2 table defined as RECORD_COUNT INTEGER, and the corresponding COBOL variable is RECORD-COUNT S9(9) USAGE COMP.

DB2 Variable : RECORD_COUNT INTEGER
COBOL(HOST VARIABLE) : RECORD-COUNT S9(9) USAGE COMP.

When I am inserting any numeric into the table For EX: 45, it is taking as 0000450000.

Question#1: How can I make sure it is right justified? For Ex: 0000000045.
Questoin#2: Is there any I can see the number what i inserted in the DB2 table instead of leading or trailing zeroes.

Internally used data format INTEGER (in DB2), or COMP (in COBOL) - both have nothing to do with neither leading nor trailing zeroes. Period.

From your unprofessional blah-blah-blah no-one is able to understand: where and how did you get "leading/trailing zeroes"?


Sorry to say this Sir, It looks like you don't know how to show respect to others. Showing some respect and decency in asking questions(From your unprofessional blah-blah-blah no-one is able to understand: where and how did you get "leading/trailing zeroes"?) is professionalism.

Not sure how old are you or how much experience, please learn how to behave in professional way icon_smile.gif
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Tue Jun 12, 2018 3:31 am
Reply with quote

Vijay_Sirisha wrote:

Sorry to say this Sir, It looks like you don't know how to show respect to others. Showing some respect and decency in asking questions(From your unprofessional blah-blah-blah no-one is able to understand: where and how did you get "leading/trailing zeroes"?) is professionalism.

Not sure how old are you or how much experience, please learn how to behave in professional way icon_smile.gif

"Professionalism" in a technical forum assumes understanding of at least fundamental principles of material being discussed. After reviewing all this topic it's getting easy to find out that even after simple introductory advices, and questions provided by others you cannot understand the difference between real life, and your terminology. Usually the Beginners Forum is recommended after diagnosis of this kind.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 418
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Tue Jun 12, 2018 7:25 am
Reply with quote

Just a casual observation:

Provide hex display of host field immediately prior to update/insert.

Provide hex display of table variable immediately after update/insert.

Create a test table with one or two columns and just use it.


Segeyken's explanation of COMP covers the behavior you should see.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Tue Jun 12, 2018 8:49 am
Reply with quote

I have been following this thread, not with any thought of adding my thoughts to it; I'm not qualified in either Cobol or DB2.

However, I think the "requirement" to drop trailing 0s is ridiculous, and I also think there are other issues with this "requirement." For example, is the modified numeric character string left justified, and are the dropped 0 characters on the right replaced with nulls or blanks.

I do agree with the topic starter that Sergeyken's "flame" of the topic starter's requirement and the topic starter's professionalism is uncalled for and is not appropriate in this forum.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Jun 12, 2018 1:00 pm
Reply with quote

Vijay_Sirisha wrote:
Let me explain clearly, because few people asked me to explain clearly.

I have a field in the DB2 table defined as RECORD_COUNT INTEGER, and the corresponding COBOL variable is RECORD-COUNT S9(9) USAGE COMP.

DB2 Variable : RECORD_COUNT INTEGER
COBOL(HOST VARIABLE) : RECORD-COUNT S9(9) USAGE COMP.

When I am inserting any numeric into the table For EX: 45, it is taking as 0000450000.

This simply means that RECORD-COUNT (the host variable) already contains 450000.
I ask again, you have to be precise and explain how you populate RECORD-COUNT (the host variable).
There must be somewhere a MOVE xyz TO RECORD-COUNT. That is what everybody want to know.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Tue Jun 12, 2018 7:14 pm
Reply with quote

Isn't it about time to close this waste of time?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jun 12, 2018 7:15 pm
Reply with quote

Prino, I agree -- topic locked.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top