✒️ABAP El Batch Input utilizando Call transaction
ABAP El Batch Input utilizando Call transaction
Batch Input using CALL TRANSACTION
The objective of BI is the initial data load into a Z table, in this case ZUSER_TABLE. For this, we need to have a text file with records that match the structure of the database table. Subsequently, we need to create a program with the following structure:
- STEP 1 - Declaration of BI-specific data: Declare an internal table (IT) and a structure, both of type BDCDATA. Declare another IT and a structure, both of type BDCMSGCOLL, to store the messages produced when executing the CALL TRANSACTION. The user IT will contain data lifted from the input file and a table to display errors among other declarations
BDCMSGCOLL: It's a standard system structure used to define the internal table that stores batch input messages.
* Internal table for BI with the structure of BDCDATA
DATA: BEGIN OF it_bdcdata OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END OF it_bdcdata.
* Structure for BI
DATA: wa_bdcdata TYPE bdcdata.
* Internal table for messages
DATA: BEGIN OF it_messages OCCURS 0.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF it_messages.
* Structure for messages
DATA: wa_messages TYPE bdcmsgcoll.
* Internal table for users
DATA: it_input_file TYPE STANDARD TABLE OF zuser_table,
wa_input_file LIKE LINE OF it_input_file.
- STEP 2 - Reading data from the input file: Execute the method GUI_UPLOAD of the class CL_GUI_FRONTEND_SERVICES to lift the input file with the information to generate the BI.
*&---------------------------------------------------------------------*
*& Form upload_input_file
*&---------------------------------------------------------------------*
*& Uploads the selected input file from the file system to the internal
*& table for further processing.
*&----------------------------------------------------------------------*
FORM upload_input_file.
DATA: lv_file TYPE string.
IF p_path IS INITIAL.
MESSAGE s000(z_prueba) WITH TEXT-003.
ELSE.
lv_file = p_path.
* Open the input file for reading
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_file
filetype = 'ASC'
has_field_separator = ''
CHANGING
data_tab = it_input_file[]
EXCEPTIONS
file_open_error = 1
file_read_error = 2
OTHERS = 19.
IF sy-subrc NE 0.
MESSAGE e000(z_test) WITH TEXT-004.
ENDIF.
IF it_input_file[] IS INITIAL.
MESSAGE s000(z_test) WITH TEXT-005.
ENDIF.
ENDIF.
ENDFORM. " upload_input_file
- STEP 3 - Loading the BDCDATA IT: use the subroutine FILL_BDCDATA_TABLE to load the IT. Before that, the initialization of the batch input IT and the messages table are required. Since there are many records, we need to handle indexes to know which row of the screen we are loading the data into, therfore the row number should be concatenated with the field name.
*&---------------------------------------------------------------------*
*& Form fill_bdcdata_table
*&---------------------------------------------------------------------*
* Fills the BDCDATA internal table with the required data for BDC processing.
* Parameters:
* - p_dynpro: Indicates whether it's a dynpro (X) or a field value (blank).
* - p_field1: First field value.
* - p_field2: Second field value.
*----------------------------------------------------------------------*
FORM fill_bdcdata_table USING p_dynpro TYPE c
p_field1
p_field2.
CLEAR wa_bdcdata.
IF p_dynpro EQ c_x.
wa_bdcdata-dynbegin = p_dynpro.
wa_bdcdata-program = p_field1.
wa_bdcdata-dynpro = p_field2.
ELSE.
wa_bdcdata-fnam = p_field1.
wa_bdcdata-fval = p_field2.
ENDIF.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM. " fill_bdcdata_table
*&---------------------------------------------------------------------*
*& Form LOAD_BDCDATA_TABLE
*&---------------------------------------------------------------------*
*& Description: Loads data into BDCDATA table for SAP transaction.
*&---------------------------------------------------------------------*
FORM load_bdcdata_table .
CLEAR: ti_bdcdata, ti_messages.
REFRESH: ti_bdcdata, ti_messages.
* Navigate to the initial screen and press the maintenance button.
PERFORM fill_bdcdata_table USING 'X' 'SAPMSVMA' '0100'.
PERFORM fill_bdcdata_table USING ' ' 'VIEWNAME' 'ZTABLE_USERS'.
PERFORM fill_bdcdata_table USING ' ' 'BDC_OKCODE' '=UPD'.
* Click on the new entries button.
PERFORM fill_bdcdata_table USING 'X' 'SAPLZTABLE_USERS' '0001'.
PERFORM fill_bdcdata_table USING ' ' 'BDC_OKCODE' '=NEWL'.
ADD 1 TO v_index.
PERFORM complete_leading_zeros.
* Load user data.
PERFORM fill_bdcdata_table USING 'X' 'SAPLZTABLE_USERS' '0001'.
CLEAR v_field.
CONCATENATE 'ZTABLE_USERS-DNI(' v_index ')' INTO v_field.
PERFORM fill_bdcdata_table USING ' ' v_field wa_file-dni.
CLEAR v_field.
CONCATENATE 'ZTABLE_USERS-NAME_LASTNAME(' v_index ')' INTO v_field.
PERFORM fill_bdcdata_table USING ' ' v_field wa_file-name_last.
CLEAR v_field.
CONCATENATE 'ZTABLE_USERS-USER_STATE(' v_index ')' INTO v_field.
PERFORM fill_bdcdata_table USING ' ' v_field wa_file-user_state.
CLEAR v_field.
CONCATENATE 'ZTABLE_USERS-BIRTHDATE(' v_index ')' INTO v_field.
PERFORM fill_bdcdata_table USING ' ' v_field wa_file-birthdate.
* Save the records.
PERFORM fill_bdcdata_table USING ' ' 'BDC_OKCODE' '=SAVE'.
* Close the second screen.
PERFORM fill_bdcdata_table USING 'X' 'SAPLZTABLE_USERS' '0001'.
PERFORM fill_bdcdata_table USING ' ' 'BDC_OKCODE' '=ENDE'.
* Close the initial screen.
PERFORM fill_bdcdata_table USING 'X' 'SAPMSVMA' '0100'.
PERFORM fill_bdcdata_table USING ' ' 'BDC_OKCODE' '/EENDE'.
ENDFORM. " LOAD_BDCDATA_TABLE"
- STEP 4 - Executing the CALL TRANSACTION statement:
*&---------------------------------------------------------------------*
*& Form call_sm30
*&---------------------------------------------------------------------*
*& Description: Calls transaction SM30 with specified parameters.
*&---------------------------------------------------------------------*
FORM call_sm30 .
CLEAR: it_messages, v_error.
REFRESH it_messages.
IF p_a EQ c_x.
v_mode = c_a.
ELSE.
v_mode = c_n.
ENDIF.
* Call transaction.
CALL TRANSACTION v_trans_code USING it_bdcdata
MODE v_mode
UPDATE v_update
MESSAGES INTO it_messages.
IF NOT sy-subrc IS INITIAL.
v_error = c_x.
ENDIF.
ENDFORM. " call_sm30
Let's review each of the options:
USING: Here we specify the BDCDATA IT to be used.
MODE: Determines the processing mode that BI will use. Possible modes are:
A: processing with visualization of all screens. It's the default value.
E: processing where screens are displayed only if an error occurs. If a breakpoint is reached, processing ends with SY-SUBRC = 1001. The field SY-MSGTY will contain "S", SY-MSGID will contain "00", SY-MSGNO will contain "344", SY-MSGV1 will contain "SAPMSSY3", and SY-MSGV2 will contain "0131".
N: processing where screens are not displayed.
P: processing where screens are not displayed. If a breakpoint is reached, control is passed to the debugger.
UPDATE: Determines the update mode of the fields that BI will produce. Possible modes are:
A: asynchronous update. The update is done similarly to what happens if we use the COMMIT WORK statement. Default value.
S: synchronous update. The update is done similarly to what happens if we use the COMMIT WORK AND WAIT statement.
L: local update.
MESSAGES INTO: With the use of this option, all messages generated during the BI processing are stored in an IT of type BDCMSGCOLL.
To build the messages, we use the function module MESSAGE_PREPARE.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
msg_id = v_msg_id
msg_no = v_msg_no
msg_var1 = v_msg_v1
msg_var2 = v_msg_v2
msg_var3 = v_msg_v3
msg_var4 = v_msg_v4
IMPORTING
msg_text = v_message
EXCEPTIONS
function_not_completed = 1
message_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Now that we've completed all the steps of BI, we execute it with processing mode "A", which allows us to see the step-by-step updates.
- Enter transaction SM30 with the name of the database table and press "Update".
- Click "New Entries", and the system informs that there are no entries in the table. =UPD
- Enter the fields of the record and press "Save". =NEWL and =SAVE
- Exit the dynpro where the database table record is completed. =ENDE
- Exit the initial screen and repeat the steps for the number of user records entered in the database table.
The CALL TRANSACTION statement is also used in reports to access a specific transaction based on the data entered on the screen, with the addition of the AND SKIP FIRST SCREEN clause.
Finally, if we view the contents of the ZUSER_TABLE through transaction SE16, we will verify that indeed, there are three records that are the ones we inserted into the table.
 
 
 
Sobre el autor
Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.
Jaime Eduardo Gomez Arango
Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C
✒️Autor de: 99 Publicaciones Académicas
🎓Cursando Actualmente: Consultor ABAP Nivel Avanzado
🎓Egresado del módulo:
Disponibilidad Laboral: FullTime
Presentación:
Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.
Certificación Académica de Jaime Gomez