2014 Oct 20 3:20 PM
Hi gurus,
Need your help in tackling a BDC scenario.
Scenario : Multiple IT0015 records having same date but different amounts.
Need : After calculations in the report, these records are to be modified and updated with new amounts using BDC(Removal of BDC to use FM is not an option here).
Problem : Since the records have same date, only the first record gets modified each time inside the loop.
Example :-
Before Calculation
Record1 - 01/01/2015 5000
Record2 - 01/01/2015 10000
Record3 - 01/01/2015 15000
Expected Result
Record1 - 01/01/2015 4500
Record2 - 01/01/2015 9500
Record3 - 01/01/2015 14000
Actual Result
Record1 - 01/01/2015 14000 - This is happening since the same record gets modified thrice resulting in the last (new) amount being displayed here.
Record2 - 01/01/2015 10000
Record3 - 01/01/2015 15000
So any idea how the multiple record update can be accomplished?
2014 Oct 21 12:32 PM
Hi,
In-order to make this logic to work in a proper way, You have to add a key field (distinct one) into the internal tables as per the requirement. Because in these internal tables there is no distinct fields and hence we cannot have a simple comparison based on existing fields.
If possible ,try to find out such a field from the requirement and, based on that field change the where condition.
note: The key field should be a distinct one for each record.
avoid the following where condition .
WHERE begda = itab_computed-begda
AND infty = itab_computed-infty
AND lgart = itab_computed-lgart
AND bonus = ( itab_computed-bonus + itab_computed-dpsp_contrib ).
I am giving a small example, I am not sure whether it will work 100 % ,because still am not clear with the logic of this requirement.
let pernr be the distinct field for each record.
include pernr field into itab_computed and itab_actual.
DATA: BEGIN OF itab_actual OCCURS 0,
pernr like p0015-pernr,
begda LIKE p0015-begda,
infty LIKE t582a-infty,
lgart LIKE p0015-lgart,
bonus LIKE p0015-betrg,
dpsp_contrib LIKE p0015-betrg,
END OF itab_actual,
BEGIN OF itab_computed OCCURS 0,
pernr like p0015-pernr,
begda LIKE p0015-begda,
infty LIKE t582a-infty,
lgart LIKE p0015-lgart,
bonus LIKE p0015-betrg,
dpsp_contrib LIKE p0015-betrg,
END OF itab_computed.
LOOP AT itab_computed.
LOOP AT itab_actual where pernr = itab_computed-pernr.
if record exists,
endloop.
endloop.
Regards ,
sajeesh
2014 Oct 21 10:36 AM
Hi,
Can you please show the logic that you have used? Your example is quite confusing .
Regards,
Sajeesh
2014 Oct 21 10:57 AM
Here goes the existing logic Sajeesh. This is a very old logic which is existent in our system. I have not implemented the solution yet for the problem.
Loop at itab_computed.
Loop at itab_actual where *<begda and lgart(wage type) match with computed record>*.
operation = 'MOD'.
PERFORM adjust_infotype USING itab_computed-infty
operation
itab_computed-begda
itab_computed-lgart
itab_actual-bonus
itab_computed-bonus.
*<Other logic/calculation pieces based on computed and actual records.>*
endloop.
endloop.
*&---------------------------------------------------------------------*
*& Form ADJUST_INFOTYPE
*&---------------------------------------------------------------------*
FORM adjust_infotype USING p_infty
p_operation
p_begda
p_lgart
p_pre_amt
p_betrg.
*<Conversion Logic>*
PERFORM bdc_dynpro USING 'SAPMP50A' '1000'.
PERFORM bdc_field USING 'BDC_OKCODE'
operation.
PERFORM bdc_field USING 'BDC_CURSOR'
'RP50G-SUBTY'.
PERFORM bdc_field USING 'RP50G-PERNR'
pernr-pernr.
PERFORM bdc_field USING 'RP50G-CHOIC'
'15'.
PERFORM bdc_field USING 'RP50G-SUBTY'
p_lgart.
PERFORM bdc_field USING 'RP50G-TIMR6'
'X'.
PERFORM bdc_field USING 'RP50G-BEGDA'
bdc_begda.
CASE operation.
WHEN 'DEL'.
operation1 = 'UPDL'.
itab_report_operation = 'DELETE'.
WHEN 'INS'.
operation1 = 'UPD'.
itab_report_operation = 'CREATE'.
WHEN 'MOD'.
operation1 = 'UPD'.
itab_report_operation = 'MODIFY'.
ENDCASE.
* Build second screen
PERFORM bdc_dynpro USING 'MP001500' '2000'.
PERFORM bdc_field USING 'BDC_OKCODE'
operation1.
PERFORM bdc_field USING 'BDC_CURSOR'
'Q0015-BETRG'.
PERFORM bdc_dynpro USING 'MP001500' '2000'.
PERFORM bdc_field USING 'BDC_OKCODE'
operation1.
PERFORM bdc_field USING 'BDC_CURSOR'
'Q0015-BETRG'.
IF operation1 = 'UPD'.
PERFORM bdc_field USING 'P0015-BEGDA'
bdc_begda.
PERFORM bdc_field USING 'P0015-LGART'
p_lgart.
PERFORM bdc_field USING 'Q0015-BETRG'
l_betrg.
ENDIF.
PERFORM bdc_dynpro USING 'MP001500' '2000'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/EBCK'.
*<Call transaction logic>*
ENDFORM. " ADJUST_INFOTYPE
2014 Oct 21 10:52 AM
Hi,
Do you want to sum up all the records based on Date? do you have any unique data in all the records?
Thansk & Regards,
Polu
2014 Oct 21 11:01 AM
Hi Ankireddy,
I do not want to add those amounts. Instead, each one of them should be replaced with their new calculated amount. The only unique column for comparison will be the amount field, which is not possible to be compared(dynamically) with the amount showing up during the BDC run.
Thanks & Regards,
Sanup.
2014 Oct 21 11:19 AM
Hi,
Please explain the below mentioned where condition .
Loop at itab_computed.
Loop at itab_actual where *<begda and lgart(wage type) match with computed record>*.
itab_computed is having the updated value right?
also show the structure of those two internal tables.
Regards,
sajeesh
2014 Oct 21 11:58 AM
Hi Sanjeesh,
The declarations -
DATA: BEGIN OF itab_actual OCCURS 0,
begda LIKE p0015-begda,
infty LIKE t582a-infty,
lgart LIKE p0015-lgart,
bonus LIKE p0015-betrg,
dpsp_contrib LIKE p0015-betrg,
END OF itab_actual,
BEGIN OF itab_computed OCCURS 0,
begda LIKE p0015-begda,
infty LIKE t582a-infty,
lgart LIKE p0015-lgart,
bonus LIKE p0015-betrg,
dpsp_contrib LIKE p0015-betrg,
END OF itab_computed.
The loop condition -
LOOP AT itab_computed.
LOOP AT itab_actual
WHERE begda = itab_computed-begda
AND infty = itab_computed-infty
AND lgart = itab_computed-lgart
AND bonus = ( itab_computed-bonus + itab_computed-dpsp_contrib ).
The second loop is used to check if the record already exists. If so, then different set of logic and BDCs are executed.
2014 Oct 21 4:17 PM
Why are you not using ENDDA in your LOOP, and everywhere else as well?
LOOP AT itab_computed.
LOOP AT itab_actual
WHERE begda = itab_computed-begda
AND endda = itab_computed-endda
AND infty = itab_computed-infty
AND lgart = itab_computed-lgart
AND bonus = ( itab_computed-bonus + itab_computed-dpsp_contrib ).
ENDDA is an integral part of the key for infotype 0015, so it should be everwhere including in your BDC but it is not?
2014 Oct 28 9:48 AM
Thank you Glen for your response and apologies for the delay in mine.
I do get it when you ask me to use the end date in the internal tables, but in IT0015, how should it matter? All the records in IT0015 will have the same begin and end dates since they are all bonus(this the way it is maintained in our system).
Let's say, I do include the end date into my internal tables. I am not facing any difficulty in comparing records inside the program. Rather, I am having trouble when I pass the records to the BDC and use call transaction on PA30. As shown in the example above, I want it to pick different records(each having same begin date and end date and belonging to the same PERNR) where the only difference between them is the amount.
Since the IT0015 records don't have a sequence number or anything as such, I am finding it difficult to tackle this.
2014 Oct 21 12:32 PM
Hi,
In-order to make this logic to work in a proper way, You have to add a key field (distinct one) into the internal tables as per the requirement. Because in these internal tables there is no distinct fields and hence we cannot have a simple comparison based on existing fields.
If possible ,try to find out such a field from the requirement and, based on that field change the where condition.
note: The key field should be a distinct one for each record.
avoid the following where condition .
WHERE begda = itab_computed-begda
AND infty = itab_computed-infty
AND lgart = itab_computed-lgart
AND bonus = ( itab_computed-bonus + itab_computed-dpsp_contrib ).
I am giving a small example, I am not sure whether it will work 100 % ,because still am not clear with the logic of this requirement.
let pernr be the distinct field for each record.
include pernr field into itab_computed and itab_actual.
DATA: BEGIN OF itab_actual OCCURS 0,
pernr like p0015-pernr,
begda LIKE p0015-begda,
infty LIKE t582a-infty,
lgart LIKE p0015-lgart,
bonus LIKE p0015-betrg,
dpsp_contrib LIKE p0015-betrg,
END OF itab_actual,
BEGIN OF itab_computed OCCURS 0,
pernr like p0015-pernr,
begda LIKE p0015-begda,
infty LIKE t582a-infty,
lgart LIKE p0015-lgart,
bonus LIKE p0015-betrg,
dpsp_contrib LIKE p0015-betrg,
END OF itab_computed.
LOOP AT itab_computed.
LOOP AT itab_actual where pernr = itab_computed-pernr.
if record exists,
endloop.
endloop.
Regards ,
sajeesh
2014 Oct 28 9:29 AM
Thank you Sajeesh and apologies for the delay in response.
I understand what you are saying about adding the key field. But the requirement here is that, we need to modify multiple bonus records all having same date for a single employee. So the only available 'distinct' field is amount field.
More importantly, the issue is not comparison inside the program(which is already being done) but to pick the different records during the BDC execution(using Call Transaction on PA30) for modifying the records. As shown in my example above, every time, a single record is being picked to modify during the BDC execution.
2014 Oct 29 1:24 PM
Sanup,
I never worked on PA30 BDCs, however, I jsut want to suggest you something here based on my understanding on the issue.
It seems like...
You don't have any issue with program logic to modify the records (though it looks little unreliable as you are modifying data based on amount field which is non-primary field of the table - But I believe you have some validations around data to pick the right record).
Are you guys maintaining SEQNR properly in the table? I think you are doing it, otherwise table will not allow you to maintain duplicate records.
Assumming my above understand is correct...and now the solution could be:
You have "Choose" field to select record(s) related to date range on PA20, right? If yes, you should record that "Choose" to filter entire data for specific date set. Now, with in that date set before making BDC call to the screen, Identify which record you want to modify (I think you should figure out how can you use SEQNR field here) and when you call BDC poistion the cursor on that record to modify.
Regards,
Naveen
2014 Oct 30 12:01 PM
Thank you very much Naveen. Your solution worked.
I captured the seqnr for every record I was processing and wrote in the piece of logic where we navigate to the next record using 'NXT' button. When the BDC was sequenced correctly with this step, the right records were getting updated perfectly.
The solution implemented -
*<Capture the seqnr of the record which has to be updated while doing the calculations and validations before BDC data is populated>*
" Populate the SAPMP50A-1000 screen the normal way "
And before you populate the MP001500-2000 screen for updating the record, insert this piece.
DO lv_it15_seqnr TIMES.
PERFORM bdc_dynpro USING 'MP001500' '2000'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/ENXT'.
PERFORM bdc_field USING 'BDC_CURSOR'
'Q0015-BETRG'.
ENDDO.
" Populate the MP001500-2000 screen the normal way to update the record "
Make sure that you have the code piece "PERFORM bdc_dynpro USING 'MP001500' '2000'." added each time you need to re populate the screen. For the same reason, it has been included inside the DO loop.
2014 Oct 30 12:02 PM
Thank you everyone for your responses. Keep coding, keep rocking!