Tom - this looks like it will get me going!
(I was looking at 'Reference Modification' in the meantime, but it appears
to me the length operand cannot be a variable).
move SQL-STATEMENT-TEXT OF QZDA-SQL-FORMAT2 (1:SQL-STATEMENT-TEXT-LEN)
Sent by: cobol400-l@xxxxxxxxxxxx
Re: [COBOL400-L] reference to
06/09/2009 04:34 variable fields in IBM copybooks
Please respond to
Scott Lindstrom wrote:
First - I reference these fields:
LIB-NAME OF QZDA-NDB-FORMAT2 (1)
LIB-NAME OF QZDA-NDB-FORMAT2 (2)
LIB-NAME OF QZDA-NDB-FORMAT2 (3)
LIB-NAME OF QZDA-NDB-FORMAT2 (4)
LIB-NAME OF QZDA-NDB-FORMAT2 (5)
This used to work but the copybook now is defined as:
05 NBR-OF-LIBRARIES PIC S9(00009) BINARY.
* Number of libraries in list
* 05 LIB-NAME PIC X(00010)
* OCCURS xxxxx TIMES.
* Varying number
* of library names
with LIB-NAME commented out. How can I readily access the first 'x'
of occurrences of LIB-NAME (up to 5 of them) so I can move these fields
the logfile record.
This response needs to be short and quick, so I'll give the most
basic answer that I know.
1. Create a simple 77- or 01-level My-Ptr POINTER data item in the
2. Create a simple 01-level LIB-NAME pic X(10) item in the LINKAGE
3. SET My-Ptr TO ADDRESS OF NBR-OF-LIBRARIES
4. SET My-Ptr UP BY LENGTH OF NBR-OF-LIBRARIES
At that moment, My-Ptr should be pointing to the first byte of
whatever comes after NBR-OF-LIBRARIES.
5. SET ADDRESS OF LIB-NAME TO My-Ptr
At that moment, when you now reference LIB-NAME, you get the 10
bytes that follow NBR-OF-LIBRARIES in memory.
5. SET My-Ptr UP BY LENGTH OF LIB-NAME
6. SET ADDRESS OF LIB-NAME TO My-Ptr
You moved the pointer value 10 bytes further into memory; then you
applied that new address to the Linkage definition. At that moment,
when you now reference LIB-NAME, you get the 10 bytes that follow
the previous LIB-NAME in memory.
Each time you increment the pointer by the length of the field and
reassociate the new address, the definition moves forward. The
incrementing will naturally be in a loop controlled by
NBR-OF-LIBRARIES -- you can set the pointer beyond the memory
described by NBR-OF-LIBRARIES, but you don't actually want to use
any value of LIB-NAME from that address.
For the SQL-STATEMENT-TEXT, it's essentially the same. Make sure
it's defined as varying length so that the LENGTH OF fits each new
statement. (I can't recall if you need to add the 2-byte length or
if it's handled.)
Hope that gets you going.
The PowerTech Group, Inc.
19426 68th Avenue South
Kent, WA 98032
Phone 253-872-7788 x313
This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing
To post a message email: COBOL400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: COBOL400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
As an Amazon Associate we earn from qualifying purchases.