01-11-2014 4:07 PM
Good experts days scn, the following code can not write data to the AFRU table, I have made the respective debbug and if it shows that the data are added in the AFRU table, but at the end of the program and check in table these data are not recorded, please tell me what could I lack in the code to record those records.
FORM toma_de .
DATA: l_n1 TYPE afru-rueck,
l_n2 TYPE afru-rueck,
lv_total TYPE i.
REFRESH: ti_log.
LOOP AT ti_input INTO st_input.
CLEAR:it_afru.
MOVE: st_input-aufnr TO it_afru-aufnr,
st_input-vornr TO it_afru-vornr,
st_input-budat TO it_afru-budat,
st_input-zzcant1 TO it_afru-zzcant1,
st_input-zzmot1 TO it_afru-zzmot1,
st_input-zzcant2 TO it_afru-zzcant2,
st_input-zzmot2 TO it_afru-zzmot2,
st_input-zzcant3 TO it_afru-zzcant3,
st_input-zzmot3 TO it_afru-zzmot3,
st_input-zzcant4 TO it_afru-zzcant4,
st_input-zzmot4 TO it_afru-zzmot4,
st_input-ltxa1 TO it_afru-ltxa1,
st_input-rueck TO it_afru-rueck.
DATA: l_budat(10) TYPE c,
l_result(10) TYPE c.
l_budat = it_afru-budat.
CONCATENATE l_budat+6(2)'.'l_budat+4(2)'.'l_budat+0(4) INTO l_result.
PERFORM bdc_dynpro USING :
'X' 'SAPLCORU_S' '0100',
' ' 'BDC_OKCODE' '/00',
' ' 'AFRUD-RUECK' it_afru-rueck,
' ' 'AFRUD-AUFNR' it_afru-aufnr,
' ' 'AFRUD-VORNR' it_afru-vornr,
' ' 'AFRUD-BUDAT' l_result. "Fecha
PERFORM bdc_dynpro USING :
'X' 'SAPLCORU_S' '0100',
' ' 'BDC_OKCODE' '=BU', "Grabar
' ' 'AFRUD-AUFNR' it_afru-aufnr,
' ' 'AFRUD-VORNR' it_afru-vornr,
' ' 'AFRUD-BUDAT' l_result,
' ' 'AFRUD-RUECK' it_afru-rueck.
s_opt-dismode = c_mod.
s_opt-updmode = c_update.
s_opt-nobinpt = ' '.
CALL TRANSACTION 'CO11N' USING it_bdc_tab[]
OPTIONS FROM s_opt
MESSAGES INTO it_messtab[].
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING
input = it_afru-vornr
IMPORTING
output = it_afru-vornr.
CALL FUNCTION 'PM_ORDER_DATA_READ'
EXPORTING
order_number = st_input-aufnr " aufk-
TABLES
iafvgd = it_func " afvgd
EXCEPTIONS
order_not_found = 1.
SORT it_func BY rueck rmzhl DESCENDING.
READ TABLE it_func INDEX 1.
* DESCRIBE TABLE it_func LINES lv_total.
IF sy-subrc = 0.
afru-zzcant1 = it_afru-zzcant1.
afru-zzmot1 = it_afru-zzmot1.
afru-zzcant2 = it_afru-zzcant2.
afru-zzmot2 = it_afru-zzmot2.
afru-zzcant3 = it_afru-zzcant3.
afru-zzmot3 = it_afru-zzmot3.
afru-zzcant4 = it_afru-zzcant4.
afru-zzmot4 = it_afru-zzmot4.
afru-ltxa1 = it_afru-ltxa1.
MODIFY afru FROM TABLE it_afru.
COMMIT WORK.
ENDIF.
ENDLOOP.
Thank you all for your valuable time.
01-11-2014 4:21 PM
Hi,
Please find my initial findings, I guess this is the way to handle!
- don't write the modify statment with in the loop. Just collect the information in table it_afru
CALL TRANSACTION 'CO11N' USING it_bdc_tab[]
OPTIONS FROM s_opt
MESSAGES INTO it_messtab[].
* handle the BDC messages properly! In this case irrespectiv success or failure you are updating the AFRU table-- i think this not correct.
*Don't use the modify stat
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING
input = it_afru-vornr
IMPORTING
output = it_afru-vornr.
CALL FUNCTION 'PM_ORDER_DATA_READ'
EXPORTING
order_number = st_input-aufnr " aufk-
TABLES
iafvgd = it_func " afvgd
EXCEPTIONS
order_not_found = 1.
SORT it_func BY rueck rmzhl DESCENDING.
READ TABLE it_func INDEX 1.
* DESCRIBE TABLE it_func LINES lv_total.
IF sy-subrc = 0.
afru-zzcant1 = it_afru-zzcant1.
afru-zzmot1 = it_afru-zzmot1.
afru-zzcant2 = it_afru-zzcant2.
afru-zzmot2 = it_afru-zzmot2.
afru-zzcant3 = it_afru-zzcant3.
afru-zzmot3 = it_afru-zzmot3.
afru-zzcant4 = it_afru-zzcant4.
afru-zzmot4 = it_afru-zzmot4.
afru-ltxa1 = it_afru-ltxa1.
endloop.
MODIFY afru FROM TABLE it_afru.
COMMIT WORK.
ENDIF.
01-11-2014 4:34 PM
First of all pleade dont update standard tables directly. What exactly are you trying to achieve..? What is the logic for this development please explain.