New to BDC Programming
Dear Guru,
I'm very new to BDC programming and methodology. Can anyone suggest me the best materials, sites or any knowledge repository to start learning with? Thank you very much. Reward will be given.
Cheers,
P.S. Any good example source code and program provided will be appreciate.
hi,
Check this thread.
bdc
Hope this helps !
Cheers
Alfred
Reward with pints for helpful answers
Similar Messages
-
I have a problem while I am doing BDC program for Maintaining Quotation.i.e,I have Header data and Item Data.In Item data it has multiple items.For each item I have to give condition type in the table control(which has already pre-existed condition types),but I have to place new Condition type at the last line of the table control.
Hi,
In pricing element Table Control we have to pass condition type. For each material a set of condition types pre-exists, for us to pass condition types we have to capture index number which changes dynamically.
We have to pass the index number to T_BDCDATA prior calling the transaction ME47 to append the condition type to the last line of the Pricing element table control which changes dynamically. -
Hi to all
I'm new to BDC Progaram
can u tell me how to write a
BDC program to upload purchase order data from legacy system.Hi Viswanath,
First i will explain the procedure step by step and will send a sample code plz check it once ok..And also i will attach a flat file at the end of SAMPLE CODE CHECK IT ONCE OK..
Steps:
1.Bulid an internal table first according to ur flat file fields.
2.select the flat file by using PARAMETER.
3.And assign that file path to GUI_UPLOAD function module.
4.Call BDC_OPEN_GROUP is used to open the session.
5.loop that flat file data and palce BDC_INSERT funtion module in that loop for uploading data into database table
6.After loop call BDC_CLOSE_GROUP to close the session.
SAMPLE CODE:
REPORT ybdc_session_mm01 NO STANDARD PAGE HEADING LINE-SIZE 255.
Global Structure for BDC Data
DATA: it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
Internal Table
DATA: BEGIN OF itab OCCURS 0,
mbrsh LIKE rmmg1-mbrsh,
mtart LIKE rmmg1-mtart,
maktx LIKE makt-maktx,
meins LIKE mara-meins,
END OF itab.
Upload the flat file
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename =
'C:\Documents and Settings\Compaq_Owner\Desktop\satish\mm01.txt'
filetype = 'ASC'
has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = itab.
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.
Session Method Starts
BDC_OPEN_GROUP
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = 'ychinnu'
HOLDDATE = FILLER8
KEEP = 'X'
USER = SY-UNAME
RECORD = FILLER1
PROG = SY-CPROG
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.
Create BDCDATA Structure
*include bdcrecx1.
START-OF-SELECTION.
PERFORM open_group.
loop at itab.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RMMG1-MBRSH'
itab-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
itab-mtart.
After enterning MBRSH,MTART we press enter
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'. "press Enter
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
View selection (Basic data1)
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'"view selection
'X'.
Select Tick Mark (ok)
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_field USING 'MAKT-MAKTX'
itab-maktx.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM bdc_field USING 'MARA-MEINS'
itab-meins.
Finally after filling the data we save the data.
PERFORM bdc_field USING 'MARA-MTPOS_MARA' "For saving
'NORM'.
PERFORM bdc_transaction USING 'MM01'.
PERFORM close_group.
BDC_INSERT
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
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.
Refresh BDCDATA
refresh it_bdcdata.
endloop.
Closing BDC 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.
Start new screen *
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. "BDC_DYNPRO
Insert field *
FORM bdc_field USING fnam fval.
IF FVAL NODATA.
CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
Flat File
*M FERT IRON KG
*M ROH STEEL KG
*M HALB IRON KG
Award points if helpful.
Kiran Kumar.G.A -
Msg of type 'S' in BDC program and same msg of type 'A'
We have to upload data for ABZON transaction of assets. When we use LSMW with recording method and try to upload say 3 records. All teh records are updated successfully but the batch input session log says last two records with a message of type 'A' "leave transaction is not possible in batch input"
But when we upload the same data with BDC program with call transaction then teh log shows same message with type 'S'.
what could be the reason for this?
Though data gets uploaded successfully the 'A' message is being displayed in LSMW batch input log.
if anyone has encountered a similar problem pls let us know how to resolve this asap.
Thanks,
Simmihi,
one crucial point I remember by using enjoy tcodes for bdc is the change of field bukrs.
you must create one bdc-map for each company - program sth like this:
LOOP AT itab.
AT NEW bukrs.
IF bk ne itab-bukrs. "not for 1st bk
PERFORM open_btci_group USING map '00000000' 'X'.
ADD 1 TO cnt.
PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.
PERFORM bdc_field USING 'BDC_OKCODE' '=FURT'.
zeile = '01'.
PERFORM bdc_field_loop USING zeile 'SVALD-VALUE' itab-bukrs.
ENDIF.
ENDAT.
hope that helps -
How to create a BDC program for given recording.
i have to create a BDC program for uploading a file.
currently i am using call function
CALL FUNCTION 'F4_FILENAME'just check out the code below it is for updating two transactions
types Declaration *
types: begin of t_tab1 ,
vendor(10),
material(18),
pur_org(4),
wglif(18),
end of t_tab1.
Data Declaration *
data : begin of it_tab5 occurs 0,
vendor(10),
material(18),
end of it_tab5.
**DATA : BEGIN OF IT_TAB6 OCCURS 0,
VENDOR(10),
MATERIAL(18),
END OF IT_TAB6.
data: it_tab1 type standard table of t_tab1 with header line.
data: wa_tab1 type t_tab1.
data: wa_tab2 type t_tab1.
data: it_tab3 like bdcdata occurs 0 with header line.
data: it_tab4 like bdcdata occurs 0 with header line.
data: it_tab2 type table of bdcmsgcoll with header line.
data: d_file_name like ibipparms-path,
d_file_name1 type string.
Start-of-selection *
start-of-selection.
FM for finding the flat file
call function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
importing
file_name = d_file_name.
d_file_name1 = d_file_name.
******FM for uploading data from flat file into internal table
call function 'GUI_UPLOAD'
exporting
filename = d_file_name1
filetype = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = it_tab5
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.
End-of-selection *
end-of-selection.
sort it_tab5 by vendor.
loop at it_tab5.
perform bdc_dynpro using 'SAPLBG00' 0101 .
perform bdc_field using 'BDC_OKCODE' '/00' .
perform bdc_dynpro using 'SAPLBG00' 1000 .
perform bdc_field using 'BDC_OKCODE' '=BUCH' .
perform bdc_field using 'BDC_SUBSCR'
'SAPLBG00 1101KOPF_1000'.
perform bdc_field using 'GBGMK-GAART' '2' .
perform bdc_field using 'GBGMK-GAERB' 'X' .
perform bdc_field using 'BDC_SUBSCR'
'SAPLBG00 1103TAB_SUB_1000'.
perform bdc_field using 'BDC_CURSOR' 'GBGMP-LSTNR(01)' .
perform bdc_field using 'GBGMP-LSTNR(01)' it_tab5-material .
call transaction 'BGM1' using it_tab3 mode 'E' messages into it_tab2
refresh it_tab3.
wa_tab1-pur_org = 'ABCP'.
loop at it_tab2.
endloop.
perform bdc_dynpro using 'SAPMM06I' 0100 .
perform bdc_field using 'BDC_CURSOR' 'EINE-EKORG' .
perform bdc_field using 'BDC_OKCODE' '/00' .
perform bdc_field using 'EINA-LIFNR' it_tab5-vendor .
perform bdc_field using 'EINA-MATNR' it_tab5-material .
perform bdc_field using 'EINE-EKORG' wa_tab1-pur_org .
perform bdc_field using 'RM06I-NORMB' 'X' .
perform bdc_dynpro using 'SAPMM06I' 0101 .
perform bdc_field using 'BDC_CURSOR' 'EINA-WGLIF' .
perform bdc_field using 'BDC_OKCODE' '=BU' .
perform bdc_field using 'EINA-WGLIF' it_tab2-msgv1 .
call transaction 'ME12' using it_tab3 mode 'E'.
refresh it_tab3.
refresh it_tab2.
endloop.
*& Form BDC_DYNPRO
Start new screen
-->P_FNAM text
-->P_FVAL text
form bdc_dynpro using program
dynpro.
clear it_tab3.
it_tab3-program = program.
it_tab3-dynpro = dynpro.
it_tab3-dynbegin = 'X'.
append it_tab3.
endform. " BDC_DYNPRO
*& Form BDC_FIELD
Insert field
-->P_FNAM text
-->P_FVAL text
form bdc_field using fnam
fval.
clear it_tab3.
it_tab3-fnam = fnam.
it_tab3-fval = fval.
append it_tab3.
endform. " BDC_FIELD
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 14, 2008 6:20 PM -
How to upload 3 more columns from excel to SAP with exiting BDC program
Dear ABAPers,
Three more columns are added to the existing excel sheet(new columns are Consignment DP, Consignment Value, Total Consignment Value).
Actual program is :The program is to upload the TXT data from MLM Solution
Transaction code syntax is in bdc prog: call transaction 'VF01' using bdcdata update 'S' mode 'N' messages into i_bill_return.
i am new to BDC concepts, please give me the complete details, how can i upload.
Thanks in advance.
HariHi Hari,
How is your input structure define, (data from excel to internal table). If you have the fields defined in it...
1.you need to change the input structure first in your program....
2. If your business needs any validation to these new fields????
3.you need to modify the BDC population code for the new fields and populate the BDC structure....
If the hint is useful Say thanks by reward .
Regards,
Prabhu Rajesh -
Error in bdc programing code-pls help
hi friends,
I was tring to do a bdc program.But it shows me an error. MY bdc program is jus to upload a 2 fields in vendoe master table.
That is LIFNR,NAME1 field for the new vendors.
I worked out an execl sheet for this, and jus copied it to the text file by selecting all and pasting.
Even then i get an error code that BDC_open does not exits.
MY code is this, please help me if iam wrong.
If anyone can help to make it more understandable,I Kindly request you to try out this program with the screen shot and mail to this id [email protected] would be very thankful for your timely help.
report Z_PK_BDC
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
parameters: p_file like rlgrap-filename default
'C:\SAP TESTING\p_file.txt'.
DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
If it is nessesary to change the data section use the rules:
1.) Each definition of a field exists of two lines
2.) The first line shows exactly the comment
'* data element: ' followed with the data element
which describes the field.
If you don't have a data element use the
comment without a data element name
3.) The second line shows the fieldname of the
structure, the fieldname must consist of
a fieldname and optional the character '_' and
three numbers and the field length in brackets
4.) Each field must be type C.
Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record OCCURS 0,
data element: LIF16
LIFNR_001(016),
data element: BUKRS
BUKRS_002(004),
data element: KTOKK
KTOKK_003(004),
data element: ANRED
ANRED_004(015),
data element: NAME1_GP
NAME1_005(035),
data element: SORTL
SORTL_006(010),
data element: NAME2_GP
NAME2_007(035),
data element: STRAS_GP
STRAS_008(035),
data element: ORT01_GP
ORT01_009(035),
data element: ORT02_GP
ORT02_010(035),
data element: PFORT_GP
PFORT_011(035),
data element: LAND1_GP
LAND1_012(003),
data element: SPRAS
SPRAS_013(002),
end of record.
End generated data section ***
start-of-selection.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = record
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
IF SY-SUBRC <> 0.
WRITE:/ 'SY-SUBRC:', SY-SUBRC.
ENDIF.
LOOP AT RECORD.
*perform open_dataset using dataset.
*perform open_group.
*do.
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
perform bdc_dynpro using 'SAPMF02K' '0105'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
record-LIFNR_001.
perform bdc_field using 'RF02K-BUKRS'
record-BUKRS_002.
perform bdc_field using 'RF02K-KTOKK'
record-KTOKK_003.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-ANRED'
record-ANRED_004.
perform bdc_field using 'LFA1-NAME1'
record-NAME1_005.
perform bdc_field using 'LFA1-SORTL'
record-SORTL_006.
perform bdc_field using 'LFA1-NAME2'
record-NAME2_007.
perform bdc_field using 'LFA1-STRAS'
record-STRAS_008.
perform bdc_field using 'LFA1-ORT01'
record-ORT01_009.
perform bdc_field using 'LFA1-ORT02'
record-ORT02_010.
perform bdc_field using 'LFA1-PFORT'
record-PFORT_011.
perform bdc_field using 'LFA1-LAND1'
record-LAND1_012.
perform bdc_field using 'LFA1-SPRAS'
record-SPRAS_013.
perform bdc_transaction using 'FK01'.
**enddo.
**perform close_group.
endloop.
**perform close_dataset using dataset.
Thanks in Advance
Rinky123Hi,
If you are using GUI_UPLOAD in 4.7 then the file path whatever you are using currently it won't work. Replace the file path like this.
P_FILE LIKE RLGRAP-FILENAME.
DATA: V_FILE TYPE STRING.
V_FILE = P_FILE.
Now take this v_file for function module.Then only it will open the file otherwise you won't get unable to open file error message.
I observerd that you are getting so many fields from the file to the internal table. -
Recording TCode for BDC program
Hi ALL,
I have a problem in recording GS01 tcode.
I have to a table control in GS01 tcode.
After some rows again i need to update the data.
How can i record this and write BDC program for the same.Hi
To uplaod the data using the table control,if number of line are more then screen.
Then use the P+ in u r code.
let assume that u can see 10 rows on screen.once the count reachs the 10 then do P+ then
new line will come and after P+ clear u r counter. -
BDC PROGRAM WITH OUT USING A FM?
Hi Experts,
I need wirte a BDC program for tcode PA30.
i did the screen recording part using tcode-shdb.
i need to use field i recorded as input fields.
Now the main part is how to write code? with out using a class/method?
class/method which i earlier used is class : CL_GUI_FRONTEND_SERVICES.
method: gui_upload.
am not using ny flat file/xml file to upload?
are there any function modules which i can use?
and how to write code with out using FM?
if any can solve my issue would be very helpful...plz provide code...which would be more helpful.
Thanks in Adv.
Krrish.Hi,
If you are migrating employee data, I would suggest you to do it through PA40 transaction rather PA30. systematic screen validations it will go through. If you dont want to use any FM and wanted to do using recording pls find the below code which will update the employee data through PA40 with call transaction method.
SELECTION SCREEN
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_plan TYPE ibipparms-path OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
TYPES: BEGIN OF ty_error,
pernr TYPE persno, " Personnel number
rel_obj_id(12), " Related Object ID
msg(200) TYPE c, " To store Message
END OF ty_error.
DATA: i_tplan TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE,
i_intern TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE,
i_error TYPE ty_error OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF w_pa000,
pernr TYPE persno,
begda TYPE begda,
END OF w_pa000.
DATA: wa_plan LIKE i_plan,
wa_messtab TYPE bdcmsgcoll, " Messages
wa_error TYPE ty_error. " Errors
DATA: it_pa000 LIKE STANDARD TABLE OF w_pa000 WITH HEADER LINE,
it_pa002 LIKE STANDARD TABLE OF w_pa000 WITH HEADER LINE,
it_pa001 LIKE STANDARD TABLE OF w_pa000 WITH HEADER LINE.
DATA: g_mode LIKE ctu_params-dismode VALUE 'N',
g_file TYPE ibipparms-path.
ALV field catalog
DATA : i_fieldcat TYPE slis_t_fieldcat_alv.
Batchinputdata of single transaction
DATA: i_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
messages of call transaction
DATA: i_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
error session opened (' ' or 'X')
Table to hold the return messages
DATA: BEGIN OF i_errmsg OCCURS 10.
INCLUDE STRUCTURE bapiret2.
DATA: END OF i_errmsg.
ALV List header table
DATA : i_header1 TYPE slis_t_listheader.
ALV List header table
DATA : i_header TYPE slis_listheader.
***ALV Events
DATA: is_layout TYPE slis_layout_alv.
DATA : it_event TYPE slis_alv_event.
DATA : it_event1 TYPE slis_t_event.
To get the F4 help for file
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_plan.
PERFORM get_filename.
START OF SELECTION
START-OF-SELECTION.
Initialise data
PERFORM initialise_events.
Retrieve data from Excel file
PERFORM retreive_data.
Populate final data into an internal table
PERFORM populate_data.
Process the excel file data to create a record for IT0007
PERFORM process_data.
END OF SELECTION
END-OF-SELECTION.
PERFORM final_output.
*& Form GET_FILENAME
FORM get_filename .
*Function module used for F4 help
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_plan.
ENDFORM. " GET_FILENAME
*& Form INITIALISE_EVENTS
FORM initialise_events .
i_header-typ = 'H'.
i_header-key = 'R'.
i_header-info = 'BDC Interface for PA Infotypes 0000,0001,0002'.
APPEND i_header TO i_header1.
CLEAR i_header.
i_header-typ = 'S'.
i_header-info = 'Hiring, Org.Assignment, Personnel Data'.
APPEND i_header TO i_header1.
CLEAR i_header.
***Events and form name
it_event-name = 'TOP_OF_PAGE'.
it_event-form = 'TOP_OF_PAGE'.
APPEND it_event TO it_event1.
ENDFORM. " INITIALISE_EVENTS
*& Form RETREIVE_DATA
FORM retreive_data .
PERFORM upload_data.
ENDFORM. " RETREIVE_DATA
*& Form UPLOAD_DATA
FORM upload_data .
FM to upload data from excel sheet to internal table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_plan
i_begin_col = g_colbeg
i_begin_row = g_rowbeg
i_end_col = g_colend
i_end_row = g_rowend
TABLES
intern = i_tplan
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 POPULATE_DATA
FORM populate_data .
processing the internal table generated from the function module
Passing data from Excel file to internal table
CLEAR: g_cnt_processed,
g_cnt_err_processed,
i_intern,
i_plan.
LOOP AT i_tplan.
AT NEW row.
CLEAR i_plan.
ENDAT.
CASE i_tplan-col.
Begin Date
WHEN '0001'.
i_plan-pernr = i_tplan-value.
End Date
WHEN '0002'.
i_plan-begda = i_tplan-value.
WHEN '0003'.
i_plan-massg = i_tplan-value.
Sign
WHEN '0004'.
i_plan-plans = i_tplan-value.
WHEN '0005'.
i_plan-werks = i_tplan-value.
WHEN '0006'.
i_plan-persg = i_tplan-value.
WHEN '0007'.
i_plan-persk = i_tplan-value.
WHEN '0008'.
i_plan-anrex = i_tplan-value.
WHEN '0009'.
i_plan-nachn = i_tplan-value.
WHEN '0010'.
i_plan-vorna = i_tplan-value.
WHEN '0011'.
i_plan-gesch = i_tplan-value.
WHEN '0012'.
i_plan-gbdat = i_tplan-value.
WHEN '0013'.
i_plan-fatxt = i_tplan-value.
WHEN '0014'.
i_plan-famdt = i_tplan-value.
WHEN '0015'.
i_plan-gblnd = i_tplan-value.
WHEN '0016'.
i_plan-anzkd = i_tplan-value.
WHEN '0017'.
i_plan-natio = i_tplan-value.
WHEN '0018'.
i_plan-btrtl = i_tplan-value.
WHEN '0019'.
i_plan-gsber = i_tplan-value.
WHEN '0020'.
i_plan-abkrs = i_tplan-value.
ENDCASE.
Appending the internal table tb_data, tb_chng
AT END OF row.
APPEND i_plan.
IF i_plan IS INITIAL.
g_cnt_err_processed = g_cnt_err_processed + 1.
ENDIF.
ENDAT.
ENDLOOP.
To get the total number of records processed
DESCRIBE TABLE i_plan LINES g_lines.
g_cnt_processed = g_cnt_err_processed + g_lines.
CLEAR g_lines.
ENDFORM. " POPULATE_DATA
*& Form PROCESS_DATA
FORM process_data .
CLEAR wa_error.
REFRESH i_bdcdata.
Check if the employee numbers from the template has already been hired
SELECT pernr
begda
FROM pa0000
INTO TABLE it_pa000
FOR ALL ENTRIES IN i_plan
WHERE pernr = i_plan-pernr
AND massn = 'ZA'.
IF sy-subrc = 0.
SORT it_pa000 BY pernr.
Check if employee has a corresponding infotype 0001 record
SELECT pernr
begda
FROM pa0001
INTO TABLE it_pa001
FOR ALL ENTRIES IN it_pa000
WHERE pernr = it_pa000-pernr AND
begda = it_pa000-begda.
IF sy-subrc = 0.
SORT it_pa001 BY pernr.
Check if employee has a corresponding infotype 0002 record
SELECT pernr
begda
FROM pa0001
INTO TABLE it_pa002
FOR ALL ENTRIES IN it_pa001
WHERE pernr = it_pa001-pernr AND
begda = it_pa001-begda.
IF sy-subrc = 0.
SORT it_pa002 BY pernr.
ENDIF.
ENDIF.
ENDIF.
LOOP AT i_plan.
REFRESH i_bdcdata.
***your recording to be pasted here***
PERFORM bdc_field USING 'BDC_CURSOR'
'P0006-BEGDA'.
PERFORM call_transaction.
APPEND wa_error TO i_error.
REFRESH: i_bdcdata, i_messtab.
CLEAR: wa_error, i_error.
ENDLOOP.
ENDFORM. " PROCESS_DATA
*& Form BDC_DYNPRO
FORM bdc_dynpro USING program dynpro.
CLEAR i_bdcdata.
i_bdcdata-program = program.
i_bdcdata-dynpro = dynpro.
i_bdcdata-dynbegin = 'X'.
APPEND i_bdcdata.
ENDFORM. "BDC_DYNPRO
*& Form BDC_FIELD
FORM bdc_field USING fnam fval.
IF fval <> nodata.
CLEAR i_bdcdata.
i_bdcdata-fnam = fnam.
i_bdcdata-fval = fval.
APPEND i_bdcdata.
ENDIF.
ENDFORM. "bdc_field
*& Form ERROR_RECORD_DATA
FORM error_record_data .
CLEAR: g_lines,
wa_messtab,
g_msg.
DESCRIBE TABLE i_messtab LINES g_lines.
READ TABLE i_messtab INTO wa_messtab INDEX g_lines.
IF sy-subrc = 0.
CLEAR g_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_messtab-msgid
lang = sy-langu
no = wa_messtab-msgnr
v1 = wa_messtab-msgv1
v2 = wa_messtab-msgv2
v3 = wa_messtab-msgv3
v4 = wa_messtab-msgv4
IMPORTING
msg = g_msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF wa_messtab-msgtyp = 'E'.
IF wa_messtab-msgtyp = 'S' AND wa_messtab-msgnr = '102' AND wa_messtab-msgid = 'PG'.
wa_error-pernr = i_plan-pernr.
wa_error-rel_obj_id = 'S'.
wa_error-msg = 'Personnel Number Created Successfully'.
ELSE.
wa_error-pernr = i_plan-pernr.
wa_error-rel_obj_id = 'E'.
wa_error-msg = g_msg.
ENDIF.
APPEND wa_error TO i_error.
CLEAR i_error.
ENDIF.
ENDFORM. " ERROR_RECORD_DATA
*& Form FINAL_OUTPUT
FORM final_output .
CLEAR g_lines.
SORT i_error.
*************added*********************************************
loop at i_error into wa_error.
if wa_error-MSG eq 'No batch input data for screen MP000600 2000'.
wa_error-rel_obj_id = 'S'.
wa_error-MSG = 'Record Created Successfully'.
modify i_error from wa_error.
endif.
endloop.
loop at i_error into wa_error.
if wa_error-rel_obj_id = 'S'.
g_cnt_success = g_cnt_success + 1. " Append success count
elseif wa_error-rel_obj_id = 'E'.
g_cnt_failure = g_cnt_failure + 1. " Append error count
endif.
endloop.
***Field catalog
PERFORM field_cat.
***Assigning Program name
g_repid = sy-repid.
SORT i_error.
***Display Output
IF NOT it_final[] IS INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'PF_STATUS_SET'
i_save = 'A'
it_events = it_event1
is_layout = is_layout
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = i_error[].
ELSE.
MESSAGE i015(zv_msg) WITH 'No Data Found for this selection'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " FINAL_OUTPUT
*& Form top_of_page
text
FORM top_of_page.
***FM for Displaying Heading
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header1[]
i_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "top_of_page
*& Form FIELD_CAT
FORM field_cat .
ENDFORM. " FIELD_CAT
*& Form CALL_TRANSACTION
FORM call_transaction .
CALL TRANSACTION 'PA40' USING i_bdcdata
MODE g_mode
UPDATE 'S'
MESSAGES INTO i_messtab.
If call transaction successful
IF sy-subrc = 0.
g_cnt_success = g_cnt_success + 1. " Append success count "changed
PERFORM error_record_data. " Populate all data
If call transaction not successful
ELSE.
PERFORM error_record_data. " Populate all table
g_cnt_failure = g_cnt_failure + 1. " Append error count "changed
ENDIF.
ENDFORM. " CALL_TRANSACTION -
Hi,
i am new to bdc.in my req.. they asked me to change bapi function module and i want replace with bdc. i want to do recording for ME21n or ME21 Tcode and bdc Session method.plz let me know the process by step by step.if any one have code for this send me.for every 1000 line items i want to crate session.
my input file type:
rectyp type char1, " Type of Record indicator - H /T / D
ebeln type ebeln, " Purchasing Document Number
bukrs type zlegacy_company, " Company Code
ekgrp type bkgrp, " Purchasing Group
bsart(6), " Purchasing Document Type
ekorg type ekorg, " Purchasing Organization
lifnr type elifn, " Vendor Account Number
bedat type ebdat, " Purchasing Document Date
ebelp type ebelp, " Item Number of Purchasing Documen
knttp type knttp, " Account Assignment Category
matkl type matkl, " Material Group
werks type werks, " Plant
txz01 type txz01, " Short Text
menge(13) type c, " Purchase Order Quantity
meins type bstme, " Purchase Order Unit of Measure
netpr(16) type c, " Net Price in Purchasing Document
peinh(5) type c, " Price Unit
bprme type bbprm, " Order Price Unit (Purchasing)
eeind type datum, " Delivery Date
mwskz type mwskz, " Sales Tax Code
saknr type saknr, " Cost Element
prctr(15), " Profit Center
po_number type ebeln, " PO Number
bwart type bwart, " Movement type
po_item type ebelp, " PO Line Item
bldat type bldat, " Document Date
lfsnr type lfsnr, " Delivery Note
frbnr type frbnr, " Bill of Laden
bktxt type bktxt, " Header Text
erfmg(13) type c,
thanks,
ankithaHi Ankitha,
Its not possible to use BDC for ME21N, becos this is Enjoy Tcode. Better create program using BAPI_PO_CREATE1 Bapi.
if u want here is the code with bapi.....
FORM create_sto .
REFRESH: i_errpo, i_error.
CLEAR: w_header, i_errpo, i_error, v_success, v_error.
LOOP AT i_header_sa INTO w_header.
CLEAR: w_errpo, w_poheaderx, w_exppurchaseorder, w_expheader,
w_return, w_poitem, w_poitemx, w_poschedule, w_poschedulex,
i_return, w_poitem, w_poitemx, i_poschedule, i_poschedulex.
REFRESH: i_return, i_poitem, i_poitemx, i_poschedule, i_poschedulex.
*--Fill Header
w_poheader-po_number = w_header-ebeln.
w_poheader-doc_type = 'ZU'.
*--The supplying plant is mapped based on the recieving plant in from the ZCA_CONV_UTILITY.
The conversion is based on the new values of the recieving plant and storage location
v_value_old = w_header-bukrs.
PERFORM convert TABLES i_values
USING 'BUKRS'
v_value_old
CHANGING v_value_new.
w_poheader-comp_code = v_value_new(4).
w_poheader-pur_group = w_header-ekgrp.
CLEAR: v_value_old, v_value_new.
v_value_old = w_header-ekorg.
PERFORM convert TABLES i_values
USING 'EKORG'
v_value_old
CHANGING v_value_new.
WRITE w_header-aedat+4(2) TO v_po_date(2).
WRITE w_header-aedat6(2) TO v_po_date2(2).
WRITE w_header-aedat(4) TO v_po_date+4(4).
w_poheader-purch_org = v_value_new(4).
w_poheader-vendor = w_header-lifnr.
w_poheader-creat_date = v_po_date.
w_poheader-item_intvl = w_header-pincr.
w_poheader-langu = w_header-spras.
w_poheader-subitemint = w_header-upinc.
w_poheader-vper_start = w_header-kdatb.
w_poheader-vper_end = w_header-kdate.
w_poheader-warranty = w_header-gwldt.
w_poheader-ref_1 = w_header-ihrez.
w_poheader-sales_pers = w_header-verkf.
w_poheader-our_ref = w_header-unsez.
w_poheader-telephone = w_header-telf1.
w_poheaderx-po_number = 'X'.
w_poheaderx-doc_type = 'X'.
w_poheaderx-suppl_plnt = 'X'.
w_poheaderx-comp_code = 'X'.
w_poheaderx-pur_group = 'X'.
w_poheaderx-purch_org = 'X'.
w_poheaderx-vendor = 'X'.
w_poheaderx-creat_date = 'X'.
w_poheaderx-item_intvl = 'X'.
w_poheaderx-langu = 'X'.
w_poheaderx-subitemint = 'X'.
w_poheaderx-vper_start = 'X'.
w_poheaderx-vper_end = 'X'.
w_poheaderx-warranty = 'X'.
w_poheaderx-ref_1 = 'X'.
w_poheaderx-sales_pers = 'X'.
w_poheaderx-our_ref = 'X'.
w_poheaderx-telephone = 'X'.
CLEAR: w_item, v_poitem.
LOOP AT i_item INTO w_item WHERE ebeln EQ w_header-ebeln.
CLEAR: w_zmm_cordlog,
v_split,
w_matnr.
READ TABLE i_zmm_cordlog INTO w_zmm_cordlog WITH KEY ponumber = w_item-ebeln
poitem = w_item-ebelp.
IF sy-subrc EQ 0.
*--If file is processed earlier, rollback work.
IF NOT w_zmm_cordlog-mdoc561 IS INITIAL. "STO has to be processed for 561 Goods Mvmt
w_errortab-ponumber = w_item-ebeln.
w_errortab-poitem = w_item-ebelp.
w_errortab-message = text-051. "Process STO for 561 Goods Mvmt.
APPEND w_errortab TO i_errortab.
ADD 1 TO v_error.
CLEAR w_errortab.
PERFORM error_pos.
CONTINUE.
ELSE.
IF NOT w_zmm_cordlog-eccpo IS INITIAL. "STO already exists
w_errortab-ponumber = w_item-ebeln.
w_errortab-poitem = w_item-ebelp.
w_errortab-eccpo = w_zmm_cordlog-eccpo.
w_errortab-eccpoitem = w_zmm_cordlog-eccpoitem.
w_errortab-message = text-052. "STO already created, record skipped
APPEND w_errortab TO i_errortab.
ADD 1 TO v_error.
CLEAR w_errortab.
PERFORM error_pos.
CONTINUE.
ENDIF.
ENDIF.
ENDIF.
CLEAR w_mard.
SELECT SINGLE * FROM mard INTO w_mard
WHERE matnr EQ w_item-matnr
AND werks EQ w_item-werks
AND lgort EQ w_item-lgort.
IF sy-subrc <> 0.
w_itmerror-ponumber = w_item-ebeln.
w_itmerror-poitem = w_item-ebelp.
CONCATENATE w_item-matnr w_item-werks w_item-lgort text-044
INTO w_itmerror-message SEPARATED BY space.
APPEND w_itmerror TO i_itmerror.
ADD 1 TO v_error.
CONTINUE.
ENDIF.
*--Plant and Storage location conversion
CLEAR: v_value_old, i_values[], v_value_new.
CONCATENATE w_item-werks w_item-lgort INTO v_value_old.
PERFORM convert TABLES i_values
USING 'WERKSLGORT'
v_value_old
CHANGING v_value_new.
w_item-werks = v_value_new+0(4).
w_item-lgort = v_value_new+4(4).
*--The converted recieving plant will be the same as the supplying plant in the new system
and the supplying storage location would be OW01.
w_poheader-suppl_plnt = w_item-werks.
*--Fill item
w_poitem-po_item = w_item-ebelp.
w_poitem-material = w_item-matnr.
w_poitem-plant = w_item-werks.
w_poitem-stge_loc = w_item-lgort.
w_poitem-po_unit = w_item-meins.
PERFORM get_valuation_type USING w_item-matnr
w_item-werks
w_item-lgort
CHANGING w_poitem-val_type.
IF w_item-matnr CP '*-R'.
SPLIT w_item-matnr AT '-R' INTO w_item-matnr v_split.
ELSEIF w_item-matnr CP '*-D'.
SPLIT w_item-matnr AT '-D' INTO w_item-matnr v_split.
ENDIF.
SELECT SINGLE matnr INTO w_matnr
FROM mara
WHERE matnr = w_item-matnr.
IF sy-subrc NE 0.
w_errortab-ponumber = w_item-ebeln.
w_errortab-poitem = w_item-ebelp.
CONCATENATE w_item-matnr 'Does not exist in the MARC table'
INTO w_errortab-message.
ADD 1 TO v_error.
CONTINUE.
ENDIF.
w_poitem-matl_group = w_item-matkl.
w_poitem-item_cat = w_item-pstyp.
w_poitem-acctasscat = w_item-knttp.
w_poitem-reminder1 = w_item-mahn1.
w_poitem-conf_ctrl = w_item-bstae.
w_poitem-ackn_reqd = w_item-kzabs.
w_poitem-quantity = w_item-menge.
w_poitem-reminder2 = w_item-mahn2.
w_poitem-acknowl_no = w_item-labnr.
w_poitem-reminder3 = w_item-mahn3.
w_poitem-trackingno = w_item-bednr.
w_poitem-gr_pr_time = w_item-webaz.
w_poitem-under_dlv_tol = w_item-untto.
w_poitem-qual_insp = w_item-insmk.
w_poitem-over_dlv_tol = w_item-uebto.
w_poitem-unlimited_dlv = w_item-uebtk.
w_poitem-no_more_gr = w_item-elikz.
w_poitem-shipping = w_item-evers.
w_poitem-period_ind_expiration_date = ' '.
APPEND w_poitem TO i_poitem.
w_poitemx-po_item = w_poitem-po_item.
w_poitemx-po_itemx = 'X'.
w_poitemx-material = 'X'.
w_poitemx-plant = 'X'.
w_poitemx-stge_loc = 'X'.
w_poitemx-po_unit = 'X'.
w_poitemx-val_type = 'X'.
w_poitemx-matl_group = 'X'.
w_poitemx-item_cat = 'X'.
w_poitemx-acctasscat = 'X'.
w_poitemx-reminder1 = 'X'.
w_poitemx-conf_ctrl = 'X'.
w_poitemx-ackn_reqd = 'X'.
w_poitemx-quantity = 'X'.
w_poitemx-reminder2 = 'X'.
w_poitemx-acknowl_no = 'X'.
w_poitemx-reminder3 = 'X'.
w_poitemx-trackingno = 'X'.
w_poitemx-gr_pr_time = 'X'.
w_poitemx-under_dlv_tol = 'X'.
w_poitemx-qual_insp = 'X'.
w_poitemx-over_dlv_tol = 'X'.
w_poitemx-unlimited_dlv = 'X'.
w_poitemx-no_more_gr = 'X'.
w_poitemx-shipping = 'X'.
w_poitemx-period_ind_expiration_date = 'X'.
APPEND w_poitemx TO i_poitemx.
CLEAR w_poitemx.
CLEAR: w_slines, v_scheditem.
LOOP AT i_slines INTO w_slines WHERE ebeln EQ w_item-ebeln
AND ebelp EQ w_item-ebelp.
*--Fill Schedule lines for PO
w_poschedule-po_item = w_item-ebelp.
w_poschedule-sched_line = w_slines-etenr.
w_poschedule-del_datcat_ext = ' '.
w_poschedule-delivery_date = w_slines-eindt.
w_poschedule-quantity = w_slines-menge.
APPEND w_poschedule TO i_poschedule.
CLEAR w_poschedule.
w_poschedulex-po_item = w_item-ebelp.
w_poschedulex-sched_line = w_slines-etenr.
w_poschedulex-po_itemx = 'X'.
w_poschedulex-sched_linex = 'X'.
w_poschedulex-del_datcat_ext = 'X'.
w_poschedulex-delivery_date = 'X'.
w_poschedulex-quantity = 'X'.
APPEND w_poschedulex TO i_poschedulex.
CLEAR w_poschedulex.
CLEAR w_slines.
ENDLOOP.
CLEAR: w_poitem,
w_item.
ENDLOOP.
SORT: i_poitem, i_poitemx, i_poschedule, i_poschedulex.
*--If the import data to BAPI is empty, then raise a message to check the Material Error file for
any PO items which are skipped.
The PO in error is also moved to the error file for reprocessing.
IF w_poheader IS INITIAL OR
i_poitem[] IS INITIAL.
CLEAR: w_poheader, w_poheaderx, i_return[], i_poitem, i_poitem[].
CONTINUE.
ENDIF.
*--BAPI call for PO creation
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = w_poheader
poheaderx = w_poheaderx
testrun = p_test
IMPORTING
exppurchaseorder = w_exppurchaseorder
expheader = w_expheader
TABLES
return = i_return
poitem = i_poitem
poitemx = i_poitemx
poschedule = i_poschedule
poschedulex = i_poschedulex.
*--Commit the transaction if a success message is returned, else rollback work.
Update the legacy PO and items in the ZMM_CORDLOG table
start of modification
WAIT UP TO time SECONDS.
end of modification
IF NOT i_return[] IS INITIAL.
LOOP AT i_return INTO w_return.
*--Read the error messages
IF w_return-type = 'E'.
w_errortab-ponumber = w_header-ebeln.
w_errortab-doctype = w_poheader-doc_type.
w_errortab-supplplnt = w_poheader-suppl_plnt.
w_errortab-vendor = w_poheader-vendor.
w_errortab-eccpo = w_expheader-po_number.
w_errortab-message = w_return-message(73).
APPEND w_errortab TO i_errortab.
ADD 1 TO v_error.
ROLLBACK WORK.
ELSEIF w_return-type = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
EXCEPTIONS
OTHERS = 1.
IF sy-subrc EQ 0.
v_success = v_success + 1.
CLEAR w_poitem.
LOOP AT i_poitem INTO w_poitem.
w_zmm_cordlog-ponumber = w_poheader-po_number.
w_zmm_cordlog-poitem = w_poitem-po_item.
w_zmm_cordlog-doctype = w_poheader-doc_type.
w_zmm_cordlog-supplplnt = w_poheader-suppl_plnt.
w_zmm_cordlog-vendor = w_poheader-vendor.
w_zmm_cordlog-eccpo = w_poheader-po_number.
w_zmm_cordlog-eccpoitem = w_poitem-po_item.
w_zmm_cordlog-message = w_return-message(73).
MODIFY zmm_cordlog FROM w_zmm_cordlog. "Modify DB table
CLEAR w_zmm_cordlog.
w_errpo-ebeln = w_poheader-po_number.
w_errpo-ebelp = w_poitem-po_item.
APPEND w_errpo TO i_errpo.
CLEAR w_errpo.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
CALL FUNCTION 'DEQUEUE_ALL'.
ENDIF.
CLEAR: w_header,
w_poheader,
w_poheaderx.
CALL FUNCTION 'DEQUEUE_ALL'.
ENDLOOP.
IF NOT i_errpo[] IS INITIAL.
*--Separate error records (all records for any PO in error).
PERFORM create_error_file TABLES i_header_sa.
*--Write data to Application Server
IF NOT i_error[] IS INITIAL.
OPEN DATASET p_error FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
MESSAGE e398 WITH text-023 space space space.
ENDIF.
LOOP AT i_error INTO w_error.
TRANSFER w_error TO p_error.
ENDLOOP.
ENDIF.
ENDIF.
COMMIT WORK.
ENDFORM. " create_sto
some other example code with bapi.. for ME21N
use BAPI_PO_CREATE1.
check this Sample code,
REPORT zpo_create .
PARAMETERS: p-file LIKE rlgrap-filename DEFAULT
'c:\demo3.txt'.
DATA: BEGIN OF itab OCCURS 0,
line(1000),
END OF itab.
DATA l_item(5) TYPE n.
TABLES : zerror.
DATA lcounter(3) TYPE n.
DATA : l_errflag.
DATA : l_po_header LIKE bapimepoheader.
DATA : l_po_headerx LIKE bapimepoheaderx.
DATA : t_po_account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE.
DATA : t_po_accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.
DATA : l_new_po(10), l_last_po(10).
DATA : l_purchaseorder LIKE bapimepoheader-po_number.
*DATA : L_HEADER LIKE BAPIMEPOHEADER STRUCTURE BAPIMEPOHEADER.
DATA : BEGIN OF t_po_items OCCURS 0.
INCLUDE STRUCTURE bapimepoitem.
DATA : END OF t_po_items.
DATA : BEGIN OF t_po_itemsx OCCURS 0.
INCLUDE STRUCTURE bapimepoitemx.
DATA : END OF t_po_itemsx.
DATA : BEGIN OF t_return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA : END OF t_return.
CLEAR : l_po_header.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p-file
filetype = 'DAT'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
LOOP AT itab.
IF itab-line(1) EQ 'K'.
l_new_po = itab-line(10).
IF l_last_po NE l_new_po AND l_last_po NE space.
PERFORM create_po.
PERFORM refresh_table.
ENDIF.
IF itab-line+13(2) EQ '40'.
PERFORM append_header.
ENDIF.
IF itab-line+13(2) EQ '81'.
PERFORM append_item.
ENDIF.
l_last_po = l_new_po.
ENDIF.
ENDLOOP.
IF sy-subrc EQ 0.
PERFORM create_po.
PERFORM refresh_table.
ENDIF.
*& Form CREATE_PO
PO Create
--> p1 text
<-- p2 text
FORM create_po .
CLEAR : l_purchaseorder.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = l_po_header
poheaderx = l_po_headerx
POADDRVENDOR =
TESTRUN =
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER =
POEXPIMPHEADERX =
VERSIONS =
NO_MESSAGING =
NO_MESSAGE_REQ =
NO_AUTHORITY =
NO_PRICE_FROM_PO =
IMPORTING
exppurchaseorder = l_purchaseorder
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
return = t_return
poitem = t_po_items
poitemx = t_po_itemsx
POADDRDELIVERY =
POSCHEDULE =
POSCHEDULEX =
poaccount = t_po_account
POACCOUNTPROFITSEGMENT =
poaccountx = t_po_accountx
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
l_errflag = space.
lcounter = 1.
LOOP AT t_return .
IF t_return-type = 'E'.
l_errflag = 'X'.
GET TIME.
PERFORM append_error.
ENDIF.
WRITE : /1 t_return-message.
ENDLOOP.
IF l_errflag EQ space.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
ENDIF.
ENDFORM. " CREATE_PO
*& Form APPEND_HEADER
PO Header print
--> p1 text
<-- p2 text
FORM append_header .
l_po_header-comp_code = '1000'." Company Code
l_po_header-doc_type = 'NB'. " Order Typr BSART
l_po_header-creat_date = sy-datum. " P.O Dt - BEDAT
*CONCATENATE '0000' ITAB+72(6) INTO L_PO_HEADER-VENDOR .
l_po_header-vendor = itab-line+71(6).
*L_PO_HEADER-VENDOR = ITAB+72(6) " 'ABC'. "Vendor - EKKO-LIFNR
IF itab-line(4) NE 'K034'.
l_po_header-purch_org = '2000'. " Purch. Org - EKKO-EKORG
l_po_header-pur_group = 'F01'. " Purch Group - EKKO-EKGRP
ELSE.
l_po_header-purch_org = '1000'. " Purch. Org - EKKO-EKORG
l_po_header-pur_group = '001'. " Purch Group - EKKO-EKGRP
ENDIF.
l_po_header-currency_iso = 'USD'. " Currency Default field for Enjoy
l_po_header-ref_1 = itab-line+1(9).
*L_PO_HEADER-DOC_CAT = 'F'. " Account Assign Cat EKPO-KNTTP
*_PO_HEADER-CREATED_BY = SY-UNAME.
CLEAR : l_po_headerx.
l_po_headerx-po_number = 'X'.
l_po_headerx-comp_code = 'X'." Company Code
l_po_headerx-doc_type = 'X'. " Order Typr BSART
l_po_headerx-vendor = 'X'. "Vendor - EKKO-LIFNR
l_po_headerx-purch_org = 'X'. " Purch. Org - EKKO-EKORG
l_po_headerx-pur_group = 'X'. " Purch Group - EKKO-EKGRP
l_po_headerx-currency_iso = 'X'. " Currency Default field for Enjoy
l_po_headerx-ref_1 = 'X'.
ENDFORM. " APPEND_HEADER
*& Form APPEND_ITEM
Material Number and Item print
--> p1 text
<-- p2 text
FORM append_item .
PO Line Items
l_item = l_item + 10.
t_po_items-po_item = l_item.
*T_PO_ITEMS-PO_ITEM = '00010'." Line Item No - EKPO-EBELP
*T_PO_ITEMS-SHORT_TEXT = 'KSR TEXT'." Line Item TEXT
CONCATENATE '00000000' itab-line+32(10) INTO t_po_items-material.
*T_PO_ITEMS-MATERIAL = '000000000000000043'. " Material No - EKPO-EMATN
CONCATENATE '00000000' itab-line+32(10) INTO t_po_items-ematerial.
t_po_items-plant = '2001'. " Plant - EKPO-WERKS
t_po_items-quantity = '1.000'.
t_po_items-net_price = '10.00'. " EKPO-NETPR
t_po_items-price_unit = '10 '.
*T_PO_ITEMS-TAX_CODE = 'A2'.
IF itab-line+0(4) EQ 'K034'.
t_po_items-acctasscat = 'R'.
t_po_items-plant = '1001'.
t_po_account-po_item = l_item.
t_po_account-profit_ctr = 'BR034'.
t_po_account-gl_account = '0000135075'.
T_PO_ACCOUNT-CO_AREA = '1000'.
APPEND t_po_account.
CLEAR t_po_account.
t_po_accountx-po_item = l_item.
t_po_accountx-profit_ctr = 'X'.
t_po_accountx-gl_account = 'X'.
T_PO_ACCOUNTX-CO_AREA = 'X'.
APPEND t_po_accountx.
CLEAR t_po_accountx.
ENDIF.
APPEND t_po_items.
CLEAR t_po_items.
t_po_itemsx-po_item = l_item.
t_po_itemsx-po_itemx = 'X'.
t_po_itemsx-acctasscat = 'X'.
t_po_itemsx-material = 'X'.
t_po_itemsx-ematerial = 'X'.
t_po_itemsx-plant = 'X'.
t_po_itemsx-quantity = 'X'.
t_po_itemsx-net_price = 'X'.
t_po_itemsx-price_unit = 'X'.
*T_PO_ITEMSX-TAX_CODE = 'X'.
APPEND t_po_itemsx.
CLEAR t_po_itemsx.
Second Line Item
ENDFORM. " APPEND_ITEM
*& Form REFRESH_TABLE
text
--> p1 text
<-- p2 text
FORM refresh_table .
REFRESH : t_po_items, t_po_itemsx.
CLEAR l_item.
ENDFORM. " REFRESH_TABLE
*& Form append_error
text
--> p1 text
<-- p2 text
FORM append_error .
MOVE : sy-datum TO zerror-zdate,
sy-uzeit TO zerror-ztime,
itab+3(5) TO zerror-document_no,
t_return-message TO zerror-message.
lcounter = lcounter + 1.
zerror-counter = lcounter .
zerror-rec_type = itab-line(1).
MODIFY zerror. CLEAR zerror.
COMMIT WORK.
ENDFORM. " append_error
~~Guduri
Mark the helpful answers
NAVEEN KUMAR GUDURI -
hi all,
My BDC program is going to dump while execution. Below I'm pasting the report.
TYPES : BEGIN OF IT_INPUT,
PERNR TYPE PERNR_D,
CHOIC TYPE CHOIC,
BEGDA TYPE CHAR10,
ENDDA TYPE CHAR10,
ANREX TYPE ANREX,
NACHN TYPE NACHN,
VORNA TYPE VORNA,
GBPAS TYPE GBPAS,
SPRSL TYPE SPRSL,
END OF IT_INPUT.
TYPES : BEGIN OF IT_RAW,
LINE TYPE CHAR120,
END OF IT_RAW.
INTERNAL TABLES
DATA : IT_FINAL TYPE STANDARD TABLE OF IT_INPUT.
DATA : IT_RAW TYPE STANDARD TABLE OF IT_RAW.
DATA : IT_ERROR TYPE STANDARD TABLE OF BDCMSGCOLL.
WORK AREA
DATA : WA_FINAL TYPE IT_INPUT.
DATA : WA_RAW TYPE IT_RAW.
DATA : WA_ERROR TYPE BDCMSGCOLL.
CONSTANTS : C_TAB TYPE C value '/'.
INCLUDE : BDCRECXY.
START-OF-SELECTION.
SUBROUTINE TO READ DATA FROM FLAT FILE
PERFORM READ_DATA_FROM_FF.
SUBROUTINE TO MAP DATA TO SCREEN FIELDS
PERFORM DATA_MAPPING.
*& Form READ_DATA_FROM_FF
text
--> p1 text
<-- p2 text
FORM READ_DATA_FROM_FF .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'E:\RAG\BDC1.txt'
TABLES
DATA_TAB = IT_RAW
IF sy-subrc eq 0.
LOOP AT IT_RAW INTO WA_RAW.
SPLIT WA_RAW
AT C_TAB
INTO WA_FINAL-PERNR
WA_FINAL-CHOIC
WA_FINAL-BEGDA
WA_FINAL-ENDDA
WA_FINAL-ANREX
WA_FINAL-NACHN
WA_FINAL-VORNA
WA_FINAL-GBPAS
WA_FINAL-SPRSL.
APPEND WA_FINAL TO IT_FINAL.
WRITE : WA_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. " READ_DATA_FROM_FF
*& Form DATA_MAPPING
text
--> p1 text
<-- p2 text
FORM DATA_MAPPING .
LOOP AT IT_FINAL INTO WA_FINAL.
FIRST SCREEN INFORMATION FOR PA30
perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'RP50G-PERNR'
WA_FINAL-PERNR.
*perform bdc_field using 'BDC_CURSOR'
'T582S-ITEXT(03)'.
perform bdc_field using 'RP50G-SELEC(03)'
'X'.
perform bdc_field using 'RP50G-TIMR6'
'X'.
perform bdc_field using 'RP50G-CHOIC'
'0002'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
SECOND SCREEN INFORMATION 0002
perform bdc_dynpro using 'MP000200' '2001'.
*perform bdc_field using 'BDC_CURSOR'
'Q0002-GBPAS'.
perform bdc_field using 'BDC_OKCODE'
'UPD'.
perform bdc_field using 'P0002-BEGDA'
WA_FINAL-BEGDA.
perform bdc_field using 'P0002-ENDDA'
WA_FINAL-ENDDA.
perform bdc_field using 'Q0002-ANREX'
WA_FINAL-ANREX.
perform bdc_field using 'P0002-NACHN'
WA_FINAL-NACHN.
perform bdc_field using 'P0002-VORNA'
WA_FINAL-VORNA.
perform bdc_field using 'Q0002-GBPAS'
WA_FINAL-GBPAS.
perform bdc_field using 'P0002-SPRSL'
WA_FINAL-SPRSL.
perform bdc_transaction tables it_error using 'PA30' 'x' 'a' 'a'.
IF it_ERROR[] IS NOT INITIAL.
LOOP AT it_ERROR INTO wa_ERROR.
WRITE : wa_ERROR.
ENDLOOP.
REFRESH it_ERROR.
ENDIF.
ENDLOOP.
Error which I was getting is 'UNABLE TO INTERPRET '/ ' AS A NUMBER'.Hi
Look out for the error in the flat file which you are uploading. I have seen this error and I found it in Flat file. its a conversion error.
Just copy few lines from the original file, make a new file and upload it. In this way, you will be able to say whether there is an error in file or in code.
Regards
Waz -
Can we call a bdc program from a report?how
hi
experts can u help me for thisHi
Yes, You can call a BDC program from Report.
see the sample report in which it is used
REPORT zm_reservation_alert
NO STANDARD PAGE HEADING
MESSAGE-ID zm_msg.
D A T A B A S E T A B L E S D E C L A R A T I O N
T Y P E S D E C L A R A T I O N S
Reservations Main Structure
TYPES: BEGIN OF s_res,
rsnum TYPE rsnum, " Reservation No
rspos TYPE rspos, " Item No
usnam TYPE usnam, " User Name
bwart TYPE bwart, " Movement Type
aufnr TYPE aufnr, " Order Number
rsart TYPE rsart, " Record Type
bdart TYPE bdart, " Reservation Type
matnr TYPE matnr, " Material No
bdter TYPE bdter, " Req Date
menge TYPE menge_d, " Quantity
kostl TYPE kostl, " Cost Center
usrid TYPE sysid, " User ID
END OF s_res.
Output Main Structure
TYPES: BEGIN OF s_rep,
usnam TYPE usnam, " User Name
rsnum TYPE rsnum, " Reservation No
rspos TYPE rspos, " Item No
matnr TYPE matnr, " Material No
bdter TYPE bdter, " Req Date
menge TYPE menge_d, " Quantity
kostl TYPE kostl, " Cost Center
aufnr TYPE aufnr, " Order Number
END OF s_rep.
User Dept Details
TYPES: BEGIN OF s_dept,
pernr TYPE persno, " Personal No
usrid TYPE sysid, " User ID
orgeh TYPE orgeh, " Orgn Unit
orgtx TYPE orgtx, " Dept Name
END OF s_dept.
For Send Mail Purpose
DATA : i_doc_data LIKE sodocchgi1.
DATA : BEGIN OF i_pack_list OCCURS 0.
INCLUDE STRUCTURE sopcklsti1.
DATA : END OF i_pack_list.
DATA : BEGIN OF i_receivers OCCURS 0.
INCLUDE STRUCTURE somlreci1.
DATA : END OF i_receivers.
DATA : BEGIN OF i_contents OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA : END OF i_contents.
DATA : BEGIN OF i_header OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA : END OF i_header.
DATA : BEGIN OF i_att OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA : END OF i_att.
Internal table for bdcdata
DATA : it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
Internal table to handle messages
DATA : it_messages LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
D A T A D E C L A R A T I O N S
DATA: gv_lines TYPE sy-index, " Total Lines int Table
gv_days TYPE i, " Difference Days
gv_date TYPE sy-datum, " Date
gv_date1 TYPE sy-datum, " Date
gv_date2 TYPE sy-datum, " Date
gv_text(85), " Text Field
gv_mesg(70), " Error Messages
gv_bdc, " BDC Flag
gv_flag TYPE i, " Flag
gv_ernam TYPE ernam. " User ID
C O N S T A N T S D E C L A R A T I O N S
CONSTANTS: c_x VALUE 'X', " Flag
c_endda TYPE endda VALUE '99991231'. " Date
I N T E R N A L T A B L E S D E C L A R A T I O N S
DATA: i_res TYPE STANDARD TABLE OF s_res WITH HEADER LINE, " Reservns
i_dept TYPE STANDARD TABLE OF s_dept WITH HEADER LINE, " Dept
i_rep TYPE STANDARD TABLE OF s_rep WITH HEADER LINE. " Output
S T A R T - O F - S E L E C T I O N *
START-OF-SELECTION.
Fetch main data
PERFORM fetch_data.
Process data
PERFORM process_data.
*& Form fetch_data
Fetching the Reservations related data from Database Tables
FORM fetch_data .
CLEAR: gv_date, gv_date1, gv_date2.
gv_date = sy-datum.
gv_date1 = sy-datum - 10.
gv_date2 = sy-datum + 10.
CLEAR i_res.
REFRESH i_res.
SELECT a~rsnum " Reservation No.
b~rspos " Reservation Item
a~usnam " User Name
a~bwart " Movement Type
a~aufnr " Order Number
b~rsart " Record Type
b~bdart " Reservation Type
b~matnr " Material No
b~bdter " Req Date
INTO TABLE i_res
FROM rkpf AS a JOIN resb AS b
ON arsnum = brsnum
WHERE ( b~bdter BETWEEN gv_date1 AND gv_date2 ) AND
b~xloek EQ ' '.
SORT i_res BY rsnum rspos.
DELETE ADJACENT DUPLICATES FROM i_res COMPARING matnr.
Add userid into the i_usr int table
LOOP AT i_res.
i_res-usrid = i_res-usnam.
MODIFY i_res INDEX sy-tabix.
ENDLOOP.
IF NOT i_res[] IS INITIAL.
Get the User Dept Name
CLEAR i_dept.
REFRESH i_dept.
SELECT a~pernr " Personal No
a~usrid " User ID
b~orgeh " Orgn Unit
c~orgtx " Dept Name
INTO TABLE i_dept
FROM pa0105 AS a JOIN pa0001 AS b
ON apernr = bpernr JOIN t527x AS c
ON borgeh = corgeh
FOR ALL ENTRIES IN i_res
WHERE a~usrid = i_res-usrid AND
a~endda EQ c_endda AND
b~endda EQ c_endda.
ENDIF.
SORT i_dept BY pernr.
DELETE ADJACENT DUPLICATES FROM i_dept COMPARING pernr.
Move the Creator of Reservation to a diff table
LOOP AT i_res.
MOVE-CORRESPONDING i_res TO i_rep.
APPEND i_rep.
CLEAR i_rep.
ENDLOOP.
SORT i_rep BY usnam rsnum rspos.
ENDFORM. " Fetch_Data
*& Form process_data
Process the Reservations related data for Expiry Date
FORM process_data .
DATA: lv_date1 LIKE sy-datum,
lv_date2 LIKE sy-datum,
lv_date3(10),
lv_menge(13),
lv_tabix LIKE sy-tabix.
LOOP AT i_rep.
CLEAR: gv_days, gv_text, lv_date1, lv_date2,lv_date3.
lv_tabix = sy-tabix.
AT NEW usnam.
Populate the Contents Table
CLEAR i_att.
REFRESH i_att.
i_att = 'Reservations Reminder'(014).
APPEND i_att.
i_att = '----
APPEND i_att.
i_att-line = ' '.
APPEND i_att.
READ TABLE i_dept WITH KEY usrid = i_rep-usnam.
CONCATENATE 'Name:'(003) i_rep-usnam 'Dept:'(015) i_dept-orgtx
INTO i_att-line SEPARATED BY space.
APPEND i_att.
i_att-line = ' '.
APPEND i_att.
i_att = 'Please find the List of expiring Reservations'(004).
APPEND i_att.
i_att-line = ' '.
APPEND i_att.
CONCATENATE '--' '' '--
' INTO
i_att-line SEPARATED BY space.
APPEND i_att.
CONCATENATE 'Reservation #'(006) 'Material #'(007) ' Quantity'(002)
'Due Date'(008) 'Work Center/CC'(005) INTO
i_att-line SEPARATED BY space.
APPEND i_att.
CONCATENATE '--' '' '--
' INTO
i_att-line SEPARATED BY space.
APPEND i_att.
i_att-line = ' '.
APPEND i_att.
ENDAT.
gv_days = i_rep-bdter - gv_date.
lv_date1 = i_rep-bdter + 5.
lv_date2 = i_rep-bdter + 10.
MOVE i_rep-menge TO lv_menge.
WRITE i_rep-bdter TO lv_date3.
IF gv_days = 10.
IF i_rep-aufnr <> space.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-aufnr 'is due for 10 days. Please collect'(009)
INTO gv_text SEPARATED BY space.
ELSE.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-kostl 'is due for 10 days. Please collect'(009)
INTO gv_text SEPARATED BY space.
ENDIF.
i_att-line = gv_text.
APPEND i_att.
CLEAR i_att.
CLEAR gv_text.
ENDIF.
IF gv_days = 5.
IF i_rep-aufnr <> space.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-aufnr 'is due for 5 days. Please collect'(010)
INTO gv_text SEPARATED BY space.
ELSE.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-kostl 'is due for 5 days. Please collect'(010)
INTO gv_text SEPARATED BY space.
ENDIF.
i_att-line = gv_text.
APPEND i_att.
CLEAR i_att.
CLEAR gv_text.
ENDIF.
IF gv_date = lv_date1.
IF i_rep-aufnr <> space.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-aufnr 'is getting cancelled on'(011) lv_date2
INTO gv_text SEPARATED BY space.
ELSE.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-kostl 'is getting cancelled on'(011) lv_date2
INTO gv_text SEPARATED BY space.
ENDIF.
i_att-line = gv_text.
APPEND i_att.
CLEAR i_att.
CLEAR gv_text.
ENDIF.
IF gv_date = lv_date2.
IF i_rep-aufnr <> space.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-aufnr 'is being cancelled'(012)
INTO gv_text SEPARATED BY space.
ELSE.
CONCATENATE i_rep-rsnum i_rep-matnr lv_menge lv_date3
i_rep-kostl 'is being cancelled'(012)
INTO gv_text SEPARATED BY space.
ENDIF.
i_att-line = gv_text.
APPEND i_att.
CLEAR i_att.
CLEAR gv_text.
Mark the Reservation Item 'DELETED' using BDC.
UPDATE resb SET xloek = c_x.
PERFORM delete_item_resb.
ENDIF.
AT END OF usnam.
IF ( gv_days = 10 OR gv_days = 5 OR gv_date = lv_date1 OR
gv_date = lv_date2 ).
Read the User who creates the Reservn and send a mail alert to him
CLEAR : i_receivers,gv_ernam.
REFRESH: i_receivers.
READ TABLE i_rep INDEX lv_tabix.
gv_ernam = i_rep-usnam.
IF gv_ernam <> space.
Send mail Alert to PR Creator(SAP inbox)
PERFORM send_alert_data.
Send Mail to External Mail ID of the SAP USER
PERFORM send_mail_external.
ENDIF.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. " Process_data
*& Form delete_item_resb
Set the Deletion Indicator for the Res. Item in RESB
FORM delete_item_resb.
gv_bdc = 'N'.
Perform to fill it_bdcdata.
PERFORM fill_it_bdcdata.
Call the Transaction MB22
CALL TRANSACTION 'MB22' USING it_bdcdata MODE 'A' UPDATE 'S'
MESSAGES INTO it_messages.
IF sy-subrc <> 0.
gv_flag = 1.
If error occurs in transaction mode run bdc session for that data
PERFORM bdc_process.
ENDIF.
Handles error messages
PERFORM error_messages.
CLEAR : it_bdcdata, it_messages.
REFRESH : it_bdcdata, it_messages.
IF gv_bdc = 'O'.
close bdc if it is open
PERFORM close_bdc.
ENDIF.
ENDFORM. "delete_item_resb
*& Form FILL_IT_BDCDATA
Filling Bdcdata structure with data
FORM fill_it_bdcdata.
PERFORM bdc_dynpro USING 'SAPMM07R' '0560'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RM07M-RSPOS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RM07M-RSNUM'
i_rep-rsnum.
PERFORM bdc_field USING 'RM07M-RSPOS'
i_rep-rspos.
PERFORM bdc_dynpro USING 'SAPMM07R' '0510'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RESB-XLOEK'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RESB-XLOEK'
c_x.
PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.
PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-KOSTL'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.
PERFORM bdc_dynpro USING 'SAPMM07R' '0510'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RESB-ERFMG'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.
PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-KOSTL'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.
ENDFORM. " FILL_IT_BDCDATA
*& Form BDC_DYNPRO
Filling the it_bdcdata table with program name & screen number
FORM bdc_dynpro USING program LIKE bdcdata-program
dynpro LIKE bdcdata-dynpro.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
CLEAR it_bdcdata.
ENDFORM. " BDC_DYNPRO
*& Form BDC_FIELD
Filling it_bdcdata with field name and field value
FORM bdc_field USING fnam LIKE bdcdata-fnam
fval.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
CLEAR it_bdcdata.
ENDFORM. " BDC_FIELD
*& Form ERROR_MESSAGES
Displaying error messages
FORM error_messages.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = sy-msgid
lang = sy-langu
IMPORTING
msg = gv_mesg
EXCEPTIONS
not_found = 1
OTHERS = 2.
LOOP AT it_messages WHERE msgtyp = 'E'.
WRITE : / 'Message :'(001) ,gv_mesg.
CLEAR it_messages.
ENDLOOP.
ENDFORM. " ERROR_MESSAGES
*& Form BDC_PROCESS
Open bdc session if call transaction fails
FORM bdc_process.
IF gv_bdc = 'N'.
open bdc session
PERFORM open_bdc.
gv_bdc = 'O'.
ENDIF.
IF gv_bdc = 'O'.
insert data into bdc session
PERFORM insert_bdc.
ENDIF.
ENDFORM. " BDC_PROCESS
*& Form OPEN_BDC
Calling function module to open bdc session
FORM open_bdc.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'ZMM'
keep = 'X'
user = sy-uname
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.
ENDFORM. " OPEN_BDC
*& Form INSERT_BDC
Insert it_bdcdata into bdc by calling function module bdc_insert
FORM insert_bdc.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'MB22'
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.
ENDFORM. " INSERT_BDC
*& Form CLOSE_BDC
Closing bdc session
FORM close_bdc.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.
ENDFORM. " CLOSE_BDC
*& Form send_alert_data
Send Alert for the Expired Contract
FORM send_alert_data .
CLEAR: gv_lines,i_receivers, i_header, i_contents,i_doc_data.
REFRESH : i_receivers,i_header,i_contents.
DESCRIBE TABLE i_att LINES gv_lines.
i_receivers-receiver = gv_ernam.
i_receivers-receiver = 'SSHEIK'.
i_receivers-rec_type = 'B'.
i_receivers-rec_date = sy-datum.
i_receivers-express = 'X'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
APPEND i_receivers.
i_doc_data-obj_name = 'SAPoffice'(013).
i_doc_data-obj_descr = 'Reservations Reminder'(014).
i_doc_data-obj_langu = 'E'.
i_doc_data-no_change = c_x.
i_doc_data-obj_prio = 1.
i_doc_data-priority = 1.
i_doc_data-doc_size = ( gv_lines - 1 ) * 255 + 135.
i_pack_list-transf_bin = c_x.
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = gv_lines.
i_pack_list-doc_type = 'DOC'.
i_pack_list-obj_name = 'SAPoffice'(013).
i_pack_list-obj_descr = 'Reservations Reminder'(014).
i_pack_list-obj_langu = 'E'.
i_pack_list-doc_size = ( gv_lines - 1 ) * 255 + 135.
APPEND i_pack_list.
i_header-line = 'Header'. APPEND i_header.
Data for contents
i_contents-line = 'Please find the Reservations Due List'(016).
APPEND i_contents.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = i_doc_data
PUT_IN_OUTBOX = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = i_pack_list
object_header = i_header
contents_bin = i_att
contents_txt = i_contents
receivers = i_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc = 0.
MESSAGE i000 WITH 'Mail Sucessfully sent'(017).
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " send_alert_data
*& Form send_mail_external
Send mail to External MAIL ID of the PR Creator
FORM send_mail_external.
DATA : lv_str(24), lv_str1(40),
lv_pernr LIKE adr6-persnumber,
lv_adrnr LIKE adr6-addrnumber,
lv_usrid LIKE pa0105-usrid,
lv_mail LIKE adr6-smtp_addr,
lv_sendor TYPE syuname,
lv_receiver TYPE string,
lv_header TYPE string,
lv_body TYPE string.
CLEAR: lv_pernr, lv_usrid, lv_adrnr,
lv_mail, lv_sendor, lv_receiver,
lv_header, lv_body .
lv_usrid = gv_ernam.
SELECT SINGLE persnumber addrnumber FROM usr21
INTO (lv_pernr,lv_adrnr)
WHERE bname = lv_usrid.
IF sy-subrc = 0.
SELECT SINGLE smtp_addr INTO lv_mail FROM adr6
WHERE addrnumber = lv_adrnr AND
persnumber = lv_pernr.
IF sy-subrc <> 0.
CONCATENATE lv_usrid '@anc.com' INTO lv_mail.
lv_receiver = lv_mail.
ELSE.
lv_receiver = lv_mail.
ENDIF.
lv_receiver = '[email protected]'.
lv_sendor = 'JALKHATAM'.
lv_header = 'Reservations Reminder'(014).
lv_str = 'Pls check your SAP Inbox'(019).
lv_str1 = 'for the status of Reservations Due List'(020).
CONCATENATE lv_str lv_str1 INTO lv_body
SEPARATED BY space.
Call Function Module To send mail
CALL FUNCTION 'UWSP_SEND_MAIL_TO_WEB'
EXPORTING
id_header = lv_header
id_body = lv_body
id_receiver = lv_receiver
id_sender = lv_sendor
ID_HTML_MAIL =
id_commit_work = 'X'
EXCEPTIONS
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.
ENDIF.
ENDFORM. " send_mail_external
<b>Reward points for useful Answers</b>
Regards
Ashu -
XK99 lsmw or BDC program to copy vendors doesn´t update db records
Hello people
I am facing a requirement to copy a list of existing vendors into about 10 new company codes. Vendors all exist in the "main" company code, so I figured it would be a good idea to use the XK99 transaction as a basis for a mass upload via lsmw or bdc program.
So
So I performed a recording and applied my logic in lsmw, ran the batch input folder in SM35, seemingly without errors. But to my srprise I saw that no database records had been created in the LFB1 table.
So I tried to incorporate the recording into a bdc program that uses call transaction, but the same thing happens. The batch input seems to be running OK, but no changes are actually made to db....
So I was wondering what could I be doing wrong? I notice one strange thing though. After carrying out the selections in XK99 manually, one needs to mark columns to be transfered and then push the ´Perform mass update´ button and THEN click save. However, when in recording mode, one may click save directly, and no error is given and the recording ends.
However, the select columns operation, if I try to do it during recording, doesnt seem to get captured....
Any ideas of what I might be doing wrong here?
Regards, Jorgen
T XK99
SAPMMSDL 0200 X
BDC_OKCODE =NEXT
BDC_SUBSCR SAPMMSDL 1000SUBTAB
BDC_CURSOR MASSTABS-TABTXT(02)
MASSTABS-MARK(02) X
SAPLMASS_SEL_DIALOG 0100 X
BDC_OKCODE =NEW
BDC_SUBSCR SAPLMASS_SEL_DIALOG 0200SUB_ALL
BDC_SUBSCR SAPLMASSFREESELECTIONS 1000SUB_SEL
BDC_CURSOR MASSFREESEL-LOW(01)
MASSFREESEL-LOW(01) 300011
SAPLMASS_SEL_DIALOG 0100 X
BDC_OKCODE /00
BDC_SUBSCR SAPLMASS_SEL_DIALOG 0400SUB_ALL
BDC_SUBSCR SAPLMASSFREESELECTIONS 1000SUB_SEL
MASSFREESEL-LOW(01) 300011
MASSFREESEL-LOW(02) 7010
BDC_SUBSCR SAPLMASSFREESELECTIONS 2000SUB_PARA
BDC_CURSOR MASSFREESEL_P-LOW(02)
MASSFREESEL_P-LOW(01) 300011
MASSFREESEL_P-LOW(02) 7000
SAPLMASS_SEL_DIALOG 0100 X
BDC_OKCODE =CRET
BDC_SUBSCR SAPLMASS_SEL_DIALOG 0400SUB_ALL
BDC_SUBSCR SAPLMASSFREESELECTIONS 1000SUB_SEL
BDC_CURSOR MASSFREESEL-LOW(01)
BDC_SUBSCR SAPLMASSFREESELECTIONS 2000SUB_PARA
SAPLMASSINTERFACE 0200 X
BDC_OKCODE =SAVE
BDC_SUBSCR SAPLMASSINTERFACE 0202FIELDS
BDC_SUBSCR SAPLMASSINTERFACE 0210SUB_HEAD
BDC_CURSOR HEADER_STRUC-FIELD2-VALUE-LEFT(01)
BDC_SUBSCR SAPLMASSINTERFACE 0212SUB_DATAHello,
first of all Transaction XK99 is more helpful in case of vendor change, not really creation.
It was also intended to cover mass maintenance so it is used instead of LSMW or any other BDC custom program.
I would say that you can go either with LSMW or CALL TRANSACTION custom program, but you should base your recording on XK/FK01 transactions.
Regards,
Grzegorz -
The BDC program for Transaction COGI not workign -need some alternative
Hi,
We are doing a SAP upgrade from 4.6c to ECC. One of the custom tcodes which were using BDC programming on COGI is now broken.Since , COGI is now changed in Ecc 6.0 with respect to the output which is now inALV and the earlier Date funtionaliy button is no more there in ECC6.0.
We are still not to able to find relevant BAPI/function module/alternative for that matter.Rerecording COGI for new environment is not working since it involves alv call functions, which cannot be recorded in BDC.
Please provide any inputs/valuable suggestions for same.HI
You can try below method.
there is one check box in COGI transaction named List Display. In your BDC recording, default that field value with 'X'.
By activating this, list will be displayed as in earlier versions.
Regards,
Krishna Mohan -
BDC programs affected after system copy.
Dear All,
We are facing a problem after system copy with regards to the HR module.
Client have created a BDC programs and it was running fine in the old server.
After the system refresh, one of the BDC is having problem and following is the brief,
1. While running a user transaction in FOREGROUND, the program is running correctly and in BACKGROUND the program is calling some other action which is not recorded in the BDC. One observation was made that, while running in DEBUG mode, with the background option, the program runs correctly.
2. In program we are calling 2 PA40 actions, whose sequence no. are 28 and 61 resp. In background mode the program calling some other PA40 action whose seq no is 22.
Is there anything we are missing in the profile or some settings in the applications to run the BDC program correctly?
Regards
PrasNo, I haven't run that transaction.
I have checked the old server, and the logical system is PRDCABS500 and the same is present in the new system.
But I am amaze that the other BDC's are working fine, just 1-2 bdc are having problems?
I have checked BD54 in new system its still showing the old..
What do you recommend and when should this activity to be done( I information says that no users should be present?).
Edited by: Prashant Dhas on Jun 13, 2008 7:05 AM
Maybe you are looking for
-
Unable to view songs in Nokia C5 MobilePhone
Hi, I downloaded the Nokia C5 PC-Suite software and connected the nokia C5 to the PC via USB and selected PC-Suite on the mobile. When opened the Memory card, I did not see any folder with name songs. I added new folder with name songs and added few
-
Is the magsafe 85W compatible with my macbook pro from 2006?
I've got a MacBook Pro from 2006 - MacBook Pro 2.2 Intel Core 2 Duo and my magsafe that has worked fine all this time is finally giving up on me. Searching for a replacement have brought me this info from Apple: "If you receive a replacement MagSafe
-
Condition on a Local Structure element-BI7
Hi All, BI7, I have to create a structure with 2 key figures and then build a condition on one of the keyfigures. I have done this but in query designer it gives me a error "condition is created on a structure element which is never visible" Pls sugg
-
Private vpn tunnel from behind NAT
Hello all, Our provider suddenly refuses to give us public ip addresses. Instead we get a private one and the provider does nat. Problem is this site has an IPSEC tunnel towards a public ip address for connectivity to main offices, the tunnel also ru
-
Firefox crashed when I open pages with many pictures
== Issue == Firefox is crashing or closing unexpectedly == Description == If I open websites like bild.de or at last schuheguenstig.net then the browser crashed sometimes, the browser isn't loading the pictures and the the browser close. == Firefox v