Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

IMPORT-VARIABLE Import variable

&pagelevel(4)&pagelevel

Domain: PROCEDURE

Command description

The IMPORT-VARIABLE command is used to import a previously declared variable into the called procedure. It is equivalent in many ways to DECLARE-VARIABLE, but eliminates the need to repeatedly list all assigned attributes.

Format

IMPORT-VARIABLE

VARIABLE-NAME = <structured-name 1..20 with-wild(40)> / list-poss(2000): <structured-name 1..20>

,FROM = *SCOPE(...)

*SCOPE(...)

SCOPE = *TASK / *CALLING-PROCEDURES

Operands

VARIABLE-NAME =
Name of a variable outside the procedure which is to be imported into the current procedure.

VARIABLE-NAME = <structured-name 1..20 with-wild(40)>
Name of a variable outside the procedure which is to be imported into the current procedure.
If the name contains wildcards, all variables are imported whose names match the search pattern specified. If a wildcard string matches no variable name, mesage SPD0519 is issued.

VARIABLE-NAME = list-poss(2000): <structured-name 1..20>
One or more names of variables which are to be imported into the current procedure. When specified as a list, the variables are imported in the specified order.

FROM= *SCOPE(...)
Specifies the scope of the variable to be imported.

SCOPE = *TASK
The search for the variable to be imported is carried out within the entire task.

SCOPE = *CALLING-PROCEDURES

The search for the variable to be imported is carried out within the called procedure. The variable must have been declared in the procedure with IMPORT-ALLOWED=*YES. The search starts in the called procedure and can be continued upwards to the first procedure (in the event of a background procedure) or to the dialog level (in the event of a foreground procedure).
(If the variable to be imported already exists in the procedure (i.e. is visible), no action is performed; in this case it is irrelevant whether the variable was declared with IMPORT-ALLOWED = *YES or *NO).

Command return codes

(SC2)

SC1

Maincode

Meaning


0CMD0001No error
10CMD0001Warning: element already declared
20SDP2000Warning: not all elements of the input list could be processed successfully.
Guaranteed message: SDP2000

1CMD0202Syntax error

3CMD2203Incorrect syntax file

32CMD0221System error (internal error)

64SDP0091Semantic error
Guaranteed messages: SDP1008, SDP1018

64SDP2001None of the elements could be imported

130SDP0099No further address space available

Examples

/DECLARE-VARIABLE VERBOSE-MODE(TYPE=*BOOLEAN, INITIAL-VALUE= YES),-
/                 SCOPE=*CURRENT(IMPORT-ALLOWED=*YES)
/LEVEL=1
/CALL-PROCEDURE MY-PROCEDURE
/           --->IMPORT-VARIABLE VERBOSE-MODE, -
/               FROM=*SCOPE(*CALLING-PROCEDURES)
/
/               LEVEL=2
/               IF (VERBOSE-MODE)
/                  WRITE-TEXT 'CURRENT PROCEDURE AT LEVEL &(LEVEL).'
/               END-IF
/           <---EXIT-PROCEDURE
/IF (VERBOSE-MODE)
/    WRITE-TEXT 'CURRENT PROCEDURE AT LEVEL &(LEVEL).'
/END-IF

The called procedure ’MY-PROCEDURE’ has access to the variable ’VERBOSE-MODE’ via the calling procedure as a result of using IMPORT-VARIABLE.
Each of the procedures has a local variable named 'LEVEL'.

See section “Scope of variables”.

/DECLARE-VARIABLE TVAR-1 (TYPE= *STRING, INIT-VAL='TV1')
/DECLARE-VARIABLE TVAR-2 (TYPE= *STRING, INIT-VAL='TV2')
/DECLARE-VARIABLE TVAR-3 (TYPE= *STRING, INIT-VAL='TV3')
/CALL-PROCEDURE IMPORT-TV-LIST ————————————————————————————————————————  (1) 
      --> /SET-PROCEDURE-OPTIONS
          /IMPORT-VARIABLE (TVAR-1, TVAR-2) -
          /      ,FROM=*SCOPE(SCOPE=*CALLING-PROCEDURE)
          /SHOW-VARIABLE
          /EXIT-PROCEDURE
TVAR-1 = TV1
TVAR-2 = TV2
*END-OF-CMD
/CALL-PROCEDURE IMPORT-TV-WILDCARD ————————————————————————————————————  (2) 
      --> /SET-PROCEDURE-OPTIONS
          /IMPORT-VARIABLE TVAR-<1,3> -
          /      ,FROM=*SCOPE(SCOPE=*CALLING-PROCEDURE)
          /SHOW-VARIABLE
          /EXIT-PROCEDURE
TVAR-1 = TV1
TVAR-3 = TV3
*END-OF-CMD

(1)

The IMPORT-TV-LIST procedure uses list specification to import the variables TVAR-1 and TVAR-2.

(2)

The IMPORT-TV-WILDCARD procedure uses wildcard specification to import the variables TVAR-1 and TVAR-3.