Skip to Content
author's profile photo Former Member
Former Member

session method

can any body sample code for session method in datail.

thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Jan 09, 2007 at 10:18 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 10:21 AM

    REPORT Zreport1.

    DATA: I_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

    DATA: BEGIN OF RECORD OCCURS 0, “Declaration of the data that is to be uploaded from the file

    LIFNR_001(016),

    KTOKK_002(004),

    NAME1_003(035),

    SORTL_004(010),

    LAND1_005(003),

    SPRAS_006(002),

    END OF RECORD.

    START-OF-SELECTION.

    PERFORM OPEN_GROUP.

    *Uploading data from the local file C:\Vendor1.txt

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = 'C:\VENDOR1.TXT '

    FILETYPE = 'DAT'

    TABLES

    DATA_TAB = RECORD.

    IF SY-SUBRC <> 0.

    WRITE 'ERROR IN UPLOAD'.

    ENDIF.

    LOOP AT RECORD. “Filling the BDC table with data

    PERFORM BDC_DYNPRO USING 'SAPMF02K' '0107'.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'RF02K-KTOKK'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '/00'.

    PERFORM BDC_FIELD USING 'RF02K-LIFNR'

    RECORD-LIFNR_001.

    PERFORM BDC_FIELD USING 'RF02K-KTOKK'

    RECORD-KTOKK_002.

    PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'LFA1-SORTL'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '/00'.

    PERFORM BDC_FIELD USING 'LFA1-NAME1'

    RECORD-NAME1_003.

    PERFORM BDC_FIELD USING 'LFA1-SORTL'

    RECORD-SORTL_004.

    PERFORM BDC_FIELD USING 'LFA1-LAND1'

    RECORD-LAND1_005.

    PERFORM BDC_FIELD USING 'LFA1-SPRAS'

    RECORD-SPRAS_006.

    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 'SAPLSPO1' '0300'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=YES'.

    PERFORM BDC_TRANSACTION USING 'MK01'.

    ENDLOOP.

    PERFORM CLOSE_GROUP. “ Closing the BDC session

    FORM OPEN_GROUP.

    CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

    CLIENT = SY-MANDT

    GROUP = 'SESSION1'

    USER = SY-UNAME

    KEEP = 'X'.

    IF SY-SUBRC <> 0.

    WRITE 'ERROR IN OPEN_GROUP'.

    ENDIF.

    ENDFORM.

    FORM BDC_DYNPRO USING PROGRAM DYNPRO.

    CLEAR I_BDCDATA.

    I_BDCDATA-PROGRAM = PROGRAM.

    I_BDCDATA-DYNPRO = DYNPRO.

    I_BDCDATA-DYNBEGIN = 'X'.

    APPEND I_BDCDATA.

    ENDFORM.

    FORM BDC_FIELD USING FNAM FVAL.

    CLEAR I_BDCDATA.

    I_BDCDATA-FNAM = FNAM.

    I_BDCDATA-FVAL = FVAL.

    APPEND I_BDCDATA.

    ENDFORM.

    FORM BDC_TRANSACTION USING TCODE.

    CALL FUNCTION 'BDC_INSERT'

    EXPORTING TCODE = TCODE

    TABLES DYNPROTAB = I_BDCDATA.

    ENDFORM.

    FORM CLOSE_GROUP.

    CALL FUNCTION 'BDC_CLOSE_GROUP'.

    ENDFORM. " CLOSE_GROUP

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 10:24 AM

    Hi Siva,

    You can go through this program.In this both Call Transaction and session method are used.

    &----


    *& Report Ztest_BDC *

    *& *

    &----


    *& Creating a test program for uplaoding a CSV or XLS file and pass *

    *& the internal table value to a BDC program *

    &----


    REPORT Ztest_BDC.

    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

    *for excel file

    PARAMETERS: P_IFILE TYPE RLGRAP-FILENAME.

    *for csv and txt file

    *PARAMETERS: p_ifile TYPE dxfile-filename.

    SELECTION-SCREEN END OF BLOCK B1.

    SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-002.

    PARAMETERS: P_SESS RADIOBUTTON GROUP G3 "create session

    DEFAULT 'X' USER-COMMAND BDC,

    P_CTU RADIOBUTTON GROUP G3. "call transaction

    SELECTION-SCREEN END OF BLOCK B3.

    *for csv and txt file

    *DATA : BEGIN OF itab OCCURS 0,

    • str TYPE string,

    • END OF itab,

    *for xls file

    DATA : ITAB LIKE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

    DATA : L_FILE TYPE STRING,

    T_BDCDATA TYPE STANDARD TABLE OF BDCDATA,

    WA_BDCDATA LIKE LINE OF T_BDCDATA.

    *----


    • AT SELECTION SCREEN ON VALUE REQUEST

    *----


    • Value request for the filename.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.

    PERFORM HELP_INPUT_FILE.

    START-OF-SELECTION.

    CLEAR L_FILE.

    *for csv and txt file

    • l_file = p_ifile.

    *for xls file

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

    FILENAME = P_IFILE

    I_BEGIN_COL = 1

    I_BEGIN_ROW = 1

    I_END_COL = 2

    I_END_ROW = 2

    TABLES

    INTERN = ITAB

    EXCEPTIONS

    INCONSISTENT_PARAMETERS = 1

    UPLOAD_OLE = 2

    OTHERS = 3.

    *for csv and txt file

    • CALL FUNCTION 'GUI_UPLOAD'

    • EXPORTING

    • filename = l_file

    • filetype = 'ASC'

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

    *Start new session

    IF P_SESS = 'X'.

    PERFORM BDC_OPEN.

    ENDIF.

    LOOP AT ITAB.

    PERFORM CREAT_BATCH_INPUT.

    PERFORM BDC_INSERT.

    IF P_CTU = 'X'.

    CALL TRANSACTION 'SE38' USING T_BDCDATA MODE 'A'.

    ENDIF.

    ENDLOOP.

    IF P_SESS = 'X'.

    PERFORM BDC_CLOSE .

    IF SY-SUBRC EQ 0.

    MESSAGE I001(ZM) WITH 'Session created check in transaction SM35'.

    ENDIF.

    ENDIF.

    &----


    *& Form bdc_open

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM BDC_OPEN .

    CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

    CLIENT = SY-MANDT

    GROUP = 'ZMUK'

    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.

    ENDFORM. " bdc_open

    &----


    *& Form creat_batch_input

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM CREAT_BATCH_INPUT .

    PERFORM BDC_DYNPRO USING 'SAPLWBABAP' '0100'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=STRT'.

    *for csv and txt file

    • PERFORM bdc_field USING 'RS38M-PROGRAMM'

    • itab-str.

    *for xls file

    PERFORM BDC_FIELD USING 'RS38M-PROGRAMM'

    ITAB-VALUE.

    PERFORM BDC_FIELD USING 'RS38M-FUNC_EDIT'

    'X'.

    PERFORM BDC_DYNPRO USING 'SAPLSLVC_FULLSCREEN' '0500'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=&F03'.

    PERFORM BDC_DYNPRO USING 'SAPLWBABAP' '0100'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=BACK'.

    *for csv and txt file

    • PERFORM bdc_field USING 'RS38M-PROGRAMM'

    • itab-str.

    *for xls file

    PERFORM BDC_FIELD USING 'RS38M-PROGRAMM'

    ITAB-VALUE.

    PERFORM BDC_FIELD USING 'RS38M-FUNC_EDIT'

    'X'.

    ENDFORM. " creat_batch_input

    &----


    *& Form bdc_insert

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM BDC_INSERT .

    CALL FUNCTION 'BDC_INSERT'

    EXPORTING

    TCODE = 'SE38'

    TABLES

    DYNPROTAB = T_BDCDATA

    EXCEPTIONS

    INTERNAL_ERROR = 1

    NOT_OPEN = 2

    QUEUE_ERROR = 3

    TCODE_INVALID = 4

    PRINTING_INVALID = 5

    POSTING_INVALID = 6

    OTHERS = 7.

    ENDFORM. " bdc_insert

    &----


    *& Form bdc_dynpro

    &----


    • text

    ----


    • -->P_0168 text

    • -->P_0169 text

    ----


    FORM BDC_DYNPRO USING P_PROGRAM TYPE ANY

    P_DYNPRO TYPE ANY.

    CLEAR WA_BDCDATA.

    WA_BDCDATA-PROGRAM = P_PROGRAM.

    WA_BDCDATA-DYNPRO = P_DYNPRO.

    WA_BDCDATA-DYNBEGIN = 'X'.

    APPEND WA_BDCDATA TO T_BDCDATA.

    ENDFORM. " bdc_dynpro

    &----


    *& Form bdc_field

    &----


    • text

    ----


    • -->P_0179 text

    • -->P_0180 text

    ----


    FORM BDC_FIELD USING P_FNAM TYPE ANY

    P_FVAL TYPE ANY.

    CLEAR WA_BDCDATA.

    WA_BDCDATA-FNAM = P_FNAM.

    WA_BDCDATA-FVAL = P_FVAL.

    CONDENSE WA_BDCDATA-FVAL.

    APPEND WA_BDCDATA TO T_BDCDATA.

    ENDFORM. " bdc_field

    &----


    *& Form bdc_close

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM BDC_CLOSE .

    CALL FUNCTION 'BDC_CLOSE_GROUP'

    EXCEPTIONS

    NOT_OPEN = 1

    QUEUE_ERROR = 2

    OTHERS = 3.

    ENDFORM. " bdc_close

    *&----


    **& Form help_input_file

    *&----


    • text

    *----


    • --> p1 text

    • <-- p2 text

    *----


    FORM HELP_INPUT_FILE .

    DATA: LT_FILE_TABLE TYPE FILETABLE,

    LA_FILE_TABLE LIKE LINE OF LT_FILE_TABLE,

    L_RC TYPE I,

    L_PCDSN TYPE CFFILE-FILENAME.

    REFRESH LT_FILE_TABLE.

    CLEAR LA_FILE_TABLE.

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

    CHANGING

    FILE_TABLE = LT_FILE_TABLE

    RC = L_RC.

    READ TABLE LT_FILE_TABLE INTO LA_FILE_TABLE INDEX 1.

    L_PCDSN = LA_FILE_TABLE-FILENAME.

    MOVE L_PCDSN TO P_IFILE.

    ENDFORM. " help_input_file

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 10:27 AM

    Hi,

    I have pasted a sample program about session method. If you want some more programs then reply back.

    REPORT z_test

    NO STANDARD PAGE HEADING LINE-SIZE 255.

    *include bdcrecx1.

    *

    *start-of-selection.

    *

    *perform open_group.

    TABLES: rf02k,lfa1,lfb1,lfm1.

    DATA: BEGIN OF itab OCCURS 0,

    lifnr LIKE rf02k-lifnr, " Vendor Account Number

    bukrs LIKE rf02k-bukrs,

    ekorg LIKE rf02k-ekorg,

    ktokk LIKE rf02k-ktokk,

    anred LIKE lfa1-anred,

    name1 LIKE lfa1-name1,

    sortl LIKE lfa1-sortl,

    land1 LIKE lfa1-land1,

    akont LIKE lfb1-akont,

    fdgrv LIKE lfb1-fdgrv,

    verkf LIKE lfm1-verkf,

    waers LIKE lfm1-waers,

    telf1 LIKE lfm1-telf1,

    END OF itab.

    DATA : bdctab LIKE bdcdata OCCURS 0 WITH HEADER LINE.

    DATA : bdcmsgtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = 'C:\Documents and Settings\temp\Desktop\prad1_file.TXT'

    FILETYPE = 'ASC'

    • HAS_FIELD_SEPARATOR = ' '

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • CHECK_BOM = ' '

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

    CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

    CLIENT = SY-MANDT

    • DEST = FILLER8

    GROUP = 'bdc session'

    • HOLDDATE = FILLER8

    KEEP = 'x'

    USER = sy-uname

    • RECORD = FILLER1

    • PROG = SY-CPROG

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

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

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

    ENDIF.

    LOOP AT itab.

    refresh bdctab.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'RF02K-EKORG'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '/00'.

    PERFORM bdc_field USING 'RF02K-LIFNR'

    itab-lifnr.

    PERFORM bdc_field USING 'RF02K-BUKRS'

    itab-bukrs.

    PERFORM bdc_field USING 'RF02K-EKORG'

    itab-ekorg.

    PERFORM bdc_field USING 'RF02K-KTOKK'

    itab-ktokk.

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

    itab-anred.

    PERFORM bdc_field USING 'LFA1-NAME1'

    itab-name1.

    PERFORM bdc_field USING 'LFA1-SORTL'

    itab-sortl.

    PERFORM bdc_field USING 'LFA1-LAND1'

    itab-land1.

    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.

    PERFORM bdc_field USING 'LFB1-FDGRV'

    itab-fdgrv.

    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-TELF1'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '/00'.

    PERFORM bdc_field USING 'LFM1-WAERS'

    itab-waers.

    PERFORM bdc_field USING 'LFM1-VERKF'

    itab-verkf.

    PERFORM bdc_field USING 'LFM1-TELF1'

    itab-telf1.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0320'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'RF02K-LIFNR'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=UPDA'.

    *CALL TRANSACTION 'XK01' USING bdctab

    • MODE 'a'

    • UPDATE 'a'

    • MESSAGES INTO bdcmsgtab.

    CALL FUNCTION 'BDC_INSERT'

    EXPORTING

    TCODE = 'xk01'

    • POST_LOCAL = NOVBLOCAL

    • PRINTING = NOPRINT

    • SIMUBATCH = ' '

    • CTUPARAMS = ' '

    TABLES

    dynprotab = bdctab

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

    *perform bdc_transaction using 'XK01'.

    *perform close_group.

    ENDLOOP.

    CALL FUNCTION 'BDC_CLOSE_GROUP'

    • EXCEPTIONS

    • NOT_OPEN = 1

    • QUEUE_ERROR = 2

    • OTHERS = 3

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    &----


    *& Form bdc_dynpro

    &----


    • subroutine for bdc_dynpro

    ----


    • -->P_0103 text

    • -->P_0104 text

    ----


    FORM bdc_dynpro USING program

    dynpro.

    CLEAR bdctab.

    bdctab-program = program.

    bdctab-dynpro = dynpro.

    bdctab-dynbegin = 'x'.

    APPEND bdctab.

    ENDFORM. " bdc_dynpro

    &----


    *& Form bdc_field

    &----


    • subroutine for bdc_field

    ----


    • -->P_0298 text

    • -->P_0299 text

    ----


    form bdc_field using fnam

    fval.

    clear bdctab.

    bdctab-fnam = fnam.

    bdctab-fval = fval.

    append bdctab.

    endform. " bdc_field

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 10:29 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.