Wednesday, May 28, 2008

SAP ABAP Random Number Generator

SAP ABAP Random Number Generator

If you wish to generate a Random Number in ABAP you can use the following function module.

QF05_RANDOM_INTEGER

Here you need to input 2 numbers ie the upper limit and the lower limit. This works only for integers.

Please find the code below.

REPORT ZEX_RANDOMNUMBER .

Parameters: p_larg like QF00-RAN_INT,
            p_small like QF00-RAN_INT.

Data: d_result like QF00-RAN_INT.

CALL FUNCTION 'QF05_RANDOM_INTEGER'
 EXPORTING
   RAN_INT_MAX         = p_larg
   RAN_INT_MIN         = p_small
 IMPORTING
   RAN_INT             = d_result
 EXCEPTIONS
  INVALID_INPUT       = 1
   OTHERS              = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


Write:/ 'The Number is = ' , d_result.



If you enter  100 and 5 then  the result would be any number between 5 and 100 inclusive of 5 and 100.

 

SAP IDOC

SAP IDOC

Basically an IDOC is formed of segments, and comprises of IDOC Type and IDOC Data. IDOC types defines the structure and format of the data being exchanged. You can see in the figure below how an IDOC is represented in the SAP system. Please note that when you are looking at an IDOC of Sales Order, the generated IDOC will have all the data stored in the Sales Order, also there are means of filtering out the data that you do not want to include in the IDOC or you can also include some addition data. The actual Sales Order will be saved in the tables associated with Sales Order example VBAK, VBAP etc. Where as the generated IDOC will be stored separately.

Typically an IDOC will have the following
  • Control Record
  • Data Records
  • Status Records
Please see the figure given below.



Control Record:

Will have all the following.
  • IDOC number
  • IDOC TYPE
  • Sender and Receiver Information
  • Message Type
Please note that there is only one control record per IDOC and the structure of IDOC control record is the same for all IDOCs.

Data Record:

This basically contains the data, the header data and the line item data for a particular IDOC for example Sales Order or Purchase Order. These are multiple records.

Status Record:

This represents the different status the IDOC goes through. And a status record will have multiple statuses. A status code, Date and Time are assigned.