AM_ call to update screen field does not update the field

SOLVED

Hello,

I am using a simple piece of code to display a field from another screen in Manual Matching (LETTRAGE). When placed in an infobox, the data displays correctly, but when trying to Affzo the field on the screen, nothing is displayed.

When the BP number is entered ([M:LTR]BPR) an info box displaying the text from a custom field in [F:BPR] (BPARTNER) called ZMATCHN is displayed:

However, the field which I added to LETTRAGE called ZMATCHN ([M:LTR]ZMATCHN) does not update. Does it need to be in a table? (See "Matching Notes" is blank to the right. It does not display "test")

$ACTION
Case ACTION
 When default
Endcase
Return

Subprog AM_BPR(VALEUR)
Variable Char    VALEUR()
If VALEUR = 'EE9391'
read [F:BPR]BPR0 = VALEUR
If fstat = 0
Infbox ([F:BPR]ZMATCHN)
[M:LTR]ZMATCHN = [F:BPR]ZMATCHN
Affzo [M:LTR]ZMATCHN
Endif
Endif
End

Top Replies

  • 0

    Hello,

    Your code seems to be good. Could you tell me what is the data type of your specific field ZMATCHN ?

    Thanks,
    Nicolas.

  • 0 in reply to NMA

    Hi , thanks for your response. The data type of ZMATCHN is ACB - length of 6 and standard text type (not rtf).

  • 0

    Try replacing everything with your IF statement with what's below. You can also verify the content by using the calculator to determine the value of "[M:LTR]ZMATCHN" after your code triggers.

    # FOR PERFORMANCE AND AS A BEST PRACTICE, DO NOT READ TABLE IF CURSOR ALREADY THERE

    If [F:BPR]BPR <> VALEUR

             Read [F:BPR]BPR0 = VALEUR

              IF fstat <> [V]CTS_AOK : End : Endif

    Endif

    [M:LTR]ZMATCHN = [V]AVOID.ACLOB

    Append [M:LTR]ZMATCHN, [F:BPR]ZMATCHN

    Affzo [M:LTR]ZMATCHN

  • 0 in reply to Zoey Mattison

    Hi, 

    For "CLOB", you have to do things differently. Try the proposed solution by Regard Hulsbos and keep us posted. 

    Regards,

    Nicolas.

  • 0 in reply to Regard Hulsbos

     thank you for your reply. Unfortunately, the value of ZMATCHN in the LETTRAGE screen is still a blank string after implementing this code. I first got an error about BPR non existent variable, however that was because [F:BPR]BPR should be BPRNUM. After fixing this, there were no errors, but the calculator returns a value of "" from [F:LTR]ZMATCHN

    I noticed there is no table referenced for the LETTRAGE screen. Is this a problem?

  • 0 in reply to Zoey Mattison

    Can you add a screen shot of the field definition on the table BPARTNER and also on the screen LETTRAGE. For the screen, could you also add a screen shot of the graphical object settings. 

  • 0 in reply to Regard Hulsbos

    BPARTNER setup for ZMATCHN

    BPR1 (Where ZMATCHN can be entered and saved):

    LETTRAGE (where ZMATCHN should be displayed):

    The graphical object is Multiline Text (can't change it to anything else). The setup for that is Length 6, Internal Type Text file (for both screens BPR1 and LETTRAGE):

    Edit:

    I noticed that the value is actually displayed for a split second. You can see here after adding an infobox to test the value of [M:LTR]ZMATCHN, the value persists but as soon as I click "ok" it goes away..

    After clicking OK:

  • 0 in reply to Zoey Mattison

    Is there a specific reason that you chose ACB as the datatype? I would rather use A - 250, and if there is a need to have it larger than that, use ACPLAIN. Clobs are sometimes difficult to work with on standard screens, given the nature of the datatype.

  • 0 in reply to Regard Hulsbos

    thanks for the tip. I chose ACB just following an example from a different screen because I wanted to have a large text box instead of just a small entry box you get if A is set to graphical type none. I didn't know you could set A to multiline text. I've changed everything over to type A with length 250 with graphical object multiline text, and adjusted my code to how it was before. However, the result is still the as above -- the text appears in the Matching Notes box for a split second before disappearing.

  • +1 in reply to Zoey Mattison
    verified answer

      I've figured out a workaround just now.

    I think the finicky-ness of this is due to the screen itself. I tried a simple trick of changing the default field of [F:LTR]ZMATCHN to be [F:BPR]ZMATCHN. After you hit enter on the BPR field in LETTRAGE to display records to be matched, the Matching Notes field updates and shows the notes accordingly, and updates with every BP you enter into the field. The field does not update at all before clicking search when you use [F:LTR]ZMATCHN = [F:BPR]ZMATCHN in the AM_BPR SPE code. However, having the read function allows it to update the default value every time.

    Here is the final set up to get this working:

    Step 1: Update the Table

    • Add a new field into the BPARTNER table of type A, length 250. For this example, I've called it ZMATCHN
    • Validate the table

    Step 2: Add the necessary screen fields

    • In BPR1, add a field called ZMATCHN, type A, length 250, Graphical Object multiline text. (I set it to 5 lines and 40 columns, type Text File).
    • In LETTRAGE, add a field called ZMATCHN, and set it up identically to the field from BPR1. Additionally, set the default value of THIS field to be [F:BPR]ZMATCHN
    • In LETTRAGE, add a AFTER CHANGE action to the BPR field - SPE, executional Always, deactivation None. This will allow us to capture the BPR value after entry
    • Validate both screens.

    Step 3: Add SPE code to read the BPARTNER table from LETTRAGE

    • Navigate to the script editor and open SPELTR
    • You will notice a section automatically added called AM_BPR
    • Add the following code to open and read the BPRARTNER table using the BPR field value as the key (note: no updating of the ZMATCHN field is required here):
    • $ACTION
      Case ACTION
      	When default
      Endcase
      Return
      
      Subprog AM_BPR(VALEUR)
      Variable Char    VALEUR()
      if !clalev([F:BPR]) : Local File BPARTNER[F:BPR] : Endif
      If [F:BPR]BPRNUM <> VALEUR
      	Read [F:BPR]BPR0 = VALEUR
      	IF fstat <> [V]CTS_AOK : End : Endif
      Endif
      End
    • Compile your code

    Step 4: Test

    • Open Manual Matching, input your AR code and then in BP field, input your BP code. You can then use the "Jump to" button to jump to the BP setup of this code, and enter any notes you may need into your ZMATCH field that we added earlier
    • Save your BP document, and click close page. Hit enter or click "search" in manual matching. The update will now display the appropriate matching notes from the BPARTNER table in the ZMATCHN field of the LETTRAGE screen:

  • 0 in reply to Zoey Mattison

    Well done, working with ACB and ABB data types are always a bit finicky on screens. Glad you got it resolved.