Welcome to SAP Central
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Upload Presentation server data to SAP (GUI_UPLOAD)

Go down

Upload Presentation server data to SAP (GUI_UPLOAD) Empty Upload Presentation server data to SAP (GUI_UPLOAD)

Post  Admin Wed Mar 14, 2012 1:15 am

If a file is present in the presentation server and you want to upload data from the file to your program then you need to use function module GUI_UPLOAD or you can use class CL_GUI_FRONTEND_SERVICES. In that one method GUI_UPLOAD.

Consider an example, you want to create a material from ‘MM01’, then you will be provided with the flat file with the following fields.


Consider Flat file contents :

100-2004 M ROH sample data KG 001
100-2005 M ROH sample data KG 001
100-2006 M ROH sample data KG 001
100-2007 M ROH sample data KG 001
100-2008 M ROH sample data KG 001

In order to fetch above data into internal table you need to write following code.


Code:


*&
*&---------------------------------------------------------------------*

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_DISPLAY_DATA.
*&---------------------------------------------------------------------*
*&      Form  sub_get_file_name
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_GET_FILE_NAME .

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

    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          = '#'

    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_display_data
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_DISPLAY_DATA .

  LOOP AT IT_MAT INTO WA_MAT.

    WRITE : / WA_MAT-MATNR,
              WA_MAT-MBRSH,
              WA_MAT-MTART,
              WA_MAT-MAKTX,
              WA_MAT-MATKL,
              WA_MAT-MEINS.

  ENDLOOP.

ENDFORM.                    " sub_display_data


Execute the program
Press F4 and select file

Upload Presentation server data to SAP (GUI_UPLOAD) 1

Select the file as input & Press Execute(F8)

Upload Presentation server data to SAP (GUI_UPLOAD) 2

Admin
Admin

Posts : 92
Join date : 2012-01-26

https://mysaplab.forumotion.com

Back to top Go down

Back to top

- Similar topics

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