Samples
This section provides an Advanced Business Application Programming (ABAP) program sample.
ABAP Program Sample
ABAP is a high level programming language used for developing application for SAP R/3 system.
Following is the sample ABAP Program for INSERTTOKEN function module created in the section Creating a Functional Module.
Section A
*&---------------------------------------------------------------------*
*& Report Z_INSERTTOKEN
*&
*&---------------------------------------------------------------------*
*&ts.insert(String value,String table,int format, boolean luhncheck);
*&ts.insert(String value,String CustomData,String table,int format,boolean luhncheck);
*&---------------------------------------------------------------------*
Section B
REPORT Z_INSERTTOKEN.
PARAMETERS : NAEUSER TYPE STRING LOWER CASE,
NAEPASS TYPE STRING LOWER CASE,
DBUSER TYPE STRING LOWER CASE,
DBPASS TYPE STRING LOWER CASE,
VALUE TYPE STRING LOWER CASE,
TABLE TYPE STRING,
CUSTDATA TYPE STRING LOWER CASE,
FORMAT TYPE I,
LUHNCHK TYPE BOOLEAN.
DATA : RFC_MESS(128) VALUE 'none',
TOKEN TYPE STRING, RFC_MESS1(128) VALUE 'none' .
Section C
CALL FUNCTION 'INSERTTOKEN'
DESTINATION 'SAPTM_DES'
EXPORTING
NAEUSER = NAEUSER
NAEPASSWORD = NAEPASS
DBUSER = DBUSER
DBPASSWORD = DBPASS
VALUE = VALUE
TABLENAME = TABLE
CUSTOMDATA = CUSTDATA
FORMAT = FORMAT
LUHNCHECK = LUHNCHK
IMPORTING
TOKEN = TOKEN
EXCEPTIONS
SYSTEM_FAILURE = 1 MESSAGE RFC_MESS
COMMUNICATION_FAILURE = 2 MESSAGE RFC_MESS1
ERROR = 3.
Section D
IF SY-SUBRC = 0.
WRITE: 'Token Received :' ,TOKEN.
ELSEIF SY-SUBRC = 1.
WRITE: 'ERROR text: ',RFC_MESS.
ELSEIF SY-SUBRC = 2.
WRITE: 'ERROR text: ',RFC_MESS1.
WRITE: 'ERROR text 3: ', SY-MSGID, SY-MSGTY , SY-MSGNO , SY-MSGV1 , SY-MSGV2.
ELSE.
WRITE: 'ERROR text: '.
ENDIF.
Section A in the preceding program consists of comments for the ABAP program. The comment should always start with ‘*&’.
Following two comments represent the TM Java API calls supported by the INSERTTOKEN function module created in SAP:
*&ts.insert(String value, String table, int format, boolean luhncheck);
*&ts.insert(String value, String CustomData, String table, int format, boolean luhncheck);
Section B in the preceding program shows the internal parameter declaration for ABAP program.
Following is the syntax to declare parameters in ABAP:
`PARAMETERS : <<Parameter Name>> TYPE <<Parameter Type>> LOWER CASE`.
where, LOWER CASE
indicates the retention of the case (Upper/Lower) provided as in Input.
Section C in the preceding program shows the actual calling of Remote Function Module (RFM) destination through ABAP. While calling RFC, user must enter the exact name and case of the function module and SAPTM_DES as the destination as shown below:
CALL FUNCTION 'INSERTTOKEN'
DESTINATION 'SAPTM_DES'
In EXPORTING, user must supply all non-optional import parameters of the function modules with values appropriate to their type.
In IMPORTING, user may receive the export parameters from the function module by assigning them to variables of the appropriate type.
In EXCEPTIONS, allows user to handle the exceptions of function module.
Section D in the preceding program shows the response handling of the function module. The SY-SUBRC
is a return code set by the ABAP program. SY-SUBRC = 0
depicts the function module was executed successfully.
However, if SY-SUBRC = 1
, then the function module has encountered an error of system failure with error message received in variable RFC_MESS
(as per the mapping done in EXCEPTIONS).
If SY-SUBRC = 2
, then the function module has encountered an error of communication failure with error message received in variable RFC_MESS1
(as per the mapping done in EXCEPTIONS).
If SY-SUBRC = 3
, then the function module has encountered an exception during the execution of CT-V API with the error message and status received in SY-MSGID
, SY-MSGTY
, SY-MSGNO
, SY-MSGV1
, SY-MSGV2
.