HOW TO FORCE AN RPG DUMP
Occasionally, we all manage to write an RPG program with a bug or two.
Hopefully, we find the bugs before the programs make it into the
production environment. If we don't, no matter how unlikely the
sequence of events that exposes the bug, it's a certainty that a user
will discover it!
In such a case, an RPG formatted dump might help you determine the
problem. All too often, users respond to error messages without
requesting a dump. Fortunately, you can use RPG's Dump opcode to force
a dump when an error occurs by including it in your error handling
routine.
To demonstrate, consider the following code snippets that show
portions of a Program Exception/Error Subroutine (*PSSR).
Below is a pre-V5R1 technique demonstrating how to force a dump:
H Debug( *Yes 
D PSSRError 1N Inz( *Off 
C *PSSR BegSr
C If PSSRError
C Eval *InLR = *On
C Return
C EndIf
C Eval PSSRError = *On
C Dump
* Insert code to handle exception
C EndSr
Notice that there is an H-spec specifying Debug(*Yes). This is a
requirement when using the Dump opcode at releases earlier than V5R1.
V5R1 removes the need to specify Debug(*Yes) by adding the A extender
to the Dump opcode. With the A extender, the Dump opcode always
performs the dump, regardless of the Debug attribute. This means you
can remove the H-spec with the Debug keyword and simply add the A
extender to the Dump opcode.
Below is a V5R1 technique demonstrating how to force a dump:
D PSSRError 1N Inz( *Off 
C *PSSR BegSr
C If PSSRError
C Eval *InLR = *On
C Return
C EndIf
C Eval PSSRError = *On
C Dump(A)
* Insert code to handle exception
C EndSr
3. UPDATE: CORRECTION TO LAST ISSUE'S WEEK OF YEAR ROUTINE
In the last issue, I included a service program (Dates) with a
procedure (RtvWeekOfYear) for determining the ISO 8601 week of the
year. The service program failed to address the case where days late
in December may actually be in the first week of the subsequent year.
I've updated the program to handle this possibility and have included
it below.
Remember, the week number returned by procedure RtvWeekOfYear may not
be in the same calendar year as that specified in the date parameter.
There are two possible cases where this is true -- days in late
December may actually be in the first week of the subsequent year and
days in early January may actually be in week 52 or 53 of the prior
year.
Below is updated service program Dates:
* ==================================================================
* = Service program... Dates =
* = Description....... Date routines =
* = =
* = CrtRPGMod Module( Dates  =
* = CrtSrvPgm SrvPgm( Dates  Module( Dates  Export( *All  =
* ==================================================================
H NoMain
* ==================================================================
* = Prototypes =
* ==================================================================
* ------------------------------------------------------------------
* - RtvDayOfWeek Retrieve day of week -
* - -
* - Parameter Usage Type -
* - Date Input Date field -
* - Return data -
* - Day of week Return Integer (0=Monday, 1=Tuesday, etc.)-
* ------------------------------------------------------------------
D RtvDayOfWeek PR 5I 0
D D Value
* ------------------------------------------------------------------
* - RtvWeekOfYear Retrieve week of year -
* - -
* - Parameter Usage Type -
* - Date Input Date field -
* - Return data -
* - Week of year Return Integer -
* ------------------------------------------------------------------
D RtvWeekOfYear PR 5I 0
D D Value
* ==================================================================
* = Procedure..... RtvDayOfWeek =
* = Description... Retrieve day of week =
* ==================================================================
P RtvDayOfWeek B Export
D RtvDayOfWeek PI 5I 0
D DateIn D Value
* ------------------------------------------------------------------
* - Data definitions -
* ------------------------------------------------------------------
D BaseMonday S D Inz( D'2001-05-21' 
D NbrDays S 10I 0
* ------------------------------------------------------------------
* - Calculate and return day of week -
* ------------------------------------------------------------------
C DateIn SubDur BaseMonday NbrDays : *D
C Return ( %Rem( %Rem( NbrDays : 7  + 7 : 7  
P RtvDayOfWeek E
* ==================================================================
* = Procedure..... RtvWeekOfYear =
* = Description... Retrieve week of year =
* ==================================================================
P RtvWeekOfYear B Export
D RtvWeekOfYear PI 5I 0
D DateIn D Value
* ------------------------------------------------------------------
* - Data definitions -
* ------------------------------------------------------------------
D DS
D Jan4Date D Inz( D'0001-01-04' 
D Jan4Year 4S 0 Overlay( Jan4Date 
D MondayDate S D
D Jan4Day S 5I 0
D NbrOfDays S 10I 0
D SundayDate S D
D ISOWeek S 5I 0
* ------------------------------------------------------------------
* - Calculate date of the last day of the week (Sunday) for the -
* - target week and calculate the week number for that Sunday to -
* - derive the week number for the target date -
* ------------------------------------------------------------------
C Eval NbrOfDays = 6 - RtvDayOfWeek( DateIn 
C DateIn AddDur NbrOfDays:*D SundayDate
* ------------------------------------------------------------------
* - Set date to January 4 of the calculated year and use to derive -
* - the date of that year's first Monday -
* ------------------------------------------------------------------
C Extrct SundayDate:*Y Jan4Year
C Eval Jan4Day = RtvDayOfWeek( Jan4Date 
C Jan4Date SubDur Jan4Day:*D MondayDate
* ------------------------------------------------------------------
* - Calculate the week of the year and return the value -
* ------------------------------------------------------------------
C SundayDate SubDur MondayDate NbrOfDays:*D
C If NbrOfDays < 0
C Eval Jan4Year = Jan4Year - 1
C Eval Jan4Day = RtvDayOfWeek( Jan4Date 
C Jan4Date SubDur Jan4Day:*D MondayDate
C SundayDate SubDur MondayDate NbrOfDays:*D
C EndIf
C Eval ISOWeek = NbrOfDays/7
C If ISOWeek >= *Zero
C Eval ISOWeek = ISOWeek + 1
C Else
C Eval ISOWeek = 53
C EndIf
C Return ISOWeek
P RtvWeekOfYear E
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/