Linkage section

Hi , 

I have a Windows form from which i accept a number and on the button click event , i take that number and call cobol program to validate the input.

I am getting error while running the application "114     Attempt to access item beyond bounds of memory".

Windows event:

method-id btnSearch_Click final private.
local-storage section.
01 ws-error pic x.
01 ws-input pic x(08).
linkage section.
01 ws-link-data.
05 ws-link-ctrb-no pic 9(08).
05 ws-link-ctrb-name pic x(50).
procedure division using by value sender as object e as type System.EventArgs.

initialize ws-error.
move self::lblContributorXNo::Text to ws-input

call "ValidateContributor" using by value ws-link-data
move "Y" to ws-error
if ws-error = "N" then
*> insert condition code
set lblCOVERNO::Visible to true
set self::lblContributorXNo::Text to self::txtSearch::Text
else
*> insert code
invoke type MessageBox::Show("Invalid Contributor No !!")
end-if

end method.

COBOL program:

program-id. ValidateContributor as "MSGC_online_screen.ValidateContributor".

data division.
working-storage section.
01 WS-ARRAY-CTRBNO pic 9(08) value 10000008.
linkage section.
01 ws-link-data.
05 ws-link-ctrb-no pic 9(08).
05 ws-link-ctrb-name pic x(50).
05 ws-error-flag pic x.
procedure division using by value ws-link-data .
if WS-ARRAY-CTRBNO = ws-link-ctrb-no
move "ZOEB PATRAWALA" to ws-link-ctrb-name
move "N" to ws-error-flag
else
move spaces to ws-link-ctrb-name
move "Y" to ws-error-flag
goback.

  • Verified Answer

    You have a couple of things wrong here.

    There is no actual storage assigned for items defined in the linkage section.A linkage section is used to define data items that are being passed into the program as parameters or that are being set to an address of another memory location, Since you are not doing either of those things in your button click method the parameters that you are passing to ValidataContributor are invalid and this is causing the 114 error.

    If you remove the linkage section header from the button click method then ws-link-data will instead be defined in local-storage by default. This means that the data items will only be in scope while the method is active. If you wish to access these same data items in other methods then you should define them in the working-storage section of the class itself.

    The second problem is that your parameters do not match between the calling method and the called program. You are defining an extra field in the group item in the subprogram.

    The third problem is that you are passing these parameters to ValidateContributor by value which means that whatever modifications that you make to them within ValidateContributor will not be seen when you return to the calling method. If you wish to change the values and have these reflected in the calling program then you should use by reference instead of by value.

    Here is the changed code:

    Windows event:

    method-id btnSearch_Click final private.
    local-storage section.
    01 ws-error pic x.
    01 ws-input pic x(08).
    01 ws-link-data.
    05 ws-link-ctrb-no pic 9(08).
    05 ws-link-ctrb-name pic x(50).
    05 ws-error-flag pic x.
    procedure division using by value sender as object e as type System.EventArgs.
    initialize ws-error.
    move self::lblContributorXNo::Text to ws-input
    call "ValidateContributor" using by reference ws-link-data
    move "Y" to ws-error
    if ws-error = "N" then
    *> insert condition code
    set lblCOVERNO::Visible to true
    set self::lblContributorXNo::Text to self::txtSearch::Text
    else
    *> insert code
    invoke type MessageBox::Show("Invalid Contributor No !!")
    end-if
    end method.

    COBOL program:
    program-id. ValidateContributor as "MSGC_online_screen.ValidateContributor".
    data division.
    working-storage section.
    01 WS-ARRAY-CTRBNO pic 9(08) value 10000008.
    linkage section.
    01 ws-link-data.
    05 ws-link-ctrb-no pic 9(08).
    05 ws-link-ctrb-name pic x(50).
    05 ws-error-flag pic x.
    procedure division using by reference ws-link-data .
    if WS-ARRAY-CTRBNO = ws-link-ctrb-no
    move "ZOEB PATRAWALA" to ws-link-ctrb-name
    move "N" to ws-error-flag
    else
    move spaces to ws-link-ctrb-name
    move "Y" to ws-error-flag
    goback.