Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
JanStallkamp
Employee
Employee

SAP on IBM DB2 for i - News from Development

memberIsLeaving, /* 9 /, failover</pre>and<br /><pre>switchPrimary,   / 10 */, switchoverTo keep this blog readable the sourcecode is not included here but can be found on a separate page here in the SDN.

h5. Codelisting of ILE CL STRSAPCRG, gets called from CRGEXIT

STRSAPCRG gets the iASP name as input from CRGEXIT, and calls SYSSTRLIST for a list of SAP_systems_to start, retrieves the instancenumbers of the SAP systems and submits a startjob for every SID in the list.

To do that, it will need the programs RTVSAPINST and GETSAPINST that should be copied from a kernellibrary to QGPL. It will be implemented as ILE CL and is simple by design for better understanding.

PGM         PARM(&PAR)

DCL         &PAR     *CHAR 256

DCL         &INST1   *CHAR   2

DCL         &INST2   *CHAR   2

DCL         &SID     *CHAR   3

DCL         &MUTE    *CHAR   1 '1'

DCL         &FAILED  *CHAR   1

DCL         &LIB400  *CHAR  10 'R3   400  '

DCL         &IASPP   *CHAR  10 '          '

DCL         &SBS     *CHAR   5

DCL         &JOB     *CHAR   8    'START   '

DCL         &USER    *CHAR   6    '   ADM'

DCL         &SYSLIST *CHAR  61    ' '

DCL         &Z       *DEC    3 0

DCL         &MSG     *CHAR 512

/* GET LIST OF SIDS    */

CHGVAR &IASPP &PAR

CALL SYSSTRLIST PARM(&SYSLIST &IASPP)

     CHGVAR     VAR(&MSG) VALUE('List is ' *CAT &SYSLIST)

     SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +

                          TOPGMQ(SAME) MSGTYPE(INFO)

IF (%SST(&SYSLIST 1 6) *EQ 'failed') DO

             CHGVAR     VAR(&MSG) VALUE('Error occured: ' *CAT &SYSLIST)

     SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +

                          TOPGMQ(PRV) MSGTYPE(INFO)

     GOTO ENDE

ENDDO

/*   */

CHGVAR &Z 1

LOOP:

CHGVAR &SID %SST(&SYSLIST &Z 3)

IF (%SST(&SID 1 1) *EQ ' ') GOTO ENDE

IF (%SST(&SID 3 1) *EQ ' ') GOTO ENDE

CHGVAR %SST(&LIB400  3  3) ( &SID )

CALL RTVSAPINST PARM(&SID &INST1 &INST2 &FAILED &MUTE)

IF (&FAILED *NE '0') DO

     CHGVAR     VAR(&MSG) VALUE('Instance(s) of system ' +

                          *CAT &SID *CAT ' could not be +

                          retrieved')

     SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +

                          TOPGMQ(SAME) MSGTYPE(INFO)

   GOTO NOINST

ENDDO

CHGVAR &SBS VALUE('R3_' *CAT &INST1)

             CHGVAR %SST(&LIB400  3  3) ( &SID )

             CHGVAR &SBS ('R3_' *CAT &INST1)

             STRSBS SBSD(&LIB400/&SBS)

             MONMSG MSGID(CPF1010)

             CHGVAR %SST(&JOB  6  3) ( &SID )

             CHGVAR %SST(&USER 1  3) ( &SID )

             DLYJOB 60

             CHGVAR    VAR(&MSG) VALUE('Now starting ' *CAT &SID)

             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +

                          TOPGMQ(SAME) MSGTYPE(INFO)

             SBMJOB     CMD(CALL PGM(STRSAP) PARM(&SID &INST1 +

                          &INST2)) JOB(&JOB) JOBD(&LIB400/&SBS) +

                          USER(&USER) INLASPGRP(&IASPP)

             MONMSG     MSGID(CPF1338) EXEC(GOTO CMDLBL(ENDE))

NOINST:

CHGVAR &Z VALUE(&Z + 3)

IF (&Z *GT 19) DO

             CHGVAR     VAR(&MSG) VALUE('Found too many entries in +

                          //usr/sap/sysstrlist')

     SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +

                          TOPGMQ(PRV) MSGTYPE(INFO)

     GOTO ENDE

ENDDO

GOTO LOOP

ENDE:

ENDPGM# comment

  1. still commentline, now following are SIDs of systems to be started

  1. and so on

int main(int argc, char *argv[])

{

  int ret, fd, rc, pos;

  char in[100]="";

  char iASP[11];

  char first = '1';

  char *inP;

  char out[100]="";

  char *outP;

  char path[512] = "";

  char SID[3];

  int flag = O_RDONLY | O_TEXTDATA | O_CCSID;

  unsigned int open_ccsid = 37;

  mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR;

  memcpy(iASP,argv[2],10);

  pos=strcspn(iASP, " ");

  iASP[pos]= ' ';

  sprintf(path, "/%s/usr/sap/sysstrlist", iASP);

  if ((fd = open(path, flag, mode, open_ccsid)) < 0)

  {

    sprintf(out, "failed, file sysstrlist not found in %s", path);

    strcpy(argv[1], out);

    return 0;

  }

  else {

      ret = read(fd, in, sizeof(in)-1);

      in[ret] = 0x00;

      if (close(fd)!= 0)

      {

         sprintf(out, "failed, file close error for %s", path);

         strcpy(argv[1], out);

         return 0;

       }

    }

  //

  inP = in;

  outP = out;

  while (*inP)

  {

     if ((inP == 0x25) && ((inP+1) == '#') || (*inP == '#') && first)

     {// comment - proceed until next CR/LF

         *inP++;

         while ((inP) && (inP != 0x25))

         {

            *inP++;

         }

     }

     first = '0';

     if((inP != ' ') && (inP != 0x0D) && (*inP != 0x25))

     {

        memcpy(SID, inP, 3);

        memcpy(outP, SID, 3);

        outP += 3;

        *inP++;

        *inP++;

     }

     *inP++;

  }

  strcpy(argv[1], out);

  return 0;

}