CALL

How to:

Use the CALL command when you need one procedure to call another. When you use CALL, both the calling and called procedures communicate using variables. Local variables that you pass between them and the global transaction variables FocError, FocErrorRow, and FocCurrent. CALL allows you to link modular procedures, so each procedure can perform its own set of discrete operations within the context of your application. Since called procedures can reside on different servers, you can physically partition applications across different platforms.

Syntax: How to Use the CALL Command

The syntax of the CALL command is:

CALL procedure [KEEP|DROP] [PATH {VAR|LIST}] [FROM var_list]
   [INTO var_list] [;]
   var_list: {variable} [{variable} ...]

where:

procedure

Is the name of the Maintain Data procedure to run.

KEEP|DROP

The DROP parameter terminates the server session. The KEEP parameter leaves the server session active for reuse by subsequent calls. KEEP is the default value.

PATH

Is used to specify additional locations (search paths) the system should use when searching for dependent resources (Master Files, imported modules, and others). The path location names are application names existing within the APPROOT directory structure or application names that have been introduced with the APP MAP command. The search path value can be in the form of a Maintain Data variable or a list of literal values enclosed in double quotation marks ("), as follows:

CALL Procedure PATH "AppDir1 AppDir2 AppDir3" ;
CALL Procedure PATH MyVariable ;

FROM

Is included if the Maintain Data procedure passes one or more variables to the called procedure.

INTO

Is included if the called Maintain Data procedure passes one or more variables back to this procedure.

var_list

Are the scalar variables and stacks that are passed to or from this procedure. Multiple variables are separated by blank spaces.

variable

Is the name of a scalar variable or stack. You can pass any variable except for those defined as variable-length character (that is, those defined as A0 or TX) and those defined using STACK OF.

;

Terminates the command. Although the semicolon is optional, it is recommended that you include it to allow for flexible syntax and better processing. For more information about the benefits of including the semicolon, see Terminating a Command's Syntax.

Example: Calling Procedures to Validate Data

The following example shows three Maintain Data procedures. The first displays a form to collect employee IDs and salaries. It then calls Validate to make sure that the salaries are in a range. If they are all valid, it calls PutData and includes them in the data source. If not, it sets FocError to the invalid row and redisplays the data.

MAINTAIN FILE EMPLOYEE
INFER EMP_ID CURR_SAL INTO EMPSTACK;
Winform Show EMPL;
 
CASE VALIDATE_DATA
CALL VALIDATE FROM EMPSTACK;
IF FOCERROR EQ 0 THEN BEGIN
   CALL PUTDATA FROM EMPSTACK;
   TYPE "DATA ACCEPTED";
ENDBEGIN
 
ELSE BEGIN
   TYPE "THERE WAS AN ERROR IN ROW <FOCERROR";
   TYPE "TRY AGAIN";
ENDBEGIN
ENDCASE
END

The Validate procedure contains:

MAINTAIN FILE EMPLOYEE FROM EMPSTACK
INFER EMP_ID INTO EMPSTACK;
COMPUTE CNT/I4=1;
REPEAT EMPSTACK.FOCCOUNT;
  IF EMPSTACK(CNT).CURR_SAL GT 100000 THEN BEGIN
     COMPUTE FOCERROR=CNT;
     GOTO EXITREPEAT;
  ENDBEGIN
  ELSE COMPUTE CNT=CNT+1;
ENDREPEAT
END

The PutData procedure, residing on a remote Reporting Server, contains:

MAINTAIN FILE EMPLOYEE FROM EMPSTACK
INFER EMP_ID INTO EMPSTACK;
FOR ALL INCLUDE EMP_ID CURR_SAL FROM EMPSTACK;
END

Example: Calling Procedures to Populate Stacks

The following example shows all of the models and body types for the displayed country and car. The first calls GETCARS to populate the stack containing Country and Car. Maintain Data then calls GETMODEL to populate the other stack with the proper information. Each time a new Country and Car combination is introduced, Maintain Data calls GETMODEL to repopulate the stack.

MAINTAIN FILE CAR
INFER COUNTRY CAR INTO CARSTK;
INFER COUNTRY CAR MODEL BODYTYPE INTO DETSTK;
CALL GETCARS INTO CARSTK;
PERFORM GET_DETAIL;
Winform Show CARFORM;
 
CASE GET_DETAIL
CALL GETMODEL FROM CARSTK INTO DETSTK;
ENDCASE
 
CASE NEXTCAR
IF CARSTK.FOCINDEX LT CARSTK.FOCCOUNT
   THEN COMPUTE CARSTK.FOCINDEX= CARSTK.FOCINDEX +1;
   ELSE COMPUTE CARSTK.FOCINDEX = 1;
PERFORM GET_DETAIL;
ENDCASE
 
CASE PREVCAR
IF CARSTK.FOCINDEX GT 1
   THEN COMPUTE CARSTK.FOCINDEX= CARSTK.FOCINDEX -1;
   ELSE COMPUTE CARSTK.FOCINDEX = CARSTK.FOCCOUNT;
PERFORM GET_DETAIL;
ENDCASE

The procedure GETCARS loads all Country and Car combinations into CARSTK.

MAINTAIN FILE CAR INTO CARSTK
FOR ALL NEXT COUNTRY CAR INTO CARSTK;
END

The procedure GETMODEL loads all model and body type combinations into CARSTK for displayed Country and Car combinations.

MAINTAIN FILE CAR FROM CARSTK INTO DETSTK
INFER COUNTRY CAR INTO CARSTK;
STACK CLEAR DETSTK;
REPOSITION COUNTRY;
FOR ALL NEXT COUNTRY CAR MODEL BODYTYPE INTO DETSTK
  WHERE COUNTRY EQ CARSTK(CARSTK.FOCINDEX).COUNTRY
    AND CAR     EQ CARSTK(CARSTK.FOCINDEX).CAR;
END