Saturday, 12 July 2014

BDC using CALL TRANSACTION METHOD in SAP ABAP

   1)      The first step in the program is to do the recording. Recording is the process in which we record the steps by means of codes. So after doing recording a file will be generated. We use this file or I should say codes in our program. Then the question arises that why we need to do the recording and get the file?? The answer is that bdc is done when we have to upload a large no of  data in sap like 1000’s or more , and creating these many entries one by one manually is not possible .so in bdc what we do is we create one entry manually and record the process . this recording is used in the program in a loop to make rest of the entries.just the values will be different each time.
So for creating a recording the do following steps-
A)     Go to transaction “ SHDB”. U will get following screen

B)      click on “ NEW RECORDING”  u will get this window. Fill the name of recording in  the first , I have given name “DEMO1”. In the 2nd field i.e transaction code give  the name of the transaction which is to be performed, I have given “MM01” which is for creating materials. Then click “START RECORDING”.
   



C)      I will show the recording of "MM01" .
    

I have selected the following. then press enter to move to 2nd screen.
Select “BASIC DATA 1”. Click ok.



Next screen will be like this.


Fill in following fields.



Press enter. The recording will be generated. now  Click on “ SAVE” and then on “BACK” buttons at the top.




d) Now select the recording and click on “PROGRAM”.





e) Now give the name of a program(new one). And click on OK.



Give description of program and click on “ SOURCE CODE” at the bottom.








f) The Following code will get copied in the program.

  

   2)      Now we have to do the coding part. The first thing that is to be done is that at the top one include will be there naming  “BDCRECX1” this is standard include. we will not use this perform so  we will get the useful things from this perform and will delete this perform.  we will also delete the parameter “ DATASET” as we will not use it. So We have to go inside the include and scroll to bottom . There bottom two performs  we have to copy and paste in the main program.  Then delete the include. in one perform there will be “ NO DATA” delete it and give   ‘   ‘. As highlighted.


   3)      Now we will declare our structure according to the recording. And then create internal tables and work area. We will not use the automatically generated structure. So will delete the data declaration. We will declare like this. This is the structure to bring the data from excel sheet.


   4)      For handling the messages generated during the bdc we need to declare structure  like this. The messages generated will be stored in the structure.


    5)      We have to declare data type for  the bdc and the  messages generated. Like this


   6)      Now we will declare the internal tables and work  areas  .


Here the 1st one will be used for a function module which will allow us to select the excel file from presentation server(desktop).
2nd and 3rd are for storing the data.
4th and 5th are for capturing the messages  using the standard table i.e bdcmsgcoll.
6th ,7th  and 8th are used to display the messages in a string format.
9th (variable) will be used in the loop.

   7)      This structure will be used  in the function module  which will bring data from excel sheet to internal table.

   8)      Creating selection screen. Here no need to remember the  parameter type  just go  inside the function “F4_FILENAME”  and see the export parameter type it is “IBIPPARMS-PATH” so we are using it.


   9)      Calling function to give option to select excel file from desktop.


   10)    Calling function to bring data from excel sheet to internal table.

   11)   Logic for loop and use of recording


Replace the hard-coding starting from “RECORD” to field of work area. like this


   12)   Use “CALL TRANSACTION METHOD”


   13)   Implement the message capturing and displaying.

   14)   Now prepare the excel sheet. I will use this excel file


   15)   Run program and select the excel sheet and execute. The output will be something like this.

   16)   To check the created material go to “MM03” enter the material no . the details will be like this



   17)   Full program code-

DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.
*       messages of call transaction
DATA:   MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
TYPES : BEGIN OF ty_excel,
          mbrsh TYPE mbrsh,
          mtart TYPE mtart,
          maktx TYPE maktx,
          matkl TYPE matkl,
          meins TYPE meins,
        END OF ty_excel.


TYPES: BEGIN OF ty_mes_res,
       message TYPE string,
     END OF ty_mes_res.
DATA:
        gv_name   TYPE rlgrap-filename,
        git_upl   TYPE STANDARD TABLE OF ty_excel,
        gwa_upl   TYPE ty_excel,
        git_mess  TYPE STANDARD TABLE OF bdcmsgcoll,
        gwa_mess  TYPE bdcmsgcoll,
        git_mes_res TYPE STANDARD TABLE OF ty_mes_res,
        gwa_mes_res TYPE ty_mes_res,
        gv_msg     TYPE string,
        gv_row_num TYPE char2.

TYPES: FS_STRUCT(4096) TYPE C OCCURS 0.
DATA: G_DAT TYPE FS_STRUCT .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file TYPE ibipparms-path.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
*     FIELD_NAME    = ' '
    IMPORTING
      file_name     = p_file.

AT SELECTION-SCREEN.

  gv_name = p_file.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR          =
*     I_LINE_HEADER              =
      I_TAB_RAW_DATA             = G_DAT
      I_FILENAME                 = p_file
    TABLES
      I_TAB_CONVERTED_DATA       = git_upl
*   EXCEPTIONS
*     CONVERSION_FAILED          = 1
*     OTHERS                     = 2
            .
  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.

  LOOP AT git_upl INTO gwa_upl.
    MOVE sy-tabix TO gv_row_num .
    REFRESH bdcdata.


    perform bdc_dynpro      using 'SAPLMGMM' '0060'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RMMG1-MTART'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_field       using 'RMMG1-MBRSH'
                                  gwa_upl-mbrsh."record-MBRSH_001.
    perform bdc_field       using 'RMMG1-MTART'
                                  gwa_upl-mtart."record-MTART_002.
    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)'
                                  'X'."record-KZSEL_01_003.
    perform bdc_dynpro      using 'SAPLMGMM' '4004'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_field       using 'MAKT-MAKTX'
                                  gwa_upl-maktx."record-MAKTX_004.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MARA-MATKL'.
    perform bdc_field       using 'MARA-MEINS'
                                  gwa_upl-meins."record-MEINS_005.
    perform bdc_field       using 'MARA-MATKL'
                                  gwa_upl-matkl."record-MATKL_006.
    perform bdc_dynpro      using 'SAPLSPO1' '0300'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=YES'.

    REFRESH : git_mess,git_mes_res.
    CALL TRANSACTION 'MM01'
         USING bdcdata
         MODE 'N'
         UPDATE 'S'
         MESSAGES INTO git_mess.

    LOOP AT git_mess INTO gwa_mess.
      CLEAR gv_msg.
      CALL FUNCTION 'FORMAT_MESSAGE'
        EXPORTING
          id   = gwa_mess-msgid
          lang = '-D'
          no   = gwa_mess-msgnr
          v1   = gwa_mess-msgv1
*         V2   = SY-MSGV2
*         V3   = SY-MSGV3
          v4   = gwa_mess-msgv4
        IMPORTING
          msg  = gv_msg.
      MOVE gv_msg TO gwa_mes_res-message.
      APPEND gwa_mes_res TO git_mes_res.
      CLEAR : gwa_mes_res,gwa_mess.
    ENDLOOP.
    CONDENSE gv_row_num.
    LOOP AT git_mes_res INTO gwa_mes_res.
      WRITE : / 'Record -', gv_row_num,'|', gwa_upl-maktx HOTSPOT ON, '|', gwa_mes_res-message COLOR 3.
      HIDE gwa_upl-maktx.
    ENDLOOP.
    CLEAR :gv_row_num,gwa_upl.
  ENDLOOP.

*perform close_group.
*perform close_dataset using dataset.
*  ----------------------------------------------------------------------*
*        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.
  IF FVAL <> ''.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
  ENDIF.
ENDFORM.                    "BDC_FIELD






7 comments:

  1. Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
    SAP ABAP TRAINING IN HYDERABAD

    ReplyDelete
  2. Hi can u please post how to do error hqndlhan in thus program

    ReplyDelete
  3. Also add screen resolution rather than all is good. nice blog

    ReplyDelete
  4. Thank you very much!!! Good explanation !!!

    ReplyDelete
  5. GRILGRIDGE BABY, INC - Online gambling website darkgg.app
    GRILGRIDGE BABY, INC. (company 쏘걸 number 카지노사이트 A1401), Company Details: EBC: SEPAHOGA, Inc. is a gambling website in California, Google Play, SEGA, Microsoft. 2022.6.19

    ReplyDelete