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

Searching a table for the field name?


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

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Sat Mar 31, 2018 2:57 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Sat Mar 31, 2018 7:43 pm
Reply with quote

Code:
SEARCH <TABLENAME>
WHEN POL-DETAIL-DES (<INDEX>) = <CURSOR VARIABLE>
    <FIELD-ORDER> = POL-DETAIL-SEQ-NBR (<INDEX>)
Back to top
View user's profile Send private message
socker_dad

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Mon Apr 02, 2018 7:54 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon Apr 02, 2018 8:33 pm
Reply with quote

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
View user's profile Send private message
socker_dad

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Wed Apr 04, 2018 3:01 am
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 04, 2018 8:07 am
Reply with quote

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
View user's profile Send private message
socker_dad

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Wed Apr 04, 2018 9:21 am
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Apr 04, 2018 2:02 pm
Reply with quote

You can use DESCRIBE CURSOR and the SQLDA to get column names.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Apr 04, 2018 7:30 pm
Reply with quote

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
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top