[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

RE: [sqr-users] on-break and multi-line printing



As for my experience goes, using sqr native on-break can be very tricky and
time consuming. For simple requirements, the effort may be minimal but in
general it puts programmers into situations where he starts compromising on
his real requirements.

The option is to code your own break logic or use EDS (Event Driven SQRs).
If you code your own break logic, later on maintenance can be time consuming
and frustrating too.

It took me only 30 minutes the achieve your functionality using EDS and the
code is:

Program reads your data from file: demo07.csv which contains:

name,sex,group
Dopey,M,1
Dopey,M,2
Dopey,M,3
Dopey,F,1
Dopey,F,2
Dopey,F,3
Lazy,M,1
Lazy,M,2
Lazy,M,3
Lazy,F,1
Lazy,F,2
Lazy,F,3
Silly,M,1
Silly,M,2
Silly,M,3
Silly,F,1
Silly,F,2
Silly,F,3

Code begin =======================

#include 'sqrp-eds.sqc'         !include eds standard procedures

#define FILE_FD     1
#define REC_LEN     1024

begin-procedure Report

    let $SqrPlus_dir = getenv('SQRPLUS_DIR')
    let $InpFile = $SqrPlus_dir || '\sqr\demo07.csv'
    open $InpFile as {FILE_FD}  for-reading record={REC_LEN}:vary
status=#filestat
    if #filestat != 0
        let $errmsg = 'Unable to Open Input File: ' || $InpFile || ',
Program aborted.'
        show $errmsg
        stop
    else
        show 'Input File: ' $InpFile
    end-if

    !Initialise EDS system for 'main' data input stream.
    do SRIT-EDS-begin-main (
            'key1=name, key2=sex',
            'my-main-detail-section',
            '',
            '',
            '')

    let #SRIT_EDS_main_no_lf = {SRIT_EDS_TRUE}   !required as first $group
does not advance line

    let #rec_cnt = 0
    while  1    ! Infinite loop, breaks when end of file is detected.

        read  {FILE_FD}  into  $rec:{REC_LEN}
        if #end-file
            break   ! End of file reached.
        end-if

        add 1 to #rec_cnt

        do SQRP-EDS-Get-Fld-By-Num ($rec, ',', 1, $name)
        do SQRP-EDS-Get-Fld-By-Num ($rec, ',', 2, $sex)
        do SQRP-EDS-Get-Fld-By-Num ($rec, ',', 3, $group)

        if #rec_cnt > 1     !ignore header record

            !submit record to EDS system
            do SRIT-EDS-process-main (
                        $name,  !first key field
                        $sex,       !second key field
                                $group, !detail line
                        $effdt)     !effdate from input stream, not
applicable in your case.

            !save/compute fields that are required in printing detail
section
            let $group_detail = $group

        end-if

    end-while

    close {FILE_FD}

    do SRIT-EDS-end-main (#no_data)   !indicate end of main input stream to
EDS system.

    if #no_data = {SRIT_EDS_TRUE}
        do SRIT-EDS-new-line (1)
        print 'No Data found to print' (,1)
    else
        do End-of-report
    end-if

end-procedure

begin-procedure main-before-name ($name, $effdt)

    if  #_SRIT_EDS_main_first_detail    = {SRIT_EDS_FALSE}
        do SRIT-EDS-new-line (1)   !blank line required before name but not 
first
time
    end-if

    do SRIT-EDS-new-line (3)    !advance to next line before printing name. If
current page
                                        !can't accommodate 3 lines, advance to 
new page.
    print $name (, 1, )

end-procedure

begin-procedure main-before-sex ($name, $sex, $effdt)

    do SRIT-EDS-new-line (2)
    print $sex (, 5, )
    let #_new_sex = {SRIT_EDS_TRUE}  !set flag, used when printing $group

end-procedure

begin-procedure my-main-detail-section

    if #new_sex = {SRIT_EDS_FALSE}
        do SRIT-EDS-new-line (1)   !advance to next line but not first time
    end-if
    print  $group_detail  (, 7, )
    let #new_sex = {SRIT_EDS_FALSE}

end-procedure

Code end =======================

The important thing is that you only code for the events as dictated by
requirements. EDS system calls these event procedure as required.

BTW: EDS is part of SqrPlus software available at www.sritech.biz

If you often produce sqr programs that require on-break logic, I suggest EDS
can be very time saving and productive methodology/tool.

Gopal.

-----Original Message-----
From: sqr-users-bounces+gkrishan=bigpond.net.au@sqrug.org
[mailto:sqr-users-bounces+gkrishan=bigpond.net.au@sqrug.org]On Behalf Of
David Donnelly
Sent: Friday, January 27, 2006 12:37 PM
To: sqr-users@sqrug.org
Subject: [sqr-users] on-break and multi-line printing


Apologies in advance for the length of this post.

I have been programming SQR a very long time, but I have never gotten the
following to work.  I always end up doing my own on-break logic to get what
I want.  Seems silly to have to do that;  someone here must have done it
right by now.

Consider the following data, which arrives in the order (observation, sex
desc, group) shown:

Observation     Sex     Group
=========================
Dopey           M       1
Dopey           M       2
Dopey           M       3
Dopey           F       1
Dopey           F       2
Dopey           F       3
Lazy            M       1
Lazy            M       2
Lazy            M       3
Lazy            F       1
Lazy            F       2
Lazy            F       3
Silly           M       1
Silly           M       2
Silly           M       3
Silly           F       1
Silly           F       2
Silly           F       3

I want to print like this:

Dopey
    M   1
        2
        3
    F   1
        2
        3

Lazy
     M  1
        2
        3
     F  1
        2
        3

Silly
    M   1
        2
        3
    F   1
        2
        3

That is, I want to skip a line when Observation changes, and then print the
Observation on a line by itself. Then I want to print each sex-group
combination on a line, but print the value of sex only when it changes or
at top-of-page.  Of course I want to print Observation again at top-of-page
if that happens in the middle of an Observation.

The closest I've gotten is this:

observation     (+1,1)  on-break print=change/top-page skiplines=1 level=1
sex             (+1,3)    on-break print=change/top-page level=2
group           (,14)

This is almost right, except that it skips a line after every sex-group
line; apparently the "+1" spacing command is interpreted whether or not the
value of sex is printed.  So I tried

observation     (+1,1)  on-break print=change/top-page skiplines=1 level=1
sex             (,3)    on-break print=change/top-page skiplines=1 level=2
groupnumber     (,14)

that is, taking out the +1 and adding skiplines.  This got rid of the blank
line between sex-group lines, all right, but the first one doesn't skip, so
it prints right on top of the observation line.

A further slight complication is that you don't want Observation to print
as the last line on the page, with the first sex-group on the next.

Can anyone offer a solution?  PLEASE, PLEASE don't dream something up and
say "try this." Believe me, I have tried everything I can think of,
including next-listing with and without need= and no-advance. It's like
squeezing Jello -- something always spurts out somewhere else.  But if you
have solved this problem -- "always skip a line, but print only on changes"
-- please tell me how.

Thanks to all for reading.

Dave





_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users


_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users