Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

bdc

Former Member
0 Likes
1,083

hi friends ,

We use shdb for recording one transaction manually , so if i want to record for 2 transcations manually

how can i do ??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,045

hi friends ,

Thanks for ur answers .

u say it is possible to use two transactions , may i know the use of using two transactions ??

10 REPLIES 10
Read only

Former Member
0 Likes
1,045

Deepti,

multiple transaction is possible using session method.

Have one BDC_OPEN_GROUP, multiple BDC_INSERT s and one BDC_CLOSE_GROUP.

You should have multiple BDC_INSERT s for multiple transactions.

call function BDC_OPENGROUP.

Build BDC data and cal lBDC_INSERT for transaction 1

Build BDC data and cal lBDC_INSERT for transaction 2

Build BDC data and cal lBDC_INSERT for transaction 3

paas the tcodes to bdc_insert.

call function BDC_CLOSE_GROUP.

OR

Check link below:

Don't forget to reward if useful...

Read only

Former Member
0 Likes
1,045

Hi,

Check the sample code to for bdc which is developed for 2 tcodes...............

REPORT zra_gl_cr NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPE-POOLS: truxs.

DATA: it_raw TYPE truxs_t_text_data.

DATA:messtab1 LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA:messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF i_mess OCCURS 0,

l_mstring(480),

msgnr(5),

msgv1(15),

END OF i_mess.

DATA:i_mess1 LIKE i_mess OCCURS 0 WITH HEADER LINE.

DATA: l_mstring(480),l_mstring1(480).

DATA: BEGIN OF it_itab OCCURS 0,

saknr(10), "G/L a/c number.

bukrs(4), "Company Code.

ktoks(4), "G/L a/c group.

xplacct(1), "P&L statement account.

xbilk(1), "Balance sheet account.

txt20_ml(20), "G/L a/c short text.

txt50_ml(50), "G/L a/c long text.

waers(5), "Account currency.

MWSKZ(2),

mitkz(1), "Reconciliation a/c for a/c type.

xopvw(1), "Open item management

xkres(1), "Line item display.

zuawa(3), "Sort Key.

fstag(4), "Field status group.

xintb(1), "Post automatically only.

hbkid(5), "House bank.

hktid(5), "Account id.

vzskz(2), "Interest indicator

END OF it_itab.

DATA: hdate LIKE sy-datum.

************************************************************************

Selection Screen *****

************************************************************************

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 5(15) text-103. " FOR FIELD P_FILE1.

SELECTION-SCREEN POSITION 25.

PARAMETERS : p_file1 LIKE rlgrap-filename.

SELECTION-SCREEN END OF LINE.

************************************************************************

Initialization *****

************************************************************************

INITIALIZATION.

************************************************************************

At Selection Screen *****

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.

Perform file_selection will help to select the location of the file

PERFORM file_selection.

************************************************************************

Start-Of-Selection *****

************************************************************************

START-OF-SELECTION.

Perform data_upload will help to upload the data from the flat file

to the internal table.

PERFORM data_upload.

PERFORM open_group.

Peform bdc_upload will help to upload the data from the internal

table into its respective fields.

PERFORM bdc_fspo.

PERFORM bdc_upload.

PERFORM exp_log.

PERFORM close_group.

Perform display_log will prepare a log for the data that has been

uploaded

PERFORM display_log.

************************************************************************

End-Of-Selection ****

************************************************************************

END-OF-SELECTION.

&----


*& Form file_selection

&----


To select the location of the file

-


FORM file_selection .

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = ' '

def_path = 'C:\'

mask = ',.txt,.xls.'

mode = 'O'

title = 'Open a excel file'

IMPORTING

filename = p_file1

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

ENDFORM. " file_selection

&----


*& Form data_upload

&----


To upload the data from the file location to the internal table.

-


FORM data_upload .

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

I_FIELD_SEPERATOR =

i_line_header = 'X'

i_tab_raw_data = it_raw

i_filename = p_file1

TABLES

i_tab_converted_data = it_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. " data_upload

&----


*& Form bdc_upload

&----


To upload the data from the internal table into its respective fields.

-


FORM bdc_upload .

LOOP AT it_itab.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=ACC_CRE'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_KEY-SAKNR'.

perform bdc_field using 'GLACCOUNT_SCREEN_KEY-SAKNR'

it_itab-SAKNR.

perform bdc_field using 'GLACCOUNT_SCREEN_KEY-BUKRS'

it_itab-BUKRS.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=2102_GROUP'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-KTOKS'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-KTOKS.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-XPLACCT'

it_itab-XPLACCT.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=2102_BS_PL'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-XBILK'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-KTOKS.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-XPLACCT'

it_itab-XPLACCT.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-XBILK'

it_itab-XBILK.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=ENTER'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-KTOKS.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-XBILK'

it_itab-XBILK.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT20_ML'

it_itab-TXT20_ML.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT50_ML'

it_itab-TXT50_ML.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-BILKT'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-BILKT'

it_itab-saknr.

PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=TAB02'.

PERFORM bdc_field USING 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-KTOKS'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-ktoks.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'

it_itab-txt20_ml.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'

it_itab-txt50_ml.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-BILKT'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-BILKT'

it_itab-saknr.

****

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=TAB02'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-KTOKS'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-KTOKS.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-KTOKS'.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-KTOKS.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-XBILK'

it_itab-XBILK.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT20_ML'

it_itab-TXT20_ML.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT50_ML'

it_itab-TXT50_ML.

perform bdc_field using 'GLACCOUNT_SCREEN_COA-BILKT'

it_itab-saknr.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=ENTER'.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-WAERS'

it_itab-waers.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-MWSKZ'

it_itab-MWSKZ.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-MITKZ'

it_itab-mitkz.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_CCODE-XOPVW'.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-XOPVW'

it_itab-XOPVW.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-XKRES'

it_itab-XKRES.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-ZUAWA'

it_itab-ZUAWA.

*******************

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-XPLACCT'

it_itab-xplacct.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-XBILK'

it_itab-xbilk.

IF it_itab-xbilk = 'X'.

*

PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=TAB03'.

PERFORM bdc_field USING 'BDC_CURSOR'

'GLACCOUNT_SCREEN_CCODE-WAERS'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-WAERS'

it_itab-waers.

*

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XOPVW'

it_itab-xopvw.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MITKZ'

it_itab-mitkz.

ENDIF.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XKRES'

it_itab-xkres.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-ZUAWA'

it_itab-zuawa.

*

PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

*

PERFORM bdc_field USING 'BDC_OKCODE'

'=SAVE'.

PERFORM bdc_field USING 'BDC_CURSOR'

'GLACCOUNT_SCREEN_CCODE-FSTAG'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-FSTAG'

it_itab-fstag.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XINTB'

it_itab-xintb.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-HBKID'

it_itab-hbkid.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-HKTID'

it_itab-hktid.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-VZSKZ'

it_itab-vzskz.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=TAB03'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_CCODE-WAERS'.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-WAERS'

it_itab-WAERS.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-MWSKZ'

it_itab-MWSKZ.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-MITKZ'

it_itab-MITKZ.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-ZUAWA'

it_itab-ZUAWA.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=ENTER'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_CCODE-FSTAG'.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-FSTAG'

it_itab-FSTAG.

perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'BDC_CURSOR'

'GLACCOUNT_SCREEN_CCODE-FSTAG'.

perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-FSTAG'

it_itab-FSTAG.

PERFORM bdc_transaction USING 'FS00'.

CALL TRANSACTION 'FS00' USING bdcdata MODE 'A'

UPDATE 'S'

MESSAGES INTO messtab1.

PERFORM mess1.

REFRESH bdcdata[].

ENDLOOP.

ENDFORM. " bdc_upload

&----


*& Form bdc_fspo

&----


text

-


FORM bdc_fspo .

LOOP AT it_itab.

PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ACC_CRE'.

PERFORM bdc_field USING 'BDC_CURSOR'

'GLACCOUNT_SCREEN_KEY-SAKNR'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-SAKNR'

it_itab-saknr.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-KTOPL'

'1000'.

PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=2102_GROUP'.

PERFORM bdc_field USING 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-KTOKS'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-ktoks.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-XPLACCT'

it_itab-xplacct.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-XBILK'

it_itab-xbilk.

PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SAVE'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'

it_itab-ktoks.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-XPLACCT'

it_itab-xplacct.

PERFORM bdc_field USING 'BDC_CURSOR'

'GLACCOUNT_SCREEN_COA-TXT50_ML'.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'

it_itab-txt20_ml.

PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'

it_itab-txt50_ml.

*perform bdc_transaction using 'FSP0'.

CALL TRANSACTION 'FSP0' USING bdcdata MODE 'A'

UPDATE 'S'

MESSAGES INTO messtab.

PERFORM mess.

REFRESH bdcdata[].

ENDLOOP.

ENDFORM. " bdc_fspo

&----


*& Form mess

&----


text

-


--> p1 text

<-- p2 text

-


FORM mess . "fsp0

LOOP AT messtab.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = messtab-msgid

lang = messtab-msgspra

no = messtab-msgnr

v1 = messtab-msgv1

v2 = messtab-msgv2

v3 = messtab-msgv3

v4 = messtab-msgv4

IMPORTING

msg = l_mstring

EXCEPTIONS

not_found = 1

OTHERS = 2.

CONDENSE l_mstring.

i_mess1-l_mstring = l_mstring(250).

i_mess1-msgnr = messtab1-msgnr.

i_mess1-msgv1 = messtab1-msgv1.

APPEND i_mess1.

ENDLOOP.

ENDFORM. " mess

&----


*& Form mess1

&----


text

-


--> p1 text

<-- p2 text

-


FORM mess1 . "fs00

LOOP AT messtab1.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = messtab1-msgid

lang = messtab1-msgspra

no = messtab1-msgnr

v1 = messtab1-msgv1

v2 = messtab1-msgv2

v3 = messtab1-msgv3

v4 = messtab1-msgv4

IMPORTING

msg = l_mstring1

EXCEPTIONS

not_found = 1

OTHERS = 2.

CONDENSE l_mstring1.

i_mess-l_mstring = l_mstring1(250).

i_mess-msgnr = messtab1-msgnr.

i_mess-msgv1 = messtab1-msgv1.

APPEND i_mess.

ENDLOOP.

ENDFORM. " mess1

&----


*& Form exp_log

&----


text

-


--> p1 text

<-- p2 text

-


FORM exp_log .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\temp\error_fsp0.txt'

filetype = 'DAT'

TABLES

data_tab = i_mess1.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\temp\error_fs00.txt'

filetype = 'DAT'

TABLES

data_tab = i_mess.

ENDFORM. " exp_log

&----


*& Form bdc_dynpro

&----


text

-


-->PROGRAM text

-->DYNPRO text

-


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

-


Insert field *

-


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "BDC_Field

Read only

0 Likes
1,045

hi friends ,

Thanks for ur answers .

u say it is possible to use two transactions , may i know the use of using two transactions ??

Read only

0 Likes
1,045

Hii .

I am Sachin .

How can create sales order through bdc.

Please give me the solutions

Read only

Former Member
0 Likes
1,046

hi friends ,

Thanks for ur answers .

u say it is possible to use two transactions , may i know the use of using two transactions ??

Read only

0 Likes
1,045

Good question Deepti,

Lemme explain u a simple scenario... let us suppose u got one requirement to do the material determination.. generally you have to use VB11 tcode to create the material determination...

but ur client gave you the requirement to maintain the material determination... ie if you get a new record in the file you have to create the matrial determination through VB11, or the record which you got in the file already exists in the data base... then you have to change the date range for that corresponding material combination through VB12...

in this case,.. u have to record both the tcodes... you have to write the logic accordingly so that based on the condition u have to do the specific operation....

I think you got my point....

Read only

0 Likes
1,045

thank you

Read only

Former Member
0 Likes
1,045

How can i transfer excel data file through bdc or lsmw

Read only

0 Likes
1,045

hi ,

We use function module ALSM_EXCEL_TO_INTERNAL_TABLE to read the data from

excel file into ABAP internal table

REPORT ztbpp102.

  • ------------------- Start of Data Declaration -----------------------*

  • Constants

CONSTANTS: c_begcol TYPE i VALUE 1,

c_begrow TYPE i VALUE 1,

c_endcol TYPE i VALUE 100,

c_endrow TYPE i VALUE 32000,

c_x(1) TYPE c VALUE 'X'.

DATA : w_field(30),

  • Flag for data check status

w_invalid_data(1) TYPE c.

FIELD-SYMBOLS : <fs> TYPE ANY.

  • Internal Tables

  • The prefix 000n is becuase the colmn in alsmex_tabline isof data

  • type n withg length 4

TYPES: BEGIN OF ty_tab,

cell_0001 TYPE alsmex_tabline-value, "Plant

cell_0002 TYPE alsmex_tabline-value, "Material No

cell_0003 TYPE alsmex_tabline-value, "Order Start Date

cell_0004 TYPE alsmex_tabline-value, "Order finish Date

cell_0005 TYPE alsmex_tabline-value, "Quantity

cell_0006 TYPE alsmex_tabline-value, "Quantity unit DV1K905068

END OF ty_tab.

TYPES: BEGIN OF ty_error,

line TYPE string,

END OF ty_error.

TYPES: BEGIN OF ty_mara,

matnr TYPE mara-matnr,

END OF ty_mara.

TYPES: BEGIN OF ty_t001w,

werks TYPE t001w-werks,

END OF ty_t001w.

DATA: it_upload_data LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE,

it_tab TYPE STANDARD TABLE OF ty_tab,

wa_tab TYPE ty_tab,

  • Internal table for BDC

it_bdcdata TYPE STANDARD TABLE OF bdcdata,

*work area

wa_bdcdata TYPE bdcdata,

  • Internal table to store error

it_error TYPE STANDARD TABLE OF ty_error,

wa_error TYPE ty_error,

it_mara TYPE STANDARD TABLE OF ty_mara,

wa_mara TYPE ty_mara,

it_t001w TYPE STANDARD TABLE OF ty_t001w,

wa_t001w TYPE ty_t001w.

  • ------------------- End of Data Declaration -----------------------*

----


Start of Selection Screen -

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_file LIKE rlgrap-filename MEMORY ID m02,

p_sesson TYPE apqi-groupid DEFAULT 'DMND_UPLOAD'.

SELECTION-SCREEN: END OF BLOCK b1.

----


End of Selection Screen -

  • Event INITIALIZATION

INITIALIZATION.

CLEAR: w_invalid_data, w_field.

REFRESH: it_upload_data, it_tab, it_error, it_bdcdata, it_mara,

it_t001w.

----


Start of at selection-screen -

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Show the file selection dialog box

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

mask = '(.xls)|.xls|(.)|.' "For excel

static = 'X'

CHANGING

file_name = p_file

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

----


End of at Selection-screen -

  • START-OF-SELECTION

START-OF-SELECTION.

  • Upload the excel data into the program

PERFORM upload_file.

  • Populate data in internal table it_tab from excel upload data

PERFORM populate_it_tab_from_excel.

  • Check the mandatory fields

PERFORM check_data.

  • When the dataset is valid proceed

IF w_invalid_data IS INITIAL.

  • Open the BDC session

PERFORM open_group.

  • Populate BDC table

PERFORM populate_bdc_session.

  • Close the BDC session

PERFORM close_group.

WRITE:/ 'Batch input session '(m01), p_sesson, ' created

successfully'(m02).

WRITE:/ 'Please process the session using transaction SM35'(m03).

ELSE.

WRITE:/ 'Error in Input Data :'(m04).

SKIP 1.

LOOP AT it_error INTO wa_error.

WRITE:/ wa_error-line.

ENDLOOP.

SKIP 1.

WRITE: 'Please correct error and try to upload again'(m05).

ENDIF.

&----


*& Form UPLOAD_FILE

&----


  • Upload the data from the excel file into ABAP internal table

----


FORM upload_file .

  • Upload the excel file in ABAP internal table

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = c_begcol

i_begin_row = c_begrow

i_end_col = c_endcol

i_end_row = c_endrow

TABLES

intern = it_upload_data

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE i999(zttl) WITH 'Error in uploading the file!'(m06).

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " UPLOAD_FILE

&----


*& Form populate_it_tab_from_excel

&----


  • Populate data in internal table it_tab from excel upload data

----


FORM populate_it_tab_from_excel .

DATA: l_col_no TYPE alsmex_tabline-col.

  • Internal table it_upload_data store data in cellwise

  • with row, colmn and value

  • Change this data to a row-wise data and populate the table it_tab

SORT it_upload_data BY row col.

  • Delete the entries with row 0001 as those row has the colmn headings

DELETE it_upload_data WHERE row = '0001'.

  • Convert the excel data to row-wise data

LOOP AT it_upload_data.

l_col_no = it_upload_data-col.

CONCATENATE 'WA_TAB-cell_' l_col_no INTO w_field.

ASSIGN (w_field) TO <fs>.

IF sy-subrc = 0.

<fs> = it_upload_data-value.

ENDIF.

AT END OF row.

APPEND wa_tab TO it_tab.

CLEAR wa_tab.

ENDAT.

ENDLOOP.

IF it_tab[] IS INITIAL.

MESSAGE i999(zttl) WITH 'No record to upload!'(m07).

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " populate_it_tab_from_excel

&----


*& Form check_data

&----


  • Do data validation

----


FORM check_data .

DATA: l_error TYPE string,

l_line_no(4) TYPE c,

l_it_tab_temp TYPE STANDARD TABLE OF ty_tab,

l_it_mara TYPE STANDARD TABLE OF ty_mara,

l_it_t001w TYPE STANDARD TABLE OF ty_t001w,

l_gsmng TYPE plaf-gsmng,

l_matnr TYPE plaf-matnr.

  • Select plant data from T001w

  • Cell_0001 is for plant

IF NOT it_tab[] IS INITIAL.

REFRESH l_it_tab_temp.

l_it_tab_temp[] = it_tab[].

SORT l_it_tab_temp BY cell_0001.

DELETE ADJACENT DUPLICATES FROM l_it_tab_temp COMPARING cell_0001.

LOOP AT l_it_tab_temp INTO wa_tab.

wa_t001w-werks = wa_tab-cell_0001.

TRANSLATE wa_t001w-werks TO UPPER CASE. "#EC TRANSLANG

APPEND wa_t001w TO l_it_t001w.

ENDLOOP.

IF NOT l_it_t001w[] IS INITIAL.

SELECT werks

FROM t001w

INTO TABLE it_t001w

FOR ALL ENTRIES IN l_it_t001w

WHERE werks = l_it_t001w-werks.

IF sy-subrc = 0.

SORT it_t001w BY werks.

ENDIF.

ENDIF.

ENDIF.

*Select data from Material master

IF NOT it_tab[] IS INITIAL.

REFRESH l_it_tab_temp.

l_it_tab_temp[] = it_tab[].

  • Cell 0002 is for material no

SORT l_it_tab_temp BY cell_0002.

DELETE ADJACENT DUPLICATES FROM l_it_tab_temp COMPARING cell_0002.

LOOP AT l_it_tab_temp INTO wa_tab.

  • call a conversion exit

CLEAR l_matnr.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'

EXPORTING

input = wa_tab-cell_0002

IMPORTING

output = l_matnr.

TRANSLATE l_matnr TO UPPER CASE. "#EC TRANSLANG

wa_mara-matnr = l_matnr.

APPEND wa_mara TO l_it_mara.

ENDLOOP.

IF NOT l_it_mara[] IS INITIAL.

SELECT matnr

FROM mara

INTO TABLE it_mara

FOR ALL ENTRIES IN l_it_mara

WHERE matnr = l_it_mara-matnr.

IF sy-subrc = 0.

SORT it_mara BY matnr.

ENDIF.

ENDIF.

ENDIF.

*Check on mandatory field

LOOP AT it_tab INTO wa_tab.

l_line_no = sy-tabix.

  • Increase the line no by 1 as the first row (have the heading)

  • is not considered

l_line_no = l_line_no + 1.

  • Check for plant (cell_0001)

IF wa_tab-cell_0001 IS INITIAL.

CLEAR: l_error, wa_error.

CONCATENATE text-m08 l_line_no ': Plant is mandatory'(m13)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ELSE.

  • Check for valid plant

CLEAR wa_t001w.

TRANSLATE wa_tab-cell_0001 TO UPPER CASE. "#EC TRANSLANG

READ TABLE it_t001w INTO wa_t001w WITH KEY werks = wa_tab-cell_0001

BINARY SEARCH.

IF sy-subrc <> 0.

CLEAR: l_error, wa_error.

CONCATENATE text-m08 l_line_no ': Invalid plant '(m14)

wa_tab-cell_0001

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ENDIF.

ENDIF.

  • Check for material number (Cell_0002)

IF wa_tab-cell_0002 IS INITIAL.

CLEAR: l_error, wa_error.

CONCATENATE 'Line'(m08) l_line_no ': Material no is mandatory'(m11)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ELSE.

  • Check for valid material

CLEAR wa_mara.

TRANSLATE wa_tab-cell_0002 TO UPPER CASE. "#EC TRANSLANG

READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_tab-cell_0002

BINARY SEARCH.

IF sy-subrc <> 0.

CLEAR: l_error, wa_error.

CONCATENATE text-m08 l_line_no ': Invalid Material no'(m12)

wa_tab-cell_0002

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ENDIF.

ENDIF.

  • Check for quantity (cell_0005)

IF wa_tab-cell_0005 IS INITIAL.

CLEAR: l_error, wa_error.

CONCATENATE text-m08 l_line_no ': Order quantity is mandatory'(m21)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ELSE.

  • Check that quantity is a number

CLEAR: l_gsmng.

CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.

l_gsmng = wa_tab-cell_0005.

IF l_gsmng = 0.

CLEAR: l_error, wa_error.

CONCATENATE 'Line'(m08) l_line_no ': Quantity cannot be zero'(m22)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ENDIF.

ENDCATCH.

  • If there is a conversion error

IF sy-subrc = 1.

CLEAR: l_error, wa_error.

CONCATENATE 'Line'(m08) l_line_no ': Quantity'(m23)

wa_tab-cell_0005 'is not a number'(m24)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ENDIF.

ENDIF.

  • Start of insert DV1K905068

IF wa_tab-cell_0006 IS INITIAL.

CLEAR: l_error, wa_error.

CONCATENATE text-m08 l_line_no ': Quantity unit is mandatory'(m25)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ENDIF.

  • End of insert DV1K905068

  • Order finish date is mandatory (Cell_0004)

IF wa_tab-cell_0004 IS INITIAL.

CLEAR: l_error, wa_error.

CONCATENATE text-m08 l_line_no ': Order finish date is mandatory'(m15)

INTO l_error SEPARATED BY space.

wa_error-line = l_error.

APPEND wa_error TO it_error.

w_invalid_data = c_x.

ENDIF.

ENDLOOP.

ENDFORM. " check_data

&----


*& Form open_group

&----


  • Open the BDC session

----


FORM open_group .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_sesson

keep = c_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.

IF sy-subrc <> 0.

MESSAGE i999(zttl) WITH 'Error in creating session'(m16).

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " open_group

&----


*& Form close_group

&----


  • Close the BDC session

----


FORM close_group .

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE i999(zttl) WITH 'Error in closing session'(m17).

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " close_group

&----


*& Form populate_bdc_session

&----


  • Populate the BDC table

----


FORM populate_bdc_session .

DATA: l_gsmng TYPE plaf-gsmng, "DV1K905068

l_meins_in TYPE mara-meins, "DV1K905068

l_matnr TYPE mara-matnr, "DV1K905068

l_string_gsmng TYPE string. "DV1K905068

LOOP AT it_tab INTO wa_tab.

REFRESH it_bdcdata.

CLEAR: wa_bdcdata.

  • First screen of transaction MD111

PERFORM bdc_dynpro USING 'SAPMM61P' '0100'.

  • Data fiels in screen 0100

PERFORM bdc_field USING 'BDC_CURSOR' 'RM61P-PASCH'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

  • Planned order profile is always LA

PERFORM bdc_field USING 'RM61P-PASCH' 'LA'.

  • Screen 2

PERFORM bdc_dynpro USING 'SAPLM61O' '0110'.

  • Data fiels in screen 0110

  • Start of change DV1K904978

  • PERFORM bdc_field USING 'BDC_OKCODE' '=TERM'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

  • End of change DV1K904978

  • Material no

PERFORM bdc_field USING 'PLAF-MATNR' wa_tab-cell_0002.

  • Plant

PERFORM bdc_field USING 'PLAF-PLWRK' wa_tab-cell_0001.

PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLM61O

0711INCLUDE1XX'.

PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLM61O

0802INCLUDE711_1'.

PERFORM bdc_field USING 'BDC_CURSOR' 'PLAF-PEDTR'.

  • Strat of change DV1K905068

  • Do a material unit conversion from given unit to kg

  • Use local variable as the fn module needs variable of

  • type meins

CLEAR: l_meins_in, l_matnr, l_gsmng, l_string_gsmng .

l_meins_in = wa_tab-cell_0006.

l_matnr = wa_tab-cell_0002.

  • Convert unit text to upper case

TRANSLATE l_matnr TO UPPER CASE. "#EC TRANSLANG

TRANSLATE l_meins_in TO UPPER CASE. "#EC TRANSLANG

  • Conversion exit on unit

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

EXPORTING

input = l_meins_in

language = sy-langu

IMPORTING

output = l_meins_in

EXCEPTIONS

unit_not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

WRITE:/ 'Unit not maintained ', l_meins_in.

CONTINUE.

ENDIF.

  • Converting the amount

CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.

l_gsmng = wa_tab-cell_0005.

ENDCATCH.

IF sy-subrc <> 0.

WRITE:/ 'Quantity is not in proper format ', wa_tab-cell_0005.

CONTINUE.

ENDIF.

CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'

EXPORTING

i_matnr = l_matnr

i_in_me = l_meins_in

i_out_me = 'KG'

i_menge = l_gsmng

IMPORTING

e_menge = l_gsmng

EXCEPTIONS

error_in_application = 1

error = 2

OTHERS = 3.

IF sy-subrc <> 0.

WRITE:/ 'Material Unit conversion not maintained for ',

wa_tab-cell_0002.

CONTINUE.

ELSE.

  • Assign to straig type variable as gsmng is packed and cannot be appended

  • directly to the BDC session

l_string_gsmng = l_gsmng.

ENDIF.

  • Quantity

  • PERFORM bdc_field USING 'PLAF-GSMNG' wa_tab-cell_0005.

PERFORM bdc_field USING 'PLAF-GSMNG' l_string_gsmng.

  • End of change DV1K905068

  • Order finish date

PERFORM bdc_field USING 'PLAF-PEDTR' wa_tab-cell_0004.

  • Order start date

PERFORM bdc_field USING 'PLAF-PSTTR' wa_tab-cell_0003.

PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLM61O

0810INCLUDE711_2'.

  • Screen 3

PERFORM bdc_dynpro USING 'SAPLM61O' '0110'.

  • Data fiels in screen 0110

PERFORM bdc_field USING 'BDC_CURSOR' 'PLAF-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE' 'HZPL'.

PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLM61O

0715INCLUDE1XX'.

*Transfer data to batch input by transaction

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'MD11'

TABLES

dynprotab = it_bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE i999(zttl) WITH 'Error in creating session'(m20).

LEAVE LIST-PROCESSING.

ENDIF.

ENDLOOP.

ENDFORM. " populate_bdc_session

&----


*& Form bdc_dynpro

&----


  • Populate the dynpros

----


  • -->P_pogram Progran name

  • -->P_dynpro Screen no

----


FORM bdc_dynpro USING p_program TYPE bdc_prog

p_dynpro TYPE bdc_dynr.

CLEAR wa_bdcdata.

wa_bdcdata-program = p_program.

wa_bdcdata-dynpro = p_dynpro.

wa_bdcdata-dynbegin = c_x.

APPEND wa_bdcdata TO it_bdcdata.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_fnam Field name

  • -->P_fval Field value

----


FORM bdc_field USING p_fnam TYPE fnam_____4

p_fval.

CLEAR wa_bdcdata.

wa_bdcdata-fnam = p_fnam.

wa_bdcdata-fval = p_fval.

APPEND wa_bdcdata TO it_bdcdata.

ENDFORM. " bdc_field

Read only

0 Likes
1,045

hi sachin ,

just check this link for lsmw

http://www.slideshare.net/arun_bala1/sap-sd-lsmw-legacy-system-migration-workbench/

reward points if useful ......

thanks