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
86

hi all,

i had to upload data to ac03. using session method.i had developed code for this its not getting uploaded. and also that transaction is in no display mode.wen we do recording also we are not able to enter vallues in this transaction. because its in display mode only,can we upload data for any transaction which is in display mode?,and i need any corrections needed in my code.

can any body help me in this regard.

thanks in advance

siva

REPORT Z_DISPLAY_SERVICE2.

PARAMETER: INFILE TYPE STRING.

DATA : BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA: OPEN_FLG(1) VALUE '0',RD_FLG(1) VALUE '0'.

DATA: SESSION LIKE APQI-GROUPID VALUE 'asserror'.

TABLES: ASMD,ASMDT,BDCMSGCOLL.

DATA: BEGIN OF ITAB OCCURS 0,

ASNUM LIKE ASMD-ASNUM,

ASTYP LIKE ASMD-ASTYP,

MEINS LIKE ASMD-MEINS,

MATKL LIKE ASMD-MATKL,

BKLAS LIKE ASMD-BKLAS,

END OF ITAB.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = infile

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'x'

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

WRITE:/ SY-SUBRC, 'ERROR IN UPLOAD'.

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

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

ENDIF.

LOOP AT ITAB.

RD_FLG = '1'.

PERFORM FILL_BDCTAB.

CALL TRANSACTION 'AC03' USING BDCTAB MODE 'A'.

IF SY-SUBRC <> 0.

IF OPEN_FLG = '0' .

WRITE πŸ˜• SY-SUBRC , 'ERROR...Session created named ASSERROR'.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = SESSION

  • HOLDDATE = FILLER8

  • KEEP = FILLER1

USER = SY-UNAME

  • RECORD = FILLER1

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

OPEN_FLG = '1'.

ELSE.

WRITE πŸ˜• SY-SUBRC ,'Error in BDC OPEN GROUP'.

ENDIF.

ENDIF.

*LOOP AT ITAB.

*REFRESH BDCTAB.

PERFORM FILL_BDCTAB.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'AC03'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

TABLES

DYNPROTAB = BDCTAB

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7.

ENDIF.

ENDLOOP.

IF OPEN_FLG = '1'.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

WRITE πŸ˜• SY-SUBRC ,' Error in BDC CLOSE GROUP '.

ENDIF.

ENDIF.

IF ( OPEN_FLG = '0' AND RD_FLG = '1' ) .

WRITE:/ 'Successfully uploaded....'.

ENDIF.

FORM FILL_BDCTAB.

REFRESH BDCTAB.

PERFORM POPULATE_BDCTAB USING:

'X' 'SAPLBAS0' '0300'.

PERFORM POPULATE_BDCTAB USING:

' ' 'ASMD-ASNUM' ITAB-ASNUM,

' ' 'ASMD-MEINS' ITAB-MEINS,

' ' 'ASMD-MATKL' ITAB-MATKL,

' ' 'ASMD-BKLAS' ITAB-BKLAS,

' ' 'BDC_OKCODE' '/11'.

ENDFORM.

FORM POPULATE_BDCTAB USING VAR1 VAR2 VAR3.

CLEAR BDCTAB.

IF VAR1 = 'X'.

BDCTAB-DYNBEGIN = 'X'.

BDCTAB-PROGRAM = VAR2.

BDCTAB-DYNPRO = VAR3.

ELSE.

  • append bdctab.

  • endform.

  • form populate_bdcfld using var4 var 5.

  • clear bdctab.

BDCTAB-FNAM = VAR2.

BDCTAB-FVAL = VAR3.

ENDIF.

APPEND BDCTAB.

  • clear bdctab.

ENDFORM.

4 REPLIES 4

Former Member
0 Kudos
37

Hi Siva,

While doing the BDC recording u need to click the 'Create New Serive' button on the toolbar which was missed in your coding. Becuase of this it is not able to enter the data

Reward with points if useful

Regards,

Krishna K.

Former Member
0 Kudos
37

Hi,

See the code for AC02 and modify as per your requirement if needed

REPORT zmm_service_master_upload

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Standard Include for Selection Screen

INCLUDE bdcrecx1.

  • Internal Table for Upload Data

DATA: BEGIN OF record OCCURS 0,

asktx(040), " Service Description

astyp(004), " Service Category

meins(003), " Unit of Measure

formelnr(010), " Formula

END OF record.

  • 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 = record

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.

  • Upload the Data from Internal Table

LOOP AT record.

PERFORM bdc_dynpro USING 'SAPLBAS0' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'ASMD-ASNUM'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=NEW'.

PERFORM bdc_dynpro USING 'SAPLBAS0' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'ASMD-ASTYP'.

PERFORM bdc_field USING 'BDC_OKCODE'

'POST'.

PERFORM bdc_field USING 'ASMDT-ASKTX'

record-asktx.

PERFORM bdc_field USING 'ASMD-ASTYP'

record-astyp.

PERFORM bdc_field USING 'ASMD-MEINS'

record-meins.

PERFORM bdc_field USING 'ASMD-FORMELNR'

record-formelnr.

  • Call the Transaction

PERFORM bdc_transaction USING 'AC02'.

ENDLOOP.

  • Close the BDC Session

PERFORM close_group.

reward points if useful

regards,

ANJI

0 Kudos
37

hi anji,

tanks for ur response, i need clarification regarding formlenr, in need to upload long text also, previously u send code for that i need combine code for this, can u provide this if u dont mine.

thnks,

siva

Former Member
0 Kudos
37

Hi,

Use the transaction code AC02 insted of AC03,

AC02 is for change always 02 for change and 03 for display.

Reg,

Hariharan natarajan