我正在研究Ada-> COBOL接口,我想知道是否有任何方法可以将文件写入Cobol默认,而不需要编写cobol代码,因为我想使用Cobol的一些规则来编写文件,但想知道如何在Ada中直接执行此操作。
例如,要读取具有cobol结构的文件,我可以使用use that:
with Interfaces.COBOL;
with COBOL_Sequential_IO; -- Assumed to be supplied by implementation
procedure Test_External_Formats is
112
-- Using data created by a COBOL program
-- Assume that a COBOL program has created a sequential file with
-- the following record structure, and that we need to
-- process the records in an Ada program
-- 01 EMPLOYEE-RECORD
-- 05 NAME PIC X(20).
-- 05 SSN PIC X(9).
-- 05 SALARY PIC 99999V99 USAGE COMP.
-- 05 ADJUST PIC S999V999 SIGN LEADING SEPARATE.
-- The COMP data is binary (32 bits), high-order byte first
113
package COBOL renames Interfaces.COBOL;
114
type Salary_Type is delta 0.01 digits 7;
type Adjustments_Type is delta 0.001 digits 6;
115
type COBOL_Employee_Record_Type is -- External representation
record
Name : COBOL.Alphanumeric(1..20);
SSN : COBOL.Alphanumeric(1..9);
Salary : COBOL.Byte_Array(1..4);
Adjust : COBOL.Numeric(1..7); -- Sign and 6 digits
end record;
pragma Convention (COBOL, COBOL_Employee_Record_Type);
116
package COBOL_Employee_IO is
new COBOL_Sequential_IO(COBOL_Employee_Record_Type);
use COBOL_Employee_IO;
117
COBOL_File : File_Type;
118
type Ada_Employee_Record_Type is -- Internal representation
record
Name : String(1..20);
SSN : String(1..9);
Salary : Salary_Type;
Adjust : Adjustments_Type;
end record;
119
COBOL_Record : COBOL_Employee_Record_Type;
Ada_Record : Ada_Employee_Record_Type;
120
package Salary_Conversions is
new COBOL.Decimal_Conversions(Salary_Type);
use Salary_Conversions;
121
package Adjustments_Conversions is
new COBOL.Decimal_Conversions(Adjustments_Type);
use Adjustments_Conversions;
122
begin
Open (COBOL_File, Name => "Some_File");
123
loop
Read (COBOL_File, COBOL_Record);
124
Ada_Record.Name := To_Ada(COBOL_Record.Name);
Ada_Record.SSN := To_Ada(COBOL_Record.SSN);
Ada_Record.Salary :=
To_Decimal(COBOL_Record.Salary, COBOL.High_Order_First);
Ada_Record.Adjust :=
To_Decimal(COBOL_Record.Adjust, COBOL.Leading_Separate);
... -- Process Ada_Record
end loop;
exception
when End_Error => ...
end Test_External_Formats;Put,我不知道如何编写cobol结构的文件,在文档中,我找不到方法;http://www-users.cs.york.ac.uk/~andy/lrm95/b_04.htm
例如,如果我在Cobol中有这个结构(基于这个示例:http://www.csis.ul.ie/cobol/examples/Sort/MaleSort.htm;http://www.csis.ul.ie/cobol/examples/SeqIns/STUDENTS.DAT )
FILE SECTION.
FD StudentFile.
01 StudentRec PIC X(30).
88 EndOfFile VALUE HIGH-VALUES.
FD MaleStudentFile.
01 MaleStudentRec PIC X(30).
SD WorkFile.
01 WorkRec.
02 FILLER PIC 9(7).
02 WStudentName PIC X(10).
02 FILLER PIC X(12).
02 WGender PIC X.
88 MaleStudent VALUE "M".如何使用Cobol接口在Ada中编写程序来编写此结构?
发布于 2014-03-18 07:07:26
身体上的思考。也就是说,输出文件的格式是什么?在设计文件时,是否在Cobol或Ada中创建该文件并不是一个直接的问题。
让我们假设Cobol Workrec描述了文件的格式。你想写一个Ada程序来调用cobol子例程来物理地写文件吗?或者你想使用一个Cobol程序来写这个文件?或者你想要一个Ada程序来写一个smae格式的文件作为Workrec??您的选择取决于您的客户的要求。
https://stackoverflow.com/questions/22405343
复制相似问题