DB2 Varchar Column to Cobol variable

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
mohanswaroopk@gmail.com
Member
Posts: 2
Joined: Tue Sep 18, 2012 3:21 pm

DB2 Varchar Column to Cobol variable

Post by mohanswaroopk@gmail.com » Tue Sep 18, 2012 3:38 pm

Hi ,

I have working storage variable with size 501 with variable length at last.

The below are last variables.

10 WS-PROTOCOL-VER PIC X(1).
10 WS-SERVICE-TYPE PIC X(4).
10 WS-ERR-DESCRIPTION.
15 WS-ERR-DSCR-LENGTH PIC S9(4) COMP.
15 WS-ERR-DSCR PIC X(254).

Now I have added 4 new variables after variable length at last.

10 WS-FTR-DCTVTN-IND PIC X(1).
10 WS-ORD-NBR PIC S9(10).
10 WS-FILENME PIC X(8).
10 WS-FK-PRPY-SIM-ORD PIC X(20).

These variables are used to unload from Table to file. When WS-ERR-DSCR-LENGTH is maximum i.e. 254. The new variables are able to written in file. If the WS-ERR-DSCR-LENGTH is less than 254 the new vraiables are getting truncated.

Is there any rule that variable length fileds should be at end of the working-storage ?

Thanks
Mohan Swaroop

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Sep 18, 2012 5:12 pm

How do you feel that Cobol knows that WS-ERR-DSCR PIC X(254) is variable in length?

It is a very bad idea to put data after variable-length fields in general anyway. It means that you have to look after the contents being what you feel they should be. If you put things before anything which is "variable" the compiler sorts everything out for you.
Last edited by William Collins on Sun Dec 30, 2012 2:32 pm, edited 1 time in total.

chaat
Member
Posts: 20
Joined: Sun Apr 18, 2010 11:51 pm
Location: St. Cloud, Minnesota, USA

Post by chaat » Sun Dec 30, 2012 8:25 am

Mohan,

it is possible to process that data in cobol but you need to use some pretty tricky logic with pointers to accomplish that.

another option is to list the columns in the db2 unload job and put the varchar column at the end so it is the last column on the output file. Then it is much simpler to process in cobol.

Chuck H.
Chuck Haatvedt

email --> clastnameatcharterdotnet

(replace lastname, at, dot with appropriate
characters)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Sun Dec 30, 2012 3:10 pm

No. Even if we go as far as to assume that PIC X(254) is variable, it can be handled in Cobol without needing a POINTER, but the point is, it is stupid to put it like that (data after a variable length) to require extra code, that has to be correct, and easy to understand, when it is all unnecessary if the data is located before the (allegedly) variable part.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others