Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Searching a table for the field name?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
socker_dad

Active User


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

PostPosted: Sat Mar 31, 2018 2:57 am    Post subject: Searching a table for the field name?
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: 8410
Location: Dubuque, Iowa, USA

PostPosted: Sat Mar 31, 2018 7:43 pm    Post subject:
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: 158
Location: Seattle, WA

PostPosted: Mon Apr 02, 2018 7:54 pm    Post subject:
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: 8410
Location: Dubuque, Iowa, USA

PostPosted: Mon Apr 02, 2018 8:33 pm    Post subject:
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: 158
Location: Seattle, WA

PostPosted: Wed Apr 04, 2018 3:01 am    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 2064
Location: NY,USA

PostPosted: Wed Apr 04, 2018 8:07 am    Post subject:
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: 158
Location: Seattle, WA

PostPosted: Wed Apr 04, 2018 9:21 am    Post subject:
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: 1303
Location: Israel

PostPosted: Wed Apr 04, 2018 2:02 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 2064
Location: NY,USA

PostPosted: Wed Apr 04, 2018 7:30 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is a table space in db2 for z/os? martin schlatter DB2 13 Sat Nov 24, 2018 11:19 pm
No new posts Modify the value of a extensionvariab... UmeySan CLIST & REXX 29 Wed Nov 14, 2018 11:48 pm
No new posts Replace comp-3 field value to comp-3 ... dharmaraok DFSORT/ICETOOL 5 Fri Sep 14, 2018 3:46 pm
No new posts Extra data in overlay field speermb DFSORT/ICETOOL 2 Thu Sep 13, 2018 6:04 pm
No new posts RPG II Problem with unsigned Packed d... Andi1982 All Other Mainframe Topics 6 Tue Sep 11, 2018 6:11 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us