Upload the XL sheet to an IT
Hi all,
While I am uploading the data from XL sheet to internal table and displaying the IT, I am not getting the actual fields. I am getting some ascii characters on the output screen. How to get the actul output.
Sathish.
Hi Sathish ,
you can use the pgm for your purpose.
REPORT YSK_TEST .
*sample program to upload an Excel file from
*presentation server and display its content
*in an ALV report
type-pools : slis.
types: begin of t_data,
name(20),
age(2),
ann_inc(8),
end of t_data.
data : i_data type standard table of t_data,
wa_data like line of i_data.
data : v_temp_file like IBIPPARMS-PATH,
file_path like IBIPPARMS-PATH .
data : itab like table of ALSMEX_TABLINE with header line.
data : crr_row type i.
*data declaration for report part.
DATA : I_LAYOUT TYPE SLIS_LAYOUT_ALV, "Internal table for layout
I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "fieldcatalog
I_EVENTS TYPE SLIS_T_EVENT, "internal table to store events
Work Area Declaration *
LINE_EVENT TYPE SLIS_ALV_EVENT,"work area for events
WA_CAT TYPE SLIS_FIELDCAT_ALV, " Catalog Attributes
WA_PRINT_ALV TYPE SLIS_PRINT_ALV, " ALV format
Variable Declaration *
REPORT_ID LIKE SY-REPID. "Report Name
*end of data declaration for report.
selection screen
parameters : pre_path TYPE RLGRAP-FILENAME default
'C:\Documents and Settings\sumitk\Desktop\sumit.xls'.
at sellection screen.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pre_path.
perform get_pre.
at selection-screen.
perform upload_data.
perform process_data.
end-of-selection.
perform write_report.
*& Form get_pre
text
--> p1 text
<-- p2 text
FORM get_pre.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = v_temp_file.
if v_temp_file <> ' '.
pre_path = v_temp_file.
endif.
ENDFORM. " get_pre
*& Form upload_data
text
--> p1 text
<-- p2 text
FORM upload_data.
move pre_path to file_path.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = file_path
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 4
I_END_ROW = 100
TABLES
INTERN = itab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
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. " upload_data
*& Form process_data
text
--> p1 text
<-- p2 text
FORM process_data.
sort itab by row col.
read table itab index 1.
crr_row = itab-row.
loop at itab.
if itab-row <> crr_row.
append wa_data to i_data.
clear wa_data.
crr_row = itab-row.
endif.
case itab-col.
when '0001'.
wa_data-name = itab-value.
when '0002'.
wa_data-age = itab-value.
when '0003'.
wa_data-*** = itab-value.
when '0004'.
wa_data-ann_inc = itab-value.
endcase.
endloop.
append wa_data to i_data.
ENDFORM. " process_data
*& Form write_report
text
--> p1 text
<-- p2 text
FORM write_report.
REPORT_ID = SY-REPID.
*create layout.
I_LAYOUT-INFO_FIELDNAME = 'COLOR'.
I_LAYOUT-DETAIL_INITIAL_LINES = 'X'. " Blank lines between records
I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = report_id
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'ALV_USER_COMMAND'
IT_EXCLUDING =
PERFORM FIELDCAT_INIT USING 'I_DATA' CHANGING I_FIELDCAT.
PERFORM MODIFY_FLDCAT TABLES I_FIELDCAT.
PERFORM ALV_PREPARE_EVENT_LIST USING I_EVENTS.
CLEAR LINE_EVENT.
READ TABLE I_EVENTS
INTO LINE_EVENT WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.
IF SY-SUBRC EQ 0.
LINE_EVENT-FORM = 'REPORT'.
MODIFY I_EVENTS FROM LINE_EVENT INDEX SY-TABIX.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = i_layout
IT_FIELDCAT = i_fieldcat
I_TABNAME = 'i_data'
IT_EVENTS = i_events
IT_SORT =
I_TEXT = ' '
TABLES
T_OUTTAB = i_data
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Display ALV report.
WA_PRINT_ALV-NO_PRINT_SELINFOS = 'X'.
WA_PRINT_ALV-NO_COVERPAGE = 'X'.
WA_PRINT_ALV-NO_PRINT_LISTINFOS = 'X'.
WA_PRINT_ALV-RESERVE_LINES = 1.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
IS_PRINT = WA_PRINT_ALV
EXCEPTIONS
PROGRAM_ERROR = 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. " write_report
*& Form FIELDCAT_INIT
text
-->P_0276 text
<--P_I_FIELDCAT text
FORM FIELDCAT_INIT USING P_ITAB
CHANGING ITAB_FLDCAT .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = REPORT_ID
I_INTERNAL_TABNAME = P_ITAB
I_STRUCTURE_NAME = 'T_DATA'
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = REPORT_ID
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = ITAB_FLDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
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. " FIELDCAT_INIT
*& Form MODIFY_FLDCAT
text
-->P_I_FIELDCAT text
FORM MODIFY_FLDCAT TABLES I_FIELDCAT .
CLEAR wa_CAT.
WA_CAT-ROW_POS = 1.
WA_CAT-COL_POS = 1.
WA_CAT-OUTPUTLEN = 20.
WA_CAT-FIELDNAME = 'NAME'.
WA_CAT-TABNAME = 'I_DATA'.
WA_CAT-SELTEXT_M = 'Name'.
APPEND WA_CAT TO I_FIELDCAT.
CLEAR wa_CAT.
WA_CAT-ROW_POS = 1.
WA_CAT-COL_POS = 2.
WA_CAT-OUTPUTLEN = 2.
WA_CAT-FIELDNAME = 'AGE'.
WA_CAT-TABNAME = 'I_DATA'.
WA_CAT-SELTEXT_M = 'Age'.
APPEND WA_CAT TO I_FIELDCAT.
CLEAR wa_CAT.
WA_CAT-ROW_POS = 1.
WA_CAT-COL_POS = 3.
WA_CAT-OUTPUTLEN = 1.
WA_CAT-FIELDNAME = '***'.
WA_CAT-TABNAME = 'I_DATA'.
WA_CAT-SELTEXT_M = '***'.
APPEND WA_CAT TO I_FIELDCAT.
CLEAR wa_CAT.
WA_CAT-ROW_POS = 1.
WA_CAT-COL_POS = 4.
WA_CAT-OUTPUTLEN = 20.
WA_CAT-FIELDNAME = 'ANN_INC'.
WA_CAT-TABNAME = 'I_DATA'.
WA_CAT-SELTEXT_M = 'Annual Income'.
APPEND WA_CAT TO I_FIELDCAT.
ENDFORM. " MODIFY_FLDCAT
*& Form ALV_PREPARE_EVENT_LIST
text
-->P_I_EVENTS text
FORM ALV_PREPARE_EVENT_LIST USING P_I_EVENTS TYPE SLIS_T_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = P_I_EVENTS
EXCEPTIONS
LIST_TYPE_WRONG = 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. " ALV_PREPARE_EVENT_LIST
FORM REPORT.
PERFORM TOP_OF_PAGE.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Excel Sheet To ALV' CENTERED.
FORMAT RESET.
ENDFORM.
*& Form TOP_OF_PAGE
text
--> p1 text
<-- p2 text
FORM TOP_OF_PAGE.
FORMAT COLOR COL_HEADING ON.
ULINE.
write 'Excel to ALV hai na mast' CENTERED.
ULINE.
FORMAT COLOR COL_HEADING OFF.
ENDFORM. " TOP_OF_PAGE
Similar Messages
-
Upload the excel sheet in table maintenance
Hi,
I have a requirement to add a button in the application toolbar of the table maintenance screen of a custom table. This button should upload the excel sheet data into the maintenance screen online.
I have created the button in the table maintenance generator. Also, uploaded the data into the internal table from the excel sheet.
The problem is I am unable to populate the data from the internal table to the maintenance screen online.
Any pointers in this regards will be appreciated.
Thanks,
Best regards,
AjithHi Mukul,
I created a custom table ZHEDGERES. Then in the table maintenance -> environment -> modification -> user interface I selected Individual interface.
Then, in the Menu painter for the program SAPLZHEDGERES, modified the PF status EULG and added the additional button in the Application toolbar. This application toolbar needs to be used to trigger the upload of excel into the custom table.
Below is the standard code which is generated in the screen painter of the custom table.
PROCESS BEFORE OUTPUT.
MODULE LISTE_INITIALISIEREN.
LOOP AT EXTRACT WITH CONTROL
TCTRL_ZHEDGERES CURSOR NEXTLINE.
MODULE LISTE_SHOW_LISTE.
ENDLOOP.
PROCESS AFTER INPUT.
MODULE LISTE_EXIT_COMMAND AT EXIT-COMMAND.
MODULE LISTE_BEFORE_LOOP.
LOOP AT EXTRACT.
MODULE LISTE_INIT_WORKAREA.
CHAIN.
FIELD ZHEDGERES-HDATE .
FIELD ZHEDGERES-CHAIN .
FIELD ZHEDGERES-HEDGE_VALUE .
FIELD ZHEDGERES-CURRENCY .
MODULE SET_UPDATE_FLAG ON CHAIN-REQUEST.
ENDCHAIN.
FIELD VIM_MARKED MODULE LISTE_MARK_CHECKBOX.
CHAIN.
FIELD ZHEDGERES-HDATE .
MODULE LISTE_UPDATE_LISTE.
ENDCHAIN.
ENDLOOP.
MODULE LISTE_AFTER_LOOP.
Need to add logic to extract the values from the excel sheet to an internal table and append the values from the internal table to the table control of the table maintenance.
Thanks,
Best regards,
Ajith -
Uploading the excel sheet in XLSX format
Hi ,
While uploading excel sheet into sap , I am using the FM 'TEXT_CONVERT_XLS_TO_SAP' .This FM works fine when the excel sheet is in 'XLS' format .But when the excel sheet is in 'XLSX' format this FM is giving error .Please advice how to correct the error.
Any pointers will be highly appreciated.
Thanks ,
NikhilCopied from the link given above
hi,
try like this once
After calling FM 'ALSM_EXCEL_TO_INTERNAL_TABLE', need to fill the final table at each row and column level,
Please check this sample of code below.
Call FM to upload file from Presentation server.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = rp_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 3
i_end_row = 6000
TABLES
intern = rt_excel[]
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Process Records and get only records into table T_FINAL.
IF rt_excel[] IS NOT INITIAL.
LOOP AT rt_excel INTO lw_file.
Move the records into final table.
IF lw_file-col = c_1.
lw_final-bukrs = lw_file-value .
ELSEIF lw_file-col = c_2.
lw_final-csl_type = lw_file-value.
ELSEIF lw_file-col = c_3.
lw_final-fpl = lw_file-value.
ENDIF.
AT END OF row.
APPEND lw_final TO rt_final.
CLEAR lw_final.
ENDAT.
CLEAR : lw_file.
ENDLOOP.
endif.
regards,
bab
Edited by: Matt on Jan 14, 2010 9:20 AM -
How to upload the Excel sheet into SAP
Hello Gurus,
Please let me know the steps how to upload excel sheet file in sap at one time.Suppose i have entered the employee details and their caste .This detail has been maintained in Excel.I want to know the total steps how to upload this total file into SAP System.
Regards
AM. TCode : LSMW.
2. Enter Project name, sub project name and object name.
Execute.
3. Maintain object attributes.
Execute
select Batch Input recording
goto->Recording overview
create
recording name.
enter transaction code.
start recording
do recording as per ur choice.
save + back.
enter recording name in lsmw screen.
save + back
Now there will be 14 steps.
2. MAINTAIN SOURCE STRUCTURES.
Here you have to enter the name of internal table.
display change
create
save + back
3. MAINTAIN SOURCE FIELDS.
display change
select structure
source_fields->copy fields.
a dialogue window will come .
select -> from data file
apply source fields
enter No. of fields
length of fields
attach file
save + back
4. MAINTAIN STRUCTURE RELATIONS
display change
save + back
5. MAINTAN FIELD MAPPING & CONVERSION RULE
display change
click on source field, select exact field from structue and enter
repeat these steps for all fields.
save+back
6. MAINTAIN FIXED VALUES, TRANSACTION, USER DEFINED
execute
save + back
7. SPECIFY FILES.
display change
click on legacy data
attah flat file
give description
select tabulatore
enter
save + back
8. ASSIGN FILE
execute
display change
save + back
9. IMPORT DATA.
execute
display change
save + back
10. DISPLAY IMPORTED DATA
enter ok, it willl show records only.
back
11. CONVERT DATA
execute
display change
save + back
12. DISPLAY CONVERTED DATA
execute
display change
save + back
13. CREATE BATCH INPUT SESSION
tick keep batch input folder
F8
back
14. RUN BATCH INPUT SESSION.
sm35 will come
Object name will be shown here
select object & process
inputs given by KAPIL -
How to handle merge cells in the excel sheet while uploading
Hi guys,
I have a requirement where i need to upload the excel sheet. The data is given below.
field1 field2 field3 field4
a x 1 1
2 2
3 3
y1 4 4
y2 5 5
y3 6
The output must be
a x 1 1
a x 2 2
a x 3 3
a y1 4 4
a y2 5 5
a y3 5 6
Here the field1 column is merged.
Please let me know if you guys have sample code to handle the merge cells in the excel sheet, that would be of gereat help.
Regards,
KarthikHi guys,
I have a requirement where i need to upload the excel sheet. The data is given below.
field1 field2 field3 field4
a x 1 1
2 2
3 3
y1 4 4
y2 5 5
y3 6
The output must be
a x 1 1
a x 2 2
a x 3 3
a y1 4 4
a y2 5 5
a y3 5 6
Here the field1 column is merged.
Please let me know if you guys have sample code to handle the merge cells in the excel sheet, that would be of gereat help.
Regards,
Karthik -
can anyone tel me how 2 upload data from a excel sheet ??
can it be done using gui_upload or os there any other funtion module ??Hi Vignesh,
Steps to create a BDC program.
1. Create an internal table with fields same as Excel sheet fields.
2. Declare an internal table with BDCDATA table to store the BDC recording.
3. Declare an internal table with BDCMSGCOL to store the error messages after
the execution of the BDC.
4. Write the code using the fun. module ALSM_EXCEL_TO_INTERNAL_TABLE
to upload the data from the excel sheet.
5. loop that internal table and write the Subroutines to fill the internal table
BDCDATA with the recording of a specified Transaction Code.
6. Using Call Transaction execute the BDC recording.
7. Check Sy-subrc = 0 and store the error messages in the internal table.
8. If you want you can pass those error records to a session using the SESSION method.
Here is an example of a BDC program, but this program is from a text file. Change the function module WS_UPLOAD with ALSM_EXCEL_TO_INTERNAL_TABLE
to upload an excel and write the program with your BDC recording. You can do recording using t-code SHDB.
Sample Program:
REPORT ZRAJ_DATASET_XD01 NO STANDARD PAGE HEADING LINE-SIZE 132
LINE-COUNT 60
MESSAGE-ID Z00.
Table/Structure declarations. *
TABLES : KNA1. "Customer master
Constants declarations. *
CONSTANTS : C_MODE VALUE 'N',
C_UPDATE VALUE 'S',
C_X VALUE 'X',
C_SESS TYPE APQI-GROUPID VALUE 'ZCUSTOMER', "Session Name
C_XD01 LIKE TSTC-TCODE VALUE 'XD01'.
Variable declarations. *
DATA : V_FNAME(15) VALUE SPACE, " Name of file to be created
V_FAILREC TYPE I, " No of failed records
V_MSG(255), " Message Text
V_ERRREC TYPE I, " No of failed records
V_LINES TYPE I. " No of records
*-- FLAG DECLARATIONS
DATA : FG_DATA_EXIST VALUE 'X', " Check for data
FG_SESSION_OPEN VALUE ' '. " Check for Session Open
Structures / Internal table declarations *
*-- Structure to hold BDC data
TYPES : BEGIN OF T_BDCTABLE.
INCLUDE STRUCTURE BDCDATA.
TYPES END OF T_BDCTABLE.
*-- Structure to trap BDC messages
TYPES : BEGIN OF T_MSG.
INCLUDE STRUCTURE BDCMSGCOLL.
TYPES : END OF T_MSG.
*-- Structure to trap ERROR messages
TYPES : BEGIN OF T_ERR_MSG,
MESSAGE(255),
END OF T_ERR_MSG.
*--Internal table to store flat file data
DATA:BEGIN OF IT_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
KTOKD LIKE T077D-KTOKD,
NAME1 LIKE KNA1-NAME1,
SORTL LIKE KNA1-SORTL,
ORT01 LIKE KNA1-ORT01,
PSTLZ LIKE KNA1-PSTLZ,
LAND1 LIKE KNA1-LAND1,
SPRAS LIKE KNA1-SPRAS,
LZONE LIKE KNA1-LZONE,
END OF IT_KNA1.
*-- Internal table to hold BDC data
DATA: IT_BDCDATA TYPE STANDARD TABLE OF T_BDCTABLE WITH HEADER LINE,
*-- Internal Table to store ALL messages
IT_MSG TYPE STANDARD TABLE OF T_MSG WITH HEADER LINE,
*-- Internal Table to store error messages
IT_ERR_MSG TYPE STANDARD TABLE OF T_ERR_MSG WITH HEADER LINE.
Selection Screen. *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_FLNAME(15) OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS : R_LIST RADIOBUTTON GROUP GRP1.
SELECTION-SCREEN COMMENT 5(20) TEXT-003.
PARAMETERS : R_SESS RADIOBUTTON GROUP GRP1.
SELECTION-SCREEN COMMENT 30(20) TEXT-004.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
Event:Initialization *
INITIALIZATION.
AT Selection Screen. *
AT SELECTION-SCREEN.
Event: Start-of-Selection *
START-OF-SELECTION.
V_FNAME = P_FLNAME.
PERFORM GET_DATA.
PERFORM GENERATE_DATASET.
Event: End-of-Selection *
END-OF-SELECTION.
IF FG_DATA_EXIST = ' '.
MESSAGE I010 WITH TEXT-009.
EXIT.
ENDIF.
PERFORM GENERATE_BDCDATA.
PERFORM DISPLAY_ERR_RECS.
Event: top-of-page
TOP-OF-PAGE.
FORM DEFINITIONS *
*& Form get_data
Subroutine to get the data from mard
--> p1 text
<-- p2 text
FORM GET_DATA.
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = 'C:\XD01.TXT'
FILETYPE = 'DAT'
ITEM = ' '
FILEMASK_MASK = ' '
FILEMASK_TEXT = ' '
FILETYPE_NO_CHANGE = ' '
FILEMASK_ALL = ' '
FILETYPE_NO_SHOW = ' '
LINE_EXIT = ' '
USER_FORM = ' '
USER_PROG = ' '
SILENT = 'S'
IMPORTING
FILESIZE =
CANCEL =
ACT_FILENAME =
ACT_FILETYPE =
TABLES
DATA_TAB = IT_KNA1
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF IT_KNA1[] IS INITIAL.
FG_DATA_EXIST = ' '.
ENDIF.
ENDFORM. " get_data
*& Form GENERATE_DATASET
text
--> p1 text
<-- p2 text
FORM GENERATE_DATASET.
MESSAGE I010 WITH 'OPENING FILE IN APPLICATION SERVER'.
**--Creating a data set in application server
OPEN DATASET V_FNAME FOR OUTPUT IN TEXT MODE.
**---Transfering data from internal table to dataset
MESSAGE I010 WITH 'TRANSFERING DATA FROM INETERAL TABLE TO THE FILE'.
LOOP AT IT_KNA1.
TRANSFER IT_KNA1 TO V_FNAME.
ENDLOOP.
**--Closing the dataset
MESSAGE I010 WITH 'CLOSING THE FILE'.
CLOSE DATASET V_FNAME.
ENDFORM. " GENERATE_DATASET
*& Form BDC_DYNPRO
text
-->P_0467 text
-->P_0468 text
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
ENDFORM.
*& Form BDC_FIELD
text
-->P_0472 text
-->P_0473 text
FORM BDC_FIELD USING FNAM FVAL.
IF NOT FVAL IS INITIAL.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDIF.
ENDFORM.
*& Form GENERATE_BDCDATA
text
--> p1 text
<-- p2 text
FORM GENERATE_BDCDATA.
REFRESH IT_KNA1.
Opening dataset for reading
OPEN DATASET V_FNAME FOR INPUT IN TEXT MODE.
Reading the file from application server
DO.
CLEAR: IT_KNA1,IT_BDCDATA.
REFRESH IT_BDCDATA.
READ DATASET V_FNAME INTO IT_KNA1.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
Populate BDC Data for Initial Screen
PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0100',
BDC_FIELD USING 'BDC_CURSOR' 'RF02D-KUNNR',
BDC_FIELD USING 'BDC_OKCODE' '/00',
BDC_FIELD USING 'RF02D-KUNNR' IT_KNA1-KUNNR,
BDC_FIELD USING 'RF02D-KTOKD' IT_KNA1-KTOKD.
Populate BDC Data for Second Screen
PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0110',
BDC_FIELD USING 'BDC_CURSOR' 'KNA1-NAME1',
BDC_FIELD USING 'BDC_OKCODE' '/00',
BDC_FIELD USING 'KNA1-NAME1' IT_KNA1-NAME1,
BDC_FIELD USING 'KNA1-SORTL' IT_KNA1-SORTL,
BDC_FIELD USING 'KNA1-ORT01' IT_KNA1-ORT01,
BDC_FIELD USING 'KNA1-PSTLZ' IT_KNA1-PSTLZ,
BDC_FIELD USING 'KNA1-LAND1' IT_KNA1-LAND1,
BDC_FIELD USING 'KNA1-SPRAS' IT_KNA1-SPRAS.
Populate BDC Data for Third Screen
PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0120',
BDC_FIELD USING 'BDC_CURSOR' 'KNA1-LZONE',
BDC_FIELD USING 'BDC_OKCODE' '=UPDA',
BDC_FIELD USING 'KNA1-LZONE' IT_KNA1-LZONE.
CALL TRANSACTION C_XD01 USING IT_BDCDATA
MODE C_MODE
UPDATE C_UPDATE
MESSAGES INTO IT_MSG.
IF SY-SUBRC <> 0.
*--In case of error list display
IF R_LIST = C_X.
V_ERRREC = V_ERRREC + 1.
PERFORM FORMAT_MESSAGE.
IT_ERR_MSG-MESSAGE = V_MSG.
APPEND IT_ERR_MSG.
CLEAR : V_MSG,IT_ERR_MSG.
ENDIF.
*--In case of session log
IF R_SESS = C_X.
*-- In case of transaction fails.
IF FG_SESSION_OPEN = ' '.
FG_SESSION_OPEN = C_X.
PERFORM BDC_OPEN_GROUP.
ENDIF. " IF FG_SESSION_OPEN = ' '.
*-- Insert BDC Data..
PERFORM BDC_INSERT_DATA.
ENDIF. " IF R_SESS = C_X.
ENDIF. " IF SY-SUBRC <> 0.
ENDIF. " IF SY-SUBRC <> 0.
ENDDO.
Closing the dataset
CLOSE DATASET V_FNAME.
*-- Close the session if opened
IF FG_SESSION_OPEN = C_X.
PERFORM BDC_CLOSE_GROUP.
CALL TRANSACTION 'SM35'.
ENDIF.
ENDFORM. " GENERATE_BDCDATA
*& Form BDC_OPEN_GROUP
text
--> p1 text
<-- p2 text
FORM BDC_OPEN_GROUP.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = C_SESS
HOLDDATE = FILLER8
KEEP = C_X
USER = SY-UNAME
RECORD = FILLER1
IMPORTING
QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
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. " BDC_OPEN_GROUP
*& Form BDC_INSERT_DATA
text
--> p1 text
<-- p2 text
FORM BDC_INSERT_DATA.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = C_XD01
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
TABLES
DYNPROTAB = IT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
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. " BDC_INSERT_DATA
*& Form BDC_CLOSE_GROUP
text
--> p1 text
<-- p2 text
FORM BDC_CLOSE_GROUP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3
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. " BDC_CLOSE_GROUP
*& Form FORMAT_MESSAGE
text
--> p1 text
<-- p2 text
FORM FORMAT_MESSAGE.
CLEAR V_LINES.
DESCRIBE TABLE IT_MSG LINES V_LINES.
READ TABLE IT_MSG INDEX V_LINES.
CLEAR V_MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = IT_MSG-MSGID
LANG = IT_MSG-MSGSPRA
NO = IT_MSG-MSGNR
V1 = IT_MSG-MSGV1
V2 = IT_MSG-MSGV2
V3 = IT_MSG-MSGV3
V4 = IT_MSG-MSGV4
IMPORTING
MSG = V_MSG
EXCEPTIONS
NOT_FOUND = 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. " FORMAT_MESSAGE
*& Form DISPLAY_ERR_RECS
text
--> p1 text
<-- p2 text
FORM DISPLAY_ERR_RECS.
LOOP AT IT_ERR_MSG.
WRITE: / IT_ERR_MSG-MESSAGE.
ENDLOOP.
ENDFORM. " DISPLAY_ERR_RECS
And
To simply load Excel to Internal table follow this :
First of all , before you move your data from excel sheet to the internal table, you need to specify a location for uploading the excel sheet into your internal table.
for this u need to use two specific FM's .
the first one for file selection : WS_FILENAME_GET.
The second one for data upload : TEXT_CONVERT_XLS_TO_SAP.
After doing this the regular part of mapping comes and then we can run the session and then execute and release it.
Hope this resolves your query.
<b>Reward all the helpful answers.</b>
Regards -
How to upload the data from two sheets in one excel into SAP
Hi experts,
My requirement is to upload the data from two sheets in an excel into an internal table.How can this be achieved.Is some OLE application has to be used?
Thanks
AbhishekHi
see this program will upload excel file to application.
*& Report ZSD_EXCEL2
REPORT ZSD_EXCEL2.
types: begin of ttab ,
fld1(30) type c,
fld2(30) type c,
fld3(30) type c,
fld4(30) type c,
fld5(30) type c,
end of ttab.
data: itab type table of ttab with header line.
selection-screen skip 1.
parameters: p_file type localfile default
'C:\test.xls'.
selection-screen skip 1.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
clear itab. refresh itab.
perform upload_data.
loop at itab.
write:/ itab-fld1, itab-fld2, itab-fld3, itab-fld4, itab-fld5.
endloop.
* Upload_Data
form upload_data.
data: file type rlgrap-filename.
data: xcel type table of alsmex_tabline with header line.
file = p_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
tables
intern = xcel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
loop at xcel.
case xcel-col.
when '0001'.
itab-fld1 = xcel-value.
when '0002'.
itab-fld2 = xcel-value.
when '0003'.
itab-fld3 = xcel-value.
when '0004'.
itab-fld4 = xcel-value.
when '0005'.
itab-fld5 = xcel-value.
endcase.
at end of row.
append itab.
clear itab.
endat.
endloop.
endform. -
Uploading the Data into BDC using Excel sheet
HI Gurus,
Iam uploading the Data Using Excel sheet.TCode:qp01.
Upto 3 screens the data is passing in a very fine manner.
From the fourth screen I'v to enter the Lineitem for a single material.
Ex: Matnr is PJBRIX.
For this material upto 3 screens the data is same ,but from the line item data,the PJBRIX has 3 characterstics.
How can I upload that data.
Structure:
Matnr Group GroupCounter MicCode Method Lower Upper
Pjbrix 5 6 zsr001 zsr001 1 15
Pjbrix 5 6 zsr002 zsr003 4 20
Pjbrix 5 6 zsr006 zsr0018 2 18
This is the Structure.
Pls gv me the advise or Gv me the code asap.
thanks in advance.HI Gurus,
Iam uploading the Data Using Excel sheet.TCode:qp01.
Upto 3 screens the data is passing in a very fine manner.
From the fourth screen I'v to enter the Lineitem for a single material.
Ex: Matnr is PJBRIX.
For this material upto 3 screens the data is same ,but from the line item data,the PJBRIX has 3 characterstics.
How can I upload that data.
Structure:
Matnr Group GroupCounter MicCode Method Lower Upper
Pjbrix 5 6 zsr001 zsr001 1 15
Pjbrix 5 6 zsr002 zsr003 4 20
Pjbrix 5 6 zsr006 zsr0018 2 18
This is the Structure.
Pls gv me the advise or Gv me the code asap.
thanks in advance. -
Need to upload mass excel sheet using the bapi bapi_acc_document_post.
I am assigned with an object, where I need to post the records from a mass excel sheet in to ECC or/and BW basing the dimensions using the bapi bapi_acc_document_post.the excel sheet has header and Item data. I am pretty much new to this bapi's
please do the need fulCheck report "ACC_BAPI_TEST_INVOICE_RECEIPT",
this report calls BAPI "BAPI_ACC_INVOICE_RECEIPT_POST",
but the parameters are nearly the same.
Best Regards, Dirk -
Upload Journal Voutures of customer master from the Excel sheet using BAPI
Hi experts,
Can U have any sample program so that it can help me for my coding.Hi,
You need write the abap program in the following manner,
1. Read the data from the excel sheet and then enforce the checks if at all any in the new program.
2. Fill all the parameters of the BAPI *BAPI_CASHJOURNALDOC_CREATE *.
3. After the above BAPI call, you need to call another *BAPI_TRANSACTION_COMMIT *.
4. Once Transaction commit bapi is successfully executed then only you will get the document number.
Please follow all the above mentioned steps then you can create the Journal Voutures migrated from an excel sheet to SAP successfully.
Thanks,
Mahesh. -
Problem to upload the data into internal table record length more than 6000
Hi all
I stuck with this problem from past 3 days. I have to upload the data from excel sheet. iam making it tab delimited and trying to upload from gui_upload. but in the structure of file, we have, one field of 4000 characters, and other fields of 255 characters.
how can i upload this into internal table . From excel sheet or from tab delimeted or any other format? or any special function module is there? while iam doing this its truncating the datat 255 characters and not uploading the other fields also...
can any one of you help me out. ASAP
thnks in advancefrom one of the forum iam just pasting code which it is used in lsmw, try the same logic in ur code hope it can work.
you have to create multiple lines with do...enddo loop., like this:
(assuming excel_long_text-text is 924 characters long, 7 lines X 132 char)
__GLOBAL_DATA__
data: offset type i,
text_132(132) type c.
__BEGIN_OF_RECORD__ Before Using Conversion Rules
Rule : Default Settings Modified
Code: /sapdmc/ltxtl = init_/sapdmc/ltxtl.
CLEAR offset.
DO 7 TIMES.
text_132 = excel_long_text-text+offset(132).
offset = offset + 132.
__END_OF_RECORD__ After Using Conversion Rules
Rule : Default Settings Modified
Code: transfer_record.
ENDDO.
also check this
COMMIT_TEXT
To load long text into SAP
READ_TEXT
To load long text into SAP -
Error While Uploading the Vendors Data
Hi Friends,
iam uploading the vendors information. In the XL-Sheet there are 5 Records are there.the first two records are correct.but iam getting the following message for the frist two records.iam using the call transaction method.
No memory is available for the CUA interface
what is the error i am not able to get it.
some times if i upload the same record with same report, i will get the following message that,
vendor 1235 has created for the company code 1000
why it so?Hi,
1) No memory is available for the CUA interface
Check With basis team
2) vendor 1235 has created for the company code 1000
Means vendor 1235 is creatred for this company.
Regards
Md.MaahboobKhan -
Problems in uploading from excel sheet to internal table
hi experts,
i got one problem regarding uploading data from excel sheet to int.table. I used FM ALSM_EXCEL_TO_INTERNAL_TABLE but in that the value is char of 50. but i need a case where i have to send value more than 50 characters. please suggest me any other FM to overcome this problem.
advanced thanks
vijayHi,
>
Vijay Krishna Arvapalli wrote:
> hi tarun,
>
> thank you for your reply
>
> but when i tried to use FM TEXT_CONVERT_XLS_TO_SAP it is giving error actually that 'Error generating the test frame'.
>
> so can you suggest me with some other option where i can upload the field with more than 50 character length.
>
> thank you
> regards
> vijay
Yes, when you execute the FM from SE37, then it displays a message.
Just copy the below code and paste it in a report (SE38) and execute.
Create a file in C:/ with name test.xls and execute it will display the records even with more than 50 characters of length.
I have tested and its working.
I have taken three fields in the excel file empid, name and doj.
TYPE-POOLS : truxs.
PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.XLS'.
DATA : BEGIN OF itab OCCURS 0,
empid(150) TYPE c,
name(150) TYPE c,
doj(150) TYPE c,
END OF itab.
DATA: it_raw TYPE truxs_t_text_data.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_file_process USING p_file.
AT SELECTION-SCREEN.
PERFORM validate_file_path USING p_file.
START-OF-SELECTION.
PERFORM upload_data.
END-OF-SELECTION.
PERFORM display_data.
*& Form F4_FILE_PROCESS
* text
* -->P_FILE_PATH text
FORM f4_file_process USING p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
IF sy-subrc NE 0.
MESSAGE e000(zsd).
ENDIF.
ENDFORM. " F4_FILE_PROCESS
*& Form VALIDATE_FILE_PATH
* text
* -->P_FILE text
FORM validate_file_path USING p_file.
DATA : lv_dir TYPE string,
lv_file TYPE string,
lv_result(1) TYPE c.
DATA : lv_filename TYPE string.
lv_filename = p_file.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = p_file
IMPORTING
stripped_name = lv_file
file_path = lv_dir
EXCEPTIONS
x_error = 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.
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = lv_dir
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result IS INITIAL.
MESSAGE 'Invalid Directory' TYPE 'E'.
ENDIF.
CLEAR lv_result.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_filename
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result IS INITIAL.
MESSAGE 'Invalid File' TYPE 'E'.
ENDIF.
ENDFORM. " VALIDATE_FILE_PATH
*& Form UPLOAD_DATA
* text
* --> p1 text
* <-- p2 text
FORM upload_data .
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = p_file
TABLES
i_tab_converted_data = itab[]
EXCEPTIONS
conversion_failed = 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. " UPLOAD_DATA
*& Form DISPLAY_DATA
* text
* --> p1 text
* <-- p2 text
FORM display_data .
LOOP AT itab.
WRITE : / itab-empid, itab-name, itab-doj.
ENDLOOP.
ENDFORM. " DISPLAY_DATA
Hope this helps you.
Regards,
Tarun -
How to upload the data from excel(3 tabs) file to sap environment
Hi all,
This is Mahesh.
how to upload the data from excel(3 tabs) file to sap environment (internal tables) while doing bdc.Hi,
The FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' makes it possible to load a worksheet into an internal table in ABAP.
However, if you want to get the data from several worksheets, I think you are stuck with OLE access to your Excel Workbook...
You can find a solution for 2 worksheets in this post :
TO UPLOAD DATA FROM 2 EXCEL SHEETS INTO TWO INTERNAL TABLES
I think you can easily modify it to handle any number of worksheets.
Hope it helps !
Best regards,
Guillaume -
Number of rows in the WebADI sheet
Hi,
I have an Integrator with a PL/SQL interface where I run a post-process (also PL/SQL) wherin I would like to know how many rows the user has uploaded.
Does anyone know if it is possible to retrieve the total number of rows that is in the WebADI sheet?
Thank you.
JeroenMETHOD wddoinit .
DATA: lo_column TYPE REF TO cl_salv_wd_column,
lo_cmp_usage TYPE REF TO if_wd_component_usage,
lo_interfacecontroller TYPE REF TO iwci_salv_wd_table,
lt_functions TYPE salv_wd_t_function_std_ref,
ls_function TYPE salv_wd_s_function_std_ref,
lo_function TYPE REF TO cl_salv_wd_function_std,
lo_data TYPE REF TO if_wd_context_node,
lo_element TYPE REF TO if_wd_context_element,
lv_index TYPE i,
lo_model TYPE REF TO cl_salv_wd_config_table.
Retrieve ALV object
lo_cmp_usage = wd_this->wd_cpuse_alv( ).
Initial? Create new
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.
Interfacecontroller
lo_interfacecontroller = wd_this->wd_cpifc_alv( ).
lo_model = lo_interfacecontroller->get_model( ).
Get main NODE DATA, this is the node which supplies the ALV
lo_data = wd_context->get_child_node( name = 'DATA' ).
How many rows has the table?
lv_index = lo_data->GET_ELEMENT_COUNT( ).
Not more then 20 rows on the screen
IF lv_index GT 20.
lv_index = 20.
ENDIF.
Put the number of rows in the screen
lo_model->if_salv_wd_table_settings~set_visible_row_count( lv_index ).
should the screen set to freeze?
lo_model->if_salv_wd_table_settings~set_fixed_table_layout( abap_true ).
Maybe you are looking for
-
Hi, We have a problem using Sharepoint 2013 explorer view. (Error - We're having a problem opening this location in file explorer. Add this web site to your trusted sites list and try again). I'm using Windows 7 Enterprise 64 bit, Office 2007 32 bit
-
My 13''macbook pro 2011 don't read the usb
i have an external hdd and it disconect every 10 sec..is a hardware problem?
-
IPhone 4.1 lost my calendar
About the time iPhone 4.1 became available, my iPhone calendar went blank. Figuring that I needed the new operating system, I upgraded. Still no calendar. I can see the calendar on Outlook and MobileMe, but my iPhone Calendar is blank. Any ideas? I'v
-
Hi gurus, I want to take backup with RMAN. I'm gonna use FRA. Now FRA size is 21 GB and i think and guess it's not enough. So want to change FRA's_dest and size coz another logical disk has much space then current. I have several questions: 1) i will
-
Spilled beer on Macbook Pro keyboard
I had a going away party and made the mistake of leaving my computer in the living room after going to sleep. I woke up in the morning and the computer was closed but when I opened it I discovered that beer had been spilt on the keyboard. Everything