UPDATE
    rlarp.osmfs_dev f
SET
    fspr = gld.fspr
FROM
    (
        SELECT 
            N1COMP COMP
            ,N1CCYY FSYRq
            ,KPMAXP PERDS
            ,N1FSPP PERD
            ,to_char(N1FSYP,'FM0000') FSPR
            ,N1SD01 SDAT
            ,N1ED01 EDAT
            ,to_char(N1ED01,'yymm') CAPR
            ,N1ED01 - N1SD01 +1 NDAYS 
            ,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
            ,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5  ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
        FROM 
            LGDAT.GLDATREF 
            INNER JOIN LGDAT.GLDATE ON 
                KPCOMP = N1COMP AND 
                KPCCYY = N1CCYY
        WHERE
            N1COMP = 93
            --AND DIGITS(N1FSYP) = '1901'
    ) gld
WHERE
    f.sdate BETWEEN gld.sdat AND gld.edat
    AND coalesce(f.fspr,'') <> gld.fspr;
