MC Emperor
MC Emperor

Reputation: 23047

How are literals as arguments for a CALL statement handled?

I'm trying to pass a string literal as an argument for a CALL statement.

CALL "SOMEPROGRAM" USING "SomeStringLiteralArg"

I must define the argument as a linkage item in the called subprogram:

LINKAGE SECTION.
 77 SOME-STRING-ARGUMENT PIC X(20).

That works, but when I pass a string literal shorter than 20 characters, the runtime starts complaining:

Passed USING item (#1) smaller than corresponding LINKAGE item.

The given string literal must be 20 characters long. But there are reasons for me to pass a string literal as argument:

One of my questions is, or course: how can I pass a literal as an argument for a CALL statement? But, more importantly, the underlying question is: how are literals passed as argument for a CALL statement handled? For example, if I pass 9, is it interpreted as a string with the contents "9", or is it compile-time converted to an integer?


I'm running MicroFocus ACUCOBOL-GT 9.2.4 on Windows 10.

Upvotes: 1

Views: 549

Answers (2)

Carlos
Carlos

Reputation: 19

Pic x any length is supported by isCobol. isCobol support the compilation of acucobol sources.

I don't know if acucobol can support but, if so, you can define a string (java.lang.string) in the linkage section. This is also supported by isCobol.

working-storage section.
77 SOME-STRING-ARGUMENT PIC X(20).

linkage section.
77  this-string object reference j-string.

procedure dividion using this-string.
main.
    set some-string-argument to this-string.

Upvotes: -1

Simon Sobisch
Simon Sobisch

Reputation: 7297

Two questions here:

First - How should I pass alphanumeric literals:

For CALL some-cobol-prog USING "alphanumeric literal" COBOL 2002 added the following:

LINKAGE SECTION.
 01 SOME-STRING-ARGUMENT PIC X ANY LENGTH.

If your compiler doesn't support it you're bound to either pad the literal or use a variable.

Second - Is a numerical literal interpreted as alphanumeric:

All compilers I've seen convert it to an integer - how and most important what type exactly depends on the compiler used...

Upvotes: 6

Related Questions