Upload Presentation server data to SAP (GUI_UPLOAD)
Page 1 of 1
Upload Presentation server data to SAP (GUI_UPLOAD)
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.
Execute the program
Press F4 and select file
Select the file as input & Press Execute(F8)
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
Select the file as input & Press Execute(F8)
Similar topics
» Batch Data Communication
» Describe data classes and Master data in SAP
» What are DATA CLUSTERS ?
» What are the different methods of passing data?
» What are type of Data classes?
» Describe data classes and Master data in SAP
» What are DATA CLUSTERS ?
» What are the different methods of passing data?
» What are type of Data classes?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP