Charles Barouch wrote:
Sanjeeb,
There are several problems with this and I strongly suggest you get some training. [AD] My company, Key Ally, does training[/AD]. However, in brief: Variables are only global within a program. Once you CALL SUB, you are in a new program and all variables in it are inherently unrelated to the variables in the calling program. To connect them you either need to use COMMON or to pass them. For example: if line 12 of MAIN said CALL SUB(REC) *and* SUB started with SUBROUTINE SUB(REC), then REC in MAIN and REC in SUB would be linked.

All of the above is correct, but there is another approach, (yeah, this is pick/u2/multi-value, there's *always* another approach.

See modified line 12, and then lines 16 through 27. If you embed the code, you don't have to pass the variables, plus you don't have the overhead of calling another external routine.

If you're going to re-use the code, then you probably want to code it as an external, in which case you need to pass it arguments as Charles said, if it's only for this routine, then you probably want to code it internally.


0001: CRT 'MAIN'
0002: OPEN 'INVENTORY.T' TO INEVNTORY ELSE STOP
0003: SENT = 'SSELECT INVENTORY.T BY ITEM_CODE'
0004: EXECUTE SENT
0005: EOF = 0
0006: LOOP
0007: READNEXT ITEM_CODE ELSE
0008: EOF = 1
0009: END
0010: UNTIL EOF DO
0011: READ  REC FROM INEVNTORY ,ITEM_CODE THEN
0012: GOSUB PRINT.LINE:
0013: END
0014: REPEAT
0015: STOP

0016: *
0017: PRINT.LINE:   ;*  Internal subroutine.
0018: CRT 'SUB'
0019: PRINTER ON
0020: PRINT "ITEM_CODE"  "L#16":REC<1>
0021: PRINT "DESCRIPTION"  "L#16": REC<2>
0022: PRINT "TYPE"  "L#16":REC<3>
0023: PRINTER OFF
0024: RETURN
0025: *  End of PRINT.LINE internal subroutine.
0026:
0027: END    ;*  For compiler.



--
Allen Egerton
aegerton at pobox dot com
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to