I am sure that I have a misunderstanding about how to use SET ADDRESS OF. In the following example I wish to pass a pointer of a field in the calling program to a called program so the called program will load a value into the area pointed to by the pointer value ie:
IDENTIFICATIONDIVISION.PROGRAM-ID.example1.ENVIRONMENTDIVISION.CONFIGURATIONSECTION.SOURCE-COMPUTER.UNIX.OBJECT-COMPUTER.UNIX. *DATADIVISION.WORKING-STORAGESECTION.01 FILLER.03 FILLER PIC X(016) VALUE 'FCSI CodeWerks:'.03 FILLER PIC X(064) VALUE'Name:example1.cbl Version:5.7.1 Date:2017-11-26'.03 FILLER PIC X(002) VALUELOW-VALUES. *01 FIELD1PIC 9(004) VALUEZEROES. *01 FIELD2PIC X(032) VALUEALL 'Z'. *01 FIELD3PIC 9(012) VALUEZEROES. * *01 CALL-AREA.03 CA-KEYTYPEPIC X(009). * Set to maximum of chars to return; returns actual char count03 CA-MAXCHARPIC 9(004). * Set this pointer to the receiving area for the value string.03 CA-POINTERUSAGEPOINTER. * /PROCEDUREDIVISION.MAIN-CODESECTION.MAIN-CODE-0000.DISPLAY ' 'LINE1 POSITION1.MOVE 'FIELD1'TOCA-KEYTYPE.MOVEZEROESTOCA-MAXCHAR.INSPECTFIELD1TALLYINGCA-MAXCHARFORCHARACTERS.SETCA-POINTERTOADDRESSOFFIELD1.CALL 'gafgetdata'USINGCALL-AREA.DISPLAY "Field1="LINE01 COL01,FIELD1(1:CA-MAXCHAR)LINE00 COL00.MOVE 'FIELD2'TOCA-KEYTYPE.MOVEZEROESTOCA-MAXCHAR.INSPECTFIELD2TALLYINGCA-MAXCHARFORCHARACTERS.SETCA-POINTERTOADDRESSOFFIELD2.CALL 'gafgetdata'USINGCALL-AREA.DISPLAY "Field3="LINE03 COL01,FIELD2(1:CA-MAXCHAR)LINE00 COL00.MOVE 'FIELD3'TOCA-KEYTYPE.MOVEZEROESTOCA-MAXCHAR.INSPECTFIELD3TALLYINGCA-MAXCHARFORCHARACTERS.SETCA-POINTERTOADDRESSOFFIELD3.CALL 'gafgetdata'USINGCALL-AREA.DISPLAY "Field3="LINE05 COL01,FIELD3(1:CA-MAXCHAR)LINE00 COL00.MAIN-CODE-EXIT.STOPRUN. * * * *================================================================*IDENTIFICATIONDIVISION.PROGRAM-ID.gafgetdata.ENVIRONMENTDIVISION.DATADIVISION.WORKING-STORAGESECTION. *01 TEXT-AREAPIC X(256)based. /LINKAGESECTION. *01 L-CALL-AREA.03 CA-KEYTYPEPIC X(009).03 CA-MAXCHARPIC 9(004).03 CA-POINTERUSAGEPOINTER. /PROCEDUREDIVISIONUSINGL-CALL-AREA. *MAIN-CODESECTION.MAIN-CODE-0000.EVALUATECA-KEYTYPEWHEN 'FIELD1'SETaddressofTEXT-AREATOaddressofCA-POINTERMOVE4 TOCA-MAXCHARMOVE '0001'TOTEXT-AREA(1:CA-MAXCHAR)WHEN 'FIELD2'SETaddressofTEXT-AREATOaddressofCA-POINTERMOVE8 TOCA-MAXCHARMOVE 'GNUCobol'TOTEXT-AREA(1:CA-MAXCHAR)WHEN 'FIELD3'SETaddressofTEXT-AREATOaddressofCA-POINTERMOVE2 TOCA-MAXCHARMOVE '12'TOTEXT-AREA(1:CA-MAXCHAR)END-EVALUATE.MAIN-CODE-EXIT.GOBACK. *ENDPROGRAMgafgetdata. *ENDPROGRAMexample1.
Expected display:
Field1=0001
Field3=GNUCobol
Field3=12
Observed display:
Field1=0000
Field3=ZZZZZZZZ
Field3=00
Obviously the values set in the calling program are not getting established by the called program.
What would be the correct way to do this?
Thank you for your comments and help.
Gregory
Last edit: Simon Sobisch 2017-11-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SETCA-POINTERTOADDRESSOFFIELD1.*> the value of CA-POINTER in your prog contains the address of FIELD1 CALL ...*> the value of CA-POINTER in gafgetdata contains the address of FIELD1SETaddressofTEXT-AREATOaddressofCA-POINTER*> TEXT-AREA contains the address of CA-POINTER
You likely wanted
SETaddressofTEXT-AREATOCA-POINTER*> TEXT-AREA is set to the value of CA-POINTER which is the address of FIELD1
Quick check:
Field1=0001
Field3=GNUCobol
Field3=12
end of program, please press a key to exit
note: the program misses auto correction to get to the real GnuCOBOL ;-)
Last edit: Simon Sobisch 2017-11-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are exactly correct. I must presume that I was relating to 'c' and ignoring the implied symantics in the docs. I knew some combination would work and I was sure that I tried your suggestion but then again maybe not.
Thanks for your help.
PS: there are a few 'address of' examples in the GNU Cobol FAQ but they don't address this style of usage very well if at all. It would be useful for common error message routines, commandline argument processing, and other library functions. Feel free to use these programs (with appropriate mods) as an added example if needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There's a separate thread for feedback about the FAQ at [c67ea739], feel free to post a request there.
Also check the Programmer's Guide, if you find something is wrong or missing post a new Wish-List item or a new Bug with the milestone "Programmer's Guide".
I am sure that I have a misunderstanding about how to use
SET ADDRESS OF
. In the following example I wish to pass a pointer of a field in the calling program to a called program so the called program will load a value into the area pointed to by the pointer value ie:Expected display:
Observed display:
Obviously the values set in the calling program are not getting established by the called program.
What would be the correct way to do this?
Thank you for your comments and help.
Gregory
Last edit: Simon Sobisch 2017-11-27
Hi Greg
Brian rescued me with this one last spring:
https://sourceforge.net/p/open-cobol/discussion/help/thread/d7a52a60/
It looks like the first 3 pointer changes are missing the "set address of"
-Pat
Mod-Edit: removed reply-to
Last edit: Simon Sobisch 2017-11-27
Hi Pat ...
Regarding " It looks like the first 3 pointer changes are missing the "set address of" ..."
I'm not seeing what you are referring to ... the called program (gafgetdata) is doing what you are suggesting ie:
Gregory
Mod-Edit: removed reply-to
Last edit: Simon Sobisch 2017-11-27
Hi Greg
I have a million things coming at me at once. I am probably not sane.
What is the program doing or not doing? You seem to know the right
syntax already, is it not working?
-pat
No worries Pat ... Simon explained the semantics and suggested the correct syntax.
G
Gregory, you did the following
You likely wanted
Quick check:
note: the program misses auto correction to get to the real GnuCOBOL ;-)
Last edit: Simon Sobisch 2017-11-27
Simon,
You are exactly correct. I must presume that I was relating to 'c' and ignoring the implied symantics in the docs. I knew some combination would work and I was sure that I tried your suggestion but then again maybe not.
Thanks for your help.
PS: there are a few 'address of' examples in the GNU Cobol FAQ but they don't address this style of usage very well if at all. It would be useful for common error message routines, commandline argument processing, and other library functions. Feel free to use these programs (with appropriate mods) as an added example if needed.
There's a separate thread for feedback about the FAQ at [c67ea739], feel free to post a request there.
Also check the Programmer's Guide, if you find something is wrong or missing post a new Wish-List item or a new Bug with the milestone "Programmer's Guide".
Related
Discussion: c67ea739
Last edit: Simon Sobisch 2017-11-28