Wednesday, September 22, 2010

Multiple Reports in SQR

Multiple Reports feature is very handful  when you need to stream the output to different reports based on some business conditions. DECLARE-REPORT and USE_REPORT are two commands used to accomplish this. Below example generates two reports based on the employee salary. each report will have a separate header.



declare-report rep1
   layout=layout1
end-declare

  declare-report rep2
    layout=layout2
  end-declare
 END-SETUP

 begin-heading 4 for-reports=rep1
  
    print 'Employee Listing Grade B' (1,1) center bold shade
    print '=' (+1,1,80) fill
    print 'EID' (3,1) bold
    print 'EName' (,10) bold
    print 'Salary' (,30) bold
 end-heading


 begin-heading 4 for-reports=rep2
    
    print 'Employee Listing Grade A' (1,1) center bold shade
    print '=' (+1,1,80) fill
    print 'EID' (3,1) bold
    print 'EName' (,10) bold
    print 'Salary' (,30) bold
 end-heading





BEGIN-PROGRAM
BEGIN-SELECT
NS_EID
NS_ENAME
NS_SALARY
    if &ns_salary <35000
      use-report rep1 
    else
      use-report rep2
    end-if
  
    print &NS_EID (+1,1)
    print &NS_ENAME (,10)
    print &NS_SALARY (,30)
FROM PS_NS_EMP_TBL
end-select
end-program


No comments:

Post a Comment