Monday, May 12, 2008

SAP ABAP Data Download to Application Server OPEN DATASET

SAP ABAP Transferring Internal Table Contents to a file on the Application Server

In SAP ABAP you can transfer the contents of the internal table to a file. This is required when you wish to extract data from SAP tables into a flat file. This file can then be used to transfer data to another SAP or NON SAP system. This can also be used for an interfacing when you wish to transfer data on a daily or a weekly basis from R/3 to NON R/3 or SAP. The command used to create a file on the application server is as follows.

OPEN DATASET

Please see example code below.

REPORT ZEX_DATATOFILE .

*&---------------------------------------------------------------------*
*& ABAPLOVERS: Data Transfer
*&---------------------------------------------------------------------*

* Parameters to enter the path
PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat'
                         LOWER CASE.
* Table Declaration
TABLES VBAK.

* Data Declaration
DATA D_MSG_TEXT(50).

* Get data for file transfer
DATA INT_VBAK LIKE VBAK OCCURS 100
                   WITH HEADER LINE.
SELECT * FROM VBAK INTO TABLE INT_VBAK.
SORT INT_VBAK BY VBELN.
LOOP AT INT_VBAK.
  WRITE: / INT_VBAK-VBELN,
           INT_VBAK-KUNNR.
ENDLOOP.

* Opening the File
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
                      MESSAGE D_MSG_TEXT.
IF SY-SUBRC NE 0.
  WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.
  EXIT.
ENDIF.
* Transferring Data
LOOP AT INT_VBAK.
  TRANSFER INT_VBAK-VBELN TO FILENAME.
ENDLOOP.
* Closing the File
CLOSE DATASET FILENAME.


SAP ABAP Function Module to POUP a Calender as per the selected Calender

SAP ABAP Function Module to POPUP a Calender as per the selected Calender

If you wish to display a calender so that the user can choose the date from the POPUP it can be done with the help of the following function module.

F4_DATE

You can select the date from the POPUP, the transaction code SCAL can be used to display Public Holidays, Holiday Calender, Factory Calender.

The following program shows the various Parameters Passed to the function module.


REPORT ZEX_CALENDERPOPUP .


Parameters: p_date like sy-datum.

Data: d_seldate like WORKFLDS-GKDAY,
      d_sweek   like SCAL-WEEK.


      CALL FUNCTION 'F4_DATE'
       EXPORTING
         DATE_FOR_FIRST_MONTH               = p_date
         DISPLAY                            = 'X'
         FACTORY_CALENDAR_ID                = 'BR'
*         GREGORIAN_CALENDAR_FLAG            = ' '
         HOLIDAY_CALENDAR_ID                = '11'
*         PROGNAME_FOR_FIRST_MONTH           = ' '
       IMPORTING
         SELECT_DATE                        = d_seldate
*         SELECT_WEEK                        =
*         SELECT_WEEK_BEGIN                  =
*         SELECT_WEEK_END                    =
        EXCEPTIONS
         CALENDAR_BUFFER_NOT_LOADABLE       = 1
         DATE_AFTER_RANGE                   = 2
         DATE_BEFORE_RANGE                  = 3
         DATE_INVALID                       = 4
         FACTORY_CALENDAR_NOT_FOUND         = 5
         HOLIDAY_CALENDAR_NOT_FOUND         = 6
         PARAMETER_CONFLICT                 = 7
         OTHERS                             = 8
                .
      IF SY-SUBRC <> 0.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.