4.3 Handling of String Parameters

When handling string parameters in the COBOL interface you have to note that the DM is internally written in C! Unfortunately, these two programming languages have a very different internal representation of strings.

 

C

COBOL

Length

dynamic, any length

statically defined length

Terminator

'\0'

none

Fill grade

length

length is different to

 

usually corresponds to the string

definition - usually filled up with blanks

To bring these two different representations of strings together, there are the following procedures in DM when handling string parameters:

  1. On the initialization call to the DM with DMcob_Initialize, the DM can be given three values that navigate the string handling:

    1. DM-setsep of DM-StdArgs

      The included character is the character with the help of which the COBOL program terminates its real strings. The DM searches for these characters and deletes all following characters in the transferred string.

    2. DM-getsep of DM-StdArgs

      The included character is the character with the help of which the DM fills up the strings up to their definition length before they are transferred to the COBOL program.

    3. DM-truncspaces of DM-StdArgs

      With this parameter you can tell the DM that all blanks at the end of a string can be regarded as non-existent and thus be deleted.

    These settings with DMcob_Initialize are valid for all functions directly called by the DM and their return values respectively.

  2. These values can be re-defined locally and temporarily at all calls to the DM-interface functions. As described under 1, there are three possibilities:

    1. DM-setsep of DM-StdArgs

    2. DM-getsep of DM-StdArgs

    3. DM-truncspaces of DM-StdArgs

    Meaning see above, 1.

The following occupation is useful:

DM-SetSep @

DM-GetSep " "

DM-truncspaces 1

With this specification, the respective values can be directly processed by the COBOL program and in the DM.

Example

In the dialog an input field is defined with a length which is limited to a length of 20 by the attribute .maxchars. The COBOL function which is to check this input, is assigned a string parameter of length 20.

function cobol void TestFkt (string[20] InString input output);

 

edittext EtEingabe

{

  .maxchars 20;

}

The following table shows the influence of the single elements on the transfer of strings before and after COBOL.

Dialog

COBOL

 

DM-GetSep Space

Result

AB in the input field

AB is filled up with 18 blank spaces

AB + 18 blank spaces

In the COBOL program this string will then be processed and a new content will be set in the string.

COBOL

Dialog

Command

Contents of String

DM-TruncSpaces 1

Result

MOVE "NEW" TO InString

NEW + 17 blank spaces

NEW

NEW