2013 Feb 14 1:29 PM
Hi at all,
I developed the following program:
FORM read_zbatpusrlog.
FIELD-SYMBOLS: <lfs_zbatran> LIKE LINE OF i_zbatrans,
<lfs_zbafreigabelog>
LIKE LINE OF i_zbafreigabe.
DATA: lw_condition TYPE string,
lw_cond_user TYPE string,
lw_type_col TYPE string,
lwa_zbavorablog LIKE LINE OF i_zba_vorab_log,
lwa_zbafreigabelog LIKE LINE OF i_zba_vorab_log,
lwa_count TYPE c LENGTH 1.
LOOP AT i_zbatrans ASSIGNING <lfs_zbatran>.
CLEAR: lw_condition, lwa_zbafreigabelog, lwa_count.
REFRESH: i_zbafreigabe, i_zvorab_with_enduser, i_zvorab,
i_zba_vorab_log.
*&---------------------------------------------------------------*
* 1) Search string Repid starting with: ZBATPREL FREIGABE mit Typ
*&---------------------------------------------------------------*
CONCATENATE 'ZBATPREL FREIGABE mit Typ%' "#EC NOTEXT
<lfs_zbatran>-trkorr '%' INTO lw_condition.
*&---------------------------------------------------------------*
* Select all element of table zbatpusrlog with have
* in the field REPID ZBATPREL FREIGABE mit Typ + transport num.
*&---------------------------------------------------------------*
SELECT datum uzeit uname repid FROM zbatpusrlog
INTO CORRESPONDING FIELDS OF TABLE i_zbafreigabe
WHERE repid LIKE lw_condition.
*&---------------------------------------------------------------*
* Search between all element found the most recent
*&---------------------------------------------------------------*
IF sy-subrc = 0.
SORT i_zbafreigabe BY datum uzeit DESCENDING.
DELETE ADJACENT DUPLICATES
FROM i_zbafreigabe COMPARING datum uname repid.
DESCRIBE TABLE i_zbafreigabe LINES lwa_count.
IF lwa_count <> 0.
READ TABLE i_zbafreigabe INDEX 1
INTO lwa_zbafreigabelog.
" Fill field of report for this transaction
PERFORM add_element_to_report USING lwa_zbafreigabelog
<lfs_zbatran>
c_week.
ENDIF.
ENDIF.
*&---------------------------------------------------------------*
* 2) Search string Repid starting with: ZBATPREL VORABTRANSPORT
* and with Repid starting with: ZBATPREL VORABTRANSPORT and
* end with Userid: Ends with _ENT or _E
*&---------------------------------------------------------------*
CLEAR lw_condition.
CONCATENATE 'ZBATPREL VORABTRANSPORT%' "#EC NOTEXT
<lfs_zbatran>-trkorr '%' INTO lw_condition.
SELECT datum uzeit uname repid FROM zbatpusrlog
INTO CORRESPONDING FIELDS
OF TABLE i_zba_vorab_log
WHERE repid LIKE lw_condition.
IF sy-subrc = 0.
LOOP AT i_zba_vorab_log INTO lwa_zbavorablog.
IF ( lwa_zbavorablog-uname CP '*#_ENT' )
OR ( lwa_zbavorablog-uname CP '*#_E' ).
APPEND lwa_zbavorablog TO i_zvorab_with_enduser.
ELSE.
APPEND lwa_zbavorablog TO i_zvorab.
ENDIF.
ENDLOOP.
DESCRIBE TABLE i_zvorab_with_enduser LINES lwa_count.
" Process before the element with Userid: Ends with _ENT or _E
IF lwa_count <> 0.
PERFORM add_zbatpusrlog_to_report
USING i_zvorab_with_enduser
<lfs_zbatran>
c_houster.
ENDIF.
CLEAR lwa_count.
DESCRIBE TABLE i_zvorab LINES lwa_count.
IF lwa_count <> 0.
PERFORM add_zbatpusrlog_to_report
USING i_zvorab
<lfs_zbatran>
c_preimport.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " READ_ZBATPUSRLOG
*&---------------------------------------------------------------------*
*& Form add_zvorab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FUW_TYPE_COL text
*----------------------------------------------------------------------*
FORM add_zbatpusrlog_to_report USING fuw_zbatpusrlog LIKE i_zvorab
fuw_zbatran LIKE LINE OF i_zbatrans
fuw_type_col TYPE string.
FIELD-SYMBOLS: <lfs_zbatpusrlog>
LIKE LINE OF i_zvorab.
DATA: lw_zvorab TYPE c LENGTH 1.
SORT fuw_zbatpusrlog BY datum uzeit DESCENDING.
DELETE ADJACENT DUPLICATES
FROM fuw_zbatpusrlog COMPARING datum uname repid.
DESCRIBE TABLE fuw_zbatpusrlog LINES lw_zvorab.
IF lw_zvorab <> 0.
READ TABLE fuw_zbatpusrlog INDEX 1
ASSIGNING <lfs_zbatpusrlog>.
" Fill field of report for this transaction
PERFORM add_element_to_report USING <lfs_zbatpusrlog>
fuw_zbatran
fuw_type_col.
ENDIF.
ENDFORM. "add_zvorab
*----------------------------------------------------------*
* FORM ADD ELEMENT TO REPORT *
*----------------------------------------------------------*
FORM add_element_to_report
USING fuw_zbatpusrlog LIKE LINE OF i_zbafreigabe
fuw_zbatran LIKE LINE OF i_zbatrans
fuw_type_col TYPE string.
CLEAR wa_report.
CASE fuw_type_col.
WHEN c_week.
wa_report-week = fuw_zbatpusrlog-repid.
WHEN c_preimport.
wa_report-preimport = fuw_zbatpusrlog-repid.
WHEN c_houster.
wa_report-houster = fuw_zbatpusrlog-repid.
ENDCASE.
wa_report-trkorr = fuw_zbatran-trkorr.
wa_report-status = fuw_zbatran-status.
wa_report-released = fuw_zbatran-released.
wa_report-text = fuw_zbatran-text.
wa_report-truser = fuw_zbatran-truser.
wa_report-exportdate = fuw_zbatran-exportdate.
wa_report-exporttime = fuw_zbatran-exporttime.
wa_report-datum = fuw_zbatpusrlog-datum.
wa_report-uzeit = fuw_zbatpusrlog-uzeit.
wa_report-uname = fuw_zbatpusrlog-uname.
APPEND wa_report TO i_report.
ENDFORM.
According to you is possible improve the code and the performance, I don´t like to have the select inside
a loop, how can improve this code??
2013 Feb 14 3:25 PM
Tony,
An idea...
Do a loop first just to put the following in a table (add lw_condition to i_zbatrans)
:
CONCATENATE 'ZBATPREL FREIGABE mit Typ%' "#EC NOTEXT
<lfs_zbatran>-trkorr '%' INTO lw_condition.
Then do this with for all entries
SELECT datum uzeit uname repid FROM zbatpusrlog
INTO CORRESPONDING FIELDS OF TABLE i_zbafreigabe
WHERE repid LIKE lw_condition.
then in your main loop, instead of a select you can do a read table.
Should improve a little but the best is to compare in Runtime Analysis.
Provare per credere...
2013 Feb 19 7:32 AM
Hi Phillip,
Thank for the answer, I try to implement the modify that you have told me, but when I try to do
this:
SELECT datum uzeit uname repid FROM zbatpusrlog
INTO CORRESPONDING FIELDS OF TABLE i_zbafreigabe
FOR ALL ENTRIES IN i_zbatrans
WHERE repid LIKE i_zbatrans-lw_condition.
The system told me this:
| BETWEEN, LIKE, and IN must not be used with the addition "FOR ALL |
| ENTRIES IN itab" in the WHERE condition |
Seems that isn´t possible used like with the statement FOR ALL ENTRIES.
Do you know how do in this case??
2013 Feb 14 3:55 PM
Is this just academical or are you facing an actual runtime problem with this code? Did you run an ABAP trace (SAT, or included in ST12) to find out the top few statements showing the longest net runtime?
Thomas
2013 Feb 15 9:34 AM
Go for a ABAP runtime analysis SE30, you will able to find which part of code is taking more time for processing with detail analysis (DB Access).
2013 Feb 18 5:45 AM
Hi Tony,
First of all remove into corresponding fieds statement in select query and define data types in program as per the order sequence (As per the data type declaration) you need to select the fields in select query due avoid short dumps.
Use proper primary key to select query.
Analyse after using tcode ST05 &SE30, here you analyse easily.
Regard,
Sanjeev K.M