pointers - Handling parameters of different length in COBOL -


if caller passes parameter of different length (e.g different record type) callee how handle in cobol. 1 way work-around situation

calee defines different type of records in linkage section , addressability using parameter.

linkage section.  01  recx       pic x(10). 01  recy       pic x(1000). 01  recz       pic x(25).  01  rectype    pic x(01). 01  rec        pic x(1). procedure division using rectype rec.   evalute true  when rectype='x' set address of recx address of rec when rectype='y' set address of recy address of rec when rectype='z' set address of recz address of rec 

would right way handle situation.

no, not really.

linkage section.  01  recx       pic x(10). 01  recy     redefines recx       pic x(1000). 01  parm       pic x(1). 01  rectype    pic x(01).     88  use-recx value "x".     88  use-recy value "y". procedure division using parm                          rectype                          recx.  evalute true   when use-recx     perform process-recx   when use-recy     perform process-recy end-evaluate  goback . 

the using ... recx causes recx address of second parameter on call. due redefines, recy gets same address. if have recz well, can made redefines of recx.

then second parameter can used identify of different data structures available on particular call.

if there in same location on both structures allows identification of 2 structures, can used instead of needing rectype.

the linkage section bunch of definitions can used once address has been assigned them. if have 300 programs calling program 291 different data-structures @ 514 different addresses, not matter, because called program sees address of current data-structure current call.

the using on procedure division (or entry statements) causes code generated loads address of storage "passed" such 01-level (or 77, don't that) named on using has address. different structures can redefinesed , automatically, when reference them, have address has been passed called program.

if @ output listing, when have done redefines, you'll notice of structures use same bll cell. mappings available address of data current call.

you could way, duplication of effort. compiler equivalent of set first item on using, actual set same address manually assign 1 of structures. duplication, introduces point @ error introduced.

a further way it, becoming more common, pass block of pointers, , use set data pointed to. seen more flexible way of being able add new parameters program without having change recompile everything. however, again there burden on getting right. more flexibility, less obvious, more difficult (relative) correct.

at end of that, way way done @ site. no-one wants pick program , have understand way technically works before chance @ business logic. if differently, different code viewed suspicion - "there's error here, , here's strange code, i'm going put displays in , see going on" rather looking actual problem.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -