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

MOve Hex values from one file to another file.


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

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Mon Apr 04, 2011 2:07 pm
Reply with quote

Hi all,
I have a below requirement.

I am reading a file which is having below layout.

FD FILE1.
01 FILE1-REC.
03 DATA-REC1 PIC 9(10).

after reading from file1 I am writing record to below file

FD FILE2.
01 FILE2-REC.
03 DATA-REC2 PIC 9(10).

In file1, If we are not having any data then 0 is written in file2.
I want to write same Hexadecimals values which are present in file1.
say for example if x'00' is present in file1 same should be written in file2.

Please Help. Thanks In advance.

Regards,
Kapil.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Mon Apr 04, 2011 2:17 pm
Reply with quote

Use PIC X(n) where n is the field length
Back to top
View user's profile Send private message
kapiltamrakar

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Mon Apr 04, 2011 2:25 pm
Reply with quote

Hi Nic,
I cant use alpha numeric clause, the file1 is having the layout which is already given, i cant change the datatype here.

Thanks for your quick suggestion.

Regards,
Kapil.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Apr 04, 2011 2:37 pm
Reply with quote

????

WRITE FILE2-REC FROM FILE1-REC
END-WRITE

By the way, x'00' would be invalid for a PIC 9 field.
Back to top
View user's profile Send private message
kapiltamrakar

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Mon Apr 04, 2011 2:45 pm
Reply with quote

Hi Dick,
For some records in file1 we are not having any data for DATA-REC1, in this case in file2, 0 would be written, that is the problem. I want exactly same records in file 2 which are in file 1. for clerifying this i have given the above hex value example.

Thanks for your attention.

Regards,
Kapil.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon Apr 04, 2011 2:49 pm
Reply with quote

Quote:
In file1, If we are not having any data then 0 is written in file2.
This indicates your code is wrong -- if you don't have any data in file 1, you should not write anything to file 2.

And your explanation of why you cannot change the 9(10) to X(10) is complete and utter rubbish. It's your program and you can describe the data any way you like -- as long as your description is consistent with the actual data. If you're writing file 2's record FROM file 1's record, whether the data is defined as 9 or X makes absolutely no difference to the program.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Apr 04, 2011 4:23 pm
Reply with quote

@kapiltamrakar

>> if you don't have data in file 1, you should not write anything to file 2.

You should not create File-2. One emty Dataset is enougth!
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Mon Apr 04, 2011 4:41 pm
Reply with quote

I think you mean that if you have no data in FILE1 then you need to write an indicator to FILE2. The best way to do this is to write a header and/or trailer record with date and number of records - 0 in this case. Whatever, what you write must be in a format that is acceptable to the program that is going to read FILE2.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Apr 04, 2011 9:07 pm
Reply with quote

kapiltamrakar wrote:
we are not having any data for DATA-REC1, in this case in file2, 0 would be written

kapiltamrakar wrote:
I want exactly same records in file 2 which are in file 1.

1. These 2 sentences are contradictory.
2. You cannot have "no data" in a field. You may have low-values...
3. You could try:
Code:
IF DATA-REC1 IS NUMERIC THEN
    MOVE DATA-REC1 TO DATA-REC2
ELSE
    MOVE 0 TO DATA-REC2
END-IF
WRITE FILE2-REC
END-WRITE
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Wed Apr 06, 2011 10:12 am
Reply with quote

Hi Kapil,

When you say X'00' is present for some records, it does NOT mean that the file1 doesnt have any data. It actually has data i.e. null values... its not numeric though.

As Mr Robert suggested:
Quote:
whether the data is defined as 9 or X makes absolutely no difference to the program



Regards,
Rakesh.
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: Wed Apr 06, 2011 8:51 pm
Reply with quote

Hi Kapil,

I can't understand what you want.

Could you put together some representative values on file1 and then show us how those would be reflected on file2, including anything generated for file2?
Back to top
View user's profile Send private message
kapiltamrakar

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Wed Apr 06, 2011 8:55 pm
Reply with quote

Hi all,
I apologize for late reply,
@Robert Sample:
I agree with you, but the record layout has been in use since last several years and we have to use the same one, other wise there may be inconsistency happen(say for future if any data will come in that field). That was the reason i was not preferring to change the layout.

@ UmeySan
The example which is have shown in the post was just for simplicity of the requirement, in actuals we have this prob in just one field of a 600 byte record. so we have to write the record.

@ Marso
IN this requirement, I wanted to have same data in file 2 which is in file 1 wheather it is Low values or any Numeric values. but if your file 1 is having low values and you are using simple write, the, in file two 0 gets written.

and I have used reference modification, for solving above prob, it is working fine now. I regret if any one of you have faced any inconvenience. Thanks for Your time and Patience.

Regards,
Kapil.
Back to top
View user's profile Send private message
kapiltamrakar

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Wed Apr 06, 2011 9:10 pm
Reply with quote

@ Bill Woodger,
I am posting below code, JCL, Input file,Output file and SYSOUT which may help you.
Code:

FILE SECTION.
FD FILE1.
01 FILE1-REC.
03 DATA-REC1 PIC 9(10).
FD FILE2.
01 FILE2-REC.
03 DATA-REC2 PIC 9(10).

WORKING-STORAGE SECTION.
01 WS-FS1 PIC 9(02).
01 WS-FS2 PIC 9(02).
01 WS-FILE-REC PIC X(80).
01 TEMP-REC1 PIC 9(10).
01 TEMP-REC2 REDEFINES TEMP-REC1 PIC 9(10) COMP.

PROCEDURE DIVISION.

PERFORM 1000-MAIN.
1000-MAIN.
OPEN INPUT FILE1.
OPEN OUTPUT FILE2.
DISPLAY 'BEFORE1'.
DISPLAY 'DATA-REC1', DATA-REC1.
DISPLAY 'DATA-REC2', DATA-REC2.
READ FILE1.
MOVE DATA-REC1 TO DATA-REC2.
DISPLAY 'AFTER'.
DISPLAY 'FILE1-REC', FILE1-REC.
DISPLAY 'FILE2-REC', FILE2-REC.
DISPLAY 'DATA-REC1', DATA-REC1.
DISPLAY 'DATA-REC2', DATA-REC2.
WRITE FILE2-REC.
CLOSE FILE1.
CLOSE FILE2.
STOP RUN.


JCL :

//JOBLIB DD DSN=XXXXXXX.MY.LOAD1,DISP=SHR
//*
//STEP010 EXEC PGM=FILEPGM
//DDF1 DD DSN=XXXXXXX.MY.TEST.INPUT,DISP=(MOD,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=10,BLKSIZE=800)
//DDF2 DD DSN=XXXXXXX.MY.TEST.OUTPUT,DISP=(MOD,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=10,BLKSIZE=800)
//SYSOUT DD SYSOUT=*
/*

INput file
EDIT XXXXXXX.MY.TEST.INPUT Columns 00001 00010
Command ===> Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001
****** **************************** Bottom of Data ****************************

OUTPUT file :

EDIT XXXXXXX.MY.TEST.OUTPUT Columns 00001 00010
Command ===> Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001 0
****** **************************** Bottom of Data ****************************

Sysout:

BEFORE1
DATA-REC1
DATA-REC2 z3
AFTER
FILE1-REC
FILE2-REC 0
DATA-REC1
DATA-REC2 0

I hope it will Help you while understanding the prob.

Regards,
Kapil.
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: Wed Apr 06, 2011 9:36 pm
Reply with quote

Kapil,

You are displaying a field in your input record before reading the first record and displaying a field in your output record before putting anything into it. The values at this time are pretty much rubbish. It doesn't so much matter that they are rubbish, just don't try to expect much before you read a record or put something in your output record.

I don't understand how you get "0" and 9 "something" from this program. 9 "something" then zero would make sense, as you have an unsigned field and you are probably using, knowingly or otherwise, some "sign fixing". Do the displays look exactly like that (the AFTER ones) on the SYSLIST? Or when you put them into the post did it remove a string of blanks?
Back to top
View user's profile Send private message
kapiltamrakar

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Wed Apr 06, 2011 11:32 pm
Reply with quote

Hi Bill,
I didn't do any modification while posting here.

Regards,
Kapil.
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: Wed Apr 06, 2011 11:49 pm
Reply with quote

Hi Kapil,

Interesting. A couple of things. In your JCL you have DISP=(MOD,CATLG,DELETE). You might want to change those. When the step finishes, the system would attempt to catalog the file, which is already in the catalog. If you step fails, both your input and output files will be deleted automatically. You are not MODifying your input file, and probably not MODifying your output either. Have your input file as just SHR or OLD. Your output can be the same, unless you want to delete (IEFBR14 with DISP=(OLD,DELETE,DELETE) it each time and specify it as NEW.

In your little program, you can remove the BEFORE displays. They just don't mean anything. Or put them after the READ if you like.

I find it good to put ">" data-name "<" when DISPLAYing, so you see exactly the position/size in the field.

So like
Code:

DISPLAY 'DATA-REC2>' DATA-REC2 '<'.



Also need to see your "SELECT" statements please.

Regards,

Bill[/code]
Back to top
View user's profile Send private message
kapiltamrakar

New User


Joined: 24 May 2009
Posts: 41
Location: Hyderabad

PostPosted: Thu Apr 07, 2011 1:59 pm
Reply with quote

Hi Bill,
Below is select Statement used in program.

FILE-CONTROL.
SELECT FILE1 ASSIGN TO DDF1
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS WS-FS1.
SELECT FILE2 ASSIGN TO DDF2
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS WS-FS2.

Regards,
Kapil.
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: Thu Apr 07, 2011 2:51 pm
Reply with quote

'morning Kapil,

Can you change the second set of displays in your little program, and add the extra lines please.

Code:

DISPLAY 'AFTER'.
DISPLAY 'FILE1-REC>'  FILE1-REC '<'.
DISPLAY 'FILE2-REC>'  FILE2-REC '<'.
DISPLAY 'DATA-REC1>' DATA-REC1 '<'.
DISPLAY 'DATA-REC2>' DATA-REC2 '<'.

MOVE ZERO TO DATA-REC2.
DISPLAY 'DATA-REC2A>' DATA-REC2 '<'.
MOVE LOW-VALUES TO FILE1-REC.
MOVE DATA-REC1 TO DATA-REC2.
DISPLAY 'DATA-REC2B>' DATA-REC2 '<'.

 


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

Global Moderator


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

PostPosted: Thu Apr 07, 2011 3:07 pm
Reply with quote

Your program is doing exactly and precisely what you told it to do:
1. There's no loop, so you only process one record.
2. Your MOVE DATA-REC1 TO DATA-REC2 takes the 10 bytes of spaces (or LOW-VALUES -- since you did not do a HEXADECIMAL display, we don't know for sure what is in DATA-REC1), moves them to DATA-REC2, then forces the last byte of DATA-REC2 to be unsigned. Forcing the value to be unsigned means the last byte now has a zero (x'F0') instead of space (x'40') or LOW-VALUES (x'00').
3. You should be using file status codes on every file, you should check for end of file before doing the move, and in general your code is very amateurish.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
Search our Forums:

Back to Top