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
713

hi expects ,

i want to upload the item data and header data which is in excel sheet , both at a time . whether it is possible?

7 REPLIES 7
Read only

Former Member
0 Likes
675

Hi Rohit,

Guess its possible if you have the data in 2 sheets of the excel. There are FM's which can be used to read the data from multiple sheets into two different internal table.

Cheers

VJ

Read only

Former Member
0 Likes
675

Hi,

Yes, you can do it both at a time.

For Po' SO' Pur requestions we upload the Header and Item data together.

See the sample code.

REPORT zmm_pr_upload_mat

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Standard Include for Selection Screen

INCLUDE bdcrecx1.

  • Internal Table for Upload Data

DATA: BEGIN OF i_pr OCCURS 0,

  • Header Screen

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

  • lpein(001), " Category of Del Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

  • Item Details

matnr(018), " Material No

menge(017), " Quantity

  • badat(010),

  • frgdt(010),

preis(014), " Valuation Price

  • waers(005), " Currency

  • peinh(005),

  • wepos(001),

  • repos(001),

sakto(010), " GL Account

kostl(010), " Cost Center

  • bnfpo(005),

END OF i_pr.

  • Internal Table for header Data

DATA: BEGIN OF it_header OCCURS 0,

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

END OF it_header.

  • Internal Table for Item Data

DATA: BEGIN OF it_item OCCURS 0,

sno(3), " SNo

matnr(018), " Material No

menge(017), " Quantity

preis(014), " Valuation Price

sakto(010), " GL Account

kostl(010), " Cost Center

END OF it_item.

  • Data Variables & Constants

CONSTANTS : c_x VALUE 'X'. " Flag

DATA : v_l(2), " Counter

v_rowno(5), " Row No

v_2(2), " Counter

v_rows LIKE sy-srows, " Rows in TC

v_field(45). " String

  • Parameters

PARAMETERS: p_file LIKE ibipparms-path. " Filename

  • At selection-screen on Value Request for file Name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get the F4 Values for the File

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

  • Start of Selection

START-OF-SELECTION.

  • Open the BDC Session

PERFORM open_group.

  • Upload the File into internal Table

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_pr

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SORT i_pr BY sno.

LOOP AT i_pr.

MOVE-CORRESPONDING i_pr TO it_item.

APPEND it_item.

CLEAR it_item.

AT END OF sno.

READ TABLE i_pr INDEX sy-tabix.

MOVE-CORRESPONDING i_pr TO it_header.

APPEND it_header.

CLEAR it_header.

ENDAT.

ENDLOOP.

SORT it_header BY sno.

SORT it_item BY sno.

v_rows = sy-srows - 6.

  • Upload the Data from Internal Table

LOOP AT it_header.

  • Header Data

PERFORM bdc_dynpro USING 'SAPMM06B' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-BEDNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-BSART'

it_header-bsart.

PERFORM bdc_field USING 'RM06B-EPSTP'

it_header-epstp.

PERFORM bdc_field USING 'EBAN-KNTTP'

it_header-knttp.

PERFORM bdc_field USING 'RM06B-EEIND'

it_header-eeind.

  • PERFORM bdc_field USING 'RM06B-LPEIN'

  • it_header-lpein.

PERFORM bdc_field USING 'EBAN-WERKS'

it_header-werks.

PERFORM bdc_field USING 'EBAN-LGORT'

it_header-lgort.

PERFORM bdc_field USING 'EBAN-EKGRP'

it_header-ekgrp.

PERFORM bdc_field USING 'EBAN-MATKL'

it_header-matkl.

PERFORM bdc_field USING 'EBAN-BEDNR'

it_header-bednr.

PERFORM bdc_field USING 'EBAN-AFNAM'

it_header-afnam.

  • Item Details

v_l = 0.

  • To add no. of rows

v_2 = 0 .

  • As the screen is showing 13 rows defaulted to 130

v_rowno = 130 .

LOOP AT it_item WHERE sno = it_header-sno.

v_l = v_l + 1.

IF v_l = 14 .

IF v_2 = 12 .

v_2 = 12 .

v_l = 2 .

  • From second time onwards it is displaying 12 rows only

v_rowno = v_rowno + 120 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ELSE.

  • V_2 initialized to 12 for second screen purpose

v_2 = 12 .

v_l = 2 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno .

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ENDIF.

ENDIF.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

CLEAR v_field.

CONCATENATE 'EBAN-MATNR(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-matnr.

CLEAR v_field.

CONCATENATE 'EBAN-MENGE(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-menge.

PERFORM bdc_dynpro USING 'SAPMM06B' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-PREIS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-PREIS'

it_item-preis.

PERFORM bdc_dynpro USING 'SAPMM06B' '0505'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBKN-SAKTO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'EBKN-SAKTO'

it_item-sakto.

  • Cost Center

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'COBL-KOSTL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'COBL-KOSTL'

it_item-kostl.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

  • Call The Transaction

PERFORM bdc_transaction USING 'ME51'.

ENDLOOP.

  • Close the BDC Session

PERFORM close_group.

Regards,

anji

Read only

Former Member
0 Likes
675

Hi,

Regards

Bala

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
675

Hi

refer the link:

Regards,

kumar

Read only

Former Member
0 Likes
675

HI,

pls go through this code,

SELECTION-SCREEN BEGIN OF BLOCK error_options WITH FRAME TITLE text-003.

PARAMETERS : p_file LIKE rlgrap-filename DEFAULT

'C:\BDC_file_INSP_PLAN.txt'.

SELECTION-SCREEN END OF BLOCK error_options.

INCLUDE bdcrecx1.

  • Data Declarations

CONSTANTS: c_grp(11) VALUE 'MAPL-PLNAL(',

c_mat(11) VALUE 'MAPL-MATNR(',

c_wrk(11) VALUE 'MAPL-WERKS(',

c_brace VALUE ')'.

DATA: ctr(2) TYPE n,

fld_matnr(16),

fld_group(16),

fld_werks(16).

DATA: w_lines(5) TYPE c.

data: n(2).

data: prev_group(8).

  • Internal Tables

DATA : BEGIN OF itab_file OCCURS 0,

group(8), "Group Number

grp_cntr(2), "Group Counter

Material(18), "Material

Plant(4), "Plant

END OF itab_file.

data: begin of igroup occurs 0,

group(8),

end of igroup.

  • At selection screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*CALL FUNCTION 'TMP_GUI_BROWSE_FOR_FOLDER'

  • EXPORTING

  • window_title = 'Select destination folder'(f01)

  • initial_folder = 'C:\'

  • IMPORTING

  • selected_folder = p_file

  • EXCEPTIONS

  • cntl_error = 1

  • OTHERS = 2.

  • This function module will help select the file for upload using "F4"

  • functionality

CALL FUNCTION '/SAPDMC/LSM_F4_FRONTEND_FILE'

EXPORTING

PATHNAME = 'C:\'

CHANGING

PATHFILE = P_FILE

EXCEPTIONS

CANCELED_BY_USER = 1

SYSTEM_ERROR = 2

OTHERS = 3.

  • Start of Selection

START-OF-SELECTION.

n = '01' .

PERFORM load_file USING p_file.

PERFORM open_group.

sort itab_file by group.

sort igroup by group.

  • loop at itab_file

loop at igroup.

perform build_screens.

endloop.

  • PERFORM close_group.

&----


*& Form LOAD_FILE

&----


  • Upload Data file

----


FORM load_file USING p_file.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = itab_file

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 NE 0.

WRITE:/ text-001.

STOP.

ENDIF.

DESCRIBE TABLE itab_file LINES w_lines.

CLEAR itab_file.

sort itab_file by group.

loop at itab_file.

at new group.

igroup-group = itab_file-group.

append igroup.

clear igroup.

endat.

endloop.

delete igroup[] where group = space.

ENDFORM. " LOAD_FILE

&----


*& Form BUILD_SCREENS

&----


  • Build QP02 Screens

----


FORM BUILD_SCREENS.

perform bdc_dynpro using 'SAPLCPDI' '8010'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC27M-WERKS'

space.

perform bdc_field using 'RC271-PLNNR'

igroup-group.

perform bdc_dynpro using 'SAPLCPDI' '1400'.

perform bdc_field using 'BDC_OKCODE'

'=MTUE'.

perform bdc_field using 'RC27X-FLG_SEL(01)'

'X'.

perform bdc_dynpro using 'SAPLCZDI' '4010'.

perform bdc_field using 'BDC_OKCODE'

'=BACK'.

CLEAR ctr.

LOOP AT itab_file WHERE group EQ igroup-group.

ADD 1 TO ctr.

CONCATENATE c_grp ctr c_brace INTO fld_group.

CONCATENATE c_mat ctr c_brace INTO fld_matnr.

CONCATENATE c_wrk ctr c_brace INTO fld_werks.

perform bdc_field using fld_group

'1'.

perform bdc_field using fld_matnr

itab_file-material.

perform bdc_field using fld_werks

itab_file-plant.

endloop.

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

  • perform bdc_field using 'MAPL-PLNAL(n)'

  • '1'.

**perform bdc_field using 'MAPL-PLNAL(02)'

    • '1'.

  • perform bdc_field using 'MAPL-MATNR(n)'

  • itab_file-material.

**perform bdc_field using 'MAPL-MATNR(02)'

    • itab_file-material.

  • perform bdc_field using 'MAPL-WERKS(n)'

  • itab_file-plant.

**perform bdc_field using 'MAPL-WERKS(02)'

    • itab_file-plant.

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

perform bdc_dynpro using 'SAPLCPDI' '1400'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_transaction using 'QP02'.

  • call transaction 'QP02' using bdcdata

  • mode 'A'.

prev_group = itab_file-group.

ENDFORM. " BUILD_SCREENS

____________________________________

For eg.. Header data vbeln

Item data posnr.

1 header data will have more item data.

Check this link for bdc in table control.

http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm

_______________________

Try this link .

http://www.sap-img.com/abap/upload-the-pricing-condtion-records-for-materials.htm

PLS:

AWARD POINTS

SRI

Read only

Former Member
0 Likes
675

Yes it is possible..

maintain the 1st record of header data in the file as the first line with some prefix identifier..

Below this write the item data with item structure and with a prefix identifier different from the above one...

now upload it into an internal table with a structure ( fields with char type which can hold the largest field value )

which can hold all the data of the file.

Now loop at this internal table and move this data into two different internal tables with header and item data structure.... ( differentiating records by using the prefix identifier ).

If prefix identifier is H move that line of the file into header table..

If prefix identifier is I move that line of the file into item table..

reward if it helps u...

sai ramesh.

Read only

Former Member
0 Likes
675

Yeah ,

Maintain ur flat file structure as an example..

H-----"detials
I-----"detials
I
I
H
I
I
H
I
H
I
I
I

here the header and items are separated by identifier literal as H and I

H followed by I is items pertaining to that header . when next h is expected that is the start of new document .

regards,

vijay