A procedure for copying sales order info to purchase order...

Hello everybody me again :)

I just want to say that I am not looking for you guys to give me a particular solution to this problem, rather I am in need of guidance on how to tackle this animal. How do professional programmers approach something like this in my situation? I know this is a big project but maybe somebody can get me started on where to look for answers and questions at that.

My task is to write a procedure that basically looks at sales order (SO) number provided by SO, then looks for bill of materials (BOM) associated with this SO num, invokes purchase order (PO) and copies some of the info from BOM and some of the info from SO into PO and PO line.

We used to have this code on v8 version of this ShopPro Enterprise Resource Planning (ERP) software but now it does not want to run with v9 version called Encompix, and I was thinking maybe I can write my own procedure, instead of copying it from the old program.


this is the old code, if its of any help:


Code:
[SIZE=1]&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE p_CreatePo SalesOrderWindow 
PROCEDURE p_CreatePo :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  for each job-hdr where job-hdr.company = g-co-id and job-hdr.so-no = so-hdr.order-no use-index so-job no-lock :  
    if job-hdr.job-status = "P" then do:
      message("Can not Create PO's for PLANNED jobs...please OPEN jobs (Tina approve)").
      return.
    end.
    
    
    find first po-line where po-line.company = g-co-id and po-line.order-no = job-hdr.order-no use-index order-seq no-lock no-error.
     if available po-line then do:
        message ("there is already a PO for one of these jobs!").
        return.
     end.  
    end.
    
/*    find first po-hdr where substring(po-hdr.po-no,1,6) = so-hdr.order-no no-lock no-error.
 *      if available po-hdr then do:
 *         message ("there is already a PO with this PO number").
 *         return.
 *      end.*/



DEF VAR vNextPoNo    LIKE po-hdr.po-no NO-UNDO.
DEF VAR vNextRank    AS INT NO-UNDO.

DEF VAR vFirstReq    LIKE po-hdr.req-no NO-UNDO.
DEF VAR ctr          AS INT NO-UNDO.
DEF VAR vNextLine    AS INT NO-UNDO.
DEF VAR vSaveBuyer   LIKE mrp.buyer.
DEF VAR vSaveDeptNo  LIKE mrp.dept-no.
DEF VAR vSaveReqDate LIKE mrp.req-date.
DEF VAR vSaveAcct    LIKE mrp.purch-account.
DEF VAR vDefaultBuyer         LIKE mrp.buyer NO-UNDO.
DEF VAR vDefaultCommodity     LIKE mrp.commodity NO-UNDO.
DEF VAR vDefaultPurchAccount  LIKE mrp.purch-account NO-UNDO.
def var vDefaultInspect       like po-line.inspect no-undo.
def var bom-flag              as log no-undo.
def var hold-est-cost         as dec no-undo.
def var work-stkloc           like po-line.stkloc no-undo.
def var work-serial           like po-line.serial no-undo.
DEF VAR vNextReq     LIKE po-hdr.req-no NO-UNDO.
def var hold-gl-account as char no-undo.
def var hold-ship-via as char no-undo.
def var hold-fob as char no-undo.
def var hold-terms-desc as char no-undo.
def var hold-item-unit-measure like uom.uom no-undo.
def var hold-item-purch-um like uom.uom no-undo.
def var hold-item-prod-code like product.prod-code no-undo.
def var po-unit-measure    like po-line.unit-measure no-undo.
def var hold-buyer as char no-undo.
def var uom-conv-factor    like uom-conv.conversion no-undo.
def var stk-qty-ordered    like po-line.qty-ordered no-undo.
def var purch-qty-ordered  like po-line.qty-ordered no-undo.
def var conv-stkloc        like item-stkloc.stkloc no-undo.
def var conv-serial        like item-stkloc.serial no-undo.
def var vcmrpPO like po-hdr.po-no.




g-hglass = SESSION:SET-WAIT-STATE('GENERAL').
 assign vReqCount = 0.
 DO TRANSACTION:
          
  mrp-block:
  FOR EACH job-hdr WHERE job-hdr.company = g-co-id and job-hdr.so-no = so-hdr.order-no,
      each job-bom where job-bom.company = g-co-id and job-bom.order-no = job-hdr.order-no and
      job-bom.req-type = "B"                               
      BREAK BY job-bom.vend-id:
        /*     BY mrp.item-no:     */

    /*dgw072202 */
    IF job-hdr.job-status <> "O" THEN DO:
       message("Job is not OPEN ! " + job-hdr.order-no).
       return.
    end.

    /* Create the purchase request header  */
    IF FIRST-OF(job-bom.vend-id) THEN DO:

      find syscntrl where syscntrl.company = g-co-id and 
                          syscntrl.system = "PO" exclusive-lock.
                         
      IF NOT AVAILABLE syscntrl THEN DO:
          g-hglass = SESSION:SET-WAIT-STATE('').
          MESSAGE "Cannot find system record.  Unable to create purchase request." 
                  view-as alert-box.
          RETURN.
      END.
      if vReqCount = 0 then
        assign vFirstReq = syscntrl.xxx-vouch-no + 1.
      ASSIGN
        vReqCount          = vReqCount + 1
        syscntrl.xxx-vouch-no  = syscntrl.xxx-vouch-no + 1
        vNextReq           = syscntrl.xxx-vouch-no.    
      RELEASE syscntrl.

      find first company where company.company = g-co-id no-lock no-error.  
      FIND vendor NO-LOCK WHERE vendor.company = g-co-vend and 
                                vendor.vend-id = job-bom.vend-id NO-ERROR.
      assign
        hold-gl-account = ""
        hold-fob = ""
        hold-ship-via = ""
        hold-terms-desc = "".
      if avail vendor then do:

        find vendor-co where vendor-co.company = g-co-id and vendor-co.vend-id = vendor.vend-id NO-LOCK.     
        hold-gl-account = vendor-co.gl-account.
        

              run main\sd-find.p (INPUT "vendor",
                            INPUT "gl-account",
                            INPUT "chart",
                            INPUT g-co-vend,
                            INPUT g-co-chart,
                            INPUT vendor.vend-id,
                            OUTPUT hold-gl-account).                                 
        run main\sd-find.p (INPUT "vendor",
                            INPUT "fob",
                            INPUT "fob",
                            INPUT g-co-vend,
                            INPUT g-co-fob,
                            INPUT vendor.vend-id,
                            OUTPUT hold-fob).
        run main\sd-find.p (INPUT "vendor",
                            INPUT "ship-via",
                            INPUT "ship-via",
                            INPUT g-co-vend,
                            INPUT g-co-ship-via,
                            INPUT vendor.vend-id,
                            OUTPUT hold-ship-via).  
        run main\sd-find.p (INPUT "vendor",
                            INPUT "terms-desc",
                            INPUT "terms",
                            INPUT g-co-vend,
                            INPUT g-co-terms,
                            INPUT vendor.vend-id,
                            OUTPUT hold-terms-desc).
      end.                                               
      
      find buyer where buyer.company = g-co-buyer and
                       buyer.buyer = so-hdr.entered-by no-lock no-error.
    
     
      assign vDefaultBuyer = if available buyer then buyer.buyer else ""
             vDefaultPurchAccount = if available vendor then hold-gl-account else ""
             vDefaultInspect = if available vendor then vendor.inspect else NO.
    
      find first deptappr where
      deptappr.company = g-co-dept use-index dept-no no-lock no-error.

      if vReqCount = 1 then vcmrpPO = static-so-no.
      if vReqCount = 2 then vcmrpPO = static-so-no + "A".
      if vReqCount = 3 then vcmrpPO = static-so-no + "B".
      if vReqCount = 4 then vcmrpPO = static-so-no + "C".
      if vReqCount = 5 then vcmrpPO = static-so-no + "D".
      if vReqCount = 6 then vcmrpPO = static-so-no + "E".
      
      find first vendcont where vendcont.vend-id = job-bom.vend-id no-lock no-error .

        
      CREATE po-hdr.  
      ASSIGN
        po-hdr.company         = g-co-id
        po-hdr.req-no          = vNextReq
        po-hdr.po-no           = vcmrpPO
        po-hdr.vend-id         = job-bom.vend-id
        po-hdr.ship-via        = (if avail vendor then hold-ship-via else '')
        po-hdr.terms           = (if avail vendor then hold-terms-desc else '')
        po-hdr.fob             = (if avail vendor then hold-fob else '')
        po-hdr.buyer           =  vDefaultBuyer
        po-hdr.enter-date      = TODAY
        po-hdr.order-date      = TODAY
        po-hdr.req-date        = if weekday(today) <> 6 then today + 1 else today + 3
        po-hdr.key             = 0
        po-hdr.hdr-status      = "O"
        po-hdr.print-flag      = NO
        po-hdr.shipto = if so-hdr.fob begins "Kansas" then "KC" else ""       
        po-hdr.attention       = if available vendcont then vendcont.name else ""
        po-hdr.name = if available company then company.name else "UNKNOWN"
        po-hdr.addr-1 = if available company then company.addr-1 else ""
        po-hdr.addr-2 = if available company then company.addr-2 else ""
        po-hdr.city = if available company then company.city else ""
        po-hdr.state = if available company then company.state else ""
        po-hdr.zip = if available company then company.zip else ""
        po-hdr.dept-no         = if avail deptappr then deptappr.dept-no else "".
   
   
   if po-hdr.shipto = "KC" then 
   assign
      po-hdr.addr-1 = "4456 Washington DR"
      po-hdr.city = "Texas"
      po-hdr.state = "MO"
      po-hdr.zip = "65489" .

       
       
       
   
    END. /* first-of job-bom(vend-id) */
   
    FIND po-hdr NO-LOCK WHERE po-hdr.company = g-co-id and 
                              po-hdr.req-no = vNextReq NO-ERROR.
    IF NOT AVAILABLE po-hdr THEN NEXT.
    
    assign vDefaultCommodity = "".
    find item where item.company = g-co-item and
                    item.item-no = job-bom.item-no no-lock no-error.
    if avail item then do:
      run main\sd-find.p (INPUT "item",
                          INPUT "commodity",
                          INPUT "commod",
                          INPUT g-co-item,
                          INPUT g-co-commod,
                          INPUT job-bom.item-no,
                          OUTPUT vDefaultCommodity).
      if vDefaultInspect = NO then 
        assign vDefaultInspect = item.xxx-inspect.
        
      assign hold-item-prod-code = "".
      run main\sd-find.p (INPUT "item",
                          INPUT "prod-code",
                          INPUT "product",
                          INPUT g-co-item,
                          INPUT g-co-id,
                          INPUT item.item-no,
                          OUTPUT hold-item-prod-code).
      find product where
        product.company = g-co-id and
        product.prod-code = hold-item-prod-code
        use-index prod-code no-lock no-error. 
      if avail product then
        assign vDefaultPurchAccount = product.xxx-inty-account.
    
                             
    end.
    
    FIND vendxref use-index vend-item exclusive-lock WHERE 
         vendxref.company = g-co-vend and
         vendxref.vend-id = mrp.vend-id and
         vendxref.item-co = g-co-item and
         vendxref.item-no = job-bom.item-no no-error.

    FIND first item-stkloc where
/*          item-stkloc.company = g-co-stkloc and gb */
         item-stkloc.item-no = job-bom.item-no
         use-index item-rank no-lock no-error.
                               
    /* Get the next line number for this po */
    FIND LAST po-line NO-LOCK USE-INDEX po-line WHERE
        po-line.company = g-co-id and
        po-line.req-no = vNextReq NO-ERROR.
    ASSIGN vNextLine = (IF AVAIL po-line THEN po-line.po-line + 1 ELSE 1).

    /* Convert actual order qty from purchasing uom to stock uom */
    if available item then do:
        assign hold-item-unit-measure = "".
        run main\sd-find.p (INPUT "item",
                            INPUT "unit-measure",
                            INPUT "uom",
                            INPUT g-co-item,
                            INPUT g-co-uom,
                            INPUT item.item-no,
                            OUTPUT hold-item-unit-measure).   
      assign hold-item-purch-um = "".
      run main\sd-find.p (INPUT "item",
                          INPUT "purch-um",
                          INPUT "uom",
                          INPUT g-co-item,
                          INPUT g-co-uom,
                          INPUT item.item-no,
                          OUTPUT hold-item-purch-um).   
      assign po-unit-measure      = (if avail vendxref then vendxref.unit-measure
                                     else hold-item-purch-um)
             work-stkloc          = (if avail item-stkloc then item-stkloc.stkloc
                                     else "")
             work-serial          = (if avail item-stkloc then item-stkloc.serial
                                     else "").    
      {incl\run.i &program="item\uom-cnvt.p"
                  &parameters="(input job-bom.item-no,
                                work-stkloc,
                                work-serial, 
                                po-unit-measure, 
                                hold-item-unit-measure,
                                output uom-conv-factor)"
                  &run_method="BATCH"}
      if uom-conv-factor > 0 then
        assign stk-qty-ordered = (job-bom.fix-qty * uom-conv-factor).
      else do:
        bell.
        message 'UM conversion factor from' po-unit-measure 'to' hold-item-unit-measure skip
                'does not exist for item: ' job-bom.item-no view-as alert-box error.
        NEXT mrp-block.          
      end.
    end.
    else stk-qty-ordered = job-bom.fix-qty.
    
   /* if not available item and job-bom.order-no <> "" /* direct purchase */ then 
 *       find first job-bom no-lock
 *         where job-bom.company = g-co-id
 *           and job-bom.order-no = mrp.order-no
 *           and job-bom.seq-no = mrp.seq-no no-error.*/
          
   /*dgw put this in 10-01-03 to assign DELIVER TO DOOR*/
    find first job-routing where job-routing.company = g-co-id and job-routing.order-no = job-bom.order-no no-lock no-error.
    find work-ctr where work-ctr.work-ctr = job-routing.work-ctr no-lock no-error.
   
    /* Create the line item and update related files */      
    CREATE po-line.
    ASSIGN
      po-line.company           = g-co-id
      po-line.po-no             = vcmrpPO
      po-line.req-no            = vNextReq
      po-line.po-line           = vNextLine
      po-line.vend-id           = po-hdr.vend-id
      po-line.item-no           = job-bom.item-no
      po-line.item-desc         = job-bom.item-desc
      po-line.key               = job-bom.key       /*dgw092402 per Diego*/
      po-line.commodity         =  vDefaultCommodity
      po-line.vend-item-no      = if avail vendxref then vendxref.vend-item-no else ""
      po-line.non-item-no       = if avail item then FALSE else TRUE
      po-line.qty-ordered       = job-bom.est-qty
      po-line.qty-received      = 0
      po-line.unit-measure      = (if available job-bom then job-bom.unit-measure
                                  else if avail vendxref then vendxref.unit-measure
                                  else if avail item then hold-item-purch-um
                                  else "")
      po-line.vend-unit-measure = (if avail vendxref then vendxref.unit-measure
                                  else if avail item then hold-item-purch-um
                                  else "")
      po-line.unit-price        = job-bom.unit-cost
      po-line.plan-price        = job-bom.unit-cost
      po-line.req-date          = if available job-bom then job-bom.due-date
                                  else today
      po-line.purch-account     =  vDefaultPurchAccount
      po-line.stkloc            = (if avail item-stkloc then item-stkloc.stkloc
                                   else "")
      po-line.serial            = (if avail item-stkloc then item-stkloc.serial
                                   else "")
      po-line.stklen            = (if avail item-stkloc then item-stkloc.stklen
                                   else 0)
      po-line.stkwid            = (if avail item-stkloc then item-stkloc.stkwid
                                   else 0)

      po-line.order-no          = job-bom.order-no
      po-line.seq-no            = job-bom.seq-no
      po-line.deliver-to        = work-ctr.x-char1
      po-line.line-status       = (IF po-line.qty-ordered > 0 THEN "O" ELSE "C")
      po-line.inspect           = vDefaultInspect.
                
    /* NOTE: Inventory allocations (on-order qty) take place when the PO number is assigned */ 
           for each xmatl where po-line.item-desc begins xmatl.note3 and xmatl.note3 <> ""   /*dimen matches substring(po-line.item-desc,1,14)*/ no-lock :
        
                   if po-line.key = 0 then do:
                     find syscntrl where syscntrl.company = "00" and syscntrl.system = "Main" exclusive-lock.
                     assign
                     syscntrl.xxx-key = syscntrl.xxx-key + 1
                     po-line.key = syscntrl.xxx-key.
                     release syscntrl.
                 
                    create notes.
                     assign
                     notes.key = po-line.key
                     notes.notes-page = 1
                     notes.notes-line = 1
                     notes.notes-text =  "%IN STK-" + string(xmatl.qty1) + " pcs " + string(xmatl.length) + " ft...location: " + xmatl.location .
                                   
                  
                    
                    end.  /* end po-line.key*/

                 
               
                    
                if po-line.key <> 0 then do:
                   def var last-line as integer.
                    find last notes where notes.key =  po-line.key.
                     last-line =  notes.notes-line.  
                 
                    create notes.
                     assign
                     notes.key = po-line.key
                     notes.notes-page = 1
                     notes.notes-line = last-line + 1
                     notes.notes-text =  "%IN STK-" + string(xmatl.qty1) + " pcs " + string(xmatl.length) + " ft...location: " + xmatl.location .
                 end.  /* end po-line.key <> 0 */
      

                end. /* for each xmatl */
              
               
               
    /* Update VENDXREF purchase information - Purchase UM */
    FIND vendxref WHERE 
         vendxref.company = g-co-vend and
         vendxref.vend-id = po-hdr.vend-id and
         vendxref.item-co = g-co-item and
         vendxref.item-no = po-line.item-no
         use-index vend-item exclusive-lock no-error.
    IF AVAILABLE vendxref THEN DO:
      ASSIGN
          vendxref.mtd-ordered = 
              vendxref.mtd-ordered + po-line.qty-ordered
          vendxref.ytd-ordered = 
              vendxref.ytd-ordered + po-line.qty-ordered.
    END.
    IF AVAILABLE vendxref THEN RELEASE vendxref.

    /* Update job-bom information - Stock UM */
    if po-line.order-no <> "" then do:
      /*find job-bom where
 *         job-bom.company = g-co-id and
 *         job-bom.order-no = po-line.order-no and
 *         job-bom.seq-no = po-line.seq-no
 *         use-index order-seq no-lock no-error.*/
      if available job-bom then do:
          
        /* Update direct purchase information */
        run sfc\dirpurc.p ( INPUT recid(job-bom), no, "PO", recid(po-line) ). 
        if return-value = "error" then
          undo mrp-block, return.
      end.
      /*find job-bom where
 *         job-bom.company = g-co-id and
 *         job-bom.order-no = po-line.order-no and
 *         job-bom.seq-no = po-line.seq-no
 *         use-index order-seq no-lock no-error.*/
      if available job-bom then do:      
        /* Recalculate parent job costs? */
        if job-bom.est-cost <> hold-est-cost then do:
          /*find job-hdr where
 *             job-hdr.company = g-co-id and
 *             job-hdr.order-no = job-bom.order-no
 *             use-index order-no no-lock no-error.*/
            
          if job-hdr.parent-order <> job-hdr.order-no then do:
            hold-order-no = job-hdr.order-no.
            run sfc/recalcu.p.
          end.
        end.
      end.
    end. /* Direct purchase update */
    
    IF LAST-OF(job-bom.vend-id) THEN DO:
      /* Create the approval records */
      assign save-hdr-recid = recid(po-hdr).
      RUN p_CreateApprovals.
    END.
    
    
       
  END.

 END.  /* transaction */

/* if vReqCount = 0 then
   message "No Purchase Orders were created"
          VIEW-AS ALERT-BOX.
 else do:
   assign hold-po-req-no = vFirstReq.
   message vReqCount "Purchase Order(s) created." skip(1)
           "PO Req Number(s):" vFirstReq "through" vNextReq skip(1)
           "PO Number : " po-hdr.po-no
           VIEW-AS ALERT-BOX.
 end.    */
 
 save-hdr-recid = recid(so-hdr).                 
 g-hglass = SESSION:SET-WAIT-STATE('GENERAL').
 {&OPEN-QUERY-{&BROWSE-NAME}}
 g-hglass = SESSION:SET-WAIT-STATE('').





END PROCEDURE.

/* _UIB-CODE-BLOCK-END */[/SIZE]

I appreciate any help
Thanks.
 
Top