IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Formatting for Excel data


IBM Mainframe Forums -> FAQ & Basics
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jun 25, 2007 10:08 pm
Reply with quote

Write an Excel macro to output the data exactly as you want in on the mainframe. I know it is VB, but you get way more control over your output format than you do when using the standard Excel exports.

The following will loop through the data and put it out in the following format:

A1|B1|C1|D1
A2|B2|C2|D2
etc...

Code:

Sub WriteDataToFile()

    Dim outfile As String
    Dim RowCounter, ColCounter As Integer
    Dim ColumnSeperator As String
    Dim outline As String
   
    ColumnSeperator = "|"
   
    outfile = "C:\outputfile.txt"
    outline = ""
'    Set fs = CreateObject("Scripting.FileSystemObject")
   
    Open outfile For Output As #1
   
    For RowCounter = 1 To ActiveCell.SpecialCells(xlCellTypeLastCell).Row
        For ColCounter = 1 To ActiveCell.SpecialCells(xlCellTypeLastCell).Column
                outline = outline & CStr(Cells(RowCounter, ColCounter).Value) & ColumnSeperator
        Next ColCounter
        outline = Left(outline, Len(outline) - 1)
        Print #1, outline
        outline = ""
    Next RowCounter
   
    Close #1
   
End Sub
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jun 25, 2007 10:09 pm
Reply with quote

Disregard this line:
' Set fs = CreateObject("Scripting.FileSystemObject")

It is left over from my testing.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Jun 25, 2007 11:40 pm
Reply with quote

Hello,

Yes, many of these things might be done - but if it were my requirement i would manipulate the data in my own mainframe code. When/if the requirement changes, i'd only have one place to modify.

As this is something that will happen repeatedly, i would surely not recommend a solution that required manual work each time at either end. The more things done manually, the longer it takes and the greater the chance of error.

Sounds like *.prn won't be much help due to the length restriction - i suppose that limit is because the intent of the .prn is a print file?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Jun 26, 2007 3:24 am
Reply with quote

You can't read the contents of an Excel file (stupid proprietary stuff) on the mainframe so the process will always require some kind of manual intervention, whether it is a Save As... or something else.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue Jun 26, 2007 5:59 pm
Reply with quote

You can knock "proprietary stuff" all you want, and I'm certainly in favor of standards and cooperation, but without proprietary stuff, we'd be living in either the stone age or a communist society, assuming they're different.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Jun 26, 2007 6:21 pm
Reply with quote

Hello,

I'm with Phil - proprietary is not a 4-letter word.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Jun 26, 2007 6:32 pm
Reply with quote

Proprietary formats have advanced us significantly. But they have brought us to the point we are today, lack of interoperation and manual conversions to use the data on our system of choice.


...You make communisim sound like a bad thing.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue Jun 26, 2007 7:16 pm
Reply with quote

Not hard to do.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Jun 26, 2007 9:01 pm
Reply with quote

Anyway back to the point at hand.

The code I presented was robust enough that it will handle anywhere from a 1x1 spreadsheet to the maximum available size in Excel. It will pipe delimit the columns and put each row out to its own line in a text file. Once it gets down to the mainframe you could unstring it using |. I think this is way better than the comma because like the OP said, there are commas in his actual data. Pipes are far less likely to occur in the data being received in the Excel file.

Another alternate is to export the data from Excel as XML document and then parse that with Cobol.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> FAQ & Basics Goto page Previous  1, 2

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
Search our Forums:

Back to Top