/*------------------------------------------------------------------*/
/*    Programmers Group & Management Resource    Copyright  1997    */
/*                                                                  */
/*                             \\\\\\\                              */
/*                            ( o   o )                             */
/*------------------------oOO----(_)----OOo-------------------------*/
/*                                                                  */
/*  System name  . . . :   PGMR Tool                                */
/*  Program name . . . :   MOVMC                                    */
/*  Text . . . . . . . :   CPP for MOVM                             */
/*                                                                  */
/*  Author . . . . . . :   Alexander Nubla                          */
/*  Creation date. . . :   11/25/97                                 */
/*  Description. . . . :   This program allows moving a member from */
/*                         one source file to another.              */
/*                                                                  */
/*                     ooooO              Ooooo                     */
/*                     (    )             (    )                    */
/*----------------------(   )-------------(   )---------------------*/
/*                       (_)               (_)                      */
/*                                                                  */
/*  Modification Log:                                               */
/*                                                                  */
/*  Date     Task  Programmer/Description                           */
/*  -------- ----- ------------------------------------------------ */
/*  11/25/97       Alex Nubla                                       */
/*                 Created                                          */
/*                                                                  */
/*------------------------------------------------------------------*/
             pgm        (&ffile        /* From File (Full)      */   +
                         &tfile        /* To File (Full)        */   +
                         &frommbr      /* From Member           */   +
                         &tombr        /* To Member             */   +
                         &replace)     /* Replace source member */

/*--------------------------------------------------------*/
/*  declaration                                           */
/*--------------------------------------------------------*/
             dcl        &ffile     *char   20
             dcl        &tfile     *char   20
             dcl        &frommbr   *char   10
             dcl        &tombr     *char   10
             dcl        &replace   *char    4

             dcl        &fromfile  *char   10
             dcl        &fromlib   *char   10
             dcl        &tofile    *char   10
             dcl        &tolib     *char   10
             dcl        &rfromlib  *char   10
             dcl        &rtolib    *char   10
             dcl        &operator  *char   15    ' moved to'

             dcl        &error     *lgl                   /* std err */
             dcl        &msgid     *char    7             /* std err */
             dcl        &msgkey    *char    4             /* std err */
             dcl        &msgdta    *char  100             /* std err */
             dcl        &msgf      *char   10             /* std err */
             dcl        &msgflib   *char   10             /* std err */
             dcl        &msgtyp    *char   10  '*DIAG'    /* std err */
             dcl        &msgtypctr *char    4 X'00000001' /* std err */
             dcl        &pgmmsgq   *char   10  '*'        /* std err */
             dcl        &stkctr    *char    4 X'00000001' /* std err */
             dcl        &errbytes  *char    4 X'00000000' /* std err */

             monmsg     msgid(cpf0000) exec(goto error)

             chgvar     &fromfile  %sst(&ffile   1 10)
             chgvar     &fromlib   %sst(&ffile  11 10)
             chgvar     &tofile    %sst(&tfile   1 10)
             chgvar     &tolib     %sst(&tfile  11 10)
             chgvar     &rfromlib  &fromlib
             chgvar     &rtolib    &tolib
/*--------------------------------------------------------*/
/*  Check to see if the user is authorized to member      */
/*--------------------------------------------------------*/
             chkobj     obj(&fromlib/&fromfile)  +
                        objtype(*file)           +
                        mbr(&frommbr)            +
                        aut(*OBJOPR *OBJEXIST *READ)
/*--------------------------------------------------------*/
/*  Check to see to member is the same as from member     */
/*--------------------------------------------------------*/
             if         (&tombr = '*FROMMBR')    do
               chgvar     &tombr     &frommbr
             enddo
/*--------------------------------------------------------*/
/*  Retrieve the from lib from the library list           */
/*--------------------------------------------------------*/
             if         (&fromlib = '*LIBL')     do
               rtvmbrd    file(&fromlib/&fromfile) +
                          mbr(&frommbr)            +
                          rtnlib(&rfromlib)
             enddo
/*--------------------------------------------------------*/
/*  Retrieve the to lib from the library list             */
/*--------------------------------------------------------*/
             if         (&tolib = '*LIBL')       do
               rtvmbrd    file(&tolib/&tofile)     +
                          mbr(&tombr)              +
                          rtnlib(&rtolib)
             enddo
/*--------------------------------------------------------*/
/*  If REPLACE(*NO) is used, check for member existence   */
/*--------------------------------------------------------*/
             if         (&replace = '*NO')       do
               chkobj     obj(&tolib/&tofile) +
                          objtype(*file)      +
                          mbr(&tombr)
          /*----------------------------------------------*/
          /*  Goto copy if member does not exist          */
          /*----------------------------------------------*/
               monmsg     cpf9815    exec(goto COPY)
          /*----------------------------------------------*/
          /*  If member exist & REPLACE(*NO) is used.     */
          /*  error out and inform user to REPLACE(*YES)  */
          /*----------------------------------------------*/
               sndpgmmsg  msgid(cpf9898)           +
                          msgf(QCPFMSG)            +
                          msgtype(*escape)         +
                          msgdta('Member'   |> &tombr   |> +
                                 'exist in' |> &tolib   |< +
                                 '/'        |< &tofile  |< +
                                 '. Use REPLACE(*YES)')
             enddo
/*--------------------------------------------------------*/
/*  REPLACE(*YES) requested at by user                    */
/*--------------------------------------------------------*/
             chkobj     obj(&tolib/&tofile) +
                        objtype(*file)      +
                        mbr(&tombr)
          /*----------------------------------------------*/
          /*  to member does not exist                    */
          /*----------------------------------------------*/
             monmsg     cpf9815    exec(goto COPY)
          /*----------------------------------------------*/
          /*  to member exist                             */
          /*----------------------------------------------*/
             chgvar     &operator  ' replaces'
/*--------------------------------------------------------*/
/*  Copy from file to file                                */
/*--------------------------------------------------------*/
 Copy:
             cpyf       fromfile(&fromlib/&fromfile)  +
                        tofile(&tolib/&tofile)        +
                        frommbr(&frommbr)             +
                        tombr(&tombr)                 +
                        mbropt(*replace)
          /*----------------------------------------------*/
          /*  Catch all error - empty member              */
          /*----------------------------------------------*/
             monmsg     msgid(cpf2817)      +
                        cmpdta(cpf2869)
/*--------------------------------------------------------*/
/*  Remove the member from the from file                  */
/*--------------------------------------------------------*/
 Rmvm:
             Rmvm       file(&fromlib/&fromfile) +
                        mbr(&frommbr)
             sndpgmmsg  msgid(cpf9898)           +
                        msgf(QCPFMSG)            +
                        msgtype(*comp)           +
                        msgdta('Member'   |> &frommbr  |> +
                               'in'       |> &fromlib  |< +
                               '/'        |< &fromfile |< +
                               &operator  |> &tombr    |> +
                               'in'       |> &tolib    |< +
                               '/'        |< &tofile)
             rmvmsg     clear(*all)
             return

/*--------------------------------------------------------*/
/*  error routine:                                        */
/*--------------------------------------------------------*/
 error:
             if         &error     (goto errordone)
               else      chgvar       &error  '1'
          /*----------------------------------------------*/
          /*  move all *DIAG message to *PRV program queue*/
          /*----------------------------------------------*/
             call       QMHMOVPM   (&msgkey      +
                                    &msgtyp      +
                                    &msgtypctr   +
                                    &pgmmsgq     +
                                    &stkctr      +
                                    &errbytes)
          /*----------------------------------------------*/
          /*  resend the last *ESCAPE message             */
          /*----------------------------------------------*/
 errordone:
             call       QMHRSNEM   (&msgkey      +
                                    &errbytes)
             monmsg     cpf0000    exec(do)
               sndpgmmsg  msgid(cpf3cf2) msgf(QCFPMSG) +
                            msgdta('QMHRSNEM') msgtype(*escape)
               monmsg     cpf0000
             enddo
 end:        endpgm
