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
 

 

Charatcer Handling

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

New User


Joined: 29 Nov 2005
Posts: 66
Location: Bangalore

PostPosted: Fri Oct 23, 2009 5:09 pm    Post subject: Charatcer Handling
Reply with quote

Hi Team

I have a fixed length file size X(80)

01 DEPT.
05 DEPT-NUM PIC 9(10).
05 DEPT-NAME PIC X(70).

data looks like
-----------------------------------------X(80)----------------------------------
0000000001HR
0000000021INFORMATION TECHNOLOGY
0000003333FINANCE
----------------------------------------------------------------------------------

Requirement is to create a variable length file as per below (~ is delimiter)

1~HR
21~INFORMATION TECHNOLOGY
3333~FINANCE


I understand byte by byte comparisons should be done. But what is the simplest way to do this?

Thanks
Nirmal
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7909
Location: Bellevue, IA

PostPosted: Fri Oct 23, 2009 5:18 pm    Post subject:
Reply with quote

I would say the simplest way would be to use the FUNCTION LOG10 of DEPT-NUM to get an integer power of ten, add 1 to it, subtract that total from 11. Use reference modification from that position to 10 to move the DEPT-NUM, move in the delimiter, then find the length of the DEPT-NAME field (using FUNCTION REVERSE and looking for leading spaces) and move those bytes over.

Why not just keep the leading zeroes and trailing spaces and move in a delimiter between the fields -- the easiest way?
Back to top
View user's profile Send private message
nirmal.poikaikumaran

New User


Joined: 29 Nov 2005
Posts: 66
Location: Bangalore

PostPosted: Fri Oct 23, 2009 5:24 pm    Post subject: Reply to: Charatcer Handling
Reply with quote

Hi

I have not used the FUNCTION LOG10 & REVERSE. I did not understand that

The thing is I have an input file of 5 Billion rows. Keeping it that way would require a lot of memory. to eliminate it , is what the requirement.

Can you give me a sample of LOG10 & REVERSE

Thanks
Nirmal
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7909
Location: Bellevue, IA

PostPosted: Fri Oct 23, 2009 5:41 pm    Post subject:
Reply with quote

Files do not have rows -- they have records. Data base tables have rows but not records. Are you sure which you have? 5 billion 80-byte records would be 400 billion bytes, so I am assuming your data is on tape? Any way you do the conversion, it will take a lot of time to run.

Click on the manuals link at the top of the page, find the COBOL Language Reference manual, and read up on the functions there. You will learn much more by doing the reading yourself than you would by having me tell you the information.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 23, 2009 6:05 pm    Post subject:
Reply with quote

Robert,

Looking thru Nirmal's previous posts show a pattern of behavior identical to that of this topic.

He does not want to learn how to do something -
he wants a solution that he can cut&paste for his own.

personally, I thought your trick of log-and-field-length to determine first significant character of a numeric field was slick
- I will add that to my bag of tricks, thx.

As far as Nirmal is concerned,
I imagine either another post/topic here (or another forum)
for a cut&paste solution for his problem.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7909
Location: Bellevue, IA

PostPosted: Fri Oct 23, 2009 6:20 pm    Post subject:
Reply with quote

Quote:
personally, I thought your trick of log-and-field-length to determine first significant character of a numeric field was slick
- I will add that to my bag of tricks, thx.
Thanks, Dick -- I've used it a number of times and as long as the data cooperates ...

I didn't review the other posts (probably should have) -- I don't generally do code unless the person shows independent action first (such as reading the manuals, trying and not succeeding to code).
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 23, 2009 6:26 pm    Post subject:
Reply with quote

and the other possible solution:
modify the process that creates the file - but I imagine that is too obvious.

Nirmal,

Quote:
Hi Team

implies an association with the members of this board - that does not exist

your team are the folks that sit with you in the office
and will not do your work for you.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Oct 23, 2009 7:51 pm    Post subject:
Reply with quote

With "3 billion records" the cost of compacting the data would not be trivial, in addition there is the cost of uncompacting it when you want to use it. If the first field is truly numeric then changing it to packed decimal would cut the size for that field almost by 50%. What are you going to do with this file?
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Oct 25, 2009 1:00 am    Post subject:
Reply with quote

Maybe I'm missing something, but what company on this planet would have 5 billion Deparments? Unless it's a Government project.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Sun Oct 25, 2009 4:10 am    Post subject:
Reply with quote

0002001abc

Considering the record above I'd do the following:
Code:

WORKING-STORAGE SECTION.
77 W-COUNTER, W-START-POSITION, W-LENGTH PIC S9(09) COMP VALUE 0.

PROCEDURE DIVISION.
INSPECT W-NUMBER TALLYING W-COUNTER FOR LEADING '0'
* W-COUNTER = 3
COMPUTE W-START-POSITION = W-COUNTER + 1
* W-START-POSITION = 4
COMPUTE W-LENGTH = LENGTH OF W-NUMBER + W-COUNTER
* W-LENGTH = 4
STRING W-NUMBER(W-COUNTER:W-LENGHT) '$' W-NAME DELIMITED BY SIZE INTO W-NEW-RECORD.
* I hope the result is the desired one.



You can use "add" statement instead of "compute".
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Oct 25, 2009 4:26 am    Post subject:
Reply with quote

Hello,

With that example:

How is w-new-record defined?
How is the variable output file (FD) defined?
How do you tell the WRITE to write only w-length output data?
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Sun Oct 25, 2009 5:20 am    Post subject:
Reply with quote

Code:
FD NEWFILE
    RECORD CONTAINS 3 TO 80 CHARACTERS
    RECORDING V.   
01 MIN-NEW-RECORD   PIC X(3).
01 MAX-NEW-RECORD   PIC X(80).

PROCEDURE DIVISION.

MOVE LOW-VALUE TO MAX-NEW-RECORD.
STRING W-NUMBER(W-COUNTER:W-LENGTH) '$' W-NAME DELIMITED BY SIZE INTO MAX-NEW-RECORD.
WRITE MAX-NEW-RECORD.


I think it may work.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Sun Oct 25, 2009 5:41 am    Post subject:
Reply with quote

STRING W-NUMBER(W-COUNTER:W-LENGTH) '$' W-NAME DELIMITED BY " " (2 BLANKS) INTO MAX-NEW-RECORD.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Oct 25, 2009 2:56 pm    Post subject:
Reply with quote

jctgf,

you have managed to go from 80 char fixed length records to
80 char var length records - which means you are extending the record length
with a vli.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Sun Oct 25, 2009 6:10 pm    Post subject:
Reply with quote

yes, you're right.
my memory leaks.
unfortunately the site allows the poster to correct the message only during the 10 minutes following the posting.
I wonder why.
code looks a little long.
little correction may be needed.
my doubt is about the variable-record format in FD (I'm not at work now).

Code:

FD OLDFILE
    RECORDING F.
01 OLD-REC.
    05 OLD-NUM PIC 9(10).
    05 OLD-NAME PIC X(70).

FD NEWFILE
RECORD IS VARYING FROM 3 TO 80
RECORDING V.
01 NEW-REC.
     03 FILLER PIC X OCCURS 3 TO 80 DEPENDING ON
         WS-NEWFILE-COUNTER.

WORKING-STORAGE SECTION.
77 WS-NEWFILE-COUNTER PIC S9999 COMP VALUE 0.
77 WS-NULL            PIC X(80).
77 WS-COUNTER-1       PIC S9999 COMP VALUE 0.
77 WS-COUNTER-2       PIC S9999 COMP VALUE 0.
77 WS-LENGTH          PIC S9999 COMP VALUE 0.
77 WS-START-POSITION  PIC S9999 COMP VALUE 0.

PROCEDURE DIVISION.


INSPECT OLD-NUM TALLYING WS-COUNTER-1 FOR LEADING '0'.

COMPUTE WS-START-POSITION  = WS-COUNTER-1 + 1.

COMPUTE WS-LENGTH          = LENGTH OF OLD-NUM - WS-COUNTER-1.

UNSTRING OLD-NAME
       DELIMITED BY ALL SPACES INTO WS-NULL
       COUNT IN WS-COUNTER-2.

STRING OLD-NUM(WS-COUNTER-1:WS-LENGTH)
       '$'
       OLD-NAME DELIMITED BY SIZE INTO NEW-REC.

COMPUTE WS-NEWFILE-COUNTER = W-COUNTER-1 + W-COUNTER-2 + 1.

WRITE NEW-REC.

 
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Oct 26, 2009 2:29 am    Post subject:
Reply with quote

Hello,

Quote:
. . .allows the poster to correct the message only during the 10 minutes following the posting.
I wonder why.
To prevent the "changing of history" . . .

On way to reduce/prevent the need to change/correct posted solutions is to actually test them before posting them. If the tested code is posted using copy/paste (and the "Code" tag, there should be no need to later edit. Has the latest code been actually executed? When posting tested code, it is helpful to post the input data used and the output created from that input.

If some correction/change is wanted/needed, post a reply asking for same. We (the moderators) also clean up topics if we see that the discussion has more confusion than clarification.
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 ON ERROR handling soundarr PL/I & Assembler 2 Wed May 11, 2016 3:37 am
No new posts Exception Handling in Native Stored P... Mariraj DB2 1 Thu Feb 25, 2016 4:08 am
No new posts Handling Rexx Abend trushant.w CLIST & REXX 3 Thu Jan 08, 2015 6:42 pm
No new posts Handling a string more than 250 chara... prasadchikane CLIST & REXX 3 Fri Nov 07, 2014 11:12 am
No new posts Handling Variable length files in SAS... mushreyas All Other Mainframe Topics 7 Fri Oct 31, 2014 11:12 am


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