Jump to content

Questions about best practices for code & beatifying code


 Share

Recommended Posts

Hi everyone,

I've written some rather cursed code and was wondering if anyone could help me improve or just beautify how it looks. I am not really privy to that side of sage's programming language and previous attempt result in syntax error so I am seeking any assistance you can give. As it is now, the below code functions flawlessly and does not seem to impact load times of GESPAY documents.

This code I've written pulls some extraneous data from certain tables, and places it into a custom field in the GESPAY function screen PAY1 array. There are 3 conditions it checks in order to run, and when I tried to convert it to a case, it doesn't like when I use the pat() function (incorrect data type), so I've gone with three separate if functions here. The code snipped is called via STYLE when a document is opened.

$ZOKYAKU
If !Clalev([ZPI]) : Local File PINVOICED[ZPI] : Endif

For i = 0 to [M:PAY1]NBLIG-1

If (pat([M:PAY1]VCRNUM(i), 'ORD*') | pat([M:PAY1]VCRNUM(i), 'BTS*') | pat([M:PAY1]VCRNUM(i), 'WEB*'))
 [M:PAY1]ZOKYAKU(i) = func AFNC.INTFLD('SORDER','BPCINV',[M:PAY1]VCRNUM(i)+'~')+' - '+func AFNC.INTFLD('SORDER','BPINAM',[M:PAY1]VCRNUM(i)+'~')
Endif

If (pat([M:PAY1]VCRNUM(i), 'PIN*') | pat([M:PAY1]VCRNUM(i), 'PCM*'))
 Filter [ZPI] Where NUM = [M:PAY1]VCRNUM(i)
 Read [ZPI] first
 [M:PAY1]ZOKYAKU(i) = func AFNC.INTFLD('BPSUPPLIER','BPSGRU',func AFNC.INTFLD('PRECEIPT','BPSNUM',[ZPI]NUMORI))+' - '+func AFNC.INTFLD('BPSUPPLIER','BPSNAM',func AFNC.INTFLD('PRECEIPT','BPSNUM',[ZPI]NUMORI))
Endif

If (pat([M:PAY1]VCRNUM(i), 'DIR*') | pat([M:PAY1]VCRNUM(i), 'INV*') | pat([M:PAY1]VCRNUM(i), 'INT*') | pat([M:PAY1]VCRNUM(i), 'SCM*'))
 [M:PAY1]ZOKYAKU(i) = func AFNC.INTFLD('SINVOICE','BPR',[M:PAY1]VCRNUM(i)+'~')+' - '+func AFNC.INTFLD('SINVOICE','BPRNAM',[M:PAY1]VCRNUM(i)+'~')
Endif

Affzo [M:PAY1]ZOKYAKU(i)
Next
Return

Thanks, and have a great day

Zoey

Edited by Zoey Mattison
Link to comment
Share on other sites

  • Zoey Mattison changed the title to Questions about best practices for code & beatifying code

I've re-written some of the calls to use GACCENTRYD and accounted for InfoPOS documents mostly not using PAY1 mask (error: NBLIG non existente)

If !Clalev([ZPI]) : Local File PINVOICED[ZPI] : Endif
If !Clalev([ZGA]) : Local File GACCENTRYD[ZGA] : Endif
If !pat([M:PAY0]NUM, 'IP*') 
For i = 0 to [M:PAY1]NBLIG-1
 If (!pat([M:PAY1]VCRNUM(i), 'ORD*') & !pat([M:PAY1]VCRNUM(i), 'BTS*') & !pat([M:PAY1]VCRNUM(i), 'WEB*'))
  Filter [ZGA] Where TYP = [M:PAY1]VCRTYP(i) & NUM = [M:PAY1]VCRNUM(i)
   Read [ZGA] First
    If fstat = 0
     If [ZGA]BPR <> 'V5555'
      [M:PAY1]ZOKYAKU(i) = [ZGA]BPR + ' - ' + func AFNC.INTFLD('BPARTNER','BPRNAM',[ZGA]BPR)
      Affzo [M:PAY1]ZOKYAKU(i)
     Else
      Filter [ZPI] Where NUM = [M:PAY1]VCRNUM(i) & NUMORI <> ''
       Read [ZPI] first
        If fstat = 0
         [M:PAY1]ZOKYAKU(i) = func AFNC.INTFLD('PRECEIPT','BPSNUM',[ZPI]NUMORI)+' - '+func AFNC.INTFLD('BPARTNER','BPRNAM',func AFNC.INTFLD('PRECEIPT','BPSNUM',[ZPI]NUMORI))
        Affzo [M:PAY1]ZOKYAKU(i)
        Endif
     Endif 
    Endif
 Else
  [M:PAY1]ZOKYAKU(i) = func AFNC.INTFLD('SORDER','BPCINV',[M:PAY1]VCRNUM(i)+'~')+' - '+func AFNC.INTFLD('SORDER','BPINAM',[M:PAY1]VCRNUM(i)+'~')
  Affzo [M:PAY1]ZOKYAKU(i)
 Endif
Next
Endif

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...