![]() |
![]() |
|
|
Fvstot, Fvttos(3fml)
Name
Fvstot(), Fvttos() - convert C structure to/from target record type
Synopsis
#include <stdio.h>
#include "fml.h"
long
Fvstot(char *cstruct, char *trecord, long treclen, char *viewname)
long
Fvttos(char *cstruct, char *trecord, char *viewname)
#include "fml32.h"
int
Fvstot32(char *cstruct, char *trecord, long treclen, char *viewname)
int
Fvttos32(char *cstruct, char *trecord, char *viewname)
int Fcodeset(char *translation_table)
Description
The Fvstot() function transfers data from a C structure to a target record type. The Fvttos() function transfers data from a target record to a C structure. trecord is a pointer to the target record. cstruct is a pointer to a C structure. viewname is a pointer to the name of a compiled view description. The VIEWDIR and VIEWFILES are used to find the directory and file containing the compiled view description.
Fvttos32() and Fvstot32() are used with 32-bit VIEWS.
To convert from an FML buffer to a target record, first call Fvftos() to convert the FML buffer to a C structure, and call Fvstot() to convert to a target record. To convert from a target record to an FML buffer, first call Fvttos() to convert to a C structure and then call Fvstof() to convert the structure to an FML buffer.
A thread in a multithreaded application may issue a call to Fvstot() or Fvttos() while running in any context state, including TPINVALIDCONTEXT.
Default Conversion-IBM/370
The default target is IBM/370 COBOL records. The default data conversion is done based on the following table.
No filler bytes are provided between fields in the IBM/370 record. The COBOL SYNC clause should not be specified for any data items that are a part of the structure corresponding to the view.
An integer field is converted to either a four or two-byte integer depending on the size of integers on the machine on which the conversion is done.
A string field in the view must be terminated with a null when converting to/from the IBM/370 format.
The data in a carray field is passed unchanged; no data translation is performed.
Packed decimals exist in the IBM/370 environment as two decimal digits packed into one byte with the low-order half byte used to store the sign. The length of a packed decimal may be 1 to 16 bytes with storage available for 1 to 31 digits and a sign.
Packed decimals are supported in C structures using the dec_t field type. The dec_t field has a defined size consisting of two numbers separated by a comma. The number to the left of the comma is the total number of bytes that the decimal occupies. The number to the right is the number of digits to the right of the decimal point. The formula for conversion is:
dec_t(m, n) => S9(2*m-(n+1))V9(n)COMP-3
Decimal values may be converted to and from other data types (for example, int, long, string, double, and float) using the functions described in decimal().
The following table provides the hex values for default character conversion of ASCII (on the left) to/from EBCDIC (on the right).
| 00 00 |01 01 |02 02 |03 03 |04 37 |05 2d |06 2e |07 2f |
| 08 16 |09 05 |0a 25 |0b 0b |0c 0c |0d 0d |0e 0e |0f 0f |
| 10 10 |11 11 |12 12 |13 13 |14 3c |15 3d |16 32 |17 26 |
| 18 18 |19 19 |1a 3f |1b 27 |1c 1c |1d 1d |1e 1e |1f 1f |
| 20 40 |21 5a |22 7f |23 7b |24 5b |25 6c |26 50 |27 7d |
| 28 4d |29 5d |2a 5c |2b 4e |2c 6b |2d 60 |2e 4b |2f 61 |
| 30 f0 |31 f1 |32 f2 |33 f3 |34 f4 |35 f5 |36 f6 |37 f7 |
| 38 f8 |39 f9 |3a 7a |3b 5e |3c 4c |3d 7e |3e 6e |3f 6f |
| 40 7c |41 c1 |42 c2 |43 c3 |44 c4 |45 c5 |46 c6 |47 c7 |
| 48 c8 |49 c9 |4a d1 |4b d2 |4c d3 |4d d4 |4e d5 |4f d6 |
| 50 d7 |51 d8 |52 d9 |53 e2 |54 e3 |55 e4 |56 e5 |57 e6 |
| 58 e7 |59 e8 |5a e9 |5b ad |5c e0 |5d bd |5e 5f |5f 6d |
| 60 79 |61 81 |62 82 |63 83 |64 84 |65 85 |66 86 |67 87 |
| 68 88 |69 89 |6a 91 |6b 92 |6c 93 |6d 94 |6e 95 |6f 96 |
| 70 97 |71 98 |72 99 |73 a2 |74 a3 |75 a4 |76 a5 |77 a6 |
| 78 a7 |79 a8 |7a a9 |7b c0 |7c 6a |7d d0 |7e a1 |7f 07 |
| 80 20 |81 21 |82 22 |83 23 |84 24 |85 15 |86 06 |87 17 |
| 88 28 |89 29 |8a 2a |8b 2b |8c 2c |8d 09 |8e 0a |8f 1b |
| 90 30 |91 31 |92 1a |93 33 |94 34 |95 35 |96 36 |97 08 |
| 98 38 |99 39 |9a 3a |9b 3b |9c 04 |9d 14 |9e 3e |9f e1 |
| a0 41 |a1 42 |a2 43 |a3 44 |a4 45 |a5 46 |a6 47 |a7 48 |
| a8 49 |a9 51 |aa 52 |ab 53 |ac 54 |ad 55 |ae 56 |af 57 |
| b0 58 |b1 59 |b2 62 |b3 63 |b4 64 |b5 65 |b6 66 |b7 67 |
| b8 68 |b9 69 |ba 70 |bb 71 |bc 72 |bd 73 |be 74 |bf 75 |
| c0 76 |c1 77 |c2 78 |c3 80 |c4 8a |c5 8b |c6 8c |c7 8d |
| c8 8e |c9 8f |ca 90 |cb 9a |cc 9b |cd 9c |ce 9d |cf 9e |
| d0 9f |d1 a0 |d2 aa |d3 ab |d4 ac |d5 4a |d6 ae |d7 af |
| d8 b0 |d9 b1 |da b2 |db b3 |dc b4 |dd b5 |de b6 |df b7 |
| e0 b8 |e1 b9 |e2 ba |e3 bb |e4 bc |e5 4f |e6 be |e7 bf |
| e8 ca |e9 cb |ea cc |eb cd |ec ce |ed cf |ee da |ef db |
| f0 dc |f1 dd |f2 de |f3 df |f4 ea |f5 eb |f6 ec |f7 ed |
| f8 ee |f9 ef |fa fa |fb fb |fc fc |fd fd |fe fe |ff ff |
An alternate character translation table can be used at run-time by calling Fcodeset(). The translation_table must point to 512 bytes of binary data. The first 256 bytes of data are interpreted as the ASCII to EBCDIC translation table. The second 256 bytes of data are intrepreted as the EBCDIC to ASCII table. Any data after the 512th byte is ignored. If the pointer is NULL, the default translation is used.
Return Values
On success, Fvstot() returns the length of the target record and Fvttos() returns the length of the C structure.
These functions return -1 on error and set Ferror to indicate the error condition.
Errors
Under the following conditions, Fvttos() fails and sets Ferror to:
One of the arguments to the function invoked was invalid (for example, specifying a NULL trecord or cstruct parameter to Fvttos()). This error is also returned if a value is out of range when converting to or from a target record.
An Associated Count Member cannot be a negative value.
viewname was not found in the files specified by VIEWDIR or VIEWFILES.
The target record is not large enough to hold the converted structure.
While trying to find viewname, the program failed to find one of the files specified by VIEWDIR or VIEWFILES.
While trying to find viewname, the program failed to open one of the files specified by VIEWDIR or VIEWFILES for reading.
While trying to find viewname, one of the files specified by VIEWDIR or VIEWFILES was corrupted or not a view file.
While trying to find viewname, malloc() failed while allocating space to hold the view information.
Example
VIEW test.v
VIEW test
#type cname fbname count flag size null
float float1 FLOAT1 1 - - 0.0
double double1 DOUBLE1 1 - - 0.0
long long1 LONG1 1 - - 0
short short1 SHORT1 1 - - 0
int int1 INT1 1 - - 0
dec_t dec1 DEC1 1 - 4,2 0
char char1 CHAR1 1 - - ''
string string1 STRING1 1 - 20 ''
carray carray1 CARRAY1 1 - 20 ''
END
Equivalent COBOL Record
02 OUTPUT-REC.
05 FLOAT1 USAGE IS COMP-1.
05 DOUBLE1 USAGE IS COMP-2.
05 LONG1 PIC S9(9) USAGE IS COMP.
05 SHORT1 PIC S9(4) USAGE IS COMP.
05 INT1 PIC S9(9) USAGE IS COMP.
05 DEC1 PIC S9(5)V9(2) COMP-3.
05 CHAR1 PIC X(01).
05 STRING1 PIC X(20).
05 CARRAY1 PIC X(20).
C Program
#include "test.h"
#include "decimal.h"
main()
{
struct test s1;
char data[100];
s1.float1 = 1.0;
s1.double1 = 2.0;
s1.long1 = 3;
s1.short1 = 4;
s1.int1 = 5;
deccvdbl(6.0,s1.dec1);
s1.char1 = '7';
(void) strcpy(s1.string1, "eight");
(void) strcpy(s1.carray1, "nine");
if (Fvstot((char *)&s1, data, reclen, "test") == -1) {
printf("Fvstot failed: %sn", Fstrerror(Ferror));
exit(0);
}
/* transfer to target machine and get response */
...
/* translate back */
if (Fvttos(data, (char *)&s1, "test") == -1) {
printf("Fvttos failed: %sn", Fstrerror(Ferror));
exit(0);
}
/* use the structure */
.....
exit(0);
}
See Also
Introduction to FML Functions, Fvftos, Fvftos32(3fml), Fvstof, Fvstof32(3fml), viewfile(5)
decimal(3) in a UNIX system reference manual
![]() |
![]() |
![]() |
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|