✒️ABAP El Batch Input utilizando el Juego de datos
ABAP El Batch Input utilizando el Juego de datos
Batch Input with Data Set
This program guides through the process of batch input with a dataset. It involves the following steps:
- Step 1 - Declaration of Batch Input Specific Data: The data type TY_BDCDATA is declared, and with that type, the internal table and the structure BDCDATA are declared. Additionally, another internal table is declared to contain the records that will be read from the input file
* Internal table for BI with the structure of BDCDATA
TYPES: BEGIN OF ty_bdcdata,
program TYPE bdc_prog,
dynpro TYPE bdc_dynr,
dynbegin TYPE bdc_start,
fnam TYPE fnam_____4,
fval TYPE bdc_fval,
END OF ty_bdcdata.
* Internal table and structure for BI
DATA: ti_bdcdata TYPE STANDARD TABLE OF ty_bdcdata,
wa_bdcdata TYPE bdcdata.
* Internal table for users
DATA: ti_archivo TYPE STANDARD TABLE OF ztabla_usuarios,
wa_archivo LIKE LINE OF ti_archivo.
- Step 2 - Reading data from the input file: involves executing the GUI_UPLOAD method within the CL_GUI_FRONTEND_SERVICES class to load the input file containing the information necessary for generating the batch input.
*&---------------------------------------------------------------------*
*& 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 - Opening the dataset session: To open the dataset session, we will use the function module BDC_OPEN_GROUP specifying the client, group, and user.
*&---------------------------------------------------------------------*
*& Form OPEN_DATASET_SESSION
*&---------------------------------------------------------------------*
* This form opens the dataset session.
*----------------------------------------------------------------------*
FORM open_dataset_session.
v_group = sy-repid.
* Call function module BDC_OPEN_GROUP to open
* the dataset session, specifying client, group, and user.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = v_group
keep = 'X'
user = sy-uname
IMPORTING
qid = v_qid
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " OPEN_DATASET_SESSION
- Step 4 - Loading the BDCDATA internal table: To load the BDCDATA internal table, we will use the subroutine FILL_BDCDATA_TABLE. Before that, we need to initialize the Batch Input internal table.
*&---------------------------------------------------------------------*
*& 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 5 - Inserting the dataset: To perform the dataset insertion, we will use the function module BDC_INSERT.
*&---------------------------------------------------------------------*
*& Form INSERT_DATASET
*&---------------------------------------------------------------------*
* This form inserts the dataset.
*----------------------------------------------------------------------*
FORM insert_dataset.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = c_sm30
TABLES
dynprotab = ti_bdcdata
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* The dataset has been launched, verify it in transaction SM35.
MESSAGE s000(z_prueba) WITH text-010 text-011.
ENDIF.
ENDFORM. " INSERT_DATASET
- Step 6 - Closing the dataset session: To close the dataset session, we will use the function module BDC_CLOSE_GROUP.
*&---------------------------------------------------------------------*
*& Form CLOSE_DATASET_SESSION
*&---------------------------------------------------------------------*
* This form closes the dataset session.
*----------------------------------------------------------------------*
FORM close_dataset_session.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 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.
ENDFORM. " CLOSE_DATASET_SESSION
- Step 7 - Executing the dataset: The ABAP program is executed, and access to transaction SM35 is obtained. Through call transaction, processing is synchronous or online, data is transferred to only one transaction, locks are not generated, and the dataset is asynchronous or background, data is transferred to multiple transactions, and locks are generated for each session.
Using RSBDCBTC for Batch Input Execution:
Execute Batch Input online by invoking standard program RSBDCBTC. To do this, a job is created using the job_open function module. Afterward, the execution of the standard program RSBDCBTC is submitted, and the job is closed using the job_close function module.
*&---------------------------------------------------------------------*
*& Form PROCESS_ONLINE
*&---------------------------------------------------------------------*
*& This form processes the dataset online.
*&---------------------------------------------------------------------*
FORM process_online.
* Assign a name to the job
v_jobname = 'ZPRUEBA_ABAP'.
v_jobgroup = v_jobname.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobgroup = v_jobgroup
jobname = v_jobname
IMPORTING
jobcount = v_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
SUBMIT rsbdcbtc
USER sy-uname
VIA JOB v_jobgroup
NUMBER v_jobcount
WITH queue_id = v_qid
WITH mappe = v_jobgroup
WITH modus = c_n "No display
WITH logall = ''
AND RETURN.
IF sy-subrc EQ 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = v_jobcount
jobname = v_jobname
strtimmed = c_x
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
invalid_target = 8
OTHERS = 9.
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.
ENDIF.
ENDIF.
ENDFORM. " PROCESS_ONLINE
 
 
 
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