473,626 Members | 3,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fixed length host variables for VARCHAR fields

I'm just learning about embedded SQL, so be gentle...

My basic question is, if I use a fixed length host variable for a column
defined as VARCHAR, will trailing spaces be removed (or not) upon INSERT or
UPDATE of this column? I tried it, and it appears they are *not* stripped.
However, the Programming Client Applications manual leads me to believe that
the spaces should be stripped. A quote from that manual:

-------------------------
In a CONNECT statement, such as shown below, COBOL character string host
variables dbname and userid will have any trailing blanks removed before
processing:
EXEC SQL CONNECT TO :dbname USER :userid USING :p-word END-EXEC.

However, because blanks can be significant in passwords, the p-word host
variable should be declared as a VARCHAR data item, so that your application
can explicitly indicate the significant password length for the CONNECT
statement as follows:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 dbname PIC X(8).
01 userid PIC X(8).
01 p-word.
49 L PIC S9(4) COMP-5.
49 D PIC X(18).
EXEC SQL END DECLARE SECTION END-EXEC.

PROCEDURE DIVISION.
MOVE "sample" TO dbname.
MOVE "userid" TO userid.
MOVE "password" TO D OF p-word.
MOVE 8 TO L of p-word.
EXEC SQL CONNECT TO :dbname USER :userid USING :p-word END-EXEC.
-------------------------

Now here is some of my actual code:

EXEC SQL BEGIN DECLARE SECTION END-EXEC.

01 ppissue-data.
05 PPISSUE-ACCOUNT-X pic x(10).

05 PPISSUE-SERIAL-NBR PIC S9(09) comp-3.

05 PPISSUE-AMT PIC S9(9)V99 comp-3.

05 PPISSUE-ISSUE-DATE PIC X(26).

05 PPISSUE-PAYEE PIC X(150).

01 ppissue-ind-table.
05 ppissue-ind pic s9(4) comp-5
occurs 5.
EXEC SQL END DECLARE SECTION END-EXEC.

move "this is a test" to ppissue-payee
EXEC SQL UPDATE ICM_POSPAY_ISSU ED_CHECKS
SET PAYEE_NAME = :ppissue-payee
WHERE ACCOUNT_NUMBER = :ppissue-account-x
AND SERIAL_NUMBER = :ppissue-serial-nbr
END-EXEC

Column PAYEE_NAME is VARCHAR(150).

I was hoping that the PAYEE_NAME column for this update would show as a
length of 14, but it appears to have a length of 150. At least,this is what
it appears to me from the following query:

SELECT PAYEE_NAME, LENGTH(PAYEE_NA ME) AS PN_LEN FROM
FJSWARBR.ICM_PO SPAY_ISSUED_CHE CKS WHERE PAYEE_NAME = 'new payee here'

PAYEE_NAME

PN_LEN
----------------------------------------------------------------------------
--------------------------------------------------------------------------
-----------
new payee here

150

If this does not, in fact, strip the trailing spaces, then I have to wonder
why its stressed that the password on a connect should always be a "variable
length" host variable (leading length indicator) instead of a fixed length
one.

Personally, I am not looking forward to a whole bunch of things like the
following:

01 payee-name.
49 L PIC S9(4) COMP-5.
49 D PIC X(150).

move 'this is a test' to D of payee-name
move zero to trailing-spaces
inspect function reverse(D of payee-name) tallying trailing-spaces for
leading spaces
compute L of payee-name = function length(D of payee-name) -
trailing-spaces

Please tell me I'm just missing something obvious! :-)

Frank

---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
Oct 4 '06 #1
2 5603
Its been a while since I've worked with Cobol but I believe you haven't
missed anything. There are, however, other ways to do this that are a
bit easier.

MOVE SPACES TO D OF PAYEE-NAME.
UNSTRING 'This is a test' delimited by ' ' INTO D OF PAYEE-NAME
COUNT IN L OF PAYEE-NAME.

The trick here is to use a delimiter that includes more spaces than any
consecutive group of them that can occur in the source string. Normal
text always uses a single space between words with an occasional data
entry error placing two spaces between words. If the text almost fills
the field, then you may end up with a couple of extra blanks stored in
the table.

Assuming that you have an RTRIM SQL function available, you should be
able to use:
EXEC SQL UPDATE ICM_POSPAY_ISSU ED_CHECKS
SET PAYEE_NAME = RTRIM(:ppissue-payee)
WHERE ACCOUNT_NUMBER = :ppissue-account-x
AND SERIAL_NUMBER = :ppissue-serial-nbr
END-EXEC

Phil Sherman
Frank Swarbrick wrote:
I'm just learning about embedded SQL, so be gentle...

My basic question is, if I use a fixed length host variable for a column
defined as VARCHAR, will trailing spaces be removed (or not) upon INSERT or
UPDATE of this column? I tried it, and it appears they are *not* stripped.
However, the Programming Client Applications manual leads me to believe that
the spaces should be stripped. A quote from that manual:

-------------------------
In a CONNECT statement, such as shown below, COBOL character string host
variables dbname and userid will have any trailing blanks removed before
processing:
EXEC SQL CONNECT TO :dbname USER :userid USING :p-word END-EXEC.

However, because blanks can be significant in passwords, the p-word host
variable should be declared as a VARCHAR data item, so that your application
can explicitly indicate the significant password length for the CONNECT
statement as follows:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 dbname PIC X(8).
01 userid PIC X(8).
01 p-word.
49 L PIC S9(4) COMP-5.
49 D PIC X(18).
EXEC SQL END DECLARE SECTION END-EXEC.

PROCEDURE DIVISION.
MOVE "sample" TO dbname.
MOVE "userid" TO userid.
MOVE "password" TO D OF p-word.
MOVE 8 TO L of p-word.
EXEC SQL CONNECT TO :dbname USER :userid USING :p-word END-EXEC.
-------------------------

Now here is some of my actual code:

EXEC SQL BEGIN DECLARE SECTION END-EXEC.

01 ppissue-data.
05 PPISSUE-ACCOUNT-X pic x(10).

05 PPISSUE-SERIAL-NBR PIC S9(09) comp-3.

05 PPISSUE-AMT PIC S9(9)V99 comp-3.

05 PPISSUE-ISSUE-DATE PIC X(26).

05 PPISSUE-PAYEE PIC X(150).

01 ppissue-ind-table.
05 ppissue-ind pic s9(4) comp-5
occurs 5.
EXEC SQL END DECLARE SECTION END-EXEC.

move "this is a test" to ppissue-payee
EXEC SQL UPDATE ICM_POSPAY_ISSU ED_CHECKS
SET PAYEE_NAME = :ppissue-payee
WHERE ACCOUNT_NUMBER = :ppissue-account-x
AND SERIAL_NUMBER = :ppissue-serial-nbr
END-EXEC

Column PAYEE_NAME is VARCHAR(150).

I was hoping that the PAYEE_NAME column for this update would show as a
length of 14, but it appears to have a length of 150. At least,this is what
it appears to me from the following query:

SELECT PAYEE_NAME, LENGTH(PAYEE_NA ME) AS PN_LEN FROM
FJSWARBR.ICM_PO SPAY_ISSUED_CHE CKS WHERE PAYEE_NAME = 'new payee here'

PAYEE_NAME

PN_LEN
----------------------------------------------------------------------------
--------------------------------------------------------------------------
-----------
new payee here

150

If this does not, in fact, strip the trailing spaces, then I have to wonder
why its stressed that the password on a connect should always be a "variable
length" host variable (leading length indicator) instead of a fixed length
one.

Personally, I am not looking forward to a whole bunch of things like the
following:

01 payee-name.
49 L PIC S9(4) COMP-5.
49 D PIC X(150).

move 'this is a test' to D of payee-name
move zero to trailing-spaces
inspect function reverse(D of payee-name) tallying trailing-spaces for
leading spaces
compute L of payee-name = function length(D of payee-name) -
trailing-spaces

Please tell me I'm just missing something obvious! :-)

Frank

---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
Oct 10 '06 #2
Phil Sherman<ps***** *@ameritech.net 10/10/06 10:03 AM >>>
>Its been a while since I've worked with Cobol but I believe you haven't
missed anything. There are, however, other ways to do this that are a
bit easier.

MOVE SPACES TO D OF PAYEE-NAME.
UNSTRING 'This is a test' delimited by ' ' INTO D OF PAYEE-NAME
COUNT IN L OF PAYEE-NAME.

The trick here is to use a delimiter that includes more spaces than any
consecutive group of them that can occur in the source string. Normal
text always uses a single space between words with an occasional data
entry error placing two spaces between words. If the text almost fills
the field, then you may end up with a couple of extra blanks stored in
the table.
Yeah, I'm not a fan of that one, because of the reasons you mention, among
others.
>Assuming that you have an RTRIM SQL function available, you should be
able to use:
EXEC SQL UPDATE ICM_POSPAY_ISSU ED_CHECKS
SET PAYEE_NAME = RTRIM(:ppissue-payee)
WHERE ACCOUNT_NUMBER = :ppissue-account-x
AND SERIAL_NUMBER = :ppissue-serial-nbr
END-EXEC
Now this is what I'm looking for! Thank you. Very simple, and no screwing
around with COBOL which doesn't really lend itself to such things.

Thanks for the tip!
Frank
---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
Oct 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2926
by: James | last post by:
I am currently working on a PHP based website that needs to be able to draw from Oracle, MS SQL Server, MySQL and given time and demand other RDBMS. I took a lot of time and care creating a flexible and solid wrapper and am deep into coding. The only problem is a noticed VARCHAR fields being drawn from SQL Server 2000 are being truncated to 255 characters. I searched around php.net and found the following : Note to Win32 Users: Due...
26
9670
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " 4". Six spaces than the value of intQuantity. This is correct. But all the others end up being string objects of only 6 characters long (with the exception of strTotal). The left most positions of the string object are being padded with one...
1
2107
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I understand that now and it seems to be fixed but the data I'm pulling from the HTML fields is not being appended correctly do my Access DB....The field in the DB now reads " ' ". I understand why it does that (my function) but what I need it to read is...
2
5986
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
7
2240
by: TinTin | last post by:
Hello, How do I concatinate a variable. Here's the scenarios: declare @var1 varchar(20) declare @var2 varchar(20) declare @var3 varchar(20) declare @var4 varchar(20) .. ..
4
13059
by: Tim.D | last post by:
People, I've ventured into the wonderful world of Stored Procedures. My first experience has been relatively successful however I am stuck on using host variables to specifiy actualy table or column names in a FROM clause. After many hours or reading all manner of manuals I've discovered it appears this is not possible and that in order to so I need to further venture into dynamic SQL. My present procedure is based on all static SQL...
4
1117
by: scorpion53061 | last post by:
This morning I let the group know that I had finished an application that categorizes posts in the vb.net and ado.net newsgroups and eliminates the trash that we hate to wade through on sites like Google and such. Well I would like to thank the multitude of you that have emailed me informing me of the bug in the datagrid (the scrollbars don't show up unless you resize the form after populating the grid). I knew you would be a tough...
5
3112
by: David Garamond | last post by:
The MySQL manual recommends that we create a "fixed-length row" if possible, for speed (especially scanning speed). A fixed-length row is a row which is comprised of only fixed-length fields. A fixed-length field takes a fixed amount of bytes for storage (e.g. INT = 4 bytes, CHAR(M) = M bytes, etc). Is there a similar recommendation in PostgreSQL? I notice that most data types are stored in variable-length mode anyway (is cidr and inet...
5
4354
by: AJA | last post by:
Hello I have problem with reading from XML when XML is to large. Program delare 1-n variables where is declaration but can no make more delarations than length 8000 :(( drop table tblBooksEx CREATE TABLE ( IDENTITY (1, 1) NOT NULL , COLLATE Polish_CI_AS NULL , CONSTRAINT PRIMARY KEY CLUSTERED
0
8268
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8641
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.