MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help w/ sort converting VB to FB
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Mon May 08, 2006 9:19 am    Post subject: Need help w/ sort converting VB to FB Reply with quote

I am creating a bunch of files (DB2 Unload with concatenation of fields in order to FTP to a vendor) of various sizes. The vendor can't take the length field, so I'm going to ship them FB, but I need to strip the first two (length) bytes off of every record in every file. Can someone help me figure out how? Thanks, in advance!
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon May 08, 2006 9:25 am    Post subject: Reply with quote

agredell,

Why would a DB2 Unload create a VB file? Unload creates a Fixed block file.

Quote:

The vendor can't take the length field, so I'm going to ship them FB, but I need to strip the first two (length) bytes off of every record in every file. Can someone help me figure out how? Thanks, in advance!


If you are shipping them a FB file with 2 bytes stripped ,aren't you loosing some data?

Show us an example of your input and desired output along with DCB properties

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Mon May 08, 2006 10:44 am    Post subject: Reply with quote

Some of the columns are variable length, here is a snippet of the select
Code:

SELECT                                                         
'"' CONCAT      ACCT_NBR               CONCAT SUBSTR('"|"',1,3)
  CONCAT        ACCT_NM                CONCAT SUBSTR('"|"',1,3)
  CONCAT        CUST_SHIP_TO_NBR       CONCAT SUBSTR('"|"',1,3)
  CONCAT        CUST_SHIP_TO_NM        CONCAT SUBSTR('"|"',1,3)
  CONCAT CASE WHEN CUST_FIRST_INV_DT IS NULL THEN '          '
           ELSE CHAR(CUST_FIRST_INV_DT)                            END                                CONCAT SUBSTR('"|"',1,3)
.
.
.
FROM DBNAME.TBNAME

Some of the output from the above:
Code:

.;"00032584"|"RICHARD CRONKHITE       "|"00032584001"|
057FFFFFFFF747DCCCCDC4CDDDDCCEC4444444747FFFFFFFFFFF74
1EF00032584FFF993819403965289350000000FFF00032584001FF

(Sorry for unaligned font, can't find a place to select a non-proportioned font on the web board!).

Fact is, because I'm creating all of the records the same length, I won't actually be losing anything. The vendor is going to use these files as input to a SQL-Server DTS script. In my limited exposure to DTS, I pity them. And I believe that they may have trouble dealing with the length data. So I suspect that an OUTREC statement will probably work for me, but I don't know what form the operands should take. Thanks for answering!
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Mon May 08, 2006 10:45 am    Post subject: Reply with quote

I should add that I'm using DSNTIAUL, not REORG UNLOAD ONLY.
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon May 08, 2006 11:00 am    Post subject: Reply with quote

agredell,

You are getting the 2 extra bytes because you are not using CHAR function on constants like ", |. change your sql to the following

Code:

SELECT CHAR('"')         CONCAT
       ACCT_NBR          CONCAT
       CHAR('"|"')       CONCAT
       ACCT_NM           CONCAT
       CHAR('"|"')       CONCAT
       CUST_SHIP_TO_NBR  CONCAT
       CHAR('"|"')       CONCAT
       CUST_SHIP_TO_NM   CONCAT
       CHAR('"|"')       CONCAT
       CASE WHEN CUST_FIRST_INV_DT IS NULL THEN CHAR(' ',10)
           ELSE CHAR(CUST_FIRST_INV_DT)
       END               CONCAT
       CHAR('"|"')       CONCAT
...

FROM DBNAME.TBNAME


Now you should not get any variable strings.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Mon May 08, 2006 3:08 pm    Post subject: Reply with quote

Thanks for trying, kolusu, but CHAR didn't work that way. I still got a variable length record, though all of the records are of the same length. I have gotten the results I need through using SORT with an OUTREC parm (I haven't used SORT in over 20 years!). My last challenge is to append an ASCII CR/LF (Carriage Return/Line Feed) character as the end of each line! I see in the OUTREC parm how that is done, but don't know the correct value to use.
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon May 08, 2006 3:15 pm    Post subject: Reply with quote

Quote:

Thanks for trying, kolusu, but CHAR didn't work that way. I still got a variable length record, though all of the records are of the same length.


Do you have anyother Varchar columns in your Select clause? I don't see a need to use another SORT step here.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Mon May 08, 2006 4:43 pm    Post subject: Reply with quote

I must have miscoded a line somewhere. I tried just one column, and it worked like you said; added a second column, it still worked like you said. I will slowly build and test until I find either a specific column that messes it up, or assume that I had performed a "finger check" when coding this stuff.

But I still need to add an ASCII CR/LF at the end. Got any ideas for that?

Thanks a bunch for sticking with this!
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon May 08, 2006 7:00 pm    Post subject: Reply with quote

Quote:

But I still need to add an ASCII CR/LF at the end. Got any ideas for that?


agredell,

Just use CHAR(X'0D0A') on the sql and you are all set as CR is "0D" in hex and the LF is "0A" hex.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Tue May 09, 2006 1:53 pm    Post subject: Reply with quote

Kolusu, here is an update! The problem causing variable length output was occurring anytime a record exceeded 254 bytes. Using commas instead of CONCAT was of some help when I reach that size for a field. I tried using commas instead of CONCAT, but that puts a low-values character between my data fields, which is unacceptable output for the vendor. The CR/LF suggestion you made is putting out the correct code, but there is an additional byte, with low-values, after that, which I can't explain. Wow, I didn't know unload was so rough!!!
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue May 09, 2006 2:12 pm    Post subject: Reply with quote

agredell,

agredcell,

I just don't understand as to why you need CONCAT on all fields. If your intention is to enclose the columns within double quotes and put a seperator after that you can do it without using CONCAT function.

ex: if you db2 table has 2 columns name and website with following data
Code:

Name            website
=====           =========
agredell        www.mvsforums.com


I am guessing that you want to send the data as
Code:

"agredell"|"www.mvsforums.com"|crlf


In that case your Sql should be as simple as this

Code:

SELECT CHAR('"')
      ,NAME
      ,CHAR('"|"')
      ,WEBSITE   
      ,CHAR('"|"')
      ,CHAR(X'0D0A')
  FROM TABLE
 ;


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Tue May 09, 2006 2:22 pm    Post subject: Reply with quote

But when I do that (I have also tried just as you suggest), it comes out more like:
Quote:

"agredell"|".www.mvsforums.com"|.crlf

where the extra periods at the beginning of the field are low values. This can't be in there. It only seems to be happening after I select at least three columns, like this:
Code:

SELECT CHAR('"')
      ,CHAR(PERIOD_KEY)
      ,CHAR('"|"')
      ,CHAR(INV_DT)
      ,CHAR('"|"')
      ,CHAR(PERIOD_CNTRY_NM)
      ,CHAR('"|"')
      ,CHAR(DAY_OF_WK_NBR)
      ,CHAR('"|"')
.
.
.

You are right about the format I am trying to match.
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue May 09, 2006 2:29 pm    Post subject: Reply with quote

Quote:

where the extra periods at the beginning of the field are low values. This can't be in there.


Does any of the column has NULL values ? If it has Null values then use a Case statement to put spaces.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
agredell
Beginner


Joined: 04 May 2006
Posts: 27
Topics: 6

PostPosted: Tue May 09, 2006 2:43 pm    Post subject: Reply with quote

You are very patient with me! All of the fields are nullable, but I have already checked which actually contain null values (this particular table is very stable, it is the time period table for a data warehouse). I use this SQL statement:

Quote:
SELECT
CHAR('"')
, CHAR(PERIOD_KEY) , CHAR('"|"')
, CHAR(INV_DT) , CHAR('"|"')
, CHAR(X'0D0A')
FROM QUALIFIER.TABLE
;

and I get these results (first few rows):
Quote:

"1 "|"2001-01-01."|"..
"2 "|"2001-01-01."|"..
"3 "|"2001-01-01."|"..

Notice that the first parts of the select look perfect; but at the end of the date field (or is it the beginning of the quote/vertical pipe/quote literal?) is a period, which is low values; the last two periods are the CR/LF, working perfectly as you suggested! But the problem with the low values seems to continue as I add more columns (there are plenty more to be selected).

Again, I really, really appreciate your help on this. You are very helpful!
_________________
Alan Gredell
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue May 09, 2006 5:06 pm    Post subject: Reply with quote

Quote:

Notice that the first parts of the select look perfect; but at the end of the date field (or is it the beginning of the quote/vertical pipe/quote literal?) is a period, which is low values; the last two periods are the CR/LF, working perfectly as you suggested! But the problem with the low values seems to continue as I add more columns (there are plenty more to be selected).


agredell,

The reason you are getting an extra low value is because of the column defintion. If you are column is defined as DECIMAL (n 0) ie. a column with zero decimal values then you will see the extra dot. In that case use DIGITS function insead of CHAR function on such columns.
ie.
Code:

 DIGITS(INV_DT)


In case your column is defined with decimals like DECIMAL (N 3) which meams it can have 3 decimals, then use CHAR function to have the explicit decimal dot.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group