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
 
Dynamic SQL with string handling functions in cobol

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

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Wed Jul 02, 2008 10:39 am    Post subject: Dynamic SQL with string handling functions in cobol
Reply with quote

I have to implement a generic dynemic query for my rerquirement in a sub routine like below,I thinks this topic comes under COBOL part in this forum,

STRING WS-DSCMD-ARW020
'SELECT * FROM ARW0.CNTL_TBE’,
' WHERE SEND_RT_NO =? ‘,
‘AND RECV_RT_NO =?’,
‘AND RESEND_IND = ? ‘,
‘AND FILE_RECV_CNT = ?’,
‘AND CREA_DTE = ?’,
‘AND CREA_TME = ?’,
‘AND CASH_LET_BUS_DTE = ?’,
‘AND CASH_LET_ID = ?’,
‘AND BUNDLE_ID = ?’,
‘AND CNTL_REC_IND = ? ’
DELIMITED BY SIZE
INTO WS-DSCMD-ARW020
END-STRING.

EXEC SQL
DECLARE ARW_X9_FH_CURSOR CURSOR FOR DYNSELECT
END-EXEC.

EXEC SQL
PREPARE DYNSELECT FROM :WS-DYNSELECT-ARW020
END-EXEC.

EXEC SQL
OPEN ARW_X9_FH_CURSOR USING :WS-DBL-SEND-ABA
:WS-DBL-FILE-RECV-IND
:WS-DBL-CREATE-DATE
:WS-DBL-CREATE-TIME
:WS-DBL-CREATE-DATE
:WS-DBL-REC-1ST
:WS-DBL-HEADER
END-EXEC.

EXEC SQL
FETCH ARW_X9_FH_CURSOR
INTO: LK-ARWENQ-DATARETURN-AREA.
END-EXEC

EXEC SQL
CLOSE ARW_X9_FH_CURSOR
END-EXEC




but i have data for few fields in the WHERE CLAUSE bcz source pgms call this subroutine and pass the values into WHERE CLAUSE of some fields,not for all all fields.

Here i want to control the data in the where cluse.If the where clause field is having defaut vales(numeric field is zeros and non numeric is specess) then that field should not be appear in the where cluse of query.The where clause should be contain only variables which contain data.

My main concern is,In the above dynemic sql cursor i am passing the data for 7 fields so the where clause also should be 7 fields only.for that how we can skip if the variable contain default values then skip from the where cluse and if the variable contain data then append that variable in to where clause of query.How we can do this logic through string handling functions.
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10326
Location: italy

PostPosted: Sun Jul 06, 2008 2:58 pm    Post subject: Reply to: Dynamic SQL with string handling functions in cobo
Reply with quote

I guess that the forum is the right one...
the issue is not, strictly speaking, db2 related,
it' s rather a generic issue of building a string skipping some substrings on some conditions

the main issue is how to identify the condition for skipping the substring

code snippet ( just the logic, check the syntax, the commas and the apost' s)
I hope that the COBOLESE purists will forgive me
Code:
..... initialize the string
STRING WS-DSCMD-ARW020
'SELECT * FROM ARW0.CNTL_TBE’,
DELIMITED BY SIZE
INTO WS-DSCMD-ARW020
END-STRING.
.... insert the substring depending on some condition
IF  SEND_RT_NO has been passed
    STRING WS-DSCMD-ARW020
    'WHERE SEND_RT_NO ......... '
    DELIMITED BY SIZE
    INTO WS-DSCMD-ARW020
    END-STRING.
end-if
.... repeat for all the parameters
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Jul 06, 2008 6:38 pm    Post subject:
Reply with quote

Hello,

You are basically talking implementing logic rather than a simple/common string statement.

You would not code a single statement string to selectivedly include/exclude pieces. You would either write some code that works from "top down" and appends the needed components or code like Enrico suggests that will allow you to iterate thru the components appending those that are needed for this query execution.
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 line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am

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