× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: CPYTOIMPF, CPYTOSTMF - create fixed length records with commafor EOR?
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Mon, 26 Mar 2001 18:00:04 -0600 (CST)



On Sat, 24 Mar 2001 mcrump@sgcontainers.com wrote:

> I have a request to create an ascii file for a customer of ours.  The 
>reqirement
> is for fixed length fields (therefore records) with comma delimeters for 
>(EOR).
> As far as I can tell this runs against the intent of any of the CPY to 
>commands.
> Am I correct here?
> 
> Essentially, the customer is looking for a file to look something like this:
> 
> Record1,Record2,Record3, Record4, Record5, Record6

Are you positive of this?  I don't know of any application that will deal
with data in this format.   I know of thousands that will work with 
comma-delimited FIELDS, however.

Perhaps they want the fields to be fixed-length, but still
comma-delimited??   In this case, the records would still be fixed length,
the fields would still be fixed length -- but the fields would be comma
seperated, and compatable with many different applications.


> So, 1.) am I correct in believing that fixed length and comma delimited are
> almost contrary terms? and 2.) any ideas on how to accomplish this?  Thanks.
> 

The only way that I can think of would be to write a program that does
this manually.   Here's a quick example of doing this in RPG IV.   This
program should be generic enough to work with any database file, though
it doesn't unpack any packed numbers, or interpret date formats.

It also doesn't do much in the way of error trapping & reporting... I'll
leave this to your staff to improve upon.



     H BNDDIR('QC2LE')

     FINPUT     IF   F32766        DISK    USROPN INFDS(dsInput)

     DINPUT_FILE       C                   CONST('LIBSCK/SERIAL')
     DOUTPUT_FILE      C                   CONST('/test/custmas.dat')

     D**********************************************************************
     D*  INFDS for INPUT file so we can find out the record length
     D**********************************************************************
     D dsInput         DS
     D   RecLen              125    126I 0

     D**********************************************************************
     D* Prototype for calling QCMDEXC command interpreter
     D**********************************************************************
     D Cmd             PR                  ExtPgm('QCMDEXC')
     D   Command                    200A   const
     D   Length                      15P 5 const

     D**********************************************************************
     D*  Flags for use in open()
     D*
     D* More than one can be used -- add them together.
     D**********************************************************************
     D*                                            Reading Only
     D O_RDONLY        C                   1
     D*                                            Writing Only
     D O_WRONLY        C                   2
     D*                                            Reading & Writing
     D O_RDWR          C                   4
     D*                                            Create File if not exist
     D O_CREAT         C                   8
     D*                                            Exclusively create
     D O_EXCL          C                   16
     D*                                            Truncate File to 0 bytes
     D O_TRUNC         C                   64
     D*                                            Append to File
     D O_APPEND        C                   256
     D*                                            Convert text by code-page
     D O_CODEPAGE      C                   8388608
     D*                                            Open in text-mode
     D O_TEXTDATA      C                   16777216

     D**********************************************************************
     D*      Mode Flags.
     D*         basically, the mode parm of open(), creat(), chmod(),etc
     D*         uses 9 least significant bits to determine the
     D*         file's mode. (peoples access rights to the file)
     D*
     D*           user:       owner    group    other
     D*           access:     R W X    R W X    R W X
     D*           bit:        8 7 6    5 4 3    2 1 0
     D*
     D* (This is accomplished by adding the flags below to get the mode)
     D**********************************************************************
     D*                                         owner authority
     D S_IRUSR         C                   256
     D S_IWUSR         C                   128
     D S_IXUSR         C                   64
     D S_IRWXU         C                   448
     D*                                         group authority
     D S_IRGRP         C                   32
     D S_IWGRP         C                   16
     D S_IXGRP         C                   8
     D S_IRWXG         C                   56
     D*                                         other people
     D S_IROTH         C                   4
     D S_IWOTH         C                   2
     D S_IXOTH         C                   1
     D S_IRWXO         C                   7

     D*--------------------------------------------------------------------
     D* Open a File
     D*
     D* int open(const char *path, int oflag, . . .);
     D*--------------------------------------------------------------------
     D open            PR            10I 0 ExtProc('open')
     D  filename                       *   value options(*string)
     D  openflags                    10I 0 value
     D  mode                         10U 0 value options(*nopass)
     D  codepage                     10U 0 value options(*nopass)

     D*--------------------------------------------------------------------
     D* Write to a file
     D*
     D* ssize_t write(int fildes, const void *buf, size_t bytes)
     D*--------------------------------------------------------------------
     D write           PR            10I 0 ExtProc('write')
     D  handle                       10I 0 value
     D  buffer                         *   value
     D  bytes                        10U 0 value

     D*--------------------------------------------------------------------
     D* Close a file
     D*
     D* int close(int fildes)
     D*--------------------------------------------------------------------
     D close           PR            10I 0 ExtProc('close')
     D  handle                       10I 0 value

     D*--------------------------------------------------------------------
     D* get the last error number
     D*--------------------------------------------------------------------
     D geterrno        PR              *   extproc('__errno')
     D p_errno         S               *
     D errno           S             10I 0 based(p_errno)

     D*--------------------------------------------------------------------
     D*  return the error message corresponding to an errno
     D*--------------------------------------------------------------------
     D strerror        PR              *   extproc('strerror')
     D   peErrNo                     10I 0 value

     D sf              S             10I 0 inz(-1)
     D FirstWrite      S              1N   inz(*On)
     D Comma           S              1A   INZ(',')

     IINPUT     NS
     i                                  132766  RECORD

     c                   eval      *inlr = *on

     C**********************************************************************
     C* Open up our database file, now:
     C**********************************************************************
     c                   callp(e)  Cmd('OVRDBF FILE(INPUT) TOFILE(' +
     c                                 %trim(INPUT_FILE) +')': 200)
     c                   if        %error
     c*         (we should really signal an error message here)
     c                   return
     c                   endif

     c                   open(e)   INPUT
     c                   if        %error
     c*         (we should really signal an error message here)
     c                   return
     c                   endif

     C**********************************************************************
     C* Create a new file in IFS.  Assign it codepage 437 (DOS ASCII)
     C*   then re-open it in our current codepage so data is
     C*   automatically translated to codepage 437.
     C**********************************************************************
     c                   eval      sf = open(OUTPUT_FILE:
     c                                  O_CREAT+O_TRUNC+O_WRONLY+O_CODEPAGE:
     c                                  S_IRWXU+S_IRWXG+S_IRWXO:
     c                                  437)
     c                   if        sf < 0
     c*         (we should really signal an error message here)
     c                   return
     c                   endif
     c                   callp     close(sf)

     c                   eval      sf = open(OUTPUT_FILE:
     c                                       O_WRONLY+O_TEXTDATA)
     c                   if        sf < 0
     c*         (we should really signal an error message here)
     c                   return
     c                   endif

     C**********************************************************************
     C* Read full records from our database, and slug them into the
     C* stream file, with a comma between each record...
     C**********************************************************************
     c                   eval      FirstWrite = *On
     c                   read      INPUT

     c                   dow       not %eof(INPUT)

     c                   if        FirstWrite
     c                   eval      FirstWrite = *Off
     c                   else
     c                   callp     write(sf: %addr(Comma): %size(Comma))
     c                   endif

     c                   if        write(sf: %addr(record): RecLen) < RecLen
     c*         (we should really signal an error message here)
     c                   eval      p_errno = geterrno
     c                   eval      Msg = %str(strerror(errno))
     c                   dsply                   Msg              52
     c                   leave
     c                   endif

     c                   read      INPUT
     c                   enddo

     C**********************************************************************
     C* Close the files and end the program:
     C**********************************************************************
     c                   callp     close(sf)
     c                   close     INPUT
     c                   callp(e)  Cmd('DLTOVR FILE(INPUT)': 200)

     c                   return

+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.