This article is specific to ACUCOBOL-GT and describes how to write a menu handling routine that creates menus dynamically by reading a file.
Problem:
You need to write menus that will change (dynamic menus) if you change the content of a file, without recompiling the program.
Resolution:
Attached to this KB article is an AcuBench demo project that contains sample code for creating dynamic menus, and a sample file for testing. The important parts of the code are described below.
Read a file and create the level and the branches needed for your menu. The demo project uses the following code to accomplish this:
Screen1-Aft-Initdata. open input filemenu/* Create a new menu */ call "w$menu" using wmenu-new giving menu-handle if menu-handle = zero go to acu-menudina-mn-1-exit end-if move low-values to filemenu-exception start filemenu key is greater than filemenu-exception read filemenu next record perform until not Valid-filemenu evaluate filemenu-level when 1 perform acu-level1-add-branch when 2 perform acu-level2-add-element end-evaluate read filemenu next record end-perform move menu-handle to Screen1-menu-handle/* show the menu */ call "w$menu" using wmenu-show, Screen1-menu-handle close filemenu . Acu-menudina-mn-1-exit. move zero to return-code ./* Create a new branch */ Acu-submenu-routine. call "w$menu" using wmenu-new giving sub-handle-1 if sub-handle-1 = zero move zero to menu-handle go to acu-menudina-mn-1-exit end-if . acu-level1-add-branch. perform Acu-submenu-routine/* Add first element to a new branch. */ call "w$menu" using wmenu-add, menu-handle, 0, 0, filemenu-name, filemenu-exception, sub-handle-1 ./* Add a new element to an existing branch. */ acu-level2-add-element. call "w$menu" using wmenu-add, sub-handle-1, 0, 0, filemenu-name, filemenu-exception .
Add the code to handle the click on the menu:
Screen1-Ex-Other. open input filemenu move key-status to filemenu-exception start filemenu key is equal filemenu-exception read filemenu if Valid-filemenu display message box filemenu-name end-if close filemenu .
This example uses the following file structure:
FD filemenu. 01 filemenu-rec. 05 filemenu-name PIC x(40). 05 filemenu-level PIC 9. 05 filemenu-program PIC x(20). 05 filemenu-exception PIC 9(4).
Filemenu-nameis the name of entry on the menu.
Filename-levelcan be:
Filemenu-programis the name of the program we want to call.
Filemenu-exceptionis the value of the exception attached to that menu choice. It is the key to recover the program to be called (when the menu is chosen this is the value we recover). In this demo, this value is also used to recover the order of creation of branches and elements.
This is everything you need to control a small dynamic menu.
Incident Number: none
Dynamic_Menu_AcuBench_ Demo.zip
graphical
Date: Click here to enter a date.Name: Description of change: Date: Click here to enter a date.Name: Description of change:



