Ir al contenido principal

Procesos Paralelos en ABAP / ABAP Parallel Processing

 Cierta vez un cliente en USA, que administra grandes volúmenes de información, me pidió que haga el proceso utilizando esta técnica, Parallel Processing, claramente no la conozco, asique busque un código en la web para adaptarlo, lo utilicé, y claramente no me andaba. Así que paso unos tips, y mi ajuste al mismo.

1- Seudocódigo: básicamente es dividir el trabajo en pequeñas tareas (tasks), e ir enviando a una función del tipo RFC, a medida que se procesan va preguntando un comparador, contra el sumador de tareas, para finalizar el programa. La idea es que se utilice con un JOB programado y se ejecute en horarios donde el servidor pueda estar con recursos plenos.

2 - Por un tipo de datos en el Form "update_status" no me funcionaba, y no podia detectar que era, pero paso el codigo arreglado el ajuste --> (form update_status using lv_task type clike ).


data wa_data type zzaaa_emp,
       it_data 
type standard table of zzaaa_emp,                              " internal table with contentss - CSK
       it_data_temp 
type standard table of zzaaa_emp.                         " Internal table to store the content to be processed

data lv_appsvr type rzllitab-classname value 'parallel_generators'.         " All the application servers assinged to an instance
" are grouped in the table rzllitab "       You can see the instance data's in tcode rz12

data lv_total     type i,                                                   " Total no of dialog work process available in the group server
       lv_available 
type i,                                                   " No of dialog work process that are free.
       lv_occupied  
type i,                                                   " No of occupied dialog process
       lv_diff      
type i,                                                   " Percentage difference of available work process
       lv_split     
type i.                                                   " No of partitions the main data is to be split

data lv_lines type i,                                                       " No of records in the internal table
       lv_lines_tab 
type i,                                                   " No of lines per tab
       lv_start 
type i,                                                       " Start point for processing
       lv_end 
type i.                                                         " End point for processing

data lv_task type string,                                                   " Name of the task to be created
       lv_index 
type string,                                                  " Variable for index
       lv_sent  
type i,                                                       " No of package sent
       lv_comp  
type i,                                                       " No of package completed
       lv_result 
type flag.                                                   " Variable to collect the result.

data lv_result_string TYPE string.                                          " Result string

start-of-selection.

* Call the function module spbt_initialize the list of application server available and those that are free

  
call function 'SPBT_INITIALIZE'
    
exporting
      group_name                     
lv_appsvr
    
importing

      max_pbt_wps                    
lv_total
      free_pbt_wps                   
lv_available
    
exceptions

      invalid_group_name             
1
      internal_error                 
2
      pbt_env_already_initialized    
3
      currently_no_resources_avail   
4
      no_pbt_resources_found         
5
      cant_init_different_pbt_groups 
6
      
others                         7.
  
if sy-subrc 0.

* Split the data to be processed into no of work processes.

    lv_occupied 
lv_total lv_available.

* Calculate the difference in percentage

    lv_diff 
= ( lv_available * 100 / lv_total.

* Based on the available no of workprocess split the data

    
if lv_diff <= 25.

      lv_split 
lv_available div 2.

    
elseif lv_diff between 25 and 50.

      lv_split 
lv_available * div 3.

    
elseif lv_diff >= 50.

      lv_split 
lv_available * div 4.

    
endif.

  
endif.

* Dummy data generation

  
do 1000 times.
    wa_data
-mandt sy-mandt.
    wa_data
-field1 sy-index.
    
append wa_data to it_data.
  
enddo.


* Split the internal table accordingly.

  lv_lines 
linesit_data ).

  lv_lines_tab 
lv_lines / lv_split.

  
do lv_split times.

    lv_index 
sy-index.

    
concatenate 'task' lv_index into lv_task.

    lv_start 
lv_start + lv_lines_tab.
    lv_end   
lv_lines_tab + 1.

    
if lv_index 1.
      lv_start 
0.
    
endif.

    
if lv_split lv_index.
      lv_end 
0.
    
endif.

    it_data_temp[] 
=  it_data[].

    
if lv_start is not initial.
      
delete it_data_temp to lv_start.
    
endif.

    
if lv_end is not initial.
      
delete it_data_temp from lv_end.
    
endif.

* Process the record set
* Call the function module to update the data.
* Here each and everytime the function module is called it will be called in a dialog work process that is free
    
call function 'ZCSK_PARALLEL_TABLE_UPDATE' starting new task lv_task destination in group lv_appsvr
      performing update_status 
on end of task

      
tables
        
data it_data_temp.

    
if sy-subrc 0.

      lv_sent 
lv_sent + 1.

    
endif.

  
enddo.


  
WAIT UNTIL lv_comp >= lv_sent.

  
write 'The no of packets sent' lv_sent,
            
'The no of packets completed'lv_comp.



*&---------------------------------------------------------------------*
*&      Form  UPDATE_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATA  text
*      -->P_=  text
*      -->P_IT_DATA_TEMP  text
*----------------------------------------------------------------------*
form update_status using lv_task type 
clike.


  lv_comp 
lv_comp + 1.

  
receive results from function 'ZCSK_PARALLEL_TABLE_UPDATE'
  
importing
    lv_result 
lv_result.

  
if lv_result is initial.
    lv_result_string 
'Success'.
  
else.
    lv_result_string 
'Failure'.
  
endif.

  
concatenate 'The data passed via task' lv_task 'updation is' lv_result_string into lv_result_string separated by space.

  
write / lv_result_string.

endform.                    " UPDATE_STATUS




Fuente:

http://www.teamabap.com/2014/05/parallel-processing-in-abap.html


Comentarios

Entradas más populares de este blog

A to Z of OLE Excel in ABAP 7.4

  SAP users, both business and end users always need to download the output of a report to spreadsheet and do their analytics.   The standard excel output from a report is very simple process but it is old fashioned and the spreadsheet looks quite boring.  There is no default formatting and the users have to do all the hard work of changing the fonts, coloring the texts, marking the borders etc. Updated 16th Aug 2019  –  If you are working in non-ABAP 7.4 (below), there is complete reference program for you too. Go to the end of this article.  Thank you  Legxis  ( LeonievonK ) for the share. I acknowledge, whatever I mentioned above can be achieved in many ways programmatically. We can do it in the old traditional ABAP way but  providing multiple tabs in the spreadsheet and formatting is quite tricky with non  OLE  method. OLE = Object Linking and Embedding The high level agenda of this article is to be the  G.O.A.T.  (please google it if you do not know the full form)  of OLE Excel Gu
How to add custom field in Additional B Tab for SAP Sales Order In this article we want to explain step by step how to add custom field in SAP Sales Order transaction VA01/VA02/VA03. This time Mr ABAPGurus will give the tutorial of enhancement to add custom field in SAP Sales order. In this sample we will add new custom field for comments and customer satisfaction, this data will save into separate table from SAP Standard table ( VBAK / VBAP ). SAP provided us with ADDITIONAL TAB in the sales order transaction ( VA01/VA02/VA03 ) which allow customer to add custom fields.  T he different between ADDITIONAL A and ADDITIONAL B is the ADDITIONAL A for field which already predefine in Sales Order Header ( VBAK ) fields and ADDITIONAL B is for field that freely define. This sample we will use ADDITIONAL B because we will store data from customer satisfaction into Z database table. 1. Create one Z table using SE11 SAP Transaction code. 2.Using SE38 Transaction code and ope

VOFM

Creating VOFM custom routine, functionality same as SAP standard routine 103 with Additional Functionality 1.    Introduction 1.1   Document Purpose 1.2    This is the document helps you to create custom routine for sales order for below specific requirement: Functional description: In case of sale order with the SD document category ‘K’ or ‘L’ or ‘H’ related to an invoice, we need to fill the fixed value date (VBKD_VALDT) with the billing reference date (VBRK_FKDAT). For example: Invoice 90001111, the billing date is 22.07.2013 If we create a sale order related to this invoice, we want the fixed value date equal to the billing reference date. As per the requirement: Sap standard routine ‘103’ triggers whenever sales order is being created with reference. Sap standard routine is configured in VOFM transaction as: Sap standard routine ‘103’ has the functionality of copying the billing document header data and billing document line item data into the