• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

如何取某一日期是一个星期中的哪一天

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 21次 | 进入软件测试论坛讨论

领测软件测试网
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/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网