          SUBROUTINE (BT,ST,PN,SHIP.BR,COMMENT)
** Version# 6.0001[1] - 01/02/2014 - 03:07pm - TSMITH - eclipse

*** Subroutine - CLEAN.SOE.COMMENTS
*---------------------------Program Description---------------------------*
*** This routine cleans a line item comment of system generated comments.
*** This should be used when copying comments from order to another so
*** that system comments are not duplicated.
***
*** This routine cleans the following system comments:
*** 1) Customer/Vendor specific part number comments
*** 2) Warehouse location comments
*** 3) Nonstock product comments
*** 4) HazMat comments
*---------------------------Paremeter Definition--------------------------*
*** BT      - The bill-to customer ID                              [IN]
*** ST      - The ship-to customer ID                              [IN]
*** PN      - The product ID on the line item                      [IN]
*** SHIP.BR - The branch the product will be shipped from          [IN]
*** COMMENT - The comment you want to clean                        [IN/OUT]
*-----------------------------Common Variables----------------------------*
***
*-------------------------------------------------------------------------*

          UT.OPEN.COMMON.FILE 'CONTROL',HNDL
          IF HNDL > 0 THEN
             CTRLFILE = FILES(HNDL)
          END ELSE
             RETURN
          END
          IF COMMENT = '' THEN RETURN
          COMMENT = TRIM(COMMENT)
          CMD = 'SELECT ENTITY.PN.IDS WITH EN.ID = ':'"':ST:'"'
          CMD := ' AND WITH PN = ':'"':PN:'"'
          EXECUTE CMD CAPTURING MSG
          READLIST XREFLIST ELSE XREFLIST = ''
          IF NOT(XREFLIST) THEN
             CMD = 'SELECT ENTITY.PN.IDS WITH EN.ID = ':'"':BT:'"'
             CMD := ' AND WITH PN = ':'"':PN:'"'
             EXECUTE CMD CAPTURING MSG
             READLIST XREFLIST ELSE XREFLIST = ''
          END
          CCNT = DCOUNT(XREFLIST,AM)
CLN.CMTS: * Routine to get ride of your # and your loc comments.
          FOR CC = 1 TO CCNT
             CLINE = XREFLIST<CC>
             CPN   = FIELD(CLINE,'~',2)
             CLOC  = FIELD(CLINE,'~',3)
             CPN   = 'Your # ':CPN
             CLOC  = 'Your Location : ':CLOC
             LCNT = 0
             ;* Be sure to clear out any already duplicated comments
             LOOP
                LCNT += 1
             WHILE LCNT LE 3
                LOCATE CPN IN COMMENT<1,1> SETTING SVPOS THEN
                   COMMENT = DELETE(COMMENT,1,1,SVPOS)
                END ELSE
                   IF INDEX(COMMENT,CPN,1) THEN
                      CSPOS = INDEX(COMMENT,CPN,1)
                      IF CSPOS GT 1 THEN
                         COMMENT = COMMENT[1,CSPOS-1]:COMMENT[CSPOS+LEN(CPN),LEN(COMMENT)]
                      END ELSE
                         COMMENT = COMMENT[CSPOS+LEN(CPN),LEN(COMMENT)]
                      END
                   END
                END
                IF CLOC THEN
                   LOCATE CLOC IN COMMENT<1,1> SETTING SVPOS THEN
                      COMMENT = DELETE(COMMENT,1,1,SVPOS)
                   END ELSE
                      IF INDEX(COMMENT,CLOC,1) THEN
                         CSPOS = INDEX(COMMENT,CLOC,1)
                         IF CSPOS GT 1 THEN
                            COMMENT = COMMENT[1,CSPOS-1]:COMMENT[CSPOS+LEN(CLOC),LEN(COMMENT)]
                         END ELSE
                            COMMENT = COMMENT[CSPOS+LEN(CLOC),LEN(COMMENT)]
                         END
                      END
                   END
                END
             REPEAT
          NEXT CC


*** Remove standard system comments.
          CTRL.ID = "NONSTOCK.COMMENT"
          GOSUB CLN.BR.CMNT
          CTRL.ID = "LEAD.PROD.COMMENT"
          GOSUB CLN.LD.CMNT
          CTRL.ID = "HAZARD.COMMENT"
          GOSUB CLN.STD.CMNT

          COMMENT = TRIM(COMMENT)

          RETURN
*-------------------------------------------------------------------------*
CLN.LD.CMNT:*** This removes the comment found in the branch specific
            *** control record specifed by CTRL.ID.
          READ CMNTS FROM CTRBFILE,CTRL.ID:'~':SHIP.BR ELSE CMNTS = ""
          NONSTOCK.COMMENTS.API CMNTS,SHIP.BR
          GOSUB CLEAN.CMNT

          RETURN
*-------------------------------------------------------------------------*
CLN.BR.CMNT:*** This removes the comment found in the branch specific
            *** control record specifed by CTRL.ID.

          READ CMNTS FROM CTRBFILE,CTRL.ID:'~':SHIP.BR ELSE CMNTS = ""
          NONSTOCK.COMMENTS.API CMNTS,SHIP.BR
          GOSUB CLEAN.CMNT

          RETURN
*-------------------------------------------------------------------------*
CLN.STD.CMNT:*** This removes the comment found in the control record
             *** specified by CTRL.ID.

          READ CMNTS FROM CTRLFILE,CTRL.ID ELSE CMNTS = ""
          GOSUB CLEAN.CMNT

          RETURN
*-------------------------------------------------------------------------*
CLEAN.CMNT:*** This removes the string in the CMNT variable from the
           *** COMMENT variable.

          FOR CX = 1 TO DCOUNT(CMNTS,VM)
             CMNT = CMNTS<1,CX>
             GOSUB CLN.CMNT
          NEXT CX

          RETURN
*-------------------------------------------------------------------------*
CLN.CMNT: *
          IF CMNT#'' THEN
             LCNT = 0
             ;* Be sure to clear out any already duplicated comments
             LOOP
                LCNT += 1
             WHILE LCNT <= 3
                LOCATE CMNT IN COMMENT<1,1> SETTING CLOC THEN
                   COMMENT = DELETE(COMMENT,1,1,CLOC)
                END ELSE
                   IF INDEX(COMMENT,CMNT,1) THEN
                      CSPOS = INDEX(COMMENT,CMNT,1)
                      IF CSPOS > 1 THEN
                         COMMENT = COMMENT[1,CSPOS-1]:COMMENT[CSPOS+LEN(CMNT),LEN(COMMENT)]
                      END ELSE
                         COMMENT = COMMENT[CSPOS+LEN(CMNT),LEN(COMMENT)]
                      END
                   END
                END
             REPEAT
          END
          RETURN
*-------------------------------------------------------------------------*

!TSMITH~01/02/14~15:07
