Db2 Tools for z/OS

 View Only

Converting a REXX proc to a JavaScript Proc

By shawn sullivan posted Tue November 16, 2021 08:33 AM

  

Converting a QMF for TSO  REXX proc to a JavaScript proc.
There is no REXX for the Web and Open Object REXX does not behave the same as REXX on TSO, so to run procs with logic, QMF supports JavaScript.

1) Very IMPORTANT: WHEN CONVERTING A REXX PROC TO A JAVASCRIPT PROC,

COPY THE REXX PROC INTO A NEW PROC WINDOW. SAVE THE NEW PROC WITH A NAME CONTAINING JS LIKE THIS
PROC10_P  becomes PROC10JS_P.  

There still will be people running the REXX PROCs so do NOT overwrite the original REXX PROC.

 

2) The REXX proc in QMF for TSO must begin with a Comment, usually containing the word REXX as the first line in the Proc.

A JavaScript proc MUST start with this string     /*JavaScript*/

Change the top line in the proc to /*JavaScript*/

 

3)  In a REXX proc the QMF commands are enclosed in double quotes like this:

"DISPLAY TABLE Q.STAFF"

In a JavaScript proc the QMF commands are enclosed in single quotes and are inside a function called proc.exec like this:

proc.exec(' DISPLAY TABLE Q.STAFF’ );

NOTE all lines in the main proc MUST end with a semi-colon (except comments)

I suggest that you use the QMF for Workstation Edit>Find and replace to first replace the FRONT double quote

DO NOT USE REPLACE ALL. That would also replace the ending quotes.

 Click the Find button to find the first doble quote.

Click Replace.

Click Find TWICE to get to the next beginning quote.

 

 

4) Subroutines to Functions.

Functions may not return generated values to the main body of the program. If you have initialization commands that generate dates, times, or other values you should NOT  put them in a function like this

 

/*JavaScript*/

 

Assign();

 

proc.messageBox(a);

 

function Assign()

{

var a = 1 ;

var b = 2;

var c = 3 ;

 

return;

 

}

 

The contents of the initialization function should be in the main body of the script like this.

Note message boxes are for development purposes. When the proc is ready for production,

 

/*JavaScript*/

 

var a = 1;

var b = 2;

var c = 3;

 

proc.messageBox(a);

proc.messageBox(b);

proc.messageBox(c);

 

 

 

The FORMAT of the JavaScript function is

 

  function <Function Name> () >

{                                                       /* open bracket is required. No semi-colon follows either of these lines*/

     <Function lines of code. These MUST end in a semi-colon.>

     <Function lines of code. These MUST end in a semi-colon.>

     <Function lines of code. These MUST end in a semi-colon.>

    return;      

}                                                     /* close bracket is required. No semi-colon follows either of these lines*/

 

 

 

 

 

 

For Example:

 

function Update()

{

   proc.exec('RUN PROC PROD.UPDATE_PROD');             

 proc.exec('RUN PROC PROD.INIT_TABLE'); 

 proc.exec('RUN PROC PROD.INSERT_DATA');

 proc.exec('SET GLOBAL(PROC_NAME=" ")');

 proc.exec('RUN QUERY PROD.DELETE_ERROR_TABLE_Q');

return;

}

 

Note in REXX the Set Global command would be like this

"SET GLOBAL(PROC_NAME=(' '     ))"

In a JavaScript proc it is like this

proc.exec('SET GLOBAL(PROC_NAME=" ")');

 

 

5) Calling Subroutines vs  calling functions

 

In REXX a subroutine is called like this

CALL UPDATE

 

In JavaScript the function is called this way

Update();

 

Note the parentheses and the semi-colon.

 

 

6) IF statements

In REXX an IF statement is like this

IF     day_of_month = '05' THEN CALL SUBRTNE5A

 

In JavaScript it is written this way

 

if (day_of_month == '05')  {FNCT5A()};

 

7) The ‘equals sign’ symbol

 

In REXX an  =  symbol is used to both assign a value to a variable and to compare two values as in the example above.

In JavaScript a single = symbol is used to assign a value

 

 var a = 10;

 

A double == symbol is used to compare two values

 

if (day_of_month == '05')  {FNCT5A()};

 

8) Iteration

In REXX to perform iteration you use a DO statement

 

DO I = 1 TO 10                                                      

   "RUN QUERY XFER_GETINFO_Q (&&DEPT="DEPT.I                             

   "BOTTOM"                                                             

   "GET GLOBAL ("NUMROWS"=DSQAO_NUM_FETCHED"                            

END     

     

In JavaScript to perform iteration you use a WHILE statement

 

while (j < 10){

     

   proc.exec('RUN QUERY XFER_GETINFO_Q (&&DEPT=DEPT.I ');                            

   proc.exec('BOTTOM');                                                             

   proc.exec('GET GLOBAL ("NUMROWS"=DSQAO_NUM_FETCHED');

j=++j;

      }

 

NOTE the opening and closing brackets with no semi-colon. {    }

 

 

9)  How do you find a list of your REXX procs              

 

This query from QMF for Workstation will give you a list of your REXX procs  

       

SELECT NAME, OWNER,CAST(A.APPLDATA AS VARCHAR(32000) CCSID 37) as TEXT

FROM Q.OBJECT_DATA A

WHERE TYPE = 'PROC' AND

POSSTR(CAST(A.APPLDATA AS VARCHAR(32000) CCSID 37),'REXX') > 0                       

10)  For other tasks you may refer to online references like https://www.w3schools.com/js/    or contact me at shawn.sullivan@rocketsoftware.com




#Db2Toolsforz/OS
#Db2QMF
#QMF
0 comments
12 views

Permalink