[Stackoverflow] [Progress OpenEdge ABL] Sometimes having error with CSV output file from 4GL program

  • Thread starter Thread starter user5586678
  • Start date Start date
Status
Not open for further replies.
U

user5586678

Guest
Sometimes I'm getting an error in the output of a CSV output file from 4GL program, what happens is instead of putting the last 2 fields then starting the next line, it skips the last 2 fields and concatenates the next line onto the end of the line it was printing. The file is for employee retirement data, and all the error records are of the same type - "T". I think the function in question is below, and since the code is T, I think the logic error might be there, maybe checking lSumFringe > 0? I would like another set of eyes to look at this because I'm having trouble getting this to run in debugger and trace it.

Code:
FUNCTION get_records()

   DEFINE lProcStatus      INTEGER,
          lMessage         STRING,
          lProgressTotal   INTEGER,
          lWindowOpened    SMALLINT,
          rpt_name         STRING,
          lStmt            STRING,
          lEmplNo          LIKE employee.empl_no,
          lstrPay          STRING,
          lstrDed          STRING,
          larr             SMALLINT,
          lOldDedCode      LIKE checkhi2.code,
          lDedTitle        CHAR(28),
          lManVoid         LIKE checkhis.man_void,
          lDedCode         LIKE checkhi2.code,
          lAmt             LIKE checkhi2.amt,
          lFringe          LIKE checkhi2.fringe,
          lSumAmt          LIKE checkhi2.amt,
          lSumFringe       LIKE checkhi2.fringe
   DEFINE lplType          CHAR                              

   # mPay1 - mPay12 holds all the pay runs we are to process
   # concatenate into a string to use in select stmt
   CALL PutInString() RETURNING lstrPay

   # find all the deduction codes we are to process
   # concatenate into a string to use in select stmt
   CALL GetDedCodes() RETURNING lstrDed

   CASE                                                         
      WHEN UPSHIFT(r_site_info.site_code)='UPD'
         LET rpt_name = mPay1, "_TSA.txt"
      OTHERWISE                                                 
         LET rpt_name = mPay1, "_TSA.csv"
   END CASE                                                     

   CALL report_hdr(132,rpt_name,"","","",
                   r_hrm_prof.company,r_hrm_prof.system,r_hrm_prof.client)
      RETURNING r_hdr.*

   IF NOT rpt_setup(-2, rpt_name) THEN
      LET int_flag = FALSE
      RETURN
   END IF
   CASE
      WHEN p_rpt_dest = "t" OR p_rpt_dest = "d"
         START REPORT tsa_remit TO p_rpt_name
      WHEN p_rpt_dest = "p"
         START REPORT tsa_remit TO PIPE p_prt_cmd
   END CASE

   # select records for processing
   LET lStmt = "SELECT COUNT(employee.empl_no) ",
               " FROM employee,person ",
               " WHERE employee.empl_no = person.empl_no"

   PREPARE ps_progress FROM lStmt
   DECLARE c_progress CURSOR FOR ps_progress
   OPEN c_progress
   FETCH c_progress INTO lProgressTotal
   CLOSE c_progress

   CALL libProgressBarStart("Processing...", lProgressTotal)
      RETURNING lProcStatus, lMessage, lWindowOpened

   IF lProgressTotal = 0 THEN
      ERROR "No records found"
      RETURN
   END IF

   LET lStmt = "SELECT DISTINCT(employee.empl_no),employee.*,person.* ",
               " FROM employee,person,checkhi2,checkhis ",
               " WHERE employee.empl_no = person.empl_no ",
               " AND employee.empl_no = checkhi2.empl_no ",
               " AND employee.empl_no = checkhis.empl_no ",
               " AND checkhis.check_no = checkhi2.check_no ",         
               " AND checkhis.pay_run IN ",lstrPay,
               " AND checkhi2.code IN ",lstrDed,
               " ORDER BY employee.empl_no"
   PREPARE ps_empl FROM lStmt
   DECLARE c_empl CURSOR FOR ps_empl

   LET lStmt = "SELECT checkhis.man_void,checkhi2.code, ",
               " checkhi2.amt,checkhi2.fringe ",
               " FROM checkhis,checkhi2 ",
               " WHERE checkhis.empl_no = checkhi2.empl_no ",
               " AND checkhis.check_no = checkhi2.check_no ",      
               " AND checkhis.empl_no = ? ",
               " AND checkhi2.earn_ded = 'D' ",
               " AND checkhis.pay_run IN ",lstrPay,
               " AND checkhi2.code IN ",lstrDed,
               " ORDER BY checkhi2.code"
   PREPARE ps_check FROM lStmt
   DECLARE c_check CURSOR FOR ps_check

   OUTPUT TO REPORT tsa_remit('1')   #V5.1.2  do header once

   FOREACH c_empl INTO lEmplNo,r_employee.*,r_person.*
      CALL libProgressBarProcess()

      # Initialize fields
      INITIALIZE mr_data.* TO NULL
      LET mr_data.code_amt[1].title = ""
      LET mr_data.code_amt[1].amt = 0
      FOR larr = 2 TO 16
         LET mr_data.code_amt[larr].title = mr_data.code_amt[1].title
         LET mr_data.code_amt[larr].amt = mr_data.code_amt[1].amt
      END FOR

      LET mr_data.empl_no = r_employee.empl_no
      LET mr_data.ssn = r_employee.ssn
      LET mr_data.l_name = r_employee.l_name
      LET mr_data.f_name = r_employee.f_name
      LET mr_data.m_name = r_employee.m_name
      LET mr_data.name_suffix = r_employee.name_suffix
      LET mr_data.birthdate = r_employee.birthdate

      # remove puncuation
      LET mr_data.addr1 = strip_punc(r_employee.addr1)
      LET mr_data.addr2 = strip_punc(r_employee.addr2)
      LET mr_data.zip = strip_punc(r_employee.zip)

      LET mr_data.city = r_employee.city
      LET mr_data.state_id = r_employee.state_id
      LET mr_data.phone = r_person.home_phone

      LET larr = 1
      LET lOldDedCode = ""
      LET lSumAmt = 0
      LET lSumFringe = 0
      FOREACH c_check USING r_employee.empl_no
         INTO lManVoid,lDedCode,lAmt,lFringe

         IF larr > 15 THEN                            
            # File can have up to 8 pairs (ded/fringe) of
            # deduction codes in file
            # 5.1.3 Adjusted test, becasue if there were A ROTH plan
            # 5.1.3 there is no matching ER contrib.
             CONTINUE FOREACH
         END IF

         IF LENGTH(lOldDedCode) = 0 OR lOldDedCode <> lDedCode THEN
            IF LENGTH(lOldDedCode) > 0 THEN
               # When deduction code changes write to the report record
               SELECT title INTO lDedTitle FROM dedtable
               WHERE ded_cd = lOldDedCode

               LET lplType = plantype(lOldDedCode)              

               # Always print the employee amount when
               # plan type is not T or U.
               IF lplType <> 'T' AND lplType <> 'U' THEN
                  LET mr_data.code_amt[larr].title = lDedTitle CLIPPED
                  LET mr_data.code_amt[larr].amt = lSumAmt
               ELSE
                  # Plan is either T or U 
                  # only include employee data if site has
                  # a fincustom record and deduct amount is > zero
                  IF mHasZERO_403_AMOUNT THEN
                     IF lSumAmt > 0 THEN
                        chec
                     ELSE
                        # An employee amount is always assumed to be 
                        # included and the array is always increased.
                        # if an employee amount is not included in file
                        # decrease the array count.
                        LET larr = larr - 1
                     END IF
                  ELSE                                          
                     LET mr_data.code_amt[larr].title = lDedTitle CLIPPED
                     LET mr_data.code_amt[larr].amt = lSumAmt
                  END IF                                        
               END IF                                           

               IF lplType = 'T' OR  lplType = 'U'  THEN     

                  # only include employer data if site has      
                  # a fincustom record and fringe amount is > zero
                  IF mHasZERO_403_AMOUNT THEN
                     IF lSumFringe > 0 THEN
                       LET larr = larr + 1
                       LET mr_data.code_amt[larr].title = lDedTitle CLIPPED," ER"
                       LET mr_data.code_amt[larr].amt = lSumFringe
                     END IF
                  ELSE                                          
                     LET larr = larr + 1
                     LET mr_data.code_amt[larr].title = lDedTitle CLIPPED," ER"
                     LET mr_data.code_amt[larr].amt = lSumFringe
                  END IF                                        
               END IF                                        
               LET larr = larr + 1
               # Reset variables in case employee has
               # more than one qualifying deduction
               LET lSumAmt = 0
               LET lSumFringe = 0
            END IF
         END IF

         IF lManVoid = "V" AND lManVoid IS NOT NULL THEN
            LET lAmt = lAmt * -1
            LET lFringe = lFringe * -1
         END IF

         LET lSumAmt = lSumAmt + lAmt
         LET lSumFringe = lSumFringe + lFringe

         LET lOldDedCode = lDedCode
      END FOREACH   # c_check

      # assign the last deduction record to the work record
      # or assign the only deduction record to the work record
      SELECT title INTO lDedTitle FROM dedtable
      WHERE ded_cd = lDedCode

      LET lplType = plantype(lOldDedCode)                       

      # Always print the employee amount when
      # plan type is not T or U.
      IF lplType <> 'T' AND lplType <> 'U' THEN
         LET mr_data.code_amt[larr].title = lDedTitle CLIPPED
         LET mr_data.code_amt[larr].amt = lSumAmt
      ELSE
         # Plan is either T or U
         # only include employee data if site has
         # a fincustom record and deduct amount is > zero
         IF mHasZERO_403_AMOUNT THEN
            IF lSumAmt > 0 THEN
               LET mr_data.code_amt[larr].title = lDedTitle CLIPPED
               LET mr_data.code_amt[larr].amt = lSumAmt
            ELSE
               # An employee amount is always assumed to be
               # included and the array is always increased.
               # if an employee amount is not included in file
               # decrease the array count.
               LET larr = larr - 1
            END IF
         ELSE                                                   
            LET mr_data.code_amt[larr].title = lDedTitle CLIPPED
            LET mr_data.code_amt[larr].amt = lSumAmt
         END IF                                                 
      END IF                                                    

           

      IF lplType = 'T' OR lplType = 'U'  THEN
         # only include employee data if site has               
         # a fincustom record and fringe amount is > zero
         IF mHasZERO_403_AMOUNT THEN                        
            IF lSumFringe > 0 THEN
               LET larr = larr + 1
               LET mr_data.code_amt[larr].title = lDedTitle CLIPPED," ER"
               LET mr_data.code_amt[larr].amt = lSumFringe
            END IF
         ELSE                                                   
            LET larr = larr + 1
            LET mr_data.code_amt[larr].title = lDedTitle CLIPPED," ER"
            LET mr_data.code_amt[larr].amt = lSumFringe
         END IF                                                 
      END IF                                        

      # Send the values to report before next employee
      OUTPUT TO REPORT tsa_remit('2')   #do detail record

   END FOREACH  # c_empl

   FINISH REPORT tsa_remit
   CALL libProgressBarFinish(TRUE)

   ERROR "Processing completed"

   IF p_rpt_dest = "t" THEN
      LET run_str = "sh -c \"$menx/use_132.sh ", p_rpt_name CLIPPED,
                    " ", use_132_mode(),"\""
      CALL libReportFileToPDF(p_rpt_name,TRUE,TRUE,TRUE)
       RETURNING lProcStatus, lMessage
   END IF

END FUNCTION  # get_records

Continue reading...
 
Status
Not open for further replies.
Back
Top