Application server in detail

Go down

Application server in detail

Post  govind on Thu Mar 15, 2012 7:20 pm

Application server is a secured location in SAP technology. Goto AL11, Double click on DIR_HOME & place your file in
Path :- /usr/sap/<System-ID>/DVEBMGSOO/work

In an application server we can write a file or we can read file from it. For that you need to use DATASET statement.

1. OPEN a file on application server -
By using open dataset statement we can open a file on the application server and if the file opens successfully then sy-subrc is equal to 0. If it fails sy-subrc is equal to 8.

OPEN DATASET < dsn >. "dsn = data set name
CLOSE DATASET .

2. Write Access -
In order to write a file on the application server we have to use OUTPUT statement along with open dataset.

Syntax :
OPEN DATASET < dsn > for output.
CLOSE DATASET < dsn >.

3. Read access -
In order to read a file from application server we have to use INPUT statement along with open dataset.

Syntax :
OPEN DATASET < dsn > for input.
CLOSE DATASET < dsn >.

4. Text mode/Binary mode -
In order to open a file in text mode or binary mode we have to use in text mode keyword along with open dataset.

Syntax :
OPEN DATASET < dsn > for <input/output> in <text/binary> mode.
CLOSE DATASET < dsn >.

5. Encoding type
In order to provide security to the file, use encoding type UTF-8, UTF-16 or DEFAULT.

Syntax :
OPEN DATASET < dsn > for <input/output> in <text/binary> mode encoding <UTF-8/UTF-16/DEFAULT>.
CLOSE DATASET < dsn >.

6. Transfer -
Transfer statement move the itab data to file.
Syntax :
TRANSFER < Work_area > to < dsn >.

Transfer is the only statement in ABAP/4 language that doesn’t affect sy-subrc.

7. Read
Read dataset statement is used to move the data from the file on the application server to internal table.
Syntax:
READ < dsn > to < Work_area >.


Example a file creating on the application server :
Code:

*&---------------------------------------------------------------------*
*& Report  ZSAMPLE_BDC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZSAMPLE_BDC.

TYPES : BEGIN OF TY_MAT,
          MATNR(18) TYPE C,
          MBRSH(1) TYPE C,
          MTART(4) TYPE C,
          MAKTX(40) TYPE C,
          MATKL(3) TYPE C,
          MEINS(9) TYPE C,
        END OF TY_MAT.

*\*********************************************
*\      Declare internal table and work area  *
*\*********************************************

DATA : IT_MAT TYPE TABLE OF TY_MAT,
      WA_MAT TYPE TY_MAT.

PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  PERFORM SUB_GET_FILE_NAME.    "******    Get F4 functionality

START-OF-SELECTION.

  PERFORM SUB_UPLOAD_DATA.      "******    Data is Retrieved in Internal Table

  PERFORM SUB_CREATE_FILE.
*&---------------------------------------------------------------------*
*&      Form  sub_get_file_name
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_GET_FILE_NAME .

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
* EXPORTING
*  PROGRAM_NAME        = SYST-REPID
*  DYNPRO_NUMBER      = SYST-DYNNR
*  FIELD_NAME          = ' '
*  STATIC              = ' '
*  MASK                = ' '
    CHANGING
      FILE_NAME          = P_FILE
  EXCEPTIONS
    MASK_TOO_LONG      = 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.

ENDFORM.                    " sub_get_file_name
*&---------------------------------------------------------------------*
*&      Form  sub_upload_data
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_DATA .

  DATA : V_FILE TYPE STRING.
  CLEAR V_FILE.
  V_FILE = P_FILE.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                      = V_FILE
*  FILETYPE                      = 'ASC'
  HAS_FIELD_SEPARATOR          = '#'
*  HEADER_LENGTH                = 0
*  READ_BY_LINE                  = 'X'
*  DAT_MODE                      = ' '
*  CODEPAGE                      = ' '
*  IGNORE_CERR                  = ABAP_TRUE
*  REPLACEMENT                  = '#'
*  CHECK_BOM                    = ' '
*  VIRUS_SCAN_PROFILE            =
*  NO_AUTH_CHECK                = ' '
*  CHECK_EMPTY                  = ' '
* IMPORTING
*  FILELENGTH                    =
*  HEADER                        =
    TABLES
      DATA_TAB                      = IT_MAT
 EXCEPTIONS
  FILE_OPEN_ERROR              = 1
  FILE_READ_ERROR              = 2
  NO_BATCH                      = 3
  GUI_REFUSE_FILETRANSFER      = 4
  INVALID_TYPE                  = 5
  NO_AUTHORITY                  = 6
  UNKNOWN_ERROR                = 7
  BAD_DATA_FORMAT              = 8
  HEADER_NOT_ALLOWED            = 9
  SEPARATOR_NOT_ALLOWED        = 10
  HEADER_TOO_LONG              = 11
  UNKNOWN_DP_ERROR              = 12
  ACCESS_DENIED                = 13
  DP_OUT_OF_MEMORY              = 14
  DISK_FULL                    = 15
  DP_TIMEOUT                    = 16
  OTHERS                        = 17
            .
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " sub_upload_data
*&---------------------------------------------------------------------*
*&      Form  SUB_CREATE_FILE
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_CREATE_FILE .

  DATA : DSN TYPE STRING VALUE 'SAMPLE.TXT'.


  OPEN DATASET DSN FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.


  LOOP AT IT_MAT INTO WA_MAT.


    TRANSFER WA_MAT TO DSN.

    CLEAR WA_MAT.

  ENDLOOP.

  CLOSE DATASET DSN.

  WRITE : / 'Successfully uploaded in application server'.

ENDFORM.                    " SUB_CREATE_FILE

govind
Admin

Posts : 54
Join date : 2012-01-31

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum