Batch Input - aidamate13/AMS-Knowledge-Base GitHub Wiki

Uploading Material Data Using Call Transaction Method

1. Call Transaction Method

Call transaction β€˜Transaction Code’ using ( BDC Internal table ) mode β€˜A or N or E’ update β€˜A or S or L’ messages into ( internal table ).

Processing Modes β†’

A -> All screen ( It will show by screen processing ) N -> No Screen ( It will not show any screen, directly we will get a output). E -> Error (If there is a error in BDC - It will show the screen where the error is, If there is no Error - It will not show any screen )

Updates Modes β†’

A -> Asynchronous ( commit work) The called transaction does not wait for any updates to be completed. Results in faster execution of the data transfer program.

S -> Synchornous (Sync between the sender and reciever , COMMIT WORK AND WAIT ) The called transaction waits for sny updates that it produces to be completed. Execution is slower that with asynchronous updating because called transaction wait for updating to be completed.

P1 P2 Sender Reciever Called Calling

L -> Local Update If the data is updated locally, the update of the database will not be processed in a separarte process, the update functions are run in the same dialog process.

Steps

i) Click on SHDB T_CODE.

iii) Click on new recording β†’ give a name β†’ give t code MM01 β†’ start recording

iv)

image

v) Press enter β†’ select basic data 1 β†’ press enter β†’ give short description β†’ Give Base unit of measure as EA β†’ click on save

vi ) select the recording click on program β†’ give program name β†’ transfer from recording β†’ click on ok β†’ ABAP editor will open β†’ give short description and click on source code β†’ a program will open denoting all the screen recording

Requirements

β†’ Taking data from user inform of Notepad

i)We will take parameters to take user input and use event AT selection screen value request.

ii) Then we will call function module F4_FILENAME or method FILE_OPEN_DIALOG of class CL_GUI_FRONTEND_SERVICES β†’ it returns the path of a file.

parameters : p_file type localfile. "To perform any action on selection request At SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

*Calling function module F4_FILENAME -> returns the path of file

CALL FUNCTION 'F4_FILENAME' EXPORTING PROGRAM_NAME = SYST-CPROG DYNPRO_NUMBER = SYST-DYNNR FIELD_NAME = ' ' IMPORTING FILE_NAME = p_file. iii) Write start-of-selection event to execute

Requirement :- To read the file

i) Call function module GUI_UPLOAD or method GUI_UPLOAD of class CL_GUI_FRONTEND_SERVICES

ii) create a type structure of all the fields of uploaded and file and define internal table and work area respectively.

iii)filename type is string, therefore we need to perform explicit type casting of our uploaded file, otherwise it will generate type conflict error at runtime.

report ZAR_MM01_RE1
       no standard page heading line-size 255.

types: begin of ty_bcd,
    matnr type matnr,
    mbrsh type mbrsh,
    mtart type mtart,
    maktx type maktx,
    meins type meins,
end of ty_bcd.

data: lt_file type table of FILE_TABLE,
      ls_file type FILE_TABLE,
       lv_rc type i,
       lv_file type string,
       lt_bcd type table of ty_bcd,
       ls_bcd type ty_bcd,
       lv_message type string,
       lt_message type table of string.

DATA:   lt_BDCDATA type table of BDCDATA,
        ls_BDCDATA type BDCDATA.
DATA: lt_messtab type table of BDCMSGCOLL,
      ls_messtab type BDCMSGCOLL.

PARAMETERS : p_file type localfile.

***********************************
ls_file-filename = p_file.
append ls_file to lt_file.
clear ls_file.
"Providing a search help.
At SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
  EXPORTING
    window_title            = 'Please Select your file'
  CHANGING
    file_table              = lt_file
    rc                      = lv_rc
  EXCEPTIONS
    file_open_dialog_failed = 1
    cntl_error              = 2
    error_no_gui            = 3
    not_supported_by_gui    = 4
    others                  = 5
        .

read table lt_file into ls_file index 1.
if sy-subrc eq 0.
   lv_file = ls_file-filename.
   clear ls_file.
endif.

START-OF-SELECTION.
*********************************
*Uploading the data using gui_upload of cl_gui_frontend_Services
CALL METHOD cl_gui_frontend_services=>gui_upload
  EXPORTING
    filename                = lv_file
    has_field_separator     = 'X'
  CHANGING
    data_tab                = lt_bcd
  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
    not_supported_by_gui    = 17
    error_no_gui            = 18
    others                  = 19
        .

* Include bdcrecx1_s:
* The call transaction using is called WITH AUTHORITY-CHECK!
* If you have own auth.-checks you can use include bdcrecx1 instead.
*include bdcrecx1_s.
*
*start-of-selection.
*
loop at lt_bcd into ls_bcd.
*perform open_group.

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MTART'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
perform bdc_field       using 'RMMG1-MBRSH'
                              ls_bcd-mbrsh.
perform bdc_field       using 'RMMG1-MTART'
                              ls_bcd-mtart.
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'.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '=BU'.
perform bdc_field       using 'MAKT-MAKTX'
                              ls_bcd-maktx.
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'
                              ls_bcd-meins.
*perform bdc_transaction using 'MM01'.

*perform close_group.

CALL TRANSACTION 'MM01' using lt_bdcdata MODE 'A' UPDATE 'S' MESSAGES INTO lt_messtab.

ENDLOOP.

*********************************
*To display the message
loop at lt_messtab into ls_messtab.
  CALL FUNCTION 'MESSAGE_TEXT_BUILD'
    EXPORTING
      msgid                     = ls_messtab-msgid
      msgnr                     = ls_messtab-msgnr
     MSGV1                     = ls_messtab-msgv1
     MSGV2                     = ls_messtab-msgv2
     MSGV3                     = ls_messtab-msgv3
     MSGV4                     = ls_messtab-msgv4
   IMPORTING
     MESSAGE_TEXT_OUTPUT       = lv_message.
            .
   write :/ lv_message.

endloop.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR ls_BDCDATA.
  ls_BDCDATA-PROGRAM  = PROGRAM.
  ls_BDCDATA-DYNPRO   = DYNPRO.
  ls_BDCDATA-DYNBEGIN = 'X'.
  APPEND ls_BDCDATA to lt_BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
    CLEAR ls_BDCDATA.
    ls_BDCDATA-FNAM = FNAM.
    ls_BDCDATA-FVAL = FVAL.
    APPEND ls_BDCDATA to lt_BDCDATA.
ENDFORM.