‎2007 Oct 15 7:22 AM
Dear Sir,
I m working on APO,i just want to upload data into ZTables.(Data are available in Flat files )
How can i done this plese tell me all steps..
Thankx in Advance.
‎2007 Oct 15 7:25 AM
Hi,
For a BDC upload you need to write a program which created BDC sessions.
Steps:
1. Work out the transaction you would use to create the data manually.
2. Use transaction SHDB to record the creation of one material master data.
Click the New recording button or the Menu - Recording - Create
3. Save the recording, and then go back a screen and go to the overview.
4. Select the recording and click on Edit - Create Program. Give the program a Z name, and select transfer from recording.
5. Edit the program. You will see that all the data you entered is hard-coded into the program. You need to make the following changes:
5.1 After the start-of-selection, Call ws_upload to upload the file (the excel file needs to be saved as TAB separated).
5.2 After the open-group, Loop on the uploaded data. For each line, perform validation checks on the data, then modify the perform bdc_field commands to use the file data.
5.3. After perform bdc_transaction, add the endloop.
Execute the program. It will have options to create a batch session or to process directly.
These are all my finds . Might be it will be useful to you.
Direct call of transactions, session handling:
/nxxxx This terminates the current transaction, and starts transaction xxxx
/n This terminates the transaction. This generally corresponds to pressing F15 to go back.
/nend This termiantes all separate sessions and logs off (corresponds to System - Logoff).
/nex This terminates all separate sessions and logs off immediately (without any warning!).
/oxxxx This opens a new session and starts transaction xxxx in This session.
/o This lists existing sessions and allows deletion or opening of a new session.
/i This terminates the current session (corresponds to System End
/i1, /i2,... This terminates the session with the number given.
.xyzw Fast path: 'xyzw' refers to the underlined letters in the menus. This type of navigation is uncommon and is provided more for emergencies (such as a defective mouse).
Batch
The following commands can be entered in correction mode ('Process in foreground' or 'Display errors only') when processing a batch input session:
/n This terminates the current batch input transaction and characterizes it as
/bdel This deletes the current batch input transaction.
/bend This terminates batch input processing and sets the session to Failed
/bda This switches from Display errors only to Process in foreground
/bde This switches from Process in foreground to Display errors only
ABAP/4
/h This switches into debugging mode.
/hs This switches into debugging mode and activates the debugging of system functions.
Buffer
WARNING: Resetting buffers can significantly change the performance of the entire system for a long time.
It should therefore only be used where there is a good reason tdso. As of release 3.0B system administator authorization is required (authorization object (S_ADMI_FCD). The action is noted in the system log.
/$SYNC This resets all buffers of the application server
/$CUA This resets the CUA buffer of the application server
/$TAB This resets the TABLE buffers of the application server
/$NAM This resets the nametab buffer of the application server
/$DYNP This resets the screen buffer of the application server
Please reward points.
Thank you,
Gangula Vikram.
‎2007 Oct 15 7:29 AM
HI Arvind,
1. First you have to down load the data from Flat file in to Internal table. For that you can use GUI_Download.
2. Then append the value from Internal table to Data base table.
Thanks.
‎2007 Oct 15 7:53 AM
HI Vijji,
i am using upload function for uploading data from Flat file to Internal table but the control goes to Application Server I don't know why.?
I just want to upload data from my local PC
Is there any default setting where i can set it.
Thankx
‎2007 Oct 15 8:06 AM
1. First you have to down load the data from Flat file in to Internal table. For that you can use <i><b>file_read_and_convert_sap_data</b></i>.
2. Then append the value from Internal table to Data base table.
‎2007 Oct 15 8:13 AM
Hi,
chek the below code
TABLES: /sapapo/matkey,
/sapapo/loc.
----
TYPES *
----
Structure for uploading the Flat file
TYPES : BEGIN OF t_upload,
item TYPE matnr, "Material Number
t(1) TYPE c, "Material Type
description TYPE maktx, "Material Description
lot TYPE charg_d, "Batch Number
status TYPE char1, "Status
quantity TYPE /sapapo/cif_omng, "Quantity
uom(3) TYPE c, "Base Unit of Measure
bpcs_facility TYPE char2, "Version Number Component
bpcs_wh TYPE zbpcs_wh, "BPCS Warehouse
location TYPE char6, "Location
exp_date TYPE datum, "Lot Expiration Date
lot_create TYPE datum, "Lot Creation Date
avl_date TYPE datum, "Lot Availability
dpl_date TYPE datum, "Inventory 0 date
END OF t_upload,
Structure for uploading the Flat file from app server
BEGIN OF t_file,
text(500) TYPE c, "Flatfile
END OF t_file,
Structure for data retrieval from db or from file
BEGIN OF t_temp,
mandt TYPE mandt, "Client
id TYPE int4, "Unique ID
item TYPE /sapapo/matnr, "Material Number
lot TYPE charg_d, "Batch Number
bpcs_facility TYPE char2, "Version Number Component
bpcs_wh TYPE zbpcs_wh, "BPCS Warehouse
location TYPE char6, "Location
material_type TYPE char1, "Material Type
description TYPE maktx, "Material Description
status TYPE char1, "Status
quantity TYPE /sapapo/cif_omng, "Quantity
uom TYPE /sapapo/meins, "Base Unit of Measure
exp_date TYPE datum, "Lot Expiration Date
lot_create TYPE datum, "Lot Creation Date
avl_date TYPE datum, "Lot Availability
dpl_date TYPE datum, "Inventory 0 date
END OF t_temp,
Structure for Material ID determination
BEGIN OF t_matid,
matid TYPE /sapapo/matid, "Internal number for product
matnr TYPE /sapapo/matnr, "Product ID
END OF t_matid,
Structure for unit of measure
BEGIN OF t_msehi,
matnr TYPE /sapapo/matnr,
meins TYPE msehi, "Unit of Measurement
meinh TYPE /sapapo/lrmei,
umrez TYPE /sapapo/umrez,
umren TYPE /sapapo/umren,
END OF t_msehi,
Declaration of table type
t_type TYPE STANDARD TABLE OF t_temp.
TYPES: BEGIN OF t_map,
bpcs_facility TYPE zbpcs_facility,
bpcs_wh TYPE zbpcs_wh,
bpcs_location TYPE zbpcs_location,
sap_plant TYPE zsap_plant,
description TYPE /sapapo/ret_text_generic,
END OF t_map.
TYPES: BEGIN OF t_err_uom,
matnr TYPE /sapapo/matnr,
uom(3),
END OF t_err_uom.
TYPES: BEGIN OF t_err,
matnr TYPE /sapapo/matnr,
maktx TYPE /sapapo/maktx,
charg TYPE charg_d, "Batch Number
bpcs_facility TYPE char2,
bpcs_wh TYPE zbpcs_wh,
location TYPE char6,
quantity TYPE /sapapo/cif_omng,
uom(3),
msg(117),
END OF t_err.
----
INTERNAL TABLE DECLARATION *
----
DATA :
Internal table for uploading the Flat file
i_upload TYPE STANDARD TABLE OF t_upload,
Internal table for data retrieval from db or from file
i_temp TYPE STANDARD TABLE OF t_temp,
Internal table for receipts(used in BAPI_POSRVAPS_GETLIST2)
i_receipts TYPE STANDARD TABLE OF bapi10502poouto,
Internal table for receipts(used in BAPI_POSRVAPS_SAVEMULTI3)
i_receiptsi TYPE STANDARD TABLE OF bapi10502poouti,
Internal table for bapireturn
i_return TYPE STANDARD TABLE OF bapiret2,
Internal table for reference receipts
i_receiptsx TYPE STANDARD TABLE OF bapi10502pooutix,
Internal table for content in email
i_email TYPE STANDARD TABLE OF solisti1,
Internal table for content in email cc
i_cc TYPE STANDARD TABLE OF solisti1,
Internal table for receiver in email
i_objcont TYPE STANDARD TABLE OF solisti1,
Internal table for mapping
i_map TYPE STANDARD TABLE OF t_map,
Internal table to capture invalid UoM
i_err_uom TYPE STANDARD TABLE OF t_err_uom,
Internal table to display error message
i_err TYPE STANDARD TABLE OF t_err,
i_matnr_err TYPE STANDARD TABLE OF bapilocrange.
----
WORKAREA DECLARATION *
----
DATA :
Workarea for uploading the Flat file
wa_upload TYPE t_upload,
Workarea for data retrieval from db or from file
wa_temp TYPE t_temp,
Workarea for receipts(used in BAPI_POSRVAPS_GETLIST2)
wa_receipts TYPE bapi10502poouto,
Workarea for BAPI return
wa_return TYPE bapiret2,
Workarea for header in email
wa_header TYPE so_text255,
Workarea for content in email
wa_objcont TYPE solisti1,
Workarea for mapping table
wa_map TYPE t_map,
Workarea for invalid UoM
wa_err_uom TYPE t_err_uom,
Workarea for error message
wa_err TYPE t_err,
wa_matnr_err TYPE bapilocrange.
----
VARIABLES *
----
DATA: v_fname TYPE rlgrap-filename, "File name variable
v_quantity(20), "For Quantity
v_mailid(50), "For MailID
v_cc(50), "For CC
v_file(250), "App server flatfile
v_tfill TYPE sy-tfill. "DB Count
----
CONSTANTS *
----
CONSTANTS : c_lpn(20) TYPE c VALUE 'ZDIR_APPDATA',"Logical File Path
c_simid(3) TYPE c VALUE '000', "Planning version
c_atpcat(2) TYPE c VALUE 'ZG', "ATP Category
c_x(1) TYPE c VALUE 'X', "Const. for 'X'.
c_1(1) TYPE c VALUE '1', "Const. for '1'.
c_3(1) TYPE c VALUE '3', "Const. for '3'.
c_midf(15) TYPE c VALUE 'BPCS_INV/SAP/', "Mid. Folders
c_low(4) TYPE c VALUE 'LOW',
c_high(4) TYPE c VALUE 'HIGH',
c_vl TYPE msehi VALUE 'VL',
c_vil TYPE msehi VALUE 'VIL',
c_vi TYPE msehi VALUE 'VI'.
----
PARAMETERS & SELECT-OPTIONS *
----
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_flint TYPE filename-pathintern
DEFAULT c_lpn OBLIGATORY , " Logical Path Name
p_aserv RADIOBUTTON GROUP grp , " Application server
p_flext TYPE filename-fileextern, " Application File Name
p_pserv RADIOBUTTON GROUP grp, " Presentation Server
p_file TYPE rlgrap-filename. " Presentation File Name
SELECTION-SCREEN : END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-f01.
SELECT-OPTIONS: s_matnr FOR /sapapo/matkey-matnr,
s_werks FOR /sapapo/loc-locno,
s_status FOR zdtsint046_inv-status,
s_type FOR zdtsint046_inv-material_typ,
s_lot FOR zdtsint046_inv-lot,
s_faclty FOR zdtsint046_inv-bpcs_facility,
s_wh FOR zdtsint046_inv-bpcs_wh,
s_bin FOR zdtsint046_inv-location.
SELECTION-SCREEN END OF BLOCK b5.
SELECTION-SCREEN : BEGIN OF BLOCK b4 WITH FRAME TITLE text-033.
PARAMETERS :p_logsys TYPE bapigenfields-logsystem
OBLIGATORY, " Logical System
p_simid TYPE bapigenfields-vrsioex
OBLIGATORY DEFAULT c_simid, " Planning Version
p_atpcat TYPE bapiapoatpcat-atpcat "ATP Category
OBLIGATORY DEFAULT c_atpcat .
SELECTION-SCREEN : END OF BLOCK b4.
SELECTION-SCREEN : BEGIN OF BLOCK b3 WITH FRAME TITLE text-032.
SELECT-OPTIONS : s_mailid FOR v_mailid NO INTERVALS OBLIGATORY, "Email
s_cc FOR v_cc NO INTERVALS. "CC
SELECTION-SCREEN : END OF BLOCK b3.
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_chk AS CHECKBOX , "Check Box for read database
p_dlt AS CHECKBOX DEFAULT 'X'."Check all PReqs
SELECTION-SCREEN : END OF BLOCK b2.
&----
*& Form getfilename
&----
It displays the f4 help for presentation server file name *
User can select the file from presentation server *
----
<--PV_file Input file name *
----
FORM getfilename CHANGING pv_file TYPE rlgrap-filename.
DATA: BEGIN OF logfile,
directory(80) TYPE c,
name(7) TYPE c,
path TYPE string,
pc_file TYPE string,
pc_path TYPE string,
selection TYPE filetable,
rc TYPE i,
action TYPE i,
no_reload TYPE c VALUE '',
lines LIKE sy-tabix,
END OF logfile.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
initial_directory = logfile-pc_path
default_filename = '.'
default_extension = '.'
CHANGING
file_table = logfile-selection
user_action = logfile-action
rc = logfile-rc
EXCEPTIONS
OTHERS = 1.
READ TABLE logfile-selection INDEX 1 INTO pv_file.
ENDFORM. " getfilename1
&----
*& Form validate_screen
&----
Subroutine to validate the selection-screen entries
----
FORM validate_screen.
IF p_aserv EQ c_x.
IF NOT p_flext IS INITIAL.
This perform generate the physical path using
file_get_name function module.
PERFORM get_physical_file.
ELSE.
Input File Name on Application server is mandatory.
MESSAGE e501.
ENDIF.
ENDIF.
IF p_pserv = c_x.
IF p_file IS INITIAL.
File Name on Presentation server is mandatory
MESSAGE e502.
ELSE.
MOVE p_file TO v_fname.
ENDIF.
ENDIF. "IF p_pserv = c_x.
ENDFORM. " validate_screen
&----
*& Form get_physical_file
&----
Subroutine to get the physical file name
----
FORM get_physical_file.
*--Call the function module to get the physical file name for the
logical file path provided.
CONCATENATE c_midf p_flext INTO v_file.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
logical_path = p_flint
file_name = v_file
IMPORTING
file_name_with_path = v_file
EXCEPTIONS
path_not_found = 1
missing_parameter = 2
operating_system_not_found = 3
file_system_not_found = 4
OTHERS = 5.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " get_physical_file
*&----
*& Form upload_file
*&----
Subroutine to upload data from App server or presentation server
*----
FORM upload_file.
*--If the presentation server radio button is chosen.
IF p_pserv = c_x .
Perform which selects the input file from presentation server
using Function GUI_UPLOAD
PERFORM get_presentation_file.
IF the application server radio button is chosen.
ELSEIF p_aserv = c_x.
Perform which selects the input file from application server
using OPEN DATASET
PERFORM get_application_file.
ENDIF.
ENDFORM. " upload_file
*&----
*& Form get_presentation_file
*&----
Subroutine to get the presentation file name
*----
FORM get_presentation_file.
*--Local Variables
DATA: lv_file TYPE string.
Local constants
CONSTANTS : lc_type TYPE char10 VALUE 'ASC'. "File type.
*--CLear
CLEAR lv_file.
MOVE v_fname TO lv_file.
*--Call the function to get the file into an internal table.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
filetype = lc_type
has_field_separator = c_x
TABLES
data_tab = i_upload
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. " get_presentation_file
*&----
*& Form get_application_file
*&----
Subroutine to get the application file name
*----
FORM get_application_file.
*--Local Variables
DATA : lv_dsn(250) TYPE c.
Declaration of local constants
CONSTANTS : lc_tab TYPE x VALUE '09'.
*--Work Area
DATA: lwa_file TYPE t_file. "App server flatfile
lv_dsn = v_file.
*-- Open Dataset
OPEN DATASET lv_dsn FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
File not found
MESSAGE e503.
ELSE.
Read each line from the dataset and append to an internal table.
DO.
*-- Read dataset and pass it to an internal table.
READ DATASET lv_dsn INTO lwa_file.
IF sy-subrc = 0.
SPLIT lwa_file-text AT lc_tab
INTO wa_upload-item
wa_upload-t
wa_upload-description
wa_upload-lot
wa_upload-status
v_quantity
wa_upload-uom
wa_upload-bpcs_facility
wa_upload-bpcs_wh
wa_upload-location
wa_upload-exp_date
wa_upload-lot_create
wa_upload-avl_date
wa_upload-dpl_date.
wa_upload-quantity = v_quantity.
CONDENSE wa_upload-item.
**Call conversion exit for material
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = wa_upload-item
IMPORTING
output = wa_upload-item.
APPEND wa_upload TO i_upload.
CLEAR :wa_upload,
lwa_file,
v_quantity.
ELSE.
EXIT.
ENDIF.
ENDDO.
*-- Close Dataset .
CLOSE DATASET lv_dsn.
ENDIF.
ENDFORM. " get_application_file
reward if helpful.
Regards,
Nagaraj