I need your help with a small SPESDH modification

Hello,

I added the small piece of code below in SPESDH. The purpose is to calculate a field on the lines when the delivery is saved and/or validated.
it only works if the delivery contains one single line.

If I add a second line, the fields are calculated correctly, and I can see the lines being updated thanks to the AFFZO.
However, once the loop is complete and the delivery is saved, only the first line's field is saved, and the second line's field returns to 0.

$MYCODE

Local Integer X
If !clalev([ZITM]): Local File ITMMASTER[ZITM] : Endif

For X = 0 to [M:SDH1]NBLIG - 1
    Read [F:ZITM]ITM0=[M:SDH1]ITMREF([L]X)
    If [M:SDH1]Z_MYFIELD([L]X) = 0 Then
        [M:SDH1]Z_MYFIELD([L]X) = [M:SDH1]QTY([L]X)/[F:ZITM]Z_PDS
        [F:SDD]Z_MYFIELD = [M:SDH1]Z_MYFIELD([L]X)
        affzo [M:SDH1]Z_MYFIELD([L]X)
    Endif
Next

Rewrite [F:SDD]

Close File [ZITM]

Return


Do you have any idea why the second line does not retain the value?

Thank you for your help.

Parents
  • Instead or rewriting the Table, why dont you pass the calculated values on the table grid before saving, then that way the values on the table grid will be transalated to the table in a standard way.

    I would suggest you call the VERIF_CRE or VERIF_MOD actions and do the following. (Just removed the [F]=[M] part as well as the rewrite)

    For X = 0 to [M:SDH1]NBLIG - 1
    Read [F:ZITM]ITM0=[M:SDH1]ITMREF([L]X)
    If [M:SDH1]Z_MYFIELD([L]X) = 0 Then
    [M:SDH1]Z_MYFIELD([L]X) = [M:SDH1]QTY([L]X)/[F:ZITM]Z_PDS
    affzo [M:SDH1]Z_MYFIELD([L]X)
    Endif
    Next

Reply
  • Instead or rewriting the Table, why dont you pass the calculated values on the table grid before saving, then that way the values on the table grid will be transalated to the table in a standard way.

    I would suggest you call the VERIF_CRE or VERIF_MOD actions and do the following. (Just removed the [F]=[M] part as well as the rewrite)

    For X = 0 to [M:SDH1]NBLIG - 1
    Read [F:ZITM]ITM0=[M:SDH1]ITMREF([L]X)
    If [M:SDH1]Z_MYFIELD([L]X) = 0 Then
    [M:SDH1]Z_MYFIELD([L]X) = [M:SDH1]QTY([L]X)/[F:ZITM]Z_PDS
    affzo [M:SDH1]Z_MYFIELD([L]X)
    Endif
    Next

Children