Search This Blog

Thursday, June 26, 2014

SQR: Global Variables

In SQR, we donot explicitly declare variable as global in general unless the variables are passed through the procedure in_list.
Below is the sample program to demonstrate usage of variable value globally.

!**********************************************************************
!begin-program
!**********************************************************************

Begin-Program
  do Stdapi-Init          !stdapi.sqc
  do Init-Report          !Init Report        
  do Process-Main       !Process-Main-Logic
  do Stdapi-Term              !stdapi.sqc 
End-Program

!**********************************************************************
!Init-Report
!**********************************************************************
begin-procedure Init-Report
let $Flag = 'N'
end-procedure Init-Report

!**********************************************************************
!Process-Main
!**********************************************************************
begin-procedure Process-Main
! Business logic
BEGIN-SELECT

show ' Before override = ' $Flag
let $Flag = 'Y'
show ' After override = ' $Flag
    do procedure-1
 END-SELECT
end-procedure Process-Main

!**********************************************************************
!procedure-1
!**********************************************************************
begin-procedure procedure-1
let $Flag = 'N'
show ' In procedure-1 = ' $Flag
end-procedure procedure-1

Output:
Before override = N
After override = Y
In procedure-1 = N

Tuesday, June 17, 2014

SQR: Date formatting in CSV file

For writing data to ouput files we use write command in SQR. And if we have date as one of the output fields, clients prefer '01062014'. This can be achieved by applying formatting to the date field.

Below is the manual way of doing in Excel file. Enter date as show in pic 1 and tab out.
Once we tab out, below is the format of the date that appears in the file.




But this is not we expected. So now lets apply formatting.
So when we prepend =" to date and append ", it converts date to Text format , thus retaining required format.



Fine. Now we need to achieve same through the SQR. Below is the sample code to do the same.
Sample Code:
  let $write_header = 'EMPLID,EFFDT,FORMATTED EFFDT'
  let $emplid = 'EMP101'
  let $effdt  = '01022014'
  let $text = '="05062014"'

  let $delim = ','
 
write 1 from $write_header

write 1 from $emplid
         $delim
         $effdt
         $delim
         $text
SQR Output for a comma separated CSV file