简体   繁体   English

IBM i(iSeries)观点脚本

[英]IBM i (iSeries) View Point Script

I am trying to take what is currently stored in ViewPoint as a Script that is run and convert it over to SQL and scheduled Tasks. 我试图将当前存储在ViewPoint中的内容作为运行的脚本,并将其转换为SQL和计划任务。 My issue is well simply put I don't know the scripting language used for I Series. 我的问题很简单,就是我不知道用于I系列的脚本语言。 Can anyone tell me what the resulting value will be for &STARTS &STARTS2 and &STARTS3 谁能告诉我&STARTS&STARTS2和&STARTS3的最终价值是什么

CHGVAR VAR(&OFFSET) VALUE(0)
CHGVAR VAR(&STARTS) VALUE(CYYMMDD(DATE(MONTH(Current Date- (&OFFSET + 1) Month)||'/22/'||YEAR(Current Date-(&OFFSET+1) month))))
CHGVAR VAR(&STARTS2) VALUE(CYYMMDD(DATE(MONTH(Current Date- (&OFFSET + 2) Month)||'/22/'||YEAR(Current Date-(&OFFSET+2) month))))
CHGVAR VAR(&STARTS3) VALUE(CYYMMDD(DATE(MONTH(Current Date- (&OFFSET + 3) Month)||'/22/'||YEAR(Current Date-(&OFFSET+3) month))))

One of the relatively nifty things about the iSeries is that it lets you do 'natural language' date math: current_date - 2 months is exactly what it sounds like, a date that is precisely two months before today. 关于iSeries的一个比较漂亮的事情是,它可以让您进行“自然语言”日期数学计算: current_date - 2 months听起来确实像是current_date - 2 months ,而这个日期恰好是今天的两个月。

So, assuming that it actually works as written, what this script is doing is: 因此,假设它实际上按书面形式工作,那么此脚本的作用是:

  • set the variable &OFFSET to 0. (the CHGVAR command is the iSeries's verbose way of assigning a value: in most languages you would write &OFFSET = 0 instead, and even with the iSeries you could shorten it to simply CHGVAR &OFFSET 0 .) 将变量&OFFSET设置为0。( CHGVAR命令是iSeries分配值的冗长方式:在大多数语言中,您将编写&OFFSET = 0来代替,即使使用iSeries,您也​​可以将其缩短为CHGVAR &OFFSET 0
  • set the variable &STARTS to the 22nd of last month, where the date is in the CYYMMDD format. 将变量&STARTS设置为上个月的22日,其中日期采用CYYMMDD格式。 (It does this by constructing the date based on "use the month that is one month before today, 22 as the day, and the year of the month that is one month before today", and then converting that to CYYMMDD format. (它的实现方式是根据“使用今天前一个月的月份,今天为22,以及今天前一个月的月份的年份”构造日期,然后将其转换为CYYMMDD格式。
  • sets the variable &STARTS2 to the 22nd of 2 months ago 将变量&STARTS2设置为2个月前的22日
  • sets the variable &STARTS3 to the 22nd of 3 months ago 将变量&STARTS3设置为3个月前的22日

If you were to tweak the value of &OFFSET (by changing its VALUE(0) assignment), your calculated dates would be that much further in the past: setting it to VALUE(4) would get you dates of 5, 6, and 7 months ago. 如果要调整&OFFSET的值(通过更改其VALUE(0)分配),则您计算的日期将比过去更远:将其设置为VALUE(4)将为您提供5、6和7的日期几个月前。

In the CYYMMDD format, by the way, the 'C' is a counter of centuries since 1900; 顺便说一下,在CYYMMDD格式中,“ C”自1900年以来就是一个世纪的计数器。 essentially, the date is an integer of the form YYYYMMDD - 19000000. So, 1/1/1999 = 19990101 in YYYYMMDD format, or 0990101 in CYYMMDD format; 因此,日期本质上是格式为YYYYMMDD-19000000的整数。因此,1/1/1999 = 19990101(采用YYYYMMDD格式)或0990101(采用CYYMMDD格式); 12/31/2011 = 20111231 in YYYYMMDD format, or 1111231 in CYYMMDD format. 2011年12月31日= 20111231为YYYYMMDD格式,或1112331为CYYMMDD格式。

So if you ran this today, 8/19/2015, you should get results of: 因此,如果您今天(2015年8月19日)执行此操作,则应获得以下结果:

  • &STARTS = 1150722 &STARTS = 1150722
  • &STARTS2 = 1150622 &STARTS2 = 1150622
  • &STARTS3 = 1150522 &STARTS3 = 1150522

By the way, the language your script is written in is called "CL" (short for "Command Language"), and the official language reference is at The IBM Knowledge Center . 顺便说一句,脚本的编写语言称为“ CL”(“命令语言”的简称),官方语言参考位于IBM知识中心

Can anyone tell me what the resulting value will be for &STARTS &STARTS2 and &STARTS3 谁能告诉我&STARTS&STARTS2和&STARTS3的最终价值是什么

TL;DR: The resulting values will be undefined since only the first CHGVAR command might compile. TL; DR:由于只有第一个CHGVAR命令可以编译,因此所得的值将是不确定的。 The others have many problems. 其他有很多问题。 As pseudocode, the statements are okay, but they will expand into a large body of code when expressed as actual CL statements. 作为伪代码,这些语句还可以,但是当表达为实际的CL语句时,它们将扩展为大量代码。

Details: 细节:

One underlying problem is thinking of CL as a "scripting language". 一个潜在的问题是将CL视为一种“脚本语言”。 While it certainly can be, and commonly is, used for "scripting", it is the system's "Control Language". 虽然肯定可以并且通常将其用于“脚本”,但它是系统的“控制语言”。 As far as "scripting" goes, it is just about as easy for a decent C programmer to replace CL with C as the "scripting" language. 就“脚本”而言,对于一个体面的C程序员来说,用C替换CL就像“脚本”语言一样简单。 Similarly, I've seen RPG developers who do much/most of their "scripting" in RPG. 同样,我见过RPG开发人员,他们在RPG中做很多/大部分的“脚本”工作。 Similarly for COBOL. 对于COBOL同样如此。

CL is also the system's "command language". CL也是系统的“命令语言”。 In currently supported versions of the OS, you can expect to find nearly 2000 commands. 在当前受支持的操作系统版本中,预计可以找到将近2000条命令。 Numerous system functions can only be done by command, or by invoking or calling a program that executes the command. 许多系统功能只能通过命令或通过调用或调用执行该命令的程序来完成。 Every native language can execute most commands interactively by passing the command string to one of the system's command processing APIs. 通过将命令字符串传递到系统的命令处理API之一,每种本地语言都可以交互地执行大多数命令。 Even CL, which is a compiled language, can execute commands interactively the same way other languages do. 即使是已编译的语言CL,也可以像其他语言一样交互式地执行命令。

Still, CL is compiled. 不过,CL已编译。 It also can fully participate as an ILE language, most especially beginning at the V5R4 version of the OS, but technically since ILE was first introduced in the AS/400 line. 它也可以作为ILE语言完全参与,尤其是从V5R4版本的OS开始,但是从I / O在AS / 400系列中首次引入以来,从技术上讲,它是可以的。

As an ILE participant, CL has full access to the same features other native languages have. 作为ILE参与者,CL可以完全访问其他母语所具有的相同功能。 For example, CL can use the C run-time library of functions. 例如,CL可以使用C运行时函数库。 So, in addition to native CL command capabilities, it can essentially do anything ILE RPG can do. 因此,除了本机CL命令功能外,它基本上可以执行ILE RPG可以执行的任何操作。 You can even compile CL *MODULEs and bind them together to create service programs (think Windows .DLLs or UNIX function libraries). 您甚至可以编译CL * MODULE并将它们绑定在一起以创建服务程序(请考虑Windows .DLL或UNIX函数库)。

But one thing CL does not have is a SQL pre-processor. 但是CL没有的一件事是SQL预处理器。

While there are a couple commands for executing interactive SQL statements, there is no facility for doing something like VALUES INTO or FETCHing from a cursor or getting results from a SQL function such as DATE(). 虽然有几个用于执行交互式SQL语句的命令,但没有进行VALUES INTO或从游标进行抓取或从SQL函数(如DATE())获取结果的功能。

Well. 好。 technically, I suppose we can say that it can be done because it is "ILE CL" after all. 从技术上讲,我想我们可以说可以做到,因为毕竟它是“ ILE CL”。 Because of that, CL can call the various SQL CLI APIs (think ODBC). 因此,CL可以调用各种SQL CLI API(例如ODBC)。 And because of that, you can program CL procedures with calls to SQLAllocEnv(), SQLAllocConnect(), SQLConnect(), SQLPrepare() and all the other functions that might be needed. 因此,您可以使用对SQLAllocEnv(),SQLAllocConnect(),SQLConnect(),SQLPrepare()和所有其他可能需要的函数的调用来编程CL过程。

But what you can't do in CL is anything like what you'd like to do in the VALUE() parameters of your last three CHGVAR commands. 但是您在CL中无法执行的操作与您在最后三个CHGVAR命令的VALUE()参数中执行的操作类似。 You could certainly code CL procedures to perform the date calculations and manipulations. 您当然可以对CL过程进行编码,以执行日期计算和操作。 Like others early on, I wrote various detailed date-math functions in CL (as well as other languages) before easy access was available to various date/time APIs. 像其他早期一样,在可以轻松访问各种日期/时间API之前,我用CL(以及其他语言)编写了各种详细的日期数学函数。 Then, with the APIs, most were replaced with more elegant ones. 然后,使用API​​,大多数都被更优雅的API所取代。

CL is arguably the most complex language on the system. 可以说CL是系统上最复杂的语言。 But it doesn't do SQL. 但是它不执行SQL。 At least not like C, RPG or COBOL can. 至少不像C,RPG或COBOL可以。 CL is intended as a "control" language, not a database nor an application language. CL旨在用作“控制”语言,而不是数据库或应用程序语言。

There is an alternative though. 不过,还有另一种选择。 There is a native "scripting" language that can run SQL -- REXX. 有一种本地的“脚本”语言可以运行SQL-REXX。 It would be far easier to use REXX to do this than CL. 使用REXX进行此操作要比CL容易得多。 Your VALUE() clauses could almost be lifted and pasted directly into an appropriate REXX procedure. 您的VALUE()子句几乎可以被提升并直接粘贴到适当的REXX过程中。 You could have a CL wrapper to invoke the procedure for each of your complex VALUE() parameters and to pull the result back from REXX. 您可能有一个CL包装器来为每个复杂的VALUE()参数调用该过程并将结果从REXX中拉回。 Or you could have REXX do all three at once. 或者,您可以让REXX一次完成所有这三个操作。

But if you want CL to do it all, there is a lot of coding yet to be done. 但是,如果您希望CL做到这一切,那么还有很多代码需要完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM