GXS AI: Tutorial, lesson 4

Testing the map

  1. Save the map.
  2. Select Test->Translate in the top menu.

  3. In the opened window enter the following values, clicking “Add” every time you add a new pair:
    • Variable Name: S_MODEL, Variable Value: D:\Trandev\models\example01\example01S.mdl
    • T_MODEL, D:\Trandev\models\example01\example01T.mdl
    • INPUT_FILE D:\Trandev\models\example01\TestData\in.txt
    • OUTPUT_FILE D:\Trandev\models\example01\TestData\out.txt

  4. Then, enter the name of the test – example01 in the dropdown list and click “Save”:

  5. Click “Translate”
  6. You’ll see the following window (see below). The translation status is 160, Translation Error. Maybe you’ve already guessed the reason of this problem, but let’s try to find the reason in the “right way”.

    Go to the D:\Trandev\WBHelp_en\ErrorCodes\ folder and find the file which name starts with 160 (our error code). It’s 160_Error_Opening_Infile.htm. If you open it you’ll see the list of possible reasons. We haven’t created the input file in spite of we’ve created this parameter (INPUT_FILE D:\Trandev\models\example01\TestData\in.txt)
  7. OK, let’s create D:\Trandev\models\example01\TestData\ directory and a text file “in.txt” in it. This file should contain the following text:
  8. Click “Translate” again. You’ll see another status – 140. And again, it’s an error

    And again, we need to check this status description in 140_No_Instance.htm file. But this file doesn’t contain any clear explanation. So, we need to check the translation log. Close the error message window and click “View Log”. You’ll see the list of files – we need to check the last one (every time you click on “Translate” it creates a new file)

    And… nothing clear again:

    TRANSLATOR TRACE LOG	[ Version otBuild: 11/17/05 at: 06:03:16 ]
    Copyright 2002. Global eXchange Services, Inc. All rights reserved.
    Start of translation at Wed Mar 31 09:58:50 2010
    Execution locale: default
    Error: type 4 msg Returning no data/instance Document status 140
    Error: type 4 msg Returning no data/instance Record status 140
    Error: type 4 msg 
    send STATUS 140 to job 1082
    Session 001082 ended at Wed Mar 31 09:58:50 2010
     	with error cd 140

    It’s because we haven’t setup the level of details.

  9. Go back to the Translation window and click on “Set Trace Level”. In the opened window select all the options and click “OK:”

  10. Run the translator again and check the log. You’ll see that it’s bigger now. Spend some time trying to understand the log. As for me, it’s “clear like mud” but in the real life developers have to know how to interpret these logs…

    Here the translator found the LIN record:

    || ----------------
    || ENTER fill_sdm(): LIN  parent->instance 0
    || ----------------
    || DM: LIN instance 0 level 2
    	fp_save set to 0 in LIN
    	line number: 0; position: 0
    	IO: c = 76 <L> Set start_char 32 end_char 126
    	IO: c = 73 <I> Set start_char 32 end_char 126
    	IO: c = 78 <N> Set start_char 32 end_char 126
    	IO: read_set returning "LIN"; byte length = 3 
    	LIN Matching LIN to LIN dm->dh 44429360
    	fill_sdm initial pre condition Rec_Code met

    Here it processed the date:

    ||| FINISHED UnitPrice: status 0 statusc 0 occurrence 1 max occurrence 1
    ||| DM: ExpirationDate instance 0 level 3
    	fp_save set to 28 in ExpirationDate
    	line number: 0; position: 28
    	IO: func DATE called
    	IO: c = 50 <2> Set start_char 32 end_char 255
    	IO: c = 48 <0> Set start_char 32 end_char 255
    	IO: c = 49 <1> Set start_char 32 end_char 255
    	IO: c = 48 <0> Set start_char 32 end_char 255
    	IO: c = 48 <0> Set start_char 32 end_char 255
    	IO: c = 52 <4> Set start_char 32 end_char 255
    	IO: c = 49 <1> Set start_char 32 end_char 255
    	IO: c = 50 <2> Set start_char 32 end_char 255
    	IO: read_set returning "20100412"; byte length = 8 
    	DATE_in: value "20100412" pic "YYYYMMDD"
    	Function DATE_in returns value: "20100412"

    Here it found all the LIN records and finished processing the input document:

    || FINISHED LIN: status 0 statusc 0 occurrence 4 max occurrence 100
    || DM: LIN instance 0 level 2
    	fp_save set to 152 in LIN
    	line number: 0; position: 144
    	pre_cond Rec_Code EOF
    | FINISHED Document: status 0 statusc 0 occurrence 1 max occurrence 1

    Here it started creating the target data and… failed!

    | DM: Initialization instance 0 cur_tdm_inst 0
    | DM: Document instance 0 cur_tdm_inst 0
    || DM: Record instance 0 cur_tdm_inst 0
    ||| DM: LineNumber instance 0 cur_tdm_inst 0
    	No value applied to required object "LineNumber".

    OK, it’s clear now – the LineNumber field is mandatory in the target model, but the map doesn’t populate it with any value!

  11. Let’s try to make it optional. To do it, change the Occurrence Min to 0

    Done? No. We need to save the map since we’ve made a change. Please note that Workbench “doesn’t see” your change until you move the focus to another UI element. If Workbench makes Save icon active it means it has noted your changes.
  12. Reun the translation again. Now the status is “0” – no errors!

    Open D:\Trandev\models\example01\TestData\out.txt – there are our first translated data!


    compare it with the expected output:


    They look similar, but there is no LineNumber (001, 002, …, 004). As soon as we make this field optional it disappeared from the target data. Not good – in case of positional data it might be a disaster.

  13. How to fix it? There are no LineNumbers in the source data, so we have to generate them with using of a rule.
  14. Go back to the target model in Workbench. Go to the Initialization group and open the Rule Builder tab. Click on the [+] button (“Add a new rule”) and write the rule:
    [ ]
    VAR->Record_Cnt = 0

    It’s a very simple rule, it creates a variable an initiates it with 0.

  15. Now we need to check this rule if it’s valid or not. To do it, click on the “Check Syntax” icon.

    As you can see in the bottom status, everything is OK: «Rules for [Initialization] were syntax checked and found to be syntactically correct»
  16. Done? No 🙂 It’s not enough just to write the rule, we need to apply it to the model. If you don’t apply it, it won’t be saved. To apply the rule click on the down arrow icon (not 3 down arrows icon!)

  17. Go to the LineNumber field and create a rule in the same way as you just did it:
    [ ]
    VAR->Record_Cnt = VAR->Record_Cnt + 1
    LineNumber = VAR->Record_Cnt

    VAR->Record_Cnt = VAR->Record_Cnt + 1 increments our variable-counter and LineNumber = VAR->Record_Cnt assigns its value to the field.

    Hope it’s clear.

    Don’t forget to check and apply the new rule and then save the model.

  18. Let’s try to run the map now. Here is our new output:

    Looks close, but incorrect – again. Instead of 001, 002, …, 004 we have 1.0, 2.0, …, 4.0. We need to get rid of the decimal part of the values.

  19. Go to D:\Trandev\WBHelp_en\FunctionCodes\FunctionCodes.htm. Open the “String Functions” section and find the NUMTRIM function. We can use it to format numbers.
  20. Change the code to
    [ ]
    VAR->Record_Cnt = VAR->Record_Cnt + 1
    LineNumber = NUMTRIM(VAR->Record_Cnt, 0)

    and try to run the map.

  21. The new output is
    011  0123456789120000125,9905004/12/10
    012  0123456654370000025,0015008/31/10
    013  6678456789140000012,0025004/16/10
    014  9923456789150000005,7510005/19/10

    There is “1 ” instead of “001”. We need to add leading zeroes.

  22. Open the “String Functions” and check the STRFILL function. It can fill a string with necessary characters:
    STRFILL(<string>, <mode? L/T>, <fill_character>, <size>)

    1st parameter is the original string, 2nd – mode. L = leading, T = trailing. 3rd parameter is a “filler” and 4th – max size of the result string.

  23. So, our new code is
    [ ]
    VAR->Record_Cnt = VAR->Record_Cnt + 1
    LineNumber = STRFILL( NUMTRIM(VAR->Record_Cnt, 0), "L", "0", 3)

  24. Check, apply, save and run… Here is the right output!


Gennady Kim


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