Este es un pequeño ejemplo de una función realizada, la cual marca la liberación de la solped para el liberador actual, y además, modifica un campo de la extensión "Z", más conocida como ExtensionIn, en este caso, para agregar el nombre del usuario liberador, con la ayuda de la función BAPI_PR_CHANGE.
FUNCTION zmm_ws03_libera_solped.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(I_SOLPED) TYPE BANFN
*" VALUE(I_USUARIO) TYPE PERSNO
*" EXPORTING
*" VALUE(E_RETORNO) TYPE BAPIRET2
*"----------------------------------------------------------------------
* liberar solped
**********************************************************************
DATA return1 TYPE TABLE OF bapireturn WITH HEADER LINE.
CALL FUNCTION 'BAPI_REQUISITION_RELEASE_GEN'
EXPORTING
number = i_solped
rel_code = 'JC' "<-- se ingresa el liberador actual
TABLES
return = return1.
LOOP AT return1 WHERE type = 'E'.
MOVE-CORRESPONDING return1 TO e_retorno.
ENDLOOP.
IF e_retorno-type = 'E'.
EXIT.
ENDIF.
* obtener nombre colaborador en HR
**********************************************************************
DATA p0002 TYPE TABLE OF p0002 WITH HEADER LINE.
DATA cname TYPE pad_cname.
rp-read-infotype i_usuario 0002 p0002 sy-datum sy-datum.
READ TABLE p0002 INDEX 1.
CONCATENATE p0002-vorna p0002-nachn p0002-name2
INTO cname SEPARATED BY space.
* insertar nombre usuario liberador
**********************************************************************
DATA return2 TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA pritem_out TYPE TABLE OF bapimereqitem WITH HEADER LINE.
DATA pritem TYPE TABLE OF bapimereqitemimp WITH HEADER LINE.
DATA pritemx TYPE TABLE OF bapimereqitemx WITH HEADER LINE.
DATA extensionin TYPE TABLE OF bapiparex WITH HEADER LINE.
DATA valuepart1 TYPE bapi_te_mereqitem.
DATA valuepart1x TYPE bapi_te_mereqitemx.
CALL FUNCTION 'BAPI_PR_GETDETAIL'
EXPORTING
number = i_solped
TABLES
return = return2
pritem = pritem_out.
LOOP AT pritem_out.
MOVE-CORRESPONDING pritem_out TO pritem.
APPEND pritem.
pritemx-preq_item = pritem_out-preq_item.
pritemx-preq_itemx = 'X'.
APPEND pritemx.
extensionin-structure = 'BAPI_TE_MEREQITEM'.
valuepart1-preq_item = pritem_out-preq_item.
valuepart1-zenc_contrato = cname.
extensionin-valuepart1 = valuepart1.
APPEND extensionin.
extensionin-structure = 'BAPI_TE_MEREQITEMX'.
valuepart1x-preq_item = pritem_out-preq_item.
valuepart1x-zenc_contrato = 'X'.
extensionin-valuepart1 = valuepart1x.
APPEND extensionin.
ENDLOOP.
CALL FUNCTION 'BAPI_PR_CHANGE'
EXPORTING
number = i_solped
testrun = ''
TABLES
return = return2
pritem = pritem
pritemx = pritemx
extensionin = extensionin.
LOOP AT return2 WHERE type = 'E'.
MOVE-CORRESPONDING return2 TO e_retorno.
ENDLOOP.
IF e_retorno-type = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
e_retorno-type = 'S'.
e_retorno-message = text-s01.
ENDIF.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(I_SOLPED) TYPE BANFN
*" VALUE(I_USUARIO) TYPE PERSNO
*" EXPORTING
*" VALUE(E_RETORNO) TYPE BAPIRET2
*"----------------------------------------------------------------------
* liberar solped
**********************************************************************
DATA return1 TYPE TABLE OF bapireturn WITH HEADER LINE.
CALL FUNCTION 'BAPI_REQUISITION_RELEASE_GEN'
EXPORTING
number = i_solped
rel_code = 'JC' "<-- se ingresa el liberador actual
TABLES
return = return1.
LOOP AT return1 WHERE type = 'E'.
MOVE-CORRESPONDING return1 TO e_retorno.
ENDLOOP.
IF e_retorno-type = 'E'.
EXIT.
ENDIF.
* obtener nombre colaborador en HR
**********************************************************************
DATA p0002 TYPE TABLE OF p0002 WITH HEADER LINE.
DATA cname TYPE pad_cname.
rp-read-infotype i_usuario 0002 p0002 sy-datum sy-datum.
READ TABLE p0002 INDEX 1.
CONCATENATE p0002-vorna p0002-nachn p0002-name2
INTO cname SEPARATED BY space.
* insertar nombre usuario liberador
**********************************************************************
DATA return2 TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA pritem_out TYPE TABLE OF bapimereqitem WITH HEADER LINE.
DATA pritem TYPE TABLE OF bapimereqitemimp WITH HEADER LINE.
DATA pritemx TYPE TABLE OF bapimereqitemx WITH HEADER LINE.
DATA extensionin TYPE TABLE OF bapiparex WITH HEADER LINE.
DATA valuepart1 TYPE bapi_te_mereqitem.
DATA valuepart1x TYPE bapi_te_mereqitemx.
CALL FUNCTION 'BAPI_PR_GETDETAIL'
EXPORTING
number = i_solped
TABLES
return = return2
pritem = pritem_out.
LOOP AT pritem_out.
MOVE-CORRESPONDING pritem_out TO pritem.
APPEND pritem.
pritemx-preq_item = pritem_out-preq_item.
pritemx-preq_itemx = 'X'.
APPEND pritemx.
extensionin-structure = 'BAPI_TE_MEREQITEM'.
valuepart1-preq_item = pritem_out-preq_item.
valuepart1-zenc_contrato = cname.
extensionin-valuepart1 = valuepart1.
APPEND extensionin.
extensionin-structure = 'BAPI_TE_MEREQITEMX'.
valuepart1x-preq_item = pritem_out-preq_item.
valuepart1x-zenc_contrato = 'X'.
extensionin-valuepart1 = valuepart1x.
APPEND extensionin.
ENDLOOP.
CALL FUNCTION 'BAPI_PR_CHANGE'
EXPORTING
number = i_solped
testrun = ''
TABLES
return = return2
pritem = pritem
pritemx = pritemx
extensionin = extensionin.
LOOP AT return2 WHERE type = 'E'.
MOVE-CORRESPONDING return2 TO e_retorno.
ENDLOOP.
IF e_retorno-type = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
e_retorno-type = 'S'.
e_retorno-message = text-s01.
ENDIF.
ENDFUNCTION.
No hay comentarios:
Publicar un comentario