#TEMPLATE (ABCRptDes, 'Report Designer template - ABC'),FAMILY('ABC')
#!
#!*******************************************************************
#!ABRptDes.TPL (C4-ABC) Copyright (c) Allerup EDB 1998-99 (20/1-99)
#! Allerup Report Designer version 2.0
#!*******************************************************************
#!
#HELP('ARDSetup.HLP')
#!
#!===================================================================
#EXTENSION(PrintRptDesReport,'Report Designer print'), PROCEDURE, HLP('ReportDesignerPrint'), LAST
#!-------------------------------------------------------------------
#SHEET
  #TAB('Report setup')
    #BOXED ('Report Designer print')
      #PROMPT ('Report type:', @S32),%RptDesType,REQ
      #PROMPT ('Msg: Report type not found', @S64), %RptDesTypeMessage,DEFAULT('Report type not found')
#! modified by DDS
  #PROMPT ('Layout selection:',DROP('Default|Select|Specific|Current')),%RptSelection,REQ,DEFAULT('Current')
  #PROMPT ('Select procedure:',PROCEDURE),%RptDesSelectProc,REQ,DEFAULT('SelectDesign')
  #ENABLE(%RptSelection='Specific')
    #PROMPT ('Layout name:', @S32),%RptDesLayout,REQ
  #DISPLAY('(Use ! to indicate a variable name)')
  #ENDENABLE
#! end modify
      #PROMPT ('Msg: Layout not found', @S64), %RptDesLayoutMessage,DEFAULT('Layout not found/selected')
      #DISPLAY('')
      #PROMPT ('Destroy all report controls before printing?',CHECK), %RptDesRemoveControls, DEFAULT(%True),At(10)
      #DISPLAY('')
      #BUTTON ('Details and number'), FROM(%ReportControl,%ReportControl & ': ' & %RptDesBandNo),WHERE((UPPER(%ReportControlType)='DETAIL' OR ((UPPER(%ReportControlType)='HEADER' OR UPPER(%ReportControlType)='FOOTER') AND %ReportControlIndent <> 0)) And %ReportControl)
        #PROMPT ('Designer band number:', @S2),%RptDesBandNo
      #ENDBUTTON
      #PREPARE
        #FOR (%ReportControl)
          #IF (%ReportControlType='FORM')
            #CYCLE
          #ELSIF (%ReportControlType='HEADER')
            #CYCLE
          #ELSIF (%ReportControlType='FOOTER')
            #CYCLE
          #ELSIF (%ReportControlType='BREAK')
            #CYCLE
          #ENDIF
          #IF (%ReportControlUse)
            #FIND (%FieldOnReport, %ReportControlUse)
            #IF (%FieldOnReport <> %ReportControlUse)
              #ADD (%FieldsOnReport, ITEMS (%FieldsOnReport) + 1)
              #SET (%FieldOnReport, %ReportControlUse)
              #CASE (%ReportControlType)
              #OF('CHECK')
                #SET(%FieldOnReportType, 'Checkbox')
              #OF('TEXT')
                #SET(%FieldOnReportType, 'Text')
              #ELSE
                #SET(%FieldOnReportType, 'Field')
              #ENDCASE
            #ENDIF
          #ENDIF
        #ENDFOR
      #ENDPREPARE
      #BUTTON ('Fields on report'), MULTI(%FieldsOnReport, %FieldOnReport)
        #PROMPT ('Report field:', FIELD), %FieldOnReport, REQ
        #PROMPT ('Control type:', DROP('Field|Checkbox|Text|Image')), %FieldOnReportType, REQ, DEFAULT('Field')
        #DISPLAY ('')
        #DISPLAY ('The following prompts are nescessary for all')
        #DISPLAY ('  non-database fields (local and global fields).')
        #DISPLAY ('These may allso be used for database fields.')
        #PROMPT ('Enduser fieldname:',@S40),%EnduserDescription
        #PROMPT ('Picture:',@S140),%DefaultPicture
        #PROMPT ('Justification',DROP('Default|Left|Right|Center')),%DefaultJust,DEFAULT('')
      #ENDBUTTON
      #BUTTON ('All File Fields on report'), MULTI(%FileFieldsOnReport, %FileFieldOnReport),At(97)
        #PROMPT ('All fields from file:', FILE), %FileFieldOnReport
      #ENDBUTTON
    #ENDBOXED
  #ENDTAB
  #TAB('Export options')
    #BOXED('Report Designer export')
      #DISPLAY('')
      #DISPLAY('You can export fields and layouts directly for import')
      #DISPLAY('into the ArdSetup program.  The information is exported')
      #DISPLAY('to files with the same 8 character name as the source')
      #DISPLAY('file for the procedure with .RDF file ending - example:')
      #DISPLAY('')
      #DISPLAY('Src001.RDF')
      #DISPLAY('')
      #DISPLAY('Includes fields for procedure in this module')
      #DISPLAY('')
      #PROMPT('Export fields ', CHECK),%RepDesExportFields,AT(10),DEFAULT(%True)
      #ENABLE(%RepDesExportFields)
        #PROMPT('Export layout ', CHECK),%RepDesExportReport,AT(10),DEFAULT(%True)
        #ENABLE(%RepDesExportReport)
          #PROMPT('Layout name',@S30),%RptDesExportLayout,REQ,DEFAULT('Standard')
        #ENDENABLE
      #ENDENABLE
    #ENDBOXED
  #ENDTAB
  #TAB('Please Read This!')
    #BOXED('Report Desinger notes!')
      #DISPLAY('')
      #DISPLAY('Please remember to include the following files')
      #DISPLAY('as Other Files:')
      #DISPLAY('')
      #DISPLAY('R_Types, R_Design and R_StdDes')
      #DISPLAY('')
      #DISPLAY('Remember to include "RptDes Global settings"')
      #DISPLAY('as Global Extension, because this procedure is')
      #DISPLAY('calling the RDReadToReport, RDReportStart,')
      #DISPLAY('and RDReportEnd functions placed in the')
      #DISPLAY('Report Designer DLL/LIB.')
    #ENDBOXED
  #ENDTAB
#ENDSHEET
#!-------------------------------------------------------------------
#AT(%DataSectionAfterReport)
Loc:ReportBandNo    Long
Loc:NextCtrlNo      Long
Loc:FieldName       String(32)
Loc:ImageQueueRecNo Long
Loc:UseIsAssigned   BYTE(0)
Loc:ImageQueue      Queue,Pre()
Loc:CtrlNo            Long
Loc:CtrlField         String(32)
                    End
Loc:ErrorMsg        String(126)
ReadRptDes::Paper           EQUATE(1)       !Identifies the paper
ReadRptDes::PageForm        EQUATE(4)       !Identifies band PageForm
ReadRptDes::PageHeader      EQUATE(5)       !Identifies band PageHeader
ReadRptDes::PageFooter      EQUATE(6)       !Identifies band PageFooter
ReadRptDes::Detail          EQUATE(7)       !Identifies band Detail
#ENDAT
#!-------------------------------------------------------------------
#AT(%WindowManagerMethodCodeSection,'Init','(),BYTE'),PRIORITY(9500)
 #INSERT(%StandardValueAssignment(Clarion),'R_T:TypeName',%RptDesType)
 #EMBED(%RptDesReportType, 'After Report type is read before error handling')
 If Access:R_Types.TryFetch(R_T:TypeNameKey) !!Errorcode()
   #EMBED(%RptDesReportType, 'After Report type is read before error handling (inside IF-statement)')
   #IF (%RptDesTypeMessage)
   #INSERT(%StandardValueAssignment(Clarion),'Loc:ErrorMsg',%RptDesTypeMessage)
   Message (Loc:ErrorMsg)
   #ENDIF
   ReturnValue = Level:Fatal
 END
 LayoutFound# = False
#!
#CASE(%RptSelection)
#OF('Specific')
 R_D:TypeNumber = R_T:TypeNumber
 #INSERT(%StandardValueAssignment(Clarion),'R_D:DesignName',%RptDesLayout)
 IF NOT ReturnValue
   IF Access:R_Design.TryFetch(R_D:TypeKey)=Level:Benign 
     LayoutFound# = True
   ELSE
#!     Clear (R_D:Record)
     R_D:TypeNumber = R_T:TypeNumber
     GlobalRequest = SelectRecord
     %RptDesSelectProc
     If GlobalResponse = RequestCompleted
       LayoutFound# = True
     End
   END !IF
 END
#OF('Default')
 R_S:TypeNr = R_T:TypeNumber
 IF Access:R_StdDes.TryFetch(R_S:TypeNumberKey)=Level:Benign And Not LayoutFound#
   R_D:DesignNumber = R_S:StandardDesign
   IF Access:R_Design.TryFetch(R_D:DesignNumberKey)=Level:Benign
     LayoutFound# = True
   ELSE
#!     Clear (R_D:Record)
     R_D:TypeNumber = R_T:TypeNumber
     GlobalRequest = SelectRecord
     %RptDesSelectProc
     If GlobalResponse = RequestCompleted
       LayoutFound# = True
     End
   END
 END
#OF('Select')
 IF LayoutFound# = False And NOT ReturnValue
#!   Clear (R_D:Record)
   R_D:TypeNumber = R_T:TypeNumber
   GlobalRequest = SelectRecord
   %RptDesSelectProc
   If GlobalResponse = RequestCompleted
     LayoutFound# = True
   Else
     ReturnValue = Level:Fatal
   End
 END
#OF('Current')
 IF ~R_D:DesignNumber            ! No design active
#!   Clear (R_D:Record)
   R_D:TypeNumber = R_T:TypeNumber
   GlobalRequest = SelectRecord
   %RptDesSelectProc
   If GlobalResponse = RequestCompleted
     LayoutFound# = True
   End
 ELSE
   LayoutFound#=True
   ReturnValue=False
 END 
#ENDCASE
#!
 #EMBED(%RptDesLayout, 'After Report layout is read before error handling')
 IF NOT LayoutFound# And NOT ReturnValue
   #IF (%RptDesLayoutMessage)
   #INSERT(%StandardValueAssignment(Clarion),'Loc:ErrorMsg',%RptDesLayoutMessage)
   Message (Loc:ErrorMsg)
   #ENDIF
   ReturnValue = Level:Fatal
 END
#ENDAT
#!-------------------------------------------------------------------
#AT(%WindowManagerMethodCodeSection,'OpenReport','(),BYTE'),PRIORITY(5001),WHERE(NOT %RPMExt)
#!BeforePrint
  If NOT Loc:UseIsAssigned
    RDReportStart(R_T:TypeName,R_D:DesignName)
    Do CreateReportControls
    Loc:UseIsAssigned = True
  End
  Do AssignImageFields
#ENDAT
#!--------------------------------
#! Used if RPM previewer installed, ensure appears before AFE
#!--------------------------------
#AT(%LSiOptionsEmbed1),PRIORITY(1)
  If NOT Loc:UseIsAssigned
    RDReportStart(R_T:TypeName,R_D:DesignName)
    Do CreateReportControls
    Loc:UseIsAssigned = True
  End
  Do AssignImageFields
#ENDAT
#!-------------------------------------------------------------------
#AT(%EndOfProcedure)
 Free (Loc:ImageQueue)
 RDReportEnd
#ENDAT
#!-------------------------------------------------------------------
#AT(%ProcedureRoutines)
!-------------------------------------------------------------------
CreateReportControls    ROUTINE
  SetTarget (%Report)
 #IF(%RptDesRemoveControls)
  Loop Loc:NextCtrlNo = FirstField() To LastField()
    If %Report$Loc:NextCtrlNo {PROP:Create} = CREATE:report Or |
       %Report$Loc:NextCtrlNo {PROP:Create} = CREATE:header Or |
       %Report$Loc:NextCtrlNo {PROP:Create} = CREATE:footer Or |
       %Report$Loc:NextCtrlNo {PROP:Create} = CREATE:break  Or |
       %Report$Loc:NextCtrlNo {PROP:Create} = CREATE:form   Or |
       %Report$Loc:NextCtrlNo {PROP:Create} = CREATE:detail
      Cycle
    End
    Destroy (Loc:NextCtrlNo)
  End
 #ENDIF
  Loc:ReportBandNo = 0
  If RDReadToReport (%Report, ReadRptDes::Paper,      0, 0, |
                     Loc:NextCtrlNo, Loc:FieldName).   !Open file
 #FOR (%ReportControl)
   #IF (%ReportControlType='FORM' And %ReportControl)
  Loc:ReportBandNo = %ReportControl
  Loop While RDReadToReport (%Report, ReadRptDes::PageForm,   0, %ReportControl, |
                             Loc:NextCtrlNo, Loc:FieldName)
    Do AssignUseVariable
  End
     #BREAK
   #ENDIF
 #ENDFOR
 #FOR (%ReportControl)
   #IF (%ReportControlType='HEADER' And %ReportControl AND %ReportControlIndent = 0)
  Loc:ReportBandNo = %ReportControl
  Loop While RDReadToReport (%Report, ReadRptDes::PageHeader, 0, %ReportControl, |
                             Loc:NextCtrlNo, Loc:FieldName)
    Do AssignUseVariable
  End
     #BREAK
   #ENDIF
 #ENDFOR
 #FOR (%ReportControl)
   #IF (%ReportControlType='FOOTER' And %ReportControl AND %ReportControlIndent = 0)
  Loc:ReportBandNo = %ReportControl
  Loop While RDReadToReport (%Report, ReadRptDes::PageFooter, 0, %ReportControl, |
                             Loc:NextCtrlNo, Loc:FieldName)
    Do AssignUseVariable
  End
     #BREAK
   #ENDIF
 #ENDFOR
 #FOR (%ReportControl)
   #IF ((%ReportControlType='DETAIL' OR ((%ReportControlType='HEADER' Or %ReportControlType='FOOTER') AND %ReportControlIndent <> 0)) And %ReportControl AND %RptDesBandNo)
  Loc:ReportBandNo = %ReportControl
  Loop While RDReadToReport (%Report, ReadRptDes::Detail, %RptDesBandNo, %ReportControl, |
                             Loc:NextCtrlNo, Loc:FieldName)
    Do AssignUseVariable
  End
   #ENDIF
 #ENDFOR
  Loc:NextCtrlNo = 0
  If RDReadToReport (%Report, 0, 0, 0, Loc:NextCtrlNo, Loc:FieldName). !Close file
  SetTarget()
!-------------------------------------------------------------------
AssignUseVariable   ROUTINE
  If Report$Loc:NextCtrlNo {PROP:type} = CREATE:Image
    Loc:CtrlNo    = Loc:NextCtrlNo
    Loc:CtrlField = Upper (Loc:FieldName)
    Add (Loc:ImageQueue)
    Exit
  End
  Case Upper (Loc:FieldName)
#DECLARE(%RptDesTemporary)
#DECLARE(%Counter1)
#DECLARE(%Counter2)
#DECLARE(%Counter3)
#DECLARE(%Counter4)
#!
 #FOR(%FieldsOnReport)
   #SET(%RptDesTemporary, UPPER(%FieldOnReport))
  Of '%RptDesTemporary'
      Report$Loc:NextCtrlNo {PROP:Use} = %FieldOnReport
 #ENDFOR
 #FOR (%FileFieldsOnReport)
   #FIX (%File, %FileFieldOnReport)
   #FOR (%Field)
     #IF(%FieldType='GROUP')
       #CYCLE
     #END
     #IF(%FieldType='END')
       #CYCLE
     #END
     #SET(%RptDesTemporary, UPPER(%Field))
     #IF( %FieldDimension4>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
         #LOOP FOR(%Counter2, 1, %FieldDimension2)
           #LOOP FOR(%Counter3, 1, %FieldDimension3)
             #LOOP FOR(%Counter4, 1, %FieldDimension4)
  Of '%RptDesTemporary[%Counter1,%Counter2,%Counter3,%Counter4]'
      Report$Loc:NextCtrlNo {PROP:Use} = %Field[%Counter1,%Counter2,%Counter3,%Counter4]
             #ENDLOOP
           #ENDLOOP
         #ENDLOOP
       #ENDLOOP
     #ELSIF( %FieldDimension3>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
         #LOOP FOR(%Counter2, 1, %FieldDimension2)
           #LOOP FOR(%Counter3, 1, %FieldDimension3)
  Of '%RptDesTemporary[%Counter1,%Counter2,%Counter3]'
      Report$Loc:NextCtrlNo {PROP:Use} = %Field[%Counter1,%Counter2,%Counter3]
           #ENDLOOP
         #ENDLOOP
       #ENDLOOP
     #ELSIF( %FieldDimension2>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
         #LOOP FOR(%Counter2, 1, %FieldDimension2)
  Of '%RptDesTemporary[%Counter1,%Counter2]'
      Report$Loc:NextCtrlNo {PROP:Use} = %Field[%Counter1,%Counter2]
         #ENDLOOP
       #ENDLOOP
     #ELSIF( %FieldDimension1>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
  Of '%RptDesTemporary[%Counter1]'
      Report$Loc:NextCtrlNo {PROP:Use} = %Field[%Counter1]
       #ENDLOOP
     #ELSE
  Of '%RptDesTemporary'
      Report$Loc:NextCtrlNo {PROP:Use} = %Field
     #ENDIF
   #ENDFOR   
 #ENDFOR
  End
  #EMBED(%RptDesAssign, 'After Use variables are assigned')
!-------------------------------------------------------------------
AssignImageFields   ROUTINE
  Loop Loc:ImageQueueRecNo = 1 To Records (Loc:ImageQueue)
    Get (Loc:ImageQueue, Loc:ImageQueueRecNo)
    Case Upper (Loc:CtrlField)
 #FOR(%FieldsOnReport)
   #SET(%RptDesTemporary, UPPER(%FieldOnReport))
    Of '%RptDesTemporary'
      Report$Loc:CtrlNo {PROP:Text} = %FieldOnReport
 #ENDFOR
 #FOR (%FileFieldsOnReport)
   #FIX (%File, %FileFieldOnReport)
   #FOR (%Field)
     #IF(%FieldType='GROUP')
       #CYCLE
     #END
     #IF(%FieldType='END')
       #CYCLE
     #END
     #SET(%RptDesTemporary, UPPER(%Field))
     #IF( %FieldDimension4>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
         #LOOP FOR(%Counter2, 1, %FieldDimension2)
           #LOOP FOR(%Counter3, 1, %FieldDimension3)
             #LOOP FOR(%Counter4, 1, %FieldDimension4)
  Of '%RptDesTemporary[%Counter1,%Counter2,%Counter3,%Counter4]'
      Report$Loc:NextCtrlNo {PROP:Text} = %Field[%Counter1,%Counter2,%Counter3,%Counter4]
             #ENDLOOP
           #ENDLOOP
         #ENDLOOP
       #ENDLOOP
     #ELSIF( %FieldDimension3>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
         #LOOP FOR(%Counter2, 1, %FieldDimension2)
           #LOOP FOR(%Counter3, 1, %FieldDimension3)
  Of '%RptDesTemporary[%Counter1,%Counter2,%Counter3]'
      Report$Loc:NextCtrlNo {PROP:Text} = %Field[%Counter1,%Counter2,%Counter3]
           #ENDLOOP
         #ENDLOOP
       #ENDLOOP
     #ELSIF( %FieldDimension2>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
         #LOOP FOR(%Counter2, 1, %FieldDimension2)
  Of '%RptDesTemporary[%Counter1,%Counter2]'
      Report$Loc:NextCtrlNo {PROP:Text} = %Field[%Counter1,%Counter2]
         #ENDLOOP
       #ENDLOOP
     #ELSIF( %FieldDimension1>0)
       #LOOP FOR(%Counter1, 1, %FieldDimension1)
  Of '%RptDesTemporary[%Counter1]'
      Report$Loc:NextCtrlNo {PROP:Text} = %Field[%Counter1]
       #ENDLOOP
     #ELSE
  Of '%RptDesTemporary'
      Report$Loc:NextCtrlNo {PROP:Text} = %Field
     #ENDIF
   #ENDFOR
 #ENDFOR
    End
  End
!-------------------------------------------------------------------
#ENDAT
#!-------------------------------------------------------------------
#ATSTART
  #FIX(%ProcFilesUsed, 'R_TYPES')
  #IF (%ProcFilesUsed <> 'R_TYPES')
    #ADD(%ProcFilesUsed, 'R_TYPES')
  #ENDIF
  #FIX(%ProcFilesUsed, 'R_DESIGN')
  #IF (%ProcFilesUsed <> 'R_DESIGN')
    #ADD(%ProcFilesUsed, 'R_DESIGN')
  #ENDIF
  #FIX(%ProcFilesUsed, 'R_STDDES')
  #IF (%ProcFilesUsed <> 'R_STDDES')
    #ADD(%ProcFilesUsed, 'R_STDDES')
  #ENDIF
#!-------------------------------------
#! Check for existance of RPM previewer
#!-------------------------------------
  #DECLARE(%RPMExt)
  #SET(%RPMExt,%FALSE)
  #FOR(%ActiveTemplate)
    #IF(UPPER(%ActiveTemplate) = 'RPM_STANDARD_RPT(LODESTAR_RPM)' OR UPPER(%ActiveTemplate) = 'RPM_CPCS_RPT(LODESTAR_RPM)')
      #SET(%RPMExt,%TRUE)
      #BREAK
    #ENDIF
  #ENDFOR
#ENDAT
#!-------------------------------------------------------------------
#ATEND
#DECLARE(%RptDesFile)
#DECLARE(%RptDesFieldType)
#DECLARE(%TempDesc)
#DECLARE(%TempJust)
#DECLARE(%TempPic)
#DECLARE(%TempLayoutName)
  #IF (SUB (%RptDesLayout, 1, 1) = '!')
    #SET(%TempLayoutName, '')
  #ELSE
    #SET(%TempLayoutName, %RptDesLayout)
  #ENDIF
  #IF(%RepDesExportFields And SUB (%RptDesType, 1, 1) <> '!')
    #SET(%RptDesFile,%ModuleBase & '.rdf')
    #MESSAGE('Generating Module:    ' & %RptDesFile,1)
    #CREATE(%RptDesFile)
    #FOR(%FieldsOnReport)
      #SET (%RptDesTemporary, INSTRING ('[', %FieldOnReport))
      #IF (%RptDesTemporary)
        #SET (%RptDesTemporary, SUB (%FieldOnReport, 1, %RptDesTemporary-1))
      #ELSE
        #SET (%RptDesTemporary, %FieldOnReport)
      #ENDIF
      #FIND(%Field,%RptDesTemporary)
      #IF(%Field = %RptDesTemporary)
        #IF(%EnduserDescription)
          #SET(%TempDesc,%EnduserDescription)
        #ELSIF(%FieldDescription)
          #SET(%TempDesc,%FieldDescription)
        #ELSE
          #SET(%TempDesc,%Field)
        #ENDIF
        #IF(%DefaultPicture)
          #SET(%TempPic,%DefaultPicture)
        #ELSE
          #SET(%TempPic,%FieldPicture)
        #END
        #IF(%DefaultJust = 'None')
          #SET(%TempJust,%FieldJustType)
        #ELSE
          #SET(%TempJust,SUB(%DefaultJust,1,1))
        #ENDIF
      #ELSE
        #IF(%EnduserDescription)
          #SET(%TempDesc,%EnduserDescription)
        #ELSE
          #SET(%TempDesc,%FALSE)
        #ENDIF
        #IF(%DefaultPicture)
          #SET(%TempPic,%DefaultPicture)
        #ELSE
          #SET(%TempPic,'@S20')
        #END
        #IF(%DefaultJust = 'None')
          #SET(%TempJust,'D')
        #ELSE
          #SET(%TempJust,SUB(%DefaultJust,1,1))
        #ENDIF
        #FIX(%LocalData,%RptDesTemporary)
        #IF(%LocalData = %RptDesTemporary)
          #IF(NOT %TempDesc)
            #SET(%TempDesc,%LocalData)
          #ENDIF
        #ELSE
          #FIX(%GlobalData,%RptDesTemporary)
          #IF(%GlobalData = %RptDesTemporary)
            #IF(NOT %TempDesc)
              #SET(%TempDesc,%GlobalData)
            #ENDIF
          #ELSE
            #CYCLE
          #ENDIF
        #ENDIF
      #ENDIF
"%Application","%Procedure","%RptDesType","%TempLayoutName","%TempDesc","%FieldOnReport","%FieldOnReportType","%TempJust","%TempPic"
    #ENDFOR
    #FOR (%FileFieldsOnReport)
      #FIX (%File, %FileFieldOnReport)
      #FOR (%Field)
        #IF(%FieldType='GROUP')
          #CYCLE
        #END
        #IF(%FieldType='END')
          #CYCLE
        #END
        #SET (%RptDesTemporary, %Field)
        #IF(%FieldDescription)
          #SET(%TempDesc,%FieldDescription)
        #ELSE
          #SET(%TempDesc,%Field)
        #ENDIF
        #SET(%TempPic,%FieldPicture)
        #SET(%TempJust,%FieldJustType)
        #IF( %FieldDimension4>0)
          #LOOP FOR(%Counter1, 1, %FieldDimension1)
            #LOOP FOR(%Counter2, 1, %FieldDimension2)
              #LOOP FOR(%Counter3, 1, %FieldDimension3)
                #LOOP FOR(%Counter4, 1, %FieldDimension4)
"%Application","%Procedure","%RptDesType","%TempLayoutName","%TempDesc[%Counter1,%Counter2,%COunter3,%Counter4]","%Field[%Counter1,%Counter2,%Counter3,%Counter4]","%FieldOnReportType","%TempJust","%TempPic"
                #ENDLOOP
              #ENDLOOP
            #ENDLOOP
          #ENDLOOP
        #ELSIF( %FieldDimension3>0)
          #LOOP FOR(%Counter1, 1, %FieldDimension1)
            #LOOP FOR(%Counter2, 1, %FieldDimension2)
              #LOOP FOR(%Counter3, 1, %FieldDimension3)
"%Application","%Procedure","%RptDesType","%TempLayoutName","%TempDesc[%Counter1,%Counter2,%COunter3]","%Field[%Counter1,%Counter2,%Counter3]","%FieldOnReportType","%TempJust","%TempPic"
              #ENDLOOP
            #ENDLOOP
          #ENDLOOP
        #ELSIF( %FieldDimension2>0)
          #LOOP FOR(%Counter1, 1, %FieldDimension1)
            #LOOP FOR(%Counter2, 1, %FieldDimension2)
"%Application","%Procedure","%RptDesType","%TempLayoutName","%TempDesc[%Counter1,%Counter2]","%Field[%Counter1,%Counter2]","%FieldOnReportType","%TempJust","%TempPic"
            #ENDLOOP
          #ENDLOOP
        #ELSIF( %FieldDimension1>0)
          #LOOP FOR(%Counter1, 1, %FieldDimension1)
"%Application","%Procedure","%RptDesType","%TempLayoutName","%TempDesc[%Counter1]","%Field[%Counter1]","%FieldOnReportType","%TempJust","%TempPic"
          #ENDLOOP
        #ELSE
"%Application","%Procedure","%RptDesType","%TempLayoutName","%TempDesc","%Field","%FieldOnReportType","%TempJust","%TempPic"
        #ENDIF
      #ENDFOR
    #ENDFOR
    #CLOSE(%RptDesFile)
  #ENDIF
  #IF(%RepDesExportReport)
    #!  Export report structure
    #DECLARE(%ScrFileName)
    #SET(%ScrFileName,%ModuleBase & '.RDF')
    #OPEN(%ScrFileName)
    #DECLARE(%NewReportStatement)
    #DECLARE(%Indentation,LONG)
    #DECLARE(%TestValue)
    #DECLARE(%ReportControlSourceLine)
    #DECLARE(%CurrentLineBeginStructure)
    #DECLARE(%PreviousLineBeginStructure)

ReportType: %RptDesType
LayoutName: %RptDesExportLayout
%[20]Report %ReportStatement
    #SET(%Indentation,0)
    #SET(%CurrentLineBeginStructure,%False)
    #FOR(%ReportControl)
      #IF(%ReportControlIndent<%Indentation)
        #LOOP
          #SET(%Indentation,%Indentation-1)
%[22+(2*%Indentation)]Null END
          #IF(%ReportControlIndent=%Indentation)
            #BREAK
          #ENDIF
        #ENDLOOP
      #ENDIF
%[22+(2*%Indentation)]ReportControlLabel %ReportControlStatement
      #IF(SUB(%ReportControlStatement,1,6)='HEADER')
        #SET(%Indentation,%Indentation+1)
      #ELSIF(SUB(%ReportControlStatement,1,6)='FOOTER')
        #SET(%Indentation,%Indentation+1)
      #ELSIF(SUB(%ReportControlStatement,1,6)='DETAIL')
        #SET(%Indentation,%Indentation+1)
      #ELSIF(SUB(%ReportControlStatement,1,6)='OPTION')
        #SET(%Indentation,%Indentation+1)
      #ELSIF(SUB(%ReportControlStatement,1,5)='GROUP')
        #SET(%Indentation,%Indentation+1)
      #ELSIF(SUB(%ReportControlStatement,1,5)='BREAK')
        #SET(%Indentation,%Indentation+1)
      #ELSIF(SUB(%ReportControlStatement,1,4)='FORM')
        #SET(%Indentation,%Indentation+1)
      #ENDIF
    #ENDFOR
    #LOOP
      #IF(%Indentation < 0)
        #BREAK
      #ENDIF
      #SET(%Indentation,%Indentation-1)
      #SET(%ReportControlSourceLine,'END')
%[22+(2*%Indentation)]Null %ReportControlSourceLine
    #ENDLOOP
    #! Export detail numbers and details
    #!

DETAILS AND NUMBERS

 #FOR (%ReportControl)
   #IF ((%ReportControlType='DETAIL' OR ((%ReportControlType='HEADER' Or %ReportControlType='FOOTER') AND %ReportControlIndent <> 0)) And %ReportControl AND %RptDesBandNo)
   #SET(%ReportControlSourceLine,Format(%RptDesBandNo,@n03) & ' ' & %ReportControl)
%ReportControlSourceLine
   #ENDIF
 #ENDFOR
    #CLOSE(%ScrFileName)
  #ENDIF
#ENDAT
#!
#!===================================================================
#CODE(CallReportDesigner,'Call the Report Designer'), HLP('ReportDesignerPrint'),REQ(GlobalRptDes)
#!-------------------------------------------------------------------
  Start (TheReportDesigner, 50000)
#!
#!===================================================================
#EXTENSION(GlobalRptDes,'RptDes Global settings'),APPLICATION
#! Global settings for Report Designer
#!-------------------------------------------------------------------
#DISPLAY('This Extension Template sets up the global settings')
#DISPLAY('for the Allerup Report Designer.')
#DISPLAY('')
#DISPLAY('1.  The correct .LIB file is added to the project.')
#DISPLAY('2.  Prototypes the four procedures in the map')
#DISPLAY('3.  Changes the attributes for the R_Types, R_Design,')
#DISPLAY('    and R_StdDes files to be generated.')
#DISPLAY('4.  If a 16-bit program, includes ARptDes.PR for secure')
#DISPLAY('    link of your application (.RSC and .ICO files)')
#DISPLAY('')
#DISPLAY('Note !')
#DISPLAY('The files R_Types, R_Design, and R_StdDes are NOT shared')
#DISPLAY('by the ReportDesigner .DLL and should not be EXTERNAL')
#DISPLAY('because of using the ReportDesigner .DLL/.LIB')
#DISPLAY('')
#DISPLAY('There are no extra settings for this Extension Template')
#!-------------------------------------------------------------------
#AT(%CustomGlobalDeclarations)
#PROJECT ('ARptDe%X%%L%.LIB')
#PROJECT ('C55asc%X%%L%.LIB')
#PROJECT ('C55bas%X%%L%.LIB')
#PROJECT ('C55tps%X%%L%.LIB')
  #IF(NOT %Target32)
    #PROJECT('arptdes.pr')
  #ENDIF
#ENDAT
#!-------------------------------------------------------------------
#AT(%GlobalMap)
  MODULE('Allerup Report Designer')
    TheReportDesigner,DLL(dll_mode)
    RDReadToReport(Report pRpt,Short pBandType,Short pDetailNo,Long pBandUse,*Long pLastUsed,*String pField),Short,DLL(dll_mode)
    RDReportStart(*String pType,*String pDesign),DLL(dll_mode)
    RDReportEnd,DLL(dll_mode)
    SetRptDesFileNames,DLL(dll_mode)
    RDRebuildKeys,DLL(dll_mode)
  END
#ENDAT
#!-------------------------------------------------------------------
#GLOBALDATA
Glo:RptDes1:Name      STRING(255),EXTERNAL,DLL(dll_mode)
Glo:Layoutfile:Name   STRING(255),EXTERNAL,DLL(dll_mode)
Glo:R_Design:Name     STRING(255),EXTERNAL,DLL(dll_mode)
Glo:R_StdDes:Name     STRING(255),EXTERNAL,DLL(dll_mode)
Glo:R_Types:Name      STRING(255),EXTERNAL,DLL(dll_mode)
#ENDGLOBALDATA
#!-------------------------------------------------------------------
#AT(%BeforeFileDeclarations)
  #IF(NOT %GlobalExternal)
Glo:Design:Name       STRING(255)
Glo:StdDes:Name       STRING(255)
Glo:Types:Name        STRING(255)
  #ELSE
Glo:Design:Name       STRING(255),EXTERNAL,DLL(dll_mode)
Glo:StdDes:Name       STRING(255),EXTERNAL,DLL(dll_mode)
Glo:Types:Name        STRING(255),EXTERNAL,DLL(dll_mode)
  #ENDIF
#ENDAT
#AT(%BeginningExports)
  #IF(NOT %GlobalExternal)
  $Glo:Design:Name       @?
  $Glo:StdDes:Name       @?
  $Glo:Types:Name        @?
  #ENDIF
#ENDAT
#ATSTART
  #FIX (%File, 'R_TYPES')
  #SET (%OverrideGenerate, %True)
  #SET (%OverrideExternal, 'Use Default')
  #SET (%OverrideExternalAPP, %False)
  #FIX (%File, 'R_DESIGN')
  #SET (%OverrideGenerate, %True)
  #SET (%OverrideExternal, 'Use Default')
  #SET (%OverrideExternalAPP, %False)
  #FIX (%File, 'R_STDDES')
  #SET (%OverrideGenerate, %True)
  #SET (%OverrideExternal, 'Use Default')
  #SET (%OverrideExternalAPP, %False)
#ENDAT
#!===================================================================
#CODE(RptDesAssignFileVariables,'Assign the Report Designer filevariables'), HLP('ReportDesignerPrint'),REQ(GlobalRptDes)
#! Code template to assign filename variables
#!-------------------------------------------------------------------
#BOXED('Assign Report Designer file variables')
#PROMPT('Name of report file: ',@S255),%RptDesReportFileName
#PROMPT('Name of layout file: ',@S255),%RptDesLayoutFileName
#DISPLAY('')
#DISPLAY('If the filename fields are left empty, this code')
#DISPLAY('template will only assign the table names.')
#DISPLAY('If filename starts with "!" it expects a variable')
#DISPLAY('that contains the name of the file(s).')
#DISPLAY('If filename does not start with "!", it expects')
#DISPLAY('a fully qualified filename (may include path).')
#ENDBOXED
#DECLARE(%ReportFileName)
#DECLARE(%LayoutFileName)
#SET(%ReportFileName,%RptDesReportFileName)
#SET(%LayoutFileName,%RptDesLayoutFileName)
 ! Assigning Allerup Report Designer file and table variables
#IF(Len(Clip(%ReportFileName))>0)
  #IF(Sub(%ReportFileName,1,1)='!')
    #SET(%ReportFileName,Sub(%ReportFileName,2,Len(Clip(%ReportFileName))-1))
 Glo:RptDes1:Name    = %ReportFileName
  #ELSE
 Glo:RptDes1:Name    = '%ReportFileName'
  #ENDIF
#ENDIF
#IF(Len(Clip(%LayoutFileName))>0)
  #IF(Sub(%LayoutFileName,1,1)='!')
    #SET(%LayoutFileName,Sub(%LayoutFileName,2,Len(Clip(%LayoutFileName))-1))
 Glo:Layoutfile:Name = %LayoutFileName
  #ELSE
 Glo:Layoutfile:Name = '%LayoutFileName'
  #ENDIF
#ENDIF
 SetRptDesFileNames
 Glo:Design:Name = Glo:R_Design:Name
 Glo:StdDes:Name = Glo:R_StdDes:Name
 Glo:Types:Name  = Glo:R_Types:Name
#!===================================================================
#CODE(CallReportSelect,'Select a report design'),LAST
#!-------------------------------------------------------------------
#DECLARE(%RptDesTypeName)
#DECLARE(%RptDesLayoutName)
#BOXED ('Call report layout selection')
  #DISPLAY('')
  #PROMPT ('Report type:', @S32),%RptDesType,REQ
  #DISPLAY('(Use ! to indicate variable name)')
  #DISPLAY('')
  #PROMPT ('Select procedure:',PROCEDURE),%RptDesSelectProc,REQ
#ENDBOXED
 #IF(SUB(%RptDesType,1,1)='!')
  #SET(%RptDesTypeName,SUB(%RptDesType,2,32))
  R_T:TypeName=%RptDesTypeName
 #ELSE
  #INSERT(%StandardValueAssignment(Clarion),'R_T:TypeName',%RptDesType)
 #ENDIF
 IF Access:R_Types.TryFetch(R_T:TypeNameKey)
   CLEAR(R_Types)
   MESSAGE('Report type not found')
   POST(Event:CloseWindow)
 END
 LayoutFound# = False
 R_D:TypeNumber = R_T:TypeNumber
 GlobalRequest = SelectRecord
 %RptDesSelectProc
 CLEAR(GlobalRequest)
 If GlobalResponse = RequestCompleted
   LayoutFound# = True
 End
#!End of code template
#!===================================================================
#CODE(CallReportSpecific,'Get a specific report design'),LAST
#!-------------------------------------------------------------------
#DECLARE(%RptDesTypeName)
#DECLARE(%RptDesLayoutName)
#BOXED('Get specific layout')
  #DISPLAY('')
  #PROMPT ('Report type:', @S32),%RptDesType,REQ
  #DISPLAY('(Use ! to indicate variable name)')
  #DISPLAY('')
  #PROMPT ('Layout name:',@S32),%RptDesLayout,REQ
  #DISPLAY('(Use ! to indicate variable name)')
  #DISPLAY('')
  #PROMPT ('Select procedure:',PROCEDURE),%RptDesSelectProc,REQ
#ENDBOXED
 #IF(SUB(%RptDesType,1,1)='!')
  #SET(%RptDesTypeName,SUB(%RptDesType,2,32))
  R_T:TypeName=%RptDesTypeName
 #ELSE
  #INSERT(%StandardValueAssignment(Clarion),'R_T:TypeName',%RptDesType)
 #ENDIF
 IF Access:R_Types.TryFetch(R_T:TypeNameKey)
   CLEAR(R_Types)
   MESSAGE ('Report type not found')
   POST(Event:CloseWindow)
 END
 LayoutFound# = False
 Clear (R_D:Record)
 #IF(SUB(%RptDesLayout,1,1)='!')
  #SET(%RptDesLayoutName,SUB(%RptDesLayout,2,32))
  R_D:DesignName=%RptDesLayoutName
 #ELSE
  #INSERT(%StandardValueAssignment(Clarion),'R_D:DesignName',%RptDesLayout)
 #ENDIF
 R_D:TypeNumber = R_T:TypeNumber
 IF Access:R_Design.TryFetch(R_D:TypeKey)=Level:Benign
   LayoutFound# = True
 ELSE
   LayoutFound#=False
#!   Clear (R_D:Record)
   R_D:TypeNumber = R_T:TypeNumber
   GlobalRequest = SelectRecord
   %RptDesSelectProc
   CLEAR(Globalrequest)
   If GlobalResponse = RequestCompleted
     LayoutFound# = True
   End
 END
#!===================================================================
#CODE(CallReportDefault,'Get the default report design'),LAST
#!-------------------------------------------------------------------
#DECLARE(%RptDesTypeName)
#DECLARE(%RptDesLayoutName)
#BOXED('Get default layout')
  #DISPLAY('')
  #PROMPT ('Report type:', @S32),%RptDesType,REQ
  #DISPLAY('(Use ! to indicate variable name)')
  #DISPLAY('')
  #PROMPT ('Select procedure:',PROCEDURE),%RptDesSelectProc,REQ
#ENDBOXED
 #IF(SUB(%RptDesType,1,1)='!')
  #SET(%RptDesTypeName,SUB(%RptDesType,2,32))
  R_T:TypeName=%RptDesTypeName
 #ELSE
  #INSERT(%StandardValueAssignment(Clarion),'R_T:TypeName',%RptDesType)
 #ENDIF
 IF Access:R_Types.TryFetch(R_T:TypeNameKey)
   CLEAR(R_Types)
   Message ('Report type not found')
   POST(Event:CloseWindow)
 END
 LayoutFound# = False
 R_S:TypeNr = R_T:TypeNumber
 IF Access:R_StdDes.TryFetch(R_S:TypeNumberKey)=Level:Benign
   R_D:DesignNumber = R_S:StandardDesign
   IF Access:R_Design.TryFetch(R_D:DesignNumberKey)=Level:Benign
     LayoutFound# = True
   ELSE
     LayoutFound#=False
#!     Clear (R_D:Record)
     R_D:TypeNumber = R_T:TypeNumber
     GlobalRequest = SelectRecord
     %RptDesSelectProc
     Clear(GlobalRequest)
     If GlobalResponse = RequestCompleted
       LayoutFound# = True
     End
   END
 END
#!===================================================================
