How to debug maps in GIS/SI (I)

Problem

Sometimes it’s good to know what happening inside the map. You can see the error messages in the MapTestTxReport.xml file, but sometimes there are no errors but the output is incorrect.

Solution 1

You can use the messagebox() function to understand how the map works. This function gives you ability to write your data into the log. It’s simply to use this function:

messagebox("<message to send>", 0);

where <message to send> is the message you want to check.

Example 1

For example, my map contains a code to process E2ADRM1001 and if #PARTNER_Q = “WE” it should populate a temporary storage for the N1 (N1-01 = ST) data in the output. Accidentally I misspelled this rule and wrote something like

IF #PARTNER_Q = "WR" THEN
	BEGIN
		$E2EDL20003_1.#TMP_ST_NAME1_N102 = #NAME1;
		$E2EDL20003_1.#TMP_ST_STREET1_N301 = #STREET1;
		$E2EDL20003_1.#TMP_ST_CITY1_N401 = #CITY1;
		$E2EDL20003_1.#TMP_ST_REGION_N402 = #REGION;
		$E2EDL20003_1.#TMP_ST_POSTL_COD1_N403 = #POSTL_COD1;
		$E2EDL20003_1.#TMP_ST_COUNTRY1_N404 = #COUNTRY1;
	END

I.e. WR instead of WE. I think that all is fine but I don’t see the Ship To address (N1 (N1-01 = ST)) in the output.

What I can do to find the reason of this problem:

  1. In the pre-session rules I add a new variable- String[200] msg;
  2. In the pre-session rule I add messagebox(“<<<<<<<<<<<<<<<<<<<<<<<<<“, 0); – it will help me to find my log messages inside the log.
  3. In the post-session rule I add messagebox(“>>>>>>>>>>>>>>>>>>>>>>>>>”, 0);. Again, this string will help me to find my messages in the log.
  4. Next, I need to check if my rule is executed. I think that the map assigns the data to the temporary fields, all is OK, but I want to make sure it does it. So, I add the following code to the map:
    IF #PARTNER_Q = "WR" THEN //SHIP TO
    	BEGIN
    messagebox("ASSIGN DATA TO TMP ST ADDRESS !!!!", 0);
    		$E2EDL20003_1.#TMP_ST_NAME1_N102 = #NAME1;
    		$E2EDL20003_1.#TMP_ST_STREET1_N301 = #STREET1;
    		$E2EDL20003_1.#TMP_ST_CITY1_N401 = #CITY1;
    		$E2EDL20003_1.#TMP_ST_REGION_N402 = #REGION;
    		$E2EDL20003_1.#TMP_ST_POSTL_COD1_N403 = #POSTL_COD1;
    		$E2EDL20003_1.#TMP_ST_COUNTRY1_N404 = #COUNTRY1;
    	END
    
  5. Now I need to compile the map and try to run it. There is NO errors, but I don’t see the ST address in the output data:

  6. Now, let’s check the log (Operations->System->Log):

  7. We need to find “System Output/Error Redirect” log, make sure it’s in “On mode”. Click on the top “noapp.log” link under this section:

  8. A new window will be opened. Let’s scroll it down till the end of the log. We see our messages from the Session start/end:

  9. But there is NO our “ASSIGN DATA TO TMP ST ADDRESS !!!!” message, and it means that our code was not executed. It’s important – we don’t see our message because the map didn’t execute anything under this condition:
    IF #PARTNER_Q = "WR" THEN //SHIP TO
    	BEGIN
    		<this piece of code was not executed!!!>
    	END
    
  10. Let’s try to go “one step up” and add the following code to the map:
    msg = "    PARTNER_Q is: " + #PARTNER_Q;
    messagebox(msg, 0);
    
    IF #PARTNER_Q = "WR" THEN //SHIP TO
    	BEGIN
    messagebox("ASSIGN DATA TO TMP ST ADDRESS !!!!", 0);
    		$E2EDL20003_1.#TMP_ST_NAME1_N102 = #NAME1;
    		$E2EDL20003_1.#TMP_ST_STREET1_N301 = #STREET1;
    		$E2EDL20003_1.#TMP_ST_CITY1_N401 = #CITY1;
    		$E2EDL20003_1.#TMP_ST_REGION_N402 = #REGION;
    		$E2EDL20003_1.#TMP_ST_POSTL_COD1_N403 = #POSTL_COD1;
    		$E2EDL20003_1.#TMP_ST_COUNTRY1_N404 = #COUNTRY1;
    	END
    
  11. Run the map and open the log again. Scroll down to the end:

  12. 12. We can see several log messages between our “<<<<<” and “>>>>>”. These values were processed during translation and we can check them against our rule. There is NO WR qualifier – that’s why out code (IF #PARTNER_Q = “WR” THEN …) was not executed.
  13. 13. Now it’s clear – there is an error in the code (in the condition) and we need to change WR to WE. Let’s fix it and run the map one more time:

Example 2

There is a complicated rule with several conditions and I need to check why it doesn’t work:

IF A THEN
    BEGIN
        IF B THEN
            BEGIN
                IF C THEN
                    BEGIN
                         <some code here, and this code is not executed>
                    END
            END
    END

I’m changing it to something like:

messagebox("=== BEGIN ==============", 0);

IF A THEN
    BEGIN
messagebox("CONDITION A");
        IF B THEN
            BEGIN
messagebox("CONDITION B");
                IF C THEN
                    BEGIN
messagebox("CONDITION C");
                         <some code here, and this code is not executed>
                    END
            END
    END

And if there is something like:

=== BEGIN ===============
CONDITION A

in the log – it means that CONDITION B is not true (because I don’t see appropriate message in the log).

Example 3

There are several places where I assign the value to a temporary fields and I need to check the sequence of these actions.

IF A THEN
   #TMP_FIELD = #FIELD01;

...
IF B THEN
   #TMP_FIELD = #FIELD02;

...
IF C THEN
   #TMP_FIELD = #FIELD03;

I’m changing it to:

IF A THEN
  BEGIN
     msg = "CONDITION A, value: " + #FIELD01;
     messagebox(msg, 0);
     #TMP_FIELD = #FIELD01;
  END

...
IF B THEN
  BEGIN
     msg = "CONDITION B, value: " + #FIELD02;
     messagebox(msg, 0);
     #TMP_FIELD = #FIELD02;
  END

...
IF C THEN
  BEGIN
     msg = "CONDITION C, value: " + #FIELD03;
     messagebox(msg, 0);
     #TMP_FIELD = #FIELD03;
  END

And if I see in the log

CONDITION C, value: 12345
CONDITION B, value: 54321

It’s clear that the condition C was executed first, then the condition B. The condition A was never executed.

Gennady Kim

Advertisements

4 thoughts on “How to debug maps in GIS/SI (I)

  1. I didn’t know you could use this messagebox, but an extremely easy way to troubleshoot is to put a cerror with a variable name that errs out the map and tells me what is in the variable. It is much easier than going through the logs since it shows up in the maptesttxreport.xml file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s