Question

I am missing something. Please can someone tell me how this works?

 let rpt.chgkey = null
  select cuschage.chgkey from cuschage where cuschage.cuschnum in
     (select shtwrd_no from crbookid where  
         crbookid.book_no = rpt.book_no and crbookid.line_no <= 3)

    let scratch = rpt.chgkey
    call make_charge_section(scratch) returning rpt.chgkey
 if rpt.chgkey is not null then
    print
    column 1, ESC, "(s0p12h0s3b4099T", ESC, "&a0.5R"
    print
    column 70, rpt.chgkey using "<<<<<<<<<"
end if
Was it helpful?

Solution

Hmmm...that SELECT statement is close to pointless. You normally* execute a SELECT statement to get data into variables, but there is no INTO clause to put the returned value into.

Given that the SELECT does nothing with rpt.chgkey, the value in scratch is NULL. The function make_charge_section is called with this value (NULL), and the result is saved in rpt.chgkey; the CALL is equivalent to:

LET rpt.chgkey = make_charge_section(scratch)

or you can do without the scratch variable and write:

LET rpt.chgkey = make_charge_section(rpt.chgkey)

(and you can do that with the CALL notation too).

Thereafter, you display some weird control sequence to your terminal — I'm not going to try and work out which terminal or what it does; are you sure you can't achieve the same effect with I4GL itself? And then you display the new (non-null) value of rpt.chgkey.

So, the big unknowns here are 'why is the SELECT statement written without an INTO clause', and 'what does make_charge_section() do when given a NULL value as input'?


* The 'abnormal' uses of a SELECT without INTO would depend on you detecting errors in the SQL. How that happens depends on what you've got the WHENEVER ERROR setting set to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top