Skip to end of metadata
Go to start of metadata

Demo program for both BI session and CTU

It is based on Flight Data Application - Demo Example for Integration Technologies. So it works on all SAP systems, whatever they are ECC, SRM, CRM, etc.

You need to call SAPBC_DATA_GENERATOR program to generate initial data.

This program creates a flight record on any existing flight (date is the maximum of existing records + 1 day).

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
report Z
       no standard page heading line-size 255.

include bdcrecx1.

start-of-selection.

TABLES sflight.
SELECT SINGLE * FROM sflight INTO sflight.
IF sy-subrc <> 0.
  MESSAGE i001(00) WITH 'Please generate flight demo data by'
  'calling SAPBC_DATA_GENERATOR program (SE38)' DISPLAY LIKE 'E'.
  EXIT.
ENDIF.
SELECT max( fldate ) FROM sflight INTO sflight-fldate
      WHERE carrid = sflight-carrid
        AND connid = sflight-connid.
ADD 1 TO sflight-fldate.
DATA l_connid TYPE c LENGTH 4.
l_connid = sflight-connid.
DATA l_date TYPE c LENGTH 10.
WRITE sflight-fldate TO l_date.

perform open_group.

perform bdc_dynpro using 'SAPBC_GLOBAL_SFLIGHT_CREATE' '0100'.
perform bdc_field  using 'BDC_CURSOR'      'SFLIGHT-FLDATE'.
perform bdc_field  using 'BDC_OKCODE'      '/00'.
perform bdc_field  using 'SFLIGHT-CARRID'  sflight-carrid.
perform bdc_field  using 'SFLIGHT-CONNID'  l_connid.
perform bdc_field  using 'SFLIGHT-FLDATE'  l_date.

perform bdc_dynpro using 'SAPBC_GLOBAL_SFLIGHT_CREATE' '0200'.
perform bdc_field  using 'BDC_CURSOR'        'SFLIGHT-PLANETYPE'.
perform bdc_field  using 'BDC_OKCODE'        '=SAVE'.
perform bdc_field  using 'SFLIGHT-PRICE'     '7'.
perform bdc_field  using 'SFLIGHT-PLANETYPE' '747-400'.

perform bdc_transaction using 'BC_GLOBAL_SFLGH_CREA'.

perform close_group.

Example when running using CTU method and "Display all screens" method:

Sample Code for Call Transaction Using (CTU) method

 TYPES:   BEGIN OF t_employee,
         pernr        TYPE    p0002-pernr, "Employee Number
         midnm        TYPE    p0002-midnm, "mid name
         rufnm        TYPE    p0002-rufnm, "nick name
         begda(10)    TYPE   c,
         endda(10)    TYPE   c,
        END OF t_employee.  
DATA:   it_employee   TYPE  STANDARD TABLE OF t_employee,
        wa_employee   TYPE t_employee,
        it_bdcdata    TYPE bdcdata OCCURS 0 WITH HEADER LINE ,
        i_file_path   TYPE localfile,
        file_name     TYPE string,
        I_SESSIONNAME(12TYPE c

SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE title1.
  SELECTION-SCREEN COMMENT 1(10) txt_01.
  PARAMETERS p_fname TYPE rlgrap-filename OBLIGATORY.
  PARAMETERS p_sess LIKE APQI-GROUPID .
SELECTION-SCREEN END OF BLOCK bk1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
  CLEAR i_file_path.
  PERFORM select_input_file_name.
  MOVE i_file_path TO p_fname.
  file_name = p_fname.

START-OF-SELECTION.

PERFORM BDC_CALL_TRANSACTION_METHOD
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename            = file_name
      filetype            = 'ASC'
      has_field_separator = 'X'
    TABLES
      data_tab            = it_employee.
FORM BDC_CALL_TRANSACTION.
    LOOP AT it_employee INTO wa_employee.

      PERFORM bdc_dynpro      USING 'SAPMP50A' '1000'.

      PERFORM bdc_field       USING 'RP50G-PERNR'
                                    wa_employee-pernr.
      PERFORM bdc_field       USING 'RP50G-TIMR6'
                                    'X'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RP50G-CHOIC'.
      PERFORM bdc_field       USING 'RP50G-CHOIC'
                                    '0002'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=MOD'.
      PERFORM bdc_dynpro      USING 'MP000200' '2044'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'P0002-RUFNM'.

      PERFORM bdc_field       USING 'P0002-BEGDA'
                                    wa_employee-begda.
      PERFORM bdc_field       USING 'P0002-ENDDA'
                                    wa_employee-endda.

      PERFORM bdc_field       USING 'P0002-MIDNM'
                                    wa_employee-midnm.
      PERFORM bdc_field       USING 'P0002-RUFNM'
                                   wa_employee-rufnm.

      CALL TRANSACTION 'PA30' USING it_bdcdata
                                MODE 'A'
                                UPDATE 's'.
     REFRESH it_bdcdata.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  select_input_file_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_input_file_name.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = sy-repid
      dynpro_number = sy-dynnr
      field_name    = 'PATH'
    IMPORTING
      file_name     = i_file_path.

ENDFORM.                    "select_input_file_name

*&---------------------------------------------------------------------*
*&      Form BDC_DYNPRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PROG       text
*      -->SCR        text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING prog scr.
  CLEAR it_bdcdata.
  it_bdcdata-program = prog.
  it_bdcdata-dynpro  = scr.
  it_bdcdata-dynbegin = 'X'.
  APPEND it_bdcdata.
ENDFORM.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FNAM       text
*      -->FVAL       text
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  CLEAR it_bdcdata.
  it_bdcdata-fnam = fnam.
  it_bdcdata-fval  = fval.
  APPEND it_bdcdata.
ENDFORM.                    "BDC_FIELD

Sample Code for Batch Input Session method

Copy the previous program, and call the following routine BDC_BATCH_INPUT_SESSION instead of calling BDC_CALL_TRANSACTION_METHOD.

 FORM BDC_BATCH_INPUT_SESSION.

  CALL FUNCTION 'BDC_OPEN_GROUP'
       EXPORTING
              CLIENT              = SY-MANDT
              GROUP               = I_SESSIONNAME
              USER                = SY-UNAME
              KEEP                = 'X'
         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.

    
* BDC Insert
LOOP AT it_employee INTO wa_employee.

      PERFORM bdc_dynpro      USING 'SAPMP50A' '1000'.

      PERFORM bdc_field       USING 'RP50G-PERNR'
                                    wa_employee-pernr.
      PERFORM bdc_field       USING 'RP50G-TIMR6'
                                    'X'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RP50G-CHOIC'.
      PERFORM bdc_field       USING 'RP50G-CHOIC'
                                    '0002'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=MOD'.
      PERFORM bdc_dynpro      USING 'MP000200' '2044'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'P0002-RUFNM'.

      PERFORM bdc_field       USING 'P0002-BEGDA'
                                    wa_employee-begda.
      PERFORM bdc_field       USING 'P0002-ENDDA'
                                    wa_employee-endda.

      PERFORM bdc_field       USING 'P0002-MIDNM'
                                    wa_employee-midnm.
      PERFORM bdc_field       USING 'P0002-RUFNM'
                                   wa_employee-rufnm.

CALL FUNCTION 'BDC_INSERT'
         EXPORTING
              TCODE            = 'PA30'
         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.
clear it_bdcdata.

    ENDLOOP.
  

* Closing Batch Input

    CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDFORM.

  • No labels