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 Upload

Former Member
0 Likes
766

Hi,

I have a BDC program.

In the Flat File, I have both Header and Line items data. For each Header record, there can be more than 2 Line items. and I have to upload the data to FB01.

I have declared two internal tables... one for Header data and one for line data.

What I am planning to do is, to get all the data into one internal table and then move them to corresponding internal tables(Header and Line). Is that a right way to do that..?

Can someone tell me how to proceed on that..? In the Flat file, the data is seperated by TAB.

Thanks in advance.

Best Regards,

Paddu.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
742

u can use indicators in one table only

if it is header then the first character of the internal table will be H and for line item L

then start populating bdc data from H to all L

if u get again H then don't populate bdc data u just call transaction and then clear bdc data

and again fill as it is.

then u req only one internal table only

u just try with this

Reward points if it is helpful.

Madhavi

7 REPLIES 7
Read only

Former Member
0 Likes
743

u can use indicators in one table only

if it is header then the first character of the internal table will be H and for line item L

then start populating bdc data from H to all L

if u get again H then don't populate bdc data u just call transaction and then clear bdc data

and again fill as it is.

then u req only one internal table only

u just try with this

Reward points if it is helpful.

Madhavi

Read only

Former Member
0 Likes
742

Hi

U r plan is exactly correct first wht u do is simply get all the data into one internal table and then from there onwards based on the indicator tht is record which identifies the line tht wheter it is a header data or line data then u make those to move to particular internal tables u declared for line and header data

plzz reward if i am usefull to u..

for any furthere quiries u can contact me on mutyalasunilkumar@gmail.com

Thanks

Sunil...

Read only

Former Member
0 Likes
742

Hi,

Check the following link:

http://sap.niraj.tripod.com/id12.html

Regards,

Bhaskar

Read only

Former Member
0 Likes
742

Hi paddu,

first declare one internal table.like below.

data: begin of t_local occurs 0,

text(1024),

end of t_local.

by calling gui_uplaod FM take the data into the above internaltable t_local.

then

loop t_local.

split at '-----' into

itab1-ebeln " header table

itabl2-ebelp. " item table.

endloop.

normally i used to follow the above way.

i hope your doubt is clear, if you need any further help. please let me know.

Thanks,

Murali

Read only

0 Likes
742

Hi Murali,

Thanks for your mail

I am following the same procedure. In my Flat File, the data is as below.

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

Header Record Type(H/L) Company Code Document number Document date Document Type

Line Record Type(H/L) Company Code Document number Document date Line counter

H 263 030108 DG

L 263 030108 0001

L 263 030108 0002

H 263 030108 DZ

L 263 030108 0001

L 263 030108 0002

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

So, I declared an internal table to hold all this data as below.

data: begin of t_local occurs 0,

text(1024) type C,

end of t_local.

When using the FM GUI_UPLOAD, it is going to DUMP. Could you please tell me how the parameters should be given in this function module. I want the record to come in the single field TEXT.

Could you please tell me how to proceed..?

Thanks,

Paddu.

Read only

0 Likes
742

Hi Paddu,

call the function module as below.

data: begin of li_file occurs 0,

data(1024),

end of li_file.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = lv_fname

filetype = 'ASC'

has_field_separator = ' '

dat_mode = 'X'

CHANGING

data_tab = LI_FILE " LL

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

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19.

IF sy-subrc <> 0.

MESSAGE I069 WITH 'Error when uploading data.'.

fp_subrc = 2.

ENDIF.

IF P_HEADER > 0.

DELETE LI_FILE TO p_header.

ENDIF.

LOOP AT LI_FILE INTO LS_FILE.

SPLIT LS_FILE AT ',' INTO

ls_tfile-REQ

ls_tfile-ASSET

ls_tfile-SUBNO

ls_tfile-CLASS

ls_tfile-BUKRS

ls_tfile-nosia

ls_tfile-refas

ls_tfile-DESCRIPT

ls_tfile-MAIN_TEXT

ls_tfile-SERIAL_NO

ls_tfile-QTY

ls_tfile-CAP_DATE

ls_tfile-CO_CENTER

ls_tfile-AUFNR

ls_tfile-WBS

ls_tfile-LOCATION

ls_tfile-ROOM.

APPEND ls_tfile TO t_file.

CLEAR ls_tfile.

ENDLOOP.

i hope this will solve your issue, still if you need any help.. let me know.

Thanks,

Murali

Read only

Former Member
0 Likes
742

Hi paddu,

Check the below program.

i think ur procedure is correct.

But don't confuse after this program.

TABLES :mara, marc.

----


  • INTERNAL TABLES *

----


DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA:BEGIN OF itab_basic OCCURS 0,

matnr LIKE mara-matnr,

zzmatnr LIKE mara-matnr,

END OF itab_basic.

DATA:BEGIN OF itab_mrp OCCURS 0,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

zzgpind LIKE marc-zzgpind,

zzdate(10) type C ,

END OF itab_mrp.

DATA: BEGIN OF tab_mara OCCURS 0.

INCLUDE STRUCTURE mara.

DATA: END OF tab_mara.

DATA: BEGIN OF tab_marc OCCURS 0.

INCLUDE STRUCTURE marc.

DATA: END OF tab_marc.

DATA: ertab_basic LIKE itab_basic OCCURS 0 WITH HEADER LINE.

DATA: ertab_mrp LIKE itab_mrp OCCURS 0 WITH HEADER LINE.

DATA : v_ctr TYPE i VALUE 1. "Ctr for no orecords

DATA : v_group(12) . "BDC Group Name

DATA : v_group_ctr(3) TYPE n . "BDC Group Counter

DATA : v_no_lines TYPE i.

DATA: v_grpname(10) TYPE c.

SELECTION-SCREEN BEGIN OF BLOCK dt-entry

WITH FRAME TITLE text-002.

selection-screen begin of line .

selection-screen comment 01(49) text-101.

parameters : p_basic radiobutton group r1.

selection-screen end of line.

selection-screen begin of line .

selection-screen comment 01(49) text-102.

parameters : p_mrp2 radiobutton group r1.

selection-screen end of line.

*

*PARAMETERS :

  • p_basic RADIOBUTTON GROUP r1,

  • p_mrp2 RADIOBUTTON GROUP r1.

SELECTION-SCREEN END OF BLOCK dt-entry.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK fl-info

WITH FRAME TITLE text-003.

PARAMETER : p_dlhead AS CHECKBOX . "DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK fl-info.

*

SELECTION-SCREEN SKIP 1.

PARAMETER : p_max TYPE i DEFAULT '5000' . "No of rec / session

SET PF-STATUS 'UPLOAD'.

AT USER-COMMAND .

IF sy-ucomm = 'UPLOAD' .

IF p_basic = 'X'.

IF NOT itab_basic[] IS INITIAL .

PERFORM bdc_upload_basic.

ENDIF.

WRITE:/10 'Please execute the session in SM35 to Upload the data'.

FORMAT INTENSIFIED OFF COLOR OFF .

REFRESH itab_basic . CLEAR itab_basic .

SET PF-STATUS space.

ENDIF.

IF p_mrp2 = 'X'.

IF NOT itab_mrp[] IS INITIAL .

PERFORM bdc_upload_mrp.

ENDIF..

WRITE:/10 'Please execute the session in SM35 to Upload the data'.

REFRESH itab_mrp . CLEAR itab_mrp .

SET PF-STATUS space.

ENDIF.

ENDIF.

START-OF-SELECTION.

IF p_basic = 'X'.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'C:\mm02_basic.txt '

filetype = 'DAT'

TABLES

data_tab = itab_basic.

IF p_dlhead EQ 'X'.

READ TABLE itab_basic INDEX 1.

DELETE itab_basic INDEX 1.

CLEAR itab_basic.

ENDIF.

PERFORM blank_data_validation.

ENDIF.

IF p_mrp2 = 'X'.

  • v_grpname = 'MRP2'.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'C:\mm02_mrp.txt '

filetype = 'DAT'

TABLES

data_tab = itab_mrp.

IF p_dlhead EQ 'X'.

READ TABLE itab_mrp INDEX 1.

DELETE itab_mrp INDEX 1.

CLEAR itab_mrp.

ENDIF.

PERFORM valid_plant_check.

ENDIF.

IF sy-subrc <> 0.

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

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

ENDIF.

PERFORM display_data.

END-OF-SELECTION.

*----


*

  • Start new screen

*

*----


*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM.

*----


*

  • Insert field

*

*----


*

FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM.

&----


*& Form blank_data_validation

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM blank_data_validation.

LOOP AT itab_basic.

IF itab_basic-matnr IS INITIAL OR itab_basic-zzmatnr IS INITIAL.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_mara FROM mara WHERE matnr = itab_basic-matnr

.

IF sy-subrc <> 0.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

*

ENDLOOP.

ENDFORM. " dt_qty_validation

&----


*& Form CALL_BDC_CLOSE_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_bdc_close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2.

IF sy-subrc NE 0.

WRITE: /5 'BDC CLOSE GROUP FAILED, return code = ', sy-subrc.

EXIT.

ENDIF.

ENDFORM. " CALL_BDC_CLOSE_GROUP

&----


*& Form CALL_BDC_INSERT

&----


  • text

----


  • -->P_0545 text

----


FORM call_bdc_insert USING v_tran_code.

DATA: xmode VALUE 'E'.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = v_tran_code

TABLES

dynprotab = bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3.

IF sy-subrc NE 0.

WRITE: /5 'BDC insert GROUP FAILED, return code = ', sy-subrc.

EXIT.

ENDIF.

ENDFORM. " CALL_BDC_INSERT

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data.

WRITE:/ 'Press','''Upload''',

'to create session with the following records'.

IF p_basic = 'X'.

PERFORM display_header.

FORMAT COLOR 2.

LOOP AT itab_basic.

WRITE :/2 itab_basic-matnr,'|',

23 itab_basic-zzmatnr,

54 '|'.

ENDIF.

ENDLOOP.

NEW-LINE.

ULINE (54).

ENDIF.

IF p_mrp2 = 'X'.

PERFORM display_header_mrp.

FORMAT COLOR 2.

LOOP AT itab_mrp.

WRITE :/2 itab_mrp-matnr,'|',

23 itab_mrp-werks,

33 '|',

37 itab_mrp-zzgpind,

49 '|',

52 itab_mrp-ZZDATE,

65 '|'.

ENDLOOP.

NEW-LINE.

ULINE (65).

FORMAT COLOR OFF.

SKIP 4.

WRITE 😕 'Records with Errors will not be Included in Session' .

PERFORM display_header_mrp.

FORMAT COLOR 2.

LOOP AT ertab_mrp.

IF NOT ertab_mrp IS INITIAL OR NOT ertab_mrp-matnr IS INITIAL.

WRITE :/2 ertab_mrp-matnr ,'|',

23 ertab_mrp-werks,

33 '|',

37 ertab_mrp-zzgpind,

49 '|' ,

52 ertab_mrp-zzdate,

65 '|'.

ENDIF.

ENDLOOP.

NEW-LINE.

ULINE (65).

ENDIF.

FORMAT COLOR OFF.

ENDFORM. " display_data

&----


*& Form BDC_UPLOAD_basic

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload_basic.

*CLEAR itab_basic. REFRESH itab_basic.

CLEAR : v_ctr , v_no_lines .

IF NOT itab_basic[] IS INITIAL .

v_group_ctr = '1' .

CONCATENATE 'BASIC_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

LOOP AT itab_basic .

IF v_ctr GE p_max .

PERFORM call_bdc_close_group .

v_group_ctr = v_group_ctr + 1 .

CLEAR v_group .

CONCATENATE 'BASIC_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

v_ctr = 0 .

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

itab_basic-matnr.

  • 'DEEPAKTESTMAT'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-ZZMATNR'.

PERFORM bdc_field USING 'MARA-ZZMATNR'

itab_basic-zzmatnr.

  • 'ADV#AM29F010-70JI'.

PERFORM call_bdc_insert USING 'MM02'.

CLEAR bdcdata . REFRESH bdcdata .

v_no_lines = v_no_lines + 1 .

v_ctr = v_ctr + 1.

ENDLOOP.

PERFORM call_bdc_close_group.

SKIP 10.

WRITE :/10 'Session by name BASIC* created' .

WRITE :/10 'Total No of records uploaded - ' , v_no_lines .

ENDIF.

ENDFORM. " BDC_UPLOAD

&----


*& Form display_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_header.

NEW-LINE.

  • set left scroll-boundary column 48.

FORMAT COLOR 1 INTENSIFIED ON.

ULINE (54).

WRITE :/' Avnet Material',

21'|' ,

23 'Green Product '

, 54 '|'.

NEW-LINE.

ULINE (54).

FORMAT COLOR OFF INTENSIFIED OFF.

ENDFORM.

&----


*& Form bdc_upload_mrp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload_mrp.

  • PERFORM call_bdc_open_group2.

CLEAR : v_ctr , v_no_lines .

IF NOT itab_mrp[] IS INITIAL .

v_group_ctr = '1' .

CONCATENATE 'MRP_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

LOOP AT itab_mrp .

IF v_ctr GE p_max .

PERFORM call_bdc_close_group .

v_group_ctr = v_group_ctr + 1 .

CLEAR v_group .

CONCATENATE 'MRP2_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

v_ctr = 0 .

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

itab_mrp-matnr.

  • 'DEEPAKTESTMAT'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(13)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(13)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-WERKS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'RMMG1-WERKS'

itab_mrp-werks.

  • 'sg11'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARC-ZZGPIND'.

PERFORM bdc_field USING 'MARC-ZZGPIND'

itab_mrp-zzgpind.

  • 'G'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARC-ZZDATE'.

PERFORM bdc_field USING 'MARC-ZZDATE'

itab_mrp-zzdate.

  • 'G'.

PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=YES'.

PERFORM call_bdc_insert USING 'MM02'.

CLEAR bdcdata . REFRESH bdcdata .

v_no_lines = v_no_lines + 1 .

v_ctr = v_ctr + 1.

ENDLOOP.

PERFORM call_bdc_close_group.

SKIP 10.

WRITE :/10 'Session by name MRP2* created' .

WRITE :/10 'Total No of records uploaded - ' , v_no_lines .

ENDIF.

ENDFORM. " bdc_upload_mrp

&----


*& Form display_header_mrp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_header_mrp.

NEW-LINE.

  • set left scroll-boundary column 48.

FORMAT COLOR 1 INTENSIFIED ON.

ULINE (65).

WRITE :/' Avnet Material',

21'|' ,

23 'Plant ' ,

33 '|',

35 'Indicator',

49 '|',

52 'Date',

65 '|' .

NEW-LINE.

ULINE (65).

FORMAT COLOR OFF INTENSIFIED OFF.

ENDFORM. " display_header_mrp

&----


*& Form valid_plant_check

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM valid_plant_check.

LOOP AT itab_mrp.

IF itab_mrp-matnr IS INITIAL OR itab_mrp-werks IS INITIAL OR

itab_mrp-zzgpind IS INITIAL.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_marc FROM marc WHERE matnr = tab_marc-matnr

AND werks = itab_mrp-werks . .

IF sy-subrc = 0.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

ENDLOOP.

ENDFORM. " valid_plant_check

----


  • FORM open_group *

----


  • ........ *

----


FORM open_group USING p_grp .

  • open batchinput group

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_grp

user = sy-uname

keep = 'X'.

ENDFORM.

Rewarde the pt.s if it is useful