SAP_CMCERR 

Use

SAP_CMCERR checks whether the data received from the R/2 or R/3 System constitutes an error message. If it does, the message is formatted for output and a pointer is returned to the error text. If the data does not contain an error message, SAP_CMCERR returns the value 0.

PCPIC_CHAR s;

..
<Build connect string and send to R/2 or R/3>
..
CMRCV(conv_id, input, &requested_length, &data_received,
&received_length, &status_received,
&request_to_send_received, &return_code);

if ((return_code != CM_OK) &&
(return_code != CM_DEALLOCATED_NORMAL))
{
printf("CMRCV: %d\n",return_code);
printf("SAP-INFO: %s\n", SAP_CMPERR());
exit(1);
}

if (return_code == CM_DEALLOCATED_NORMAL)
{
if ((s = SAP_CMCERR(input, &received_length)) != (PCPIC_CHAR *)0)
{
printf("CPIC-Login-Error: %s\n", s);
exit(1);
}
else
{
printf("CMRCV: %d\n",return_code);
printf("SAP-INFO: %s\n", SAP_CMPERR());
exit(1);
}
}
..