Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to merge two tables into one... 2

Status
Not open for further replies.

C2GUICOBOL

Programmer
Mar 15, 2005
9
US
Hello,

can you please help me with this problem. I am trying to
combine two tables (structs) into one single table
(struct), so I can pass that incorporated table as a single
parameter when calling an API?
I am using micro focus NE 3.0 with windows 2k pro.

case in point:
01 Table1.
05 item1 pic xxx.
05 item2 pic xxx.
05 item3 pic xxx.
01 Table2.
05 sub1 pic xxx.
05 sub2 pic xxx.
05 sub3 pic xxx.

table1 and table2 must be passed as a single table by using
the "By Reference" clause.

call staticAPI "windowsAPI" using
by reference Table1
returning return-code
end-call.

thanks a bunch for the help.

 
Code:
01  table3.
    05  table1-D       pic x(9).
    05  table2-D       pic x(9).

MOVE TABLE1 TO TABLE1-D.
MOVE TABLE2 TO TABLE2-D.
CALL STATICAPI "WINDOWSAPI" USING BY REFERENCE TABLE3.
 
Hi Glenn9999,

thanks for the help. The items in table1 and table2 should
not be combined into a single item (member) --- each table
must keep all its items as an individual entity. Thanks.
 
The only other way to do what you're talking about (pass both tables as a single variable) is to subjugate them both under the same 01.

Code:
01  ALL-TABLES.
    05  TABLE1.
        10  ITEM1.
    05  TABLE2.
        10  ITEM1.
...
 
Hi Glenn9999,

I declared the master table as you have described above,
however, the API function returns a -1 error code. Is
there a way to declare the second table as a child of the
first table? The MSDN website saying that the first table
is a Header and the second table is a structure that must
follows and be aligned on a DWORD size boundry.
thanks for the efforts.
 
OK that changes things a bit then...

Alignment on a double word boundary means you need to stick some padding in between your tables on that definition so it lines up with some multiple of 4.

To use your example, you have two tables of 9 bytes. To align the second table on a word boundary, you need to stick three bytes in between them...

(1,2,3)(4,5,6)(7,8,9)-10,11,12-(1,2,3)(4,5,6)(7,8,9).

The 01 levels do align things on DW boundaries, the catch is you can only refer to one of them at a time...

The other thought I had was 77 levels, but I'm not sure you can stick those under 01 levels. Likely not.

Hope this helps.
 
Many/most compilers automatically align 01 levels on a double-word boundary (or feature switches/directives that cause it to do so). You may not have to change the original program. Simply make sure Table2 immediately follows Table1.

Another option to explore is whether the SYNC clause will help. Finally, you can explore using a 66 level if necessary to properly redefine the second table.

Regards.

Glenn
 
Yeah I didn't think about putting SYNC on the 2nd main table level. That would be better than what I suggested.

The only problem with using two 01s is that the COBOL compiler won't send both 01 levels to the API call...

I'd have to look up what a 66 level does before I can comment on that...
 
Glenn9999-

But the compiler doesn't NEED to send both 01 levels. The call requires simply a single address pointing to the appropriate memory. Of course COBOL can put each 01 level anywhere it chooses so there's technically no guarantee they'll follow each other in memory or occupy the same segment etc...but I think it'll work fine for most implementations.

As for the Level 66, forget it. It has to rename items in a single record (01 level) and not across records, so I was off base on that suggestion.

BTW, it would helpful if the poster would identify the specific Win32 API that he needs to use.

Glenn
 
Hi 3gm and Glenn9999,

I really appreciate you helping me with this problem.

the SYNC clause is only for the mainFrame compilers, it is
ignored on the PC though and treated as a comment. I have
used the approach that glenn9999 have recommended -- but it
did not help at all, the compiler is not Happy with the
fact that I am trying to merge these two tables. If I call
the win32 API function with the first table ONLY (header),
the function works like a charm, however, when I include
the second table to the bottom of the first table, I get
the error code -1 which means failed. The win32 API that
I am trying to call is: DialogBoxIndirectParam,
and the first table (header) is: DLGTEMPLATEEX
and the second table (array) is: DLGITEMTEMPLATEEX

thanks.
 
C2GUICOBOL -

I took a look at the definition of these structures. Getting them set up properly is a daunting task to say the least. Wish I had NE3.0; it would be a challenging little project.

Some comments:

1. You just need one 01 level. The contents of this 01 level will have to be filled out dynamically using reference modification or perhaps pointers (depending on your experience/preference and compiler features). Fill out the part that represents the DLGTEMPLATEEX "structure" and then follow it with the DLGTEMTEMPLATEEX structures as needed. E.g.:
Code:
01  DLGTEMPLATEEX.
    05  DLGVER            S9(4) BINARY.
    05  SIGNATURE         S9(4) BINARY.
    05  HELPID            S9(9) BINARY.
    05  EXSTYLE           S9(9) BINARY.
    05  CDLGITEMS         S9(4) BINARY.
    05  X                 COMP-1.
    05  Y                 COMP-1.
    05  CX                COMP-1.
    05  CY                COMP-1.
    05  DLG-REST          PIC X(5000).
...
MOVE LOW-VALUES TO DLGTEMPLATEEX
MOVE 1          TO DLGVER
MOVE -1         TO SIGNATURE
...
MOVE LOW-VALUES         TO DLG-REST(1:2)
MOVE ...
Note that there may be a better way of defining the WORD and DWORD variables in NE3.0 and I'm not sure that COMP-1 is the appropriate choice for a single-precision floating point. The choice of PIC x(5000) is arbitrary. Acquiring storage directly and using pointers may allow you to avoid that ugliness.

2. In several places you're required to use UNICODE strings; make sure you do.

Good luck!

Glenn

 
Hi Glen,

thanks for the kind help. I will try your approach and
see if I can get it to work. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top