Problems with calling Procedural Cobol from Java in VC Eclipse and the use of the RM/COBOL File handler

[Migrated content. Thread originally posted on 26 January 2012]

Hello,

I have this code (from the Microfocus documentation) to test


program-id. StringAdd.
thread-local-storage section.
copy "javatypes.cpy".
01 lsNewPtr pointer.
01 lsSize jint. *> type defined in javatypes.cpy
01 i jint.
01 lsStatus jint.
01 lsBigBuffer pic x(1024).
linkage section.
01 lnkJString mf-jstring.
01 lnkJStringBuffer mf-jstring.
01 lnkString pic x(256).
01 lnkStringbuffer pic x(256).

procedure division using lnkJString lnkJStringBuffer.

           set address of lnkStringBuffer to
                              ptr2string of lnkJStringBuffer.
           set address of lnkString to ptr2string of lnkJString
      *>Check that lnkJStringBuffer is a Java StringBuffer
           if capacity of lnkJStringBuffer > 0
             add len of lnkJString to len of lnkJStringBuffer
                    giving lsSize
      *>Check we don't overflow concatenation buffer
             if lsSize
               move len of lnkJString to i
               move lnkString(1:i) to lsBigBuffer
               add 1 to i
               move lnkStringBuffer to lsBigBuffer(i:lsSize)
               set ptr2string of lnkJStringBuffer
                                 to address of lsBigBuffer
               move lsSize to len of lnkJStringBuffer
             end-if
           end-if.



import mfcobol.*;
public class StringsToCobol {
public static void main(String[] args) throws Exception {
   StringBuffer sb1 = new StringBuffer("ginger") ;
   Object theParams[] = {"fred" , sb1} ;
   RuntimeSystem.cobcall_int("stringadd", theParams) ;
   System.out.println(sb1) ;
}
}


This works correctly. This display “fredginger”.

We have to work with RM/COBOL file handler, so we use the next compiler directives in the Cobol Program :

SHOW-DIR
CALLFH(ACUFH)
RM "GIVING"
RM "ANSI"
PERFORM-TYPE"RM"


But then the programs don’t work. The Java program display “ginger”.

Where can be the problem?


Thank you

  • Verified Answer

    I just found the solution ...



         ...
         SPECIAL-NAMES.
               CALL-CONVENTION 0 IS VisualCobolCall       
               DECIMAL-POINT IS COMMA.
         ....
         PROCEDURE DIVISION VisualCobolCall
                           using lnkJString lnkJStringBuffer.
         ...
  • Verified Answer

    I just found the solution ...



         ...
         SPECIAL-NAMES.
               CALL-CONVENTION 0 IS VisualCobolCall       
               DECIMAL-POINT IS COMMA.
         ....
         PROCEDURE DIVISION VisualCobolCall
                           using lnkJString lnkJStringBuffer.
         ...
  • Verified Answer

    I just found the solution ...



         ...
         SPECIAL-NAMES.
               CALL-CONVENTION 0 IS VisualCobolCall       
               DECIMAL-POINT IS COMMA.
         ....
         PROCEDURE DIVISION VisualCobolCall
                           using lnkJString lnkJStringBuffer.
         ...