Week number

140 pts.
Tags:
AS/400
CLP
I can't see a system value for the week number. Is it held somewhere else on the i5 system or does anyone have a CL program they've written and willing to share to calculate it ? Thanks.

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can use a BIF in embedded SQL in an HLL as follows (RPG):

C/EXEC SQL
C+ SELECT WEEK(MyDateField)
C+ INTO :WeekNum
C+ FROM MyTable
C+ WHERE {whatever}
C/END-EXEC

This will return an integer between 1-54 where Sunday is the first day of the week and 1/1/xx is always in the first week. The date field must be a date or timestamp data type, or a character string formatted correctly.

======================================================

If you don’t have the SQL Dev Kit, you still might be able to use the SQL CLI APIs to execute the SQL. Since that might be difficult for a CL programmer who isn’t proficient in RPG, COBOL or C (or if you simply don’t have the compilers available), you can always use REXX. The basic REXX for the above:<pre>
sql_Stmt = ,
‘select WEEK(CURRENT DATE)’,
‘ from sysibm/sysdummy1′

‘execsql ‘,
‘PREPARE S1 FROM :sql_Stmt ‘
‘execsql ‘,
‘DECLARE C1 CURSOR FOR S1′
‘execsql ‘,
‘OPEN C1 ‘

‘execsql ‘,
‘FETCH C1 INTO :WEEKNBR’

say RC ‘<‘WEEKNBR’>’

‘execsql ‘,
‘CLOSE C1′</pre>
WEEKNBR can be placed on the external REXX queue with the QUEUE statement and retrieved into CL with the QREXQ API. The REXX would be executed using STRREXPRC CMDENV(*EXECSQL) command environment. (Or the SQL statements can be directed individually to the *EXECSQL command environment.)

Every AS/400, iSeries and System i has REXX and REXX can always use SQL regardless of the presence of the SQL Dev Kit.

Tom

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following