Application Development 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: 

BDC

Former Member
0 Kudos

hi all.

i done a recording in shdb on transaction mm02.. the code of bdc recording is as follows

report YASEC_BDC

no standard page heading line-size 255.

include bdcrecx1.

parameters: dataset(132) lower case.

      • 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,

  • data element: MATNR

MATNR_001(018),

  • data element: XFELD

KZSEL_01_002(001),

  • data element: MAKTX

MAKTX_003(040),

  • data element: MEINS

MEINS_004(003),

  • data element: MATKL

MATKL_005(009),

  • data element: BISMT

BISMT_006(018),

  • data element: SPART

SPART_007(002),

  • data element: PRODH_D

PRDHA_008(018),

  • data element: MTPOS_MARA

MTPOS_MARA_009(004),

  • data element: BRGEW

BRGEW_010(017),

  • data element: GEWEI

GEWEI_011(003),

  • data element: NTGEW

NTGEW_012(017),

  • data element: MAGRV

MAGRV_013(004),

end of record.

      • End generated data section ***

start-of-selection.

perform open_dataset using dataset.

perform open_group.

do.

read dataset dataset into record.

if sy-subrc <> 0. exit. 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'

record-MATNR_001.

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)'

record-KZSEL_01_002.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'MAKT-MAKTX'

record-MAKTX_003.

perform bdc_field using 'BDC_CURSOR'

'MARA-BISMT'.

perform bdc_field using 'MARA-MEINS'

record-MEINS_004.

perform bdc_field using 'MARA-MATKL'

record-MATKL_005.

perform bdc_field using 'MARA-BISMT'

record-BISMT_006.

perform bdc_field using 'MARA-SPART'

record-SPART_007.

perform bdc_field using 'MARA-PRDHA'

record-PRDHA_008.

perform bdc_field using 'MARA-MTPOS_MARA'

record-MTPOS_MARA_009.

perform bdc_field using 'MARA-BRGEW'

record-BRGEW_010.

perform bdc_field using 'MARA-GEWEI'

record-GEWEI_011.

perform bdc_field using 'MARA-NTGEW'

record-NTGEW_012.

perform bdc_field using 'MARA-MAGRV'

record-MAGRV_013.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

perform bdc_transaction using 'MM02'.

enddo.

perform close_group.

perform close_dataset using dataset.

now how to write a program in se38 and include this recording in my program..

please help me

regards

nikesh kumar

5 REPLIES 5

Former Member
0 Kudos

hi, i have done for xk01,follow the same

reward points if this is useful

report ztest_bdc

no standard page heading line-size 255.

types: begin of ty_data,

lifnr type lfa1-lifnr,

bukrs type rf02k-bukrs,

ekorg type rf02k-ekorg,

ktokk type rf02k-ktokk,

name1 type lfa1-name1,

sortl type lfa1-sortl,

land1 type lfa1-land1,

akont type lfb1-akont,

fdgrv type lfb1-fdgrv,

waers type lfm1-waers,

end of ty_data.

data: itab type table of ty_data with header line.

parameters: pname like rlgrap-filename.

include bdcrecx1.

start-of-selection.

call function 'GUI_UPLOAD'

exporting

filename = 'C:/bdc.txt'

filetype = 'ASC'

has_field_separator = '#'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • 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.

perform open_group.

loop at itab.

perform bdc_dynpro using 'SAPMF02K' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-KTOKK'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-LIFNR'

itab-lifnr."'test2'.

perform bdc_field using 'RF02K-BUKRS'

itab-bukrs."'1000'.

perform bdc_field using 'RF02K-EKORG'

itab-ekorg."'1000'.

perform bdc_field using 'RF02K-KTOKK'

itab-ktokk."'0001'.

perform bdc_dynpro using 'SAPMF02K' '0110'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-LAND1'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFA1-NAME1'

itab-name1."'test2'.

perform bdc_field using 'LFA1-SORTL'

itab-sortl."'TE'.

perform bdc_field using 'LFA1-LAND1'

itab-land1."'iN'.

perform bdc_dynpro using 'SAPMF02K' '0120'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-KUNNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-BANKS(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_dynpro using 'SAPMF02K' '0210'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-FDGRV'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFB1-AKONT'

itab-akont."'197100'.

perform bdc_field using 'LFB1-FDGRV'

itab-fdgrv."'A1'.

perform bdc_dynpro using 'SAPMF02K' '0215'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-ZTERM'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0220'.

perform bdc_field using 'BDC_CURSOR'

'LFB5-MAHNA'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0310'.

perform bdc_field using 'BDC_CURSOR'

'LFM1-WAERS'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFM1-WAERS'

itab-waers."'inr'.

perform bdc_dynpro using 'SAPMF02K' '0320'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-LIFNR'.

perform bdc_field using 'BDC_OKCODE'

'=UPDA'.

perform bdc_transaction using 'XK01'.

endloop.

perform close_group.

Former Member
0 Kudos

this code that you have given.. is a report generated via recording...

if you want to develope a BDC using recording follow this template....

<b>1. CREATE INTERNAL TABLE CONTAINING BDC FIELDS (it_upload)

(Pick this data from recording)</b>

data: begin of it_upload occurs 0 with header line,

end of it_upload.

  • Batchinputdata of single transaction

data: bdcdata like bdcdata occurs 0 with header line.

*----


*Variables

*----


data: return(30).

*----


*Selection Screens

*----


selection-screen begin of block b1 with frame title text-000.

parameters p_fname like rlgrap-filename. "To get file name.. for uploading data

selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-001.

parameters : p_sname(12),

p_keep default 'X' as checkbox.

selection-screen end of block b2.

*----


*At Selection-Screen

*----


at selection-screen on value-request for p_fname.

call function 'WS_FILENAME_GET'

exporting

  • DEF_FILENAME = ' '

  • DEF_PATH = ' '

mask = ',*.txt.'

mode = 'O'

  • TITLE = ' '

importing

filename = p_fname

  • RC =

exceptions

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

others = 5

.

if sy-subrc <> 0.

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

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

endif.

at selection-screen.

call function 'WS_QUERY'

exporting

  • ENVIRONMENT =

filename = p_fname

query = 'FE'

  • WINID =

importing

return = return

exceptions

inv_query = 1

no_batch = 2

frontend_error = 3

others = 4

.

if sy-subrc <> 0.

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

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

elseif return = 0.

message e005 with 'File does not exist'.

endif.

*----


*Start-of-selection

*----


start-of-selection.

*<b>Uploading the flat file containig the infotype records.</b>

call function 'WS_UPLOAD'

exporting

  • CODEPAGE = ' '

filename = p_fname

filetype = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

tables

data_tab = it_upload

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.

message e005 with 'File upload failed'.

endif.

*Opening the session

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

group = p_sname

keep = p_keep

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 e005 with 'Unable to open a BDC group'.

endif.

loop at it_upload.

<b>2. Perform BDC_DYNPRO & BDC_FIELD for each screen & its fields...Eliminate those fields which are not necessary.OKCODE is mandatory

(Pick this data from recording)</b>

*these details are as per SHDB recoding

perform bdc_dynpro using 'SAPMF02K' '0106'.

perform bdc_field using:

'BDC_CURSOR' 'RF02K-D0130',

'BDC_OKCODE' '/00',

'RF02K-LIFNR' it_upload-vendor_code,

'RF02K-BUKRS' it_upload-company_code,

'RF02K-D0110' 'X',

'RF02K-D0120' 'X',

'RF02K-D0130' 'X'.

<b>3. Perform BDC_INSERT here b4 endloop</b>

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'FBD1' “put ur TCODE 4 whch u r doin BDC

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

dynprotab = 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.

endloop.

<b>*Closing the session</b> call function 'BDC_CLOSE_GROUP'

exceptions

not_open = 1

queue_error = 2

others = 3.

if sy-subrc <> 0.

message e005 with 'Unable to close the BDC group'.

endif.

----


  • 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.

Former Member
0 Kudos

HI

after that you need to follow like this

the BDC program should be in this format

How to Upload Presentation Server Flat file to SAP R/3 system???

How to upload application server file to R/3 system?

Definition

Example - Call Transaction Method

<b>Upload Flat file from Presentation Server to SAP R/3</b>

CALL FUNCTION ‘GUI_UPLOAD'

EXPORTING

CODEPAGE = ‘IBM'

FILENAME = P_UFILE

FILETYPE = 'DAT'

TABLES

DATA_TAB = INT_TAB

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.

MESSAGE E999(FR) WITH 'ERROR IN FILE UPLOAD'.

ENDIF.

<b>Upload file from application server to SAP R/3</b>

Open the the application server file

OPEN DATASET <dsn> FOR INPUT <mode>

Read the data from application server file

READ DATASET <dsn> INTO <wa>

And then close the application server file

CLOSE DATASET <dsn>

<b>Definition- Declaring BDC Table</b>

DATA: BDC_TAB LIKE STANDARD TABLE OF

BDCDATA INITIAL SIZE 6

WITH HEADER LINE .

The internal table used to collect the transaction’s information must be declared “LIKE BDCDATA”.

<b>Filling BDC Table – Method #1</b>

FORM FILL_BDC_TAB.

REFRESH BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-PROGRAM = ‘SAPMF02K’.

BDC_TAB-DYNPRO = ‘01016’.

BDC_TAB-DYNBEGIN = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘RF02K-LIFNR’.

BDC_TAB-FVAL = ‘TEST1’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘RF02K-D0010’.

BDC_TAB-FVAL = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-PROGRAM = ‘SAPMF02K’.

BDC_TAB-DYNPRO = ‘0110’.

BDC_TAB-DYNBEGIN = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘LFA1-STRAS’.

BDC_TAB-FVAL = ‘123 Main St.’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘BDC_OKCODE’.

BDC_TAB-FVAL = ‘/11’.

APPEND BDC_TAB.

ENDFORM.

<b>Filling BDC Table – Method #2</b>

FORM FILL_BDC_TAB.

REFRESH BDC_TAB.

PERFORM POPULATE_BDC_TAB

USING:

‘1’ ‘SAPMF02K’ ‘0106’,

‘ ‘ ‘RF02K-LIFNR’ ‘TEST1’,

‘ ‘ ‘RF02K-D0010’ ‘X’,

‘1’ ‘SAPMF02K’ ‘0110’,

‘ ‘ ‘LFA1-STRAS’, ‘123 Main St.’,

‘ ‘ ‘BDC_OKCODE’, ‘/11’.

ENDFORM.

FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.

CLEAR BDC_TAB.

IF FLAG = ‘1’.

BDC_TAB-PROGRAM = VAR1.

BDC_TAB-DYNPRO = VAR2..

BDC_TAB-DYNBEGIN = ‘X’.

ELSE.

BDC_TAB-FNAM = VAR1.

BDC_TAB-FVAL = VAR2.

ENDIF.

APPEND BDC_TAB.

ENDFORM.

This two subroutine method to fill the BDC table is preferable because the “POPULATE_BDC_TABLE” subroutine is reusable throughout all batch input programs.

<b>Example #1 - Change Vendor (Call Transaction Method)</b>

<b>Example #1- Declaration Section</b>

REPORT Y180DM10.

DATA: BDC_TAB LIKE STANDARD TABLE OF

BDCDATA INITIAL SIZE 6 WITH HEADER LINE.

INFILE(20) VALUE ‘/tmp/bc180_file4’.

DATA: BEGIN OF INREC.

VENDNUM LIKE LFA1-LIFNR.

STREET LIKE LFA1-STRAS.

END OF INREC.

PARAMETERS: DISPMODE DEFAULT ‘A’,

UPDAMODE DEFAULT ‘S’.

START-OF-SELECTION.

OPEN DATASET INFILE

FOR INPUT IN TEXT MODE.

DO.

READ DATASET INFILE INTO INREC.

IF SY-SUBRC < > 0. EXIT. ENDIF.

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE DISPMODE

UPDATE UPDAMODE.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

CLOSE DATASET INFILE.

<b>synchronous updating</b>

DO.

………

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE ‘N’

UPDATE ‘S’.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

With synchronous updating, we can check SY-SUBRC to determine the success of the transaction and the actual update to the database.

<b>asynchronous updating</b>

DO.

………

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE ‘N’

UPDATE ‘A’.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

With asynchronous updating, we can check SY-SUBRC to determine the success of the transaction only, not the actual update to the database.

<b>Error Handling</b>

Write an error report.

Send the record(s) in error to an error file.

Create a batch input session with the record(s) in error.

To store error messages ( CALL TRANSACTION )

data: begin of Tab_Mess occurs 0.

include structure bdcmsgcoll.

data : end of Tab_Mess,

CALL TRANSACTION ‘FK02’ USING BDC_TAB MODE ‘N’ UPDATE ‘S’

MESSAGES INTO TAB_MESS.

IF SY-SUBRC NE 0.

WRITE: / Tab_MESS-TCODE, Tab_MESS-DYNUMB, Tab_MESS-MSGTYP ,

Tab_MESS-MSGID.

ENDIF.

<b>i am giving you example for Change Vendor you practice for ur tcode</b>

For our example, we will use the “Change Vendor” transaction (“FK02”) to add a street address to an already existing vendor.

Step #1

Use “System&#61664;Status” menu path to determine online program name (SAPMF02K), screen number (0110)

Step #2

Use “F1” key and “Technical Info” pushbutton in each screen field to be filled to determine the field name.

Step #3

Determine how to proceed in the transaction

(save the record by clicking on the ‘Save’ pushbutton or pressing the ‘F11’ key).

BDC Table Contents

After researching the transaction we can determine the contents of the BDC table.

PROGRAM DYNPRO DYNBEGIN FNAM FVAL

SAMPF02K 0106 X

RF02K-LIFNR TEST1

RF02K-D0110 X

SAMPF02K 0110 X

LFA1-STRAS 123 Main St.

BDC_OKCODE /11

<b>Batch Input Methods</b>

“CALL TRANSACTION USING”

STATEMENT

Call transaction - for data transfer

Processing batch input data with CALL TRANSACTION USING is the faster of the two recommended data transfer methods. In this method, legacy data is processed inline in your data transfer program.

Syntax:

CALL TRANSACTION <tcode>

USING <bdc_tab>

MODE <mode>

UPDATE <update>

A Display all

E Display errors only

N No display

S Synchronous

A Asynchronous

L Local update

<b>The process flow of CALL TRANSACTION</b>

A program that uses CALL TRANSACTION USING to process legacy data should execute thefollowing steps:

Prepare a BDCDATA structure for the transaction that you wish to run.

Prepare a internal table to store error messages Tab_Mess like structure of BDCMSGCOLL.

With a CALL TRANSACTION USING statement, call the transaction and prepare the BDCDATA structure. For example:

CALL TRANSACTION ‘MM01' USING BDCDATA MODE 'A' UPDATE 'S'. MESSAGES INTO TAB_MESS.

IF SY-SUBRC <> 0.

<Error_handling>.

ENDIF.

<b>Overview of Batch Input Session</b>

The first batch input method is to create a batch input session. It is the processing of this batch input session that updates the database, not the execution of the batch input program.

<b>Reward if usefull</b>

Former Member
0 Kudos

copy all performs...

double click on one of the performs and copy forms also.....

now declare itab with fields...in data : begin of record....

ex. Data: begin of itab occurs 0,

matnr(018),

end of itab.

declare below internal tables also....

DATA : it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

  • Internal table for getting the Messages.

DATA : BEGIN OF it_bdcmsgcoll OCCURS 0.

INCLUDE STRUCTURE bdcmsgcoll. " Table to hold messages

DATA : END OF it_bdcmsgcoll.

data : gv_message(255).

now,

*--populate internal table with data.....

loop at itab.

*copy all performs here....change fields..

ex. record-MATNR_001 should be replaced by itab-matnr

*****after performs write...

CALL TRANSACTION 'PA30' USING it_bdcdata

MODE 'A'

UPDATE 'S'

MESSAGES INTO it_bdcmsgcoll.

*--use trasaction which u have recorded in above statement instead of PA30

use mode : A or N or E.....all screen,no screen,error screen....

if sy-subrc <> 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = it_bdcmsgcoll-msgid

lang = sy-langu

no = it_bdcmsgcoll-msgnr

v1 = it_bdcmsgcoll-msgv1

v2 = it_bdcmsgcoll-msgv2

v3 = it_bdcmsgcoll-msgv3

v4 = it_bdcmsgcoll-msgv4

IMPORTING

msg = gv_message

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

write:/ gv_message.

ENDIF.

endif.

endif.

endloop.

Former Member
0 Kudos

USE THIS.

report YASEC_BDC

no standard page heading line-size 255.

*include bdcrecx1.

*

*parameters: dataset(132) lower case.

      • 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,

  • data element: MATNR

MATNR_001(018),

  • data element: XFELD

KZSEL_01_002(001),

  • data element: MAKTX

MAKTX_003(040),

  • data element: MEINS

MEINS_004(003),

  • data element: MATKL

MATKL_005(009),

  • data element: BISMT

BISMT_006(018),

  • data element: SPART

SPART_007(002),

  • data element: PRODH_D

PRDHA_008(018),

  • data element: MTPOS_MARA

MTPOS_MARA_009(004),

  • data element: BRGEW

BRGEW_010(017),

  • data element: GEWEI

GEWEI_011(003),

  • data element: NTGEW

NTGEW_012(017),

  • data element: MAGRV

MAGRV_013(004),

end of record.

      • End generated data section ***

DATA: BEGIN OF BDCDATA OCCURS 0.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF BDCDATA.

DATA: BEGIN OF MSGTAB OCCURS 0.

INCLUDE STRUCTURE BDCMSGCOLL.

DATA: END OF MSGTAB.

DATA : ITAB LIKE STANDARD TABLE OF RECORD WITH HEADER LINE.

start-of-selection.

*perform open_dataset using dataset.

*perform open_group.

*

*do.

*

*read dataset dataset into record.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = ' '

FILETYPE = 'dat'

TABLES

DATA_TAB = ITAB

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

LOOP AT ITAB INTO RECORD.

if sy-subrc <> 0. exit. 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'

record-MATNR_001.

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)'

record-KZSEL_01_002.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'MAKT-MAKTX'

record-MAKTX_003.

perform bdc_field using 'BDC_CURSOR'

'MARA-BISMT'.

perform bdc_field using 'MARA-MEINS'

record-MEINS_004.

perform bdc_field using 'MARA-MATKL'

record-MATKL_005.

perform bdc_field using 'MARA-BISMT'

record-BISMT_006.

perform bdc_field using 'MARA-SPART'

record-SPART_007.

perform bdc_field using 'MARA-PRDHA'

record-PRDHA_008.

perform bdc_field using 'MARA-MTPOS_MARA'

record-MTPOS_MARA_009.

perform bdc_field using 'MARA-BRGEW'

record-BRGEW_010.

perform bdc_field using 'MARA-GEWEI'

record-GEWEI_011.

perform bdc_field using 'MARA-NTGEW'

record-NTGEW_012.

perform bdc_field using 'MARA-MAGRV'

record-MAGRV_013.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

*perform bdc_transaction using 'MM02'.

*

*enddo.

*

*perform close_group.

*perform close_dataset using dataset.

CALL TRANSACTION 'MM02' USING BDCDATA

MODE 'A' UPDATE 'S' MESSAGES INTO MSGTAB.

CLEAR BDCDATA[].

REFRESH BDCDATA.

ENDLOOP.

&----


*& Form BDC_DYNPRO

&----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


FORM BDC_FIELD USING FNAM FVAL.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDFORM. " BDC_FIELD