COBOL - Move to variables with same name (solved) - cobol

My Cobol structure:
01. MyData.
02. Corp-Entity
03. Corp-Branch1.
04. Address.
05. AddressLine1 PIC X(20).
05. AddressLine2 PIC X(20).
05. PostalCode PIC 9(05).
02. PIC-Entity.
03. Address.
04. AddressLine1 PIC X(20).
04. AddressLine2 PIC X(20).
04. PostalCode PIC 9(05).
I have the data to move in Address of Corp-Entity and another data to move in Address of PIC-Entity
But when I try to move the value
move valueAddressLine1 to AddressLine1
of Address
of PIC-Entity
Error Message :
"AddressLine1 of Address of PIC-Entity" was not a uniquely defined name.
The definition to be used could not be determined from the context. The reference to the name was discarded.
How to move 'valueAddressLine1' to AddressLine1 of Address of PIC-Entity?

You can change it to:
move valueAddressLine1 to AddressLine1
in Address
in PIC-Entity
in MyData
most likely you have PIC-Entity that has same structure somewhere else outside MyData definition.

Related

How to replace some letters in a copybook

Looking to replace the beginning letters of this copybook from "O-" to "IT-". Would anyone know how to do this.
FD INPUT-TRANSACTION-FILE
RECORDING MODE IS F.
01 ITRANS-RECORD.
05 O-ACCOUNT-ID PIC X(6).
05 O-FIRST-NAME PIC X(15).
05 O-SURNAME PIC X(20).
05 O-SALARY PIC 9(6)V99.
05 O-TEMP REDEFINES O-SALARY PIC X(7).
When I call the copybook in my program I want to replace the "O" to "IT". I believe you can use REPLACING but I cannot seem to get it to work
It depends on the compiler in use (which you did not specify) but "in COBOL" you have a LEADING phrase for the REPLACING clause:
COPY FDITF REPLACING LEADING ==O-== BY ==IT-==.
It seems like you are building the copy inside your program.
In that case, you can call them whatever you like, so just change them from 'O' to 'IT' manually.
If the copy (say we call it 'ITRANS') is outside the program,
you need to add to the copy a colon (:) before and after the letters to change:
FD INPUT-TRANSACTION-FILE
RECORDING MODE IS F.
01 ITRANS-RECORD.
COPY 'ITRANS' REPLACING ==:O:== BY ==IT==.
Where the file copy 'ITRANS' is in the copy library.
05 :O:-ACCOUNT-ID PIC X(6).
05 :O:-FIRST-NAME PIC X(15).
05 :O:-SURNAME PIC X(20).
05 :O:-SALARY PIC 9(6)V99.
05 :O:-TEMP REDEFINES :O:-SALARY PIC X(7).
IBM DOC - COPY statement

COBOL : Move PIC X TO PIC S9.99 COMP-3

How I can move data from example :
I-DATA PIC X7 VALUE ' 12.34'.
to
O-DATA PIC S9(13)V99 COMP-3.
05 I-DATA PIC X(7).
05 I-NUMERIC REDEFINES I-DATA PIC 9999.99.
.
.
MOVE I-NUMERIC TO O-DATA.
You need to redefine you AlphaNumerc as a Display Numeric which can then be moved to the packed decimal variable. Be careful as this will bomb out with an OC7 if there is anything other than numbers or spaces plus the '.' in the data.
Your pic clause for i-data is bad (it should be PIC X(7)).
Anyway to answer your question, use MOVE ... TO ... WITH CONVERSION ON EXCEPTION ... END-MOVE
05 I-DATA PIC X(7).
05 O-DATA PIC S9(13)V99 COMP-3.
05 HAD-ERROR-FLAG PIC X.
88 HAD-ERROR VALUE "Y" FALSE "N".
...
MOVE I-DATA TO O-DATA WITH CONVERSION
ON EXCEPTION
MOVE ZERO TO O-DATA
SET HAD-ERROR TO TRUE
NOT ON EXCEPTION
SET HAD-ERROR TO FALSE
END-MOVE

Cobol: Is there a way to output the names of Copybook-fields as headers

We are about to convert datasets on a Mainframe to CSV format. The data fields are stored in copybooks, I would like to know if it's possible to output the names of the fields (not the values) one after the other for a header. it would be good if there was an automated Solution, because there are about 100 tables with 15< fields. For example:
01 TABLE1.
05 FIELDA PIC X(1) .
05 FIELDB PIC X(7) .
05 FIELDC PIC X(6) .
05 FIELDD PIC X(4) .
05 FIELDE PIC X(4) .
05 FIELDF PIC X(2) .
What i want to have now is like:
FIELDA;FIELDB;FIELDC;FIELDD;FIELDE;FIELDF
It would be great if the Solution would be written in COBOL :)

Splitting digits from a packed-decimal field

I have a 7-digit packed-decimal field on my file. How can I define data items that would extract/separate these 7 digits?
For example I want to have the first two digits in one data item and the other digits in another, so I can manipulate them later.
In some other languages one of the things which may be common would be to "divide by a multiple of 10", an appropriate multiple, of course.
However, don't ever consider that with COBOL. A "divide" is "expensive".
05 input-packed-decimal
PACKED-DECIMAL PIC 9(7).
Then:
05 FILLER
REDEFINES input-packed-decimal.
10 ipd-split-two-and-five
PACKED-DECIMAL PIC 99V9(5).
01 two-digits PIC 99.
01 five-digits PIC 9(5).
01 FILLER
REDEFINES five-digits.
05 five-digits-as-decimals PIC V9(5).
MOVE ipd-split-two-and-five TO two-digits
five-digits-as-decimals
Then you are able to use two-digits and five-digits for whatever you want.
Another way:
01 ws-input-seven PIC 9(7).
01 FILLER
REDEFINES ws-input-seven.
05 two-digits PIC 99.
05 five-digits PIC 9(5).
MOVE input-packed-decimal TO ws-input-seven
The first way will also work for signed source fields (just put an S in the appropriate place in each PICture clause).
The second will not work with signed fields, because the source sign will no propagate to the two-digits field because the MOVE is not even aware that there is such a field.
Take care when REDEFINESing PACKED-DECIMAL or BINARY fields (on an IBM Mainframe, these can also have USAGE COMP-3 and COMP/COMP-4/COMP-5). Always, when defining with the same, or similar, USAGE, define the same number of digits. For a REDEFINES field the compiler will always assume that you know what you are doing, so it will not do any "truncation of source" for you. So you have to ensure that you are not, explicitly or implicitly, expecting truncation of source when you use fields subordinate to a REDEFINES.
To get the second digit, don't ever do this:
05 FILLER
REDEFINES input-packed-decimal.
10 ignore-one-use-2nd-next-five
PACKED-DECIMAL PIC 9V9(5).
To get the second digit, use PACKED-DECIMAL PIC 99V9(5) as before, but define the receiving field with only one digit position. The compiler will happily then generate code to do the truncation you expect.
If you are "unable to use REDEFINES" you'll have to create a new field in the WORKING-STORAGE with the same characteristics as your input field, and use that.
The data-names I've used here are solely for this general explanation. Use good, descriptive, names to your task. If the first two digits are part-type, and the last five are part-number, make sure that is clear fro your naming.
Don't name them "Var(n)" or similar and don't give them names which are misleading.
01 the-array.
03 filler pic x(02) value '00'.
03 filler pic x(02) value '01'.
03 filler pic x(02) value '02'.
and so on, until
03 filler pic x(02) value 'FF'.
01 two-array redefines the-array.
03 harry occurs 256 pic x(02).
91 sub1.
03 filler pic x(01) value low-values.
93 sub1-byte2 pic x(01).
01 sub2 redefines sub1 comp.
01 pd pic x(04).
01 pub pic 9(04).
01 eggs.
03 eggs1 pic x(01).
03 eggs2 pic x(01).
perform varying pub
from 1 by 1
until pub > 4
move pd(pub:1) to sub1-byte2
move harry(sub2 + 1) to eggs
display eggs1 egg2
end-perform.
So an array of 256 2 byte fields with values of '00' thru 'FF'.
step thru the 4 byte field that holds your packed decimal field.
use each byte as a subscript into the array (add 1 to ensure '00' points to first field in array).
2 byte field pointed to has the values of the 2 nibbles that represent that byte from the packed decimal field.
the right hand nibble of the fourth byte in the packed decimal field is for the sign.

How do I move a PIC X field to a PIC S9 COMP-3 field in COBOL?

My situation is as follows.
I'm reading input from a file into the following working storage field:
WORKING-STORAGE SECTION.
01 WORK-FIELDS.
05 W1-INPUT.
10 TESTCASE-NUMBER PIC X(02).
10 PIC X(01).
10 TESTCASE-ID PIC X(18).
10 PIC X(01).
10 TESTCASE-CONTENT PIC X(20).
Depending on what the TESTCASE-ID contains, I have to eventually move the content of the TESTCASE-CONTENT field into either the AMOUNT-DECIMAL-FORMAT or the AMOUNT-DECIMAL-NUMBER field in the following copybook:
05 (*)AMOUNT.
10 AMOUNT-DECIMAL-FORMAT PIC S9(18) COMP-3.
10 AMOUNT-DECIMAL-NUMBER PIC S9(01) COMP-3.
10 AMOUNT-IN-XML-FORMAT PIC N(20).
I then have to do a call to another program which will process these parameters and fill the AMOUNT-IN-XML-FORMAT field.
Anyway, so my question is: What's the best way to move the content of my PIC X field into my S9 COMP-3 field?
Thanks in advance for your time!

Resources