View previous topic :: View next topic
|
Author |
Message |
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
Back to my dynamic program.
I've used a cursor to load a COBOL table with the field name, the order number as it will appear on the resulting report, and the name by which it will be called when the report is generated:
Code: |
POL_DETAIL_CODE POL_DETAIL_SEQ_NBR POL_DETAIL_DES
CHAR(25) SMALLINT CHAR(200)
-PKEY5------------------- -PKEY6------------ -----------------
********************************* TOP OF DATA *****************
FIRST_COLUMN_HEAD 1 SKR1_CAPTURE_GOOD
CNTL_TYPE 2 CNTL_TYPE
POL_CORR_MAINCD 3 IT_STORY
POL_CORR_SUBCD 4 MODE_TRNS
POL_CORR_SEQ_NBR 5 CORR#
POL_SYMBOL 6 POL_SYMBOL
POL_NBR 7 POL_NBR |
POL_DETAIL_CODE is the name of the fields that are going to be read for the report detail cursor. The order in which the fields are retrieved have nothing to do with the order in which they appear in the above sample.
What I need to know is: when the cursor retrieves a field value - POL_NBR for example - the 25th column in the cursor, but the 7th in the output - can that field name be used to read the the COBOL table to get the field's order in the output record? My 25 years of experience says no, that only the contents can be used, but I've been wrong more times than I care to admit. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Code: |
SEARCH <TABLENAME>
WHEN POL-DETAIL-DES (<INDEX>) = <CURSOR VARIABLE>
<FIELD-ORDER> = POL-DETAIL-SEQ-NBR (<INDEX>)
|
|
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
so....."<cursor variable>" searches for the field name, not contents?
Like this?
Code: |
SEARCH WS-FIELD-TABLE
WHEN POL-DETAIL-DES (SEARCH-NDX) = PHB03-FIELD-NAME
Do whatever
|
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
so....."<cursor variable>" searches for the field name, not contents? |
Yes, as long as you've loaded the table with the field names. You have to do the work loading the table and every time the field names change you will have to update your load routine. |
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
The table has been loaded with the column headings:
Code: |
01 WS-REPORT-TABLE.
05 WS-REPORT-LAYOUT-DATA OCCURS 200 TIMES
ASCENDING KEY WS-RPT-SEQ-NBR
INDEXED BY WS-RPT-NDX.
10 WS-RPT-SEQ-NBR PIC S9(4) COMP.
10 WS-RPT-FLD-DESC PIC X(25).
|
The cursor fetches many rows - to keep it simple, one of the fields it fetches is PHB03-POLICY_ID, which contains the value 'ABC123456'. I need to use the field name PHB03-POLICY_ID to read the above table for the real column header, so here's my search statement:
Code: |
SEARCH ALL WS-REPORT-LAYOUT-DATA
AT END DISPLAY 'ENTRY NOT FOUND'
WHEN WS-RPT-FLD-DESC (WS-TPR-NDX) = PHB03-POLICY_ID
DISPLAY 'NEW HEADER FOUND'
END-SEARCH |
However, this is only searching for the value 'ABC123456', not PHB03-POLICY-ID. What did I forget? I tried the keyword 'CURSOR', but that just gave me a compile error.
(Yes, I RTFM - which is incredibly short on examples.) |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Do I understand correctly that you’re trying to find a column name instead of the values and asking if that’s possible? |
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
Believe it or not, the boss wants me to get BOTH the value and the column name. I thought it was a joke, but he's serious! |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
You can use DESCRIBE CURSOR and the SQLDA to get column names. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Why don't you create a temp table and load all the values of WS-RPT-FLD-DESC into it and then simply use the inner join to know the matches or LEFT Outer Join to know mismatches and matches instead of complicating the stuff? |
|
Back to top |
|
|
|