在进度10.2b中输入.i

时间:2013-07-02 18:08:33

标签: progress-4gl openedge

我正在输入需要转换为xml文件的文件,但我还想输入一个.i,其中包含用于创建xml的临时表的定义。分隔符也不起作用(我需要一种方法将变量转换为命令可以读取的内容)。谢谢!

define input  parameter pInputFile   as character no-undo.
define input  parameter pDelimiter   as character no-undo.
???define input  parameter pIncludeFile as character no-undo.???
define output parameter pOutputFile  as character no-undo init "/tmp/out..

/* start of .i */
define temp-table ttGeneric no-undo
  field cust_id  as integer
  field name     as character
  field address  as character
  field address2 as character
  field city     as character
  field state    as character
  field zip      as character
  field cust_key as character
index idx is primary cust_id.
/* end of .i */



input stream sImport from value(pInputFile) no-echo.
repeat:      
  create ttGeneric.
  import stream sImport delimiter pDelimiter ttGeneric.
 end.
input stream sImport close.

temp-table ttGeneric:write-xml("LONGCHAR", pOutputFile, yes).

可能在调用程序中设置预处理器(一些如何)。

1 个答案:

答案 0 :(得分:3)

IMPORT和EXPORT的分隔符必须是文字字符串。你不能使用变量,字段,参数或类似的东西。

我偶尔通过CASE声明解决了这个问题。即:

case pDelimiter:
  when "," then import stream sImport delimiter "," ttGeneric.
  when "|" then import stream sImport delimiter "|" ttGeneric.
end.

难看。但它确实有效。

我想您可能想说要传递包含TT定义的包含文件的名称?并以某种方式将该定义与临时表相关联?

如果这或多或少是正确的,那么你可能对你的要求过于具体了 - 你可能真的只想动态创建一个TT,其定义在程序外部并且在编译时是未知的。

这样做的一种方法是使用read-xmlschema()方法 - 你已经使用了write-xml()所以这只是一小步...首先将你的.i转换成一个.p就像这样:

define temp-table ttGeneric no-undo
  field cust_id  as integer
  field name     as character
  field address  as character
  field address2 as character
  field city     as character
  field state    as character
  field zip      as character
  field cust_key as character
index idx is primary cust_id.

buffer ttGeneric:write-xmlschema( "file", "ttgeneric.xsd", true, ?, ?, ? ).

return.

(这个小存根允许你创建.XSD文件。它没有任何其他用途。只需运行一次即可获得该文件。)

然后当你想使用那个临时表时:

define variable tx as handle no-undo.

create temp-table tx.
tx:read-xmlschema( "ttgeneric.xsd", "file", ?, ?, ? ).

(注意:与分隔符不同,您可以为xsd名称使用变量和参数等,它可以在longchar而不是文件中......)

您将遇到的下一个冒险是找出适用于动态临时表的IMPORT的替代品。缓冲区句柄没有import()和export()方法:(

以下摘要可能有所帮助:

define variable dummy as character no-undo extent 128.
...
dummy = ?.
import dummy.
...
do i = 1 to 128:
  if dummy[i] = ? then leave.
  tx:buffer-field( i ):buffer-value() = dummy[i].
end.