IBI WebFOCUS - Useful tips and tricks

Many times while working on the projects, we face some small issues which takes a long time to fix it or achieve the requirement even if it looks very small. For example concatenation of 2 columns seperated by a '-' and it should contain 1 space between '-' and second column. It looks very small but when I tried to do that, it took me a long time to find out a very simple solution. There are many example like that. I want to share such things with you which I faced in my day to day coding.

Concatenation with space: 
You can either do it in define or compute as given below:

COUNTRY_CAR/A50=CAR||(' - ' |COUNTRY);

User defined function in WebFOCUS: 
If we need to perform repeative set of statements again and again, user defined funtion is a very good approach. Below is a simple example of function ADDNO to add 2 numbers and return the output:

DEFINE FUNCTION ADDNO(NO1/D20.2, NO2/D20.2)
ADDNO/D20.2 = NO1+NO2;
END
-RUN

TABLE FILE CAR
PRINT COUNTRY
COMPUTE NO_SUM/D20.2 = ADDNO(SALES, DEALER_COST);
BY CAR
ON TABLE PCHOLD FORMAT HTML
END

Creating an Accordion Report: 
This example shows how to use an EXPANDABLE command to create an Accordion Report. 
TABLE FILE GGSALES
SUM UNITS DOLLARS
BY REGION BY ST BY CITY BY CATEGORY
ON TABLE SET EXPANDABLE ON
END

You can test and debug your procedure with the following: 
The &ECHO variable controls the display of command lines as they execute so you can test and debug procedures. 

The &STACK variable enables you to test the logic of Dialogue Manager commands. Setting this variable to OFF lets you run the procedure while preventing the execution of stacked commands. This gives you the ability to view the sequence of commands and see how the variable values are resolved. 

The &RETCODE variable returns a code after a procedure is executed. If the procedure results in normal output or no records are retrieved, the value of &RETCODE is 1. If an error occurs while parsing the procedure, the value of &RETCODE is 8. 

&RETCODE can be used to test the result of an operating system command. This retrieves the return code from the operating system.

The &IORETURN variable tests the result of Dialogue Manager -READ and -WRITE commands. After a -READ or -WRITE operation, a non-zero return code indicates an error such as end-of-file being reached. 
&IORETURN can be used to test the result of the following:
A -READ command. If &IORETURN equals zero, a value was successfully read from the external file. 
A -WRITE command. If &IORETURN equals zero, a value was successfully written to the external file. 

The .EXIST suffix tests the presence of a value. 
The .EVAL suffix tests the value of a variable. 
The .LENGTH suffix tests the length of a value. 
The .TYPE suffix tests the type of a value. 

Happy Reporting in WebFOCUS!!!
Suggestions and questions are always welcome.

Comments

Popular posts from this blog

IBI WebFOCUS - Functions available and syntax to use

IBI WebFOCUS - Difference (Preference) between Join and Match:

IBI WebFOCUS - Testing and Debugging in WebFOCUS codes