0% found this document useful (0 votes)
11 views

Sessionmethod

This document contains code for reading data from an Excel file into an internal table and then using BDC programming to submit that data into a SAP transaction (ZAPC11). It opens a BDC session, loops through the internal table, calls dynpro and field functions to populate the BDC data table, and finally inserts the data via a BDC call. Helper forms are used for the dynpro and field BDC calls.

Uploaded by

Subodh Kant
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Sessionmethod

This document contains code for reading data from an Excel file into an internal table and then using BDC programming to submit that data into a SAP transaction (ZAPC11). It opens a BDC session, loops through the internal table, calls dynpro and field functions to populate the BDC data table, and finally inserts the data via a BDC call. Helper forms are used for the dynpro and field BDC calls.

Uploaded by

Subodh Kant
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

*&---------------------------------------------------------------------*

*& Report  ZDEMO_BDC_SESS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZDEMO_BDC_SESS.
*report ZDEMO11
*       no standard page heading line-size 255.

data :   it_demo TYPE TABLE OF zapc,
         wa_demo type zapc.
data : it_bdcdata type TABLE OF bdcdata,
       wa_bdcdata type bdcdata.

DATA : V_FILE TYPE LOCALFILE.
parameter : pa_file type rlgrap-filename.
DATA :it_excel TYPE STANDARD TABLE OF alsmex_tabline,
      WA_excel TYPE  alsmex_tabline.
at SELECTION-SCREEN on VALUE-REQUEST FOR pa_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = ' '
    IMPORTING
      file_name     = pa_file.

V_FILE = PA_FILE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  EXPORTING
    filename                      = v_FILE
    i_begin_col                   = 1
    i_begin_row                   = 2
    i_end_col                     = 2
    i_end_row                     = 500
  tables
    intern                        = IT_EXCEL
* EXCEPTIONS
*   INCONSISTENT_PARAMETERS       = 1
*   UPLOAD_OLE                    = 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.

start-of-selection.
SORT it_excel BY row col.
  LOOP AT it_excel INTO wa_excel.
    CASE wa_excel-col.
      WHEN '0001'.
        wa_DEMO-EID = wa_excel-value.
      WHEN '0002'.
        wa_DEMO-NAME = wa_excel-value.
        AT END OF row.
          APPEND wa_DEMO TO it_DEMO.
          CLEAR wa_DEMO.
        ENDAT.
    ENDCASE.
  ENDLOOP.

CALL FUNCTION 'BDC_OPEN_GROUP'
 EXPORTING
   GROUP                     = 'SESS1'
   KEEP                      = 'X'
   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
          .

loop at it_demo into wa_demo.
perform bdc_dynpro      using 'ZDEMO_BDC' '9000'.
perform bdc_field       using 'BDC_CURSOR'
                              'ZAPC-EID'.
perform bdc_field       using 'ZAPC-EID'
                              wa_demo-eid.
perform bdc_field       using 'ZAPC-NAME'
                              wa_demo-name.
perform bdc_field       using 'BDC_OKCODE'
                              '=SUBMIT'.
perform bdc_dynpro      using 'ZDEMO_BDC' '9000'.
perform bdc_field       using 'BDC_OKCODE'
                              '=BACK'.
CALL FUNCTION 'BDC_INSERT'
 EXPORTING
   TCODE                  = 'ZAPC11'
  TABLES
    dynprotab              = it_bdcdata
 EXCEPTIONS
   INTERNAL_ERROR         = 1
   NOT_OPEN               = 2
   QUEUE_ERROR            = 3
   TCODE_INVALID          = 4
   PRINTING_INVALID       = 5
   POSTING_INVALID        = 6
   OTHERS                 = 7
          .
endloop.

CALL FUNCTION 'BDC_CLOSE_GROUP'
 EXCEPTIONS
   NOT_OPEN          = 1
   QUEUE_ERROR       = 2
   OTHERS            = 3
          .

form bdc_dynpro using PROGRAM DYNPRO.
  CLEAR WA_BDCDATA.
  wa_bdcdata-program  = program.
  wa_bdcdata-dynpro   = dynpro.
  wa_bdcdata-dynbegin = 'X'.
  APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.

form bdc_field using fnam fval.
  clear wa_bdcdata.
  wa_bdcdata-fnam = fnam.
  wa_bdcdata-fval = fval.
  append wa_bdcdata to it_bdcdata.
endform.

You might also like