‎2021 Aug 18 10:55 AM
Hey guys,
I have a problem with a program that uses a Batch Input.
When the IDOBJ exist in table, it makes the correct update, but when it doesn't exists it doesn't make the insert. I copy the code:
FORM realizar_carga USING pt_alv TYPE tt_alv.
DATA: ls_cab LIKE LINE OF pt_alv.
data: lv_op(4) type c.
LOOP AT pt_alv[] INTO ls_cab.
*lectura cabecera documento
REFRESH gt_bdcdata.
SELECT SINGLE * FROM HRP1000 WHERE
plvar eq '01' and
otype eq 'P0' and
OBJID eq ls_cab-id.
if sy-subrc eq 0.
lv_op = '=UPD'.
ELSE.
lv_op = '=INS'.
endif.
* --------------------------------------------------------------------*
PERFORM f_bdc_dynpro USING 'SAPMH5A0' '5000'.
PERFORM f_bdc_field USING 'BDC_CURSOR' 'PM0D1-SEARK' space.
PERFORM f_bdc_field USING 'BDC_OKCODE' '/00' space.
PERFORM f_bdc_field USING 'PPHDR-PLVAR' '01' space.
PERFORM f_bdc_field USING 'PPHDR-OTYPE' 'P0' space.
PERFORM f_bdc_field USING 'PM0D1-SEARK' ls_cab-id space.
PERFORM f_bdc_field USING 'BDC_SUBSCR' 'SAPMH5A0' '5005SUB1'.
* --------------------------------------------------------------------*
PERFORM f_bdc_dynpro USING 'SAPMH5A0' '5000'.
PERFORM f_bdc_field USING 'BDC_OKCODE' '=AEND' space.
PERFORM f_bdc_field USING 'PPHDR-PLVAR' '01' space.
PERFORM f_bdc_field USING 'PPHDR-OTYPE' 'P0' space.
PERFORM f_bdc_field USING 'PM0D1-SEARK' ls_cab-id space.
PERFORM f_bdc_field USING 'BDC_SUBSCR' 'SAPMH5A0' '5005SUB1'.
PERFORM f_bdc_field USING 'BDC_CURSOR' 'TT_T777T-ITEXT(01)' space.
PERFORM f_bdc_field USING 'MARKFELD(01)' 'X' space.
* --------------------------------------------------------------------*
PERFORM f_bdc_dynpro USING 'MP100000' '2000'.
PERFORM f_bdc_field USING 'BDC_CURSOR' 'P1000-STEXT' space.
* PERFORM f_bdc_field USING 'BDC_OKCODE' '=UPD' space.
PERFORM f_bdc_field USING 'BDC_OKCODE' lv_op space.
PERFORM f_bdc_field USING 'P1000-SHORT' ls_cab-desc_breve space.
PERFORM f_bdc_field USING 'P1000-STEXT' ls_cab-desc space.
PERFORM f_bdc_field USING 'P1000-LANGU' ls_cab-idioma space.
DATA: ctumode LIKE ctu_params-dismode VALUE 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
DATA: cupdate LIKE ctu_params-updmode VALUE 'A'.
"S: synchronously
"A: asynchronously
"L: local
DATA: messtab TYPE STANDARD TABLE OF bdcmsgcoll,
ls_messtab TYPE bdcmsgcoll.
CLEAR messtab.
CALL TRANSACTION 'PP01' USING gt_bdcdata
MODE ctumode
* UPDATE cupdate
MESSAGES INTO messtab.
READ TABLE messtab INTO ls_messtab WITH KEY msgtyp = 'E'.
IF sy-subrc NE 0.
* select single * from HRP1000
* where OTYPE eq 'P0'
* AND OBJID EQ gt_bdcdata-
gs_alv-icon = icon_green_light .
ELSE.
gs_alv-icon = icon_red_light .
ENDIF.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon.
ENDLOOP.
‎2021 Aug 18 11:52 AM
(please, edit the question by selecting all the code and pressing the CODE button... it will make your post much more readable)
First of all: try to find another way to do that work. I'm not sure which SAP object the PP01 transaction works with, but if you find a BAPI or a class that does that same work, it will make your life easier and the program much more resistant to SAP updates.
A Batch Input is nothing else than a recorded process. It behaves just like the system will do if you do the whole process manually, so if your data raises a message or a pop-up asking for information or any other unexpected thing, the whole process will stop working.
Put a breakpoint inside the LOOP, and when it reaches the idobj you know it "crashes", keep going line by line until you have your CTUMODE as "N"... then change its value to "E" (or even to "A").
Then keep the execution (F8) and you will see every step of the recording.
Once you know what's happening, you'll need to adapt the "recording" to take care of the special case (ie adding another screen with info).
An easier and maybe cleaner way to fix this may be to create a new recording using information of the new case and use one or the other depending on the info of the loop's row.
But I strongly advice to seek for an alternate process before. To use a Batch Input is like to walk into a lightstorm carrying a copper stick raised over your head.
------------------------ spanish translation
(edita el mensaje seleccionando el código y dándole al botón CODE... será mucho más agradable y fácil de leer)
Primero: intenta encontrar otra forma de hacer lo que intentas. No sé qué hace la PP01, pero si encuentras una BAPI o una clase que haga lo mismo que la transacción, tu vida será más fácil y el programa más resistente a actualizaciones de SAP.
Un BI es una grabación de un proceso. Se comporta exactamente como lo harÃa el sistema si le fueras metiendo la info a mano, asà que si tus datos hacen que SAP quiera sacar un mensaje o un popup pidiendo información adicional, o cualquier otra cosa que no está en la grabación, el proceso se va al carajo.
Pon un break-point en el LOOP, y cuando estés en el registro que no funciona, debuga hasta que CTUMODE tenga el valor "N" y cámbialo por "E" (o mejor por "A").
Dale a seguir (F8) y verás lo que le pasa a la grabación.
Cuando sepas lo que pasa, tendrás que adaptar la grabación para tener en cuenta el caso especial (añadiendo la información de la pantalla adicional, o lo que sea).
Una forma más sencilla y quizá más limpia serÃa crear una grabación nueva con los datos que te generan el error, y ejecutar una grabación o la otra en función de la información de la lÃnea del LOOP.
Pero sigo recomendándote buscar una vÃa alternativa. Usar un batch input es como pasear bajo los rayos llevando un poste de cobre sobre la cabeza.
‎2021 Aug 18 11:52 AM
(please, edit the question by selecting all the code and pressing the CODE button... it will make your post much more readable)
First of all: try to find another way to do that work. I'm not sure which SAP object the PP01 transaction works with, but if you find a BAPI or a class that does that same work, it will make your life easier and the program much more resistant to SAP updates.
A Batch Input is nothing else than a recorded process. It behaves just like the system will do if you do the whole process manually, so if your data raises a message or a pop-up asking for information or any other unexpected thing, the whole process will stop working.
Put a breakpoint inside the LOOP, and when it reaches the idobj you know it "crashes", keep going line by line until you have your CTUMODE as "N"... then change its value to "E" (or even to "A").
Then keep the execution (F8) and you will see every step of the recording.
Once you know what's happening, you'll need to adapt the "recording" to take care of the special case (ie adding another screen with info).
An easier and maybe cleaner way to fix this may be to create a new recording using information of the new case and use one or the other depending on the info of the loop's row.
But I strongly advice to seek for an alternate process before. To use a Batch Input is like to walk into a lightstorm carrying a copper stick raised over your head.
------------------------ spanish translation
(edita el mensaje seleccionando el código y dándole al botón CODE... será mucho más agradable y fácil de leer)
Primero: intenta encontrar otra forma de hacer lo que intentas. No sé qué hace la PP01, pero si encuentras una BAPI o una clase que haga lo mismo que la transacción, tu vida será más fácil y el programa más resistente a actualizaciones de SAP.
Un BI es una grabación de un proceso. Se comporta exactamente como lo harÃa el sistema si le fueras metiendo la info a mano, asà que si tus datos hacen que SAP quiera sacar un mensaje o un popup pidiendo información adicional, o cualquier otra cosa que no está en la grabación, el proceso se va al carajo.
Pon un break-point en el LOOP, y cuando estés en el registro que no funciona, debuga hasta que CTUMODE tenga el valor "N" y cámbialo por "E" (o mejor por "A").
Dale a seguir (F8) y verás lo que le pasa a la grabación.
Cuando sepas lo que pasa, tendrás que adaptar la grabación para tener en cuenta el caso especial (añadiendo la información de la pantalla adicional, o lo que sea).
Una forma más sencilla y quizá más limpia serÃa crear una grabación nueva con los datos que te generan el error, y ejecutar una grabación o la otra en función de la información de la lÃnea del LOOP.
Pero sigo recomendándote buscar una vÃa alternativa. Usar un batch input es como pasear bajo los rayos llevando un poste de cobre sobre la cabeza.
‎2021 Aug 18 1:06 PM
You cannot edit your question anymore now that there is an answer, but next time please select your code and press the [CODE] button to format it correctly. Thank you. Like this:
FORM realizar_carga USING pt_alv TYPE tt_alv.
DATA: ls_cab LIKE LINE OF pt_alv.
data: lv_op(4) type c.
LOOP AT pt_alv[] INTO ls_cab.
* lectura cabecera documento
REFRESH gt_bdcdata.
SELECT SINGLE * FROM HRP1000 WHERE
plvar eq '01' and
otype eq 'P0' and
OBJID eq ls_cab-id.
if sy-subrc eq 0.
lv_op = '=UPD'.
ELSE.
lv_op = '=INS'.
endif.
* --------------------------------------------------------------------*
PERFORM f_bdc_dynpro USING 'SAPMH5A0' '5000'.
PERFORM f_bdc_field USING 'BDC_CURSOR' 'PM0D1-SEARK' space.
PERFORM f_bdc_field USING 'BDC_OKCODE' '/00' space.
PERFORM f_bdc_field USING 'PPHDR-PLVAR' '01' space.
PERFORM f_bdc_field USING 'PPHDR-OTYPE' 'P0' space.
PERFORM f_bdc_field USING 'PM0D1-SEARK' ls_cab-id space.
PERFORM f_bdc_field USING 'BDC_SUBSCR' 'SAPMH5A0' '5005SUB1'.
* --------------------------------------------------------------------*
PERFORM f_bdc_dynpro USING 'SAPMH5A0' '5000'.
PERFORM f_bdc_field USING 'BDC_OKCODE' '=AEND' space.
PERFORM f_bdc_field USING 'PPHDR-PLVAR' '01' space.
PERFORM f_bdc_field USING 'PPHDR-OTYPE' 'P0' space.
PERFORM f_bdc_field USING 'PM0D1-SEARK' ls_cab-id space.
PERFORM f_bdc_field USING 'BDC_SUBSCR' 'SAPMH5A0' '5005SUB1'.
PERFORM f_bdc_field USING 'BDC_CURSOR' 'TT_T777T-ITEXT(01)' space.
PERFORM f_bdc_field USING 'MARKFELD(01)' 'X' space.
* --------------------------------------------------------------------*
PERFORM f_bdc_dynpro USING 'MP100000' '2000'.
PERFORM f_bdc_field USING 'BDC_CURSOR' 'P1000-STEXT' space.
* PERFORM f_bdc_field USING 'BDC_OKCODE' '=UPD' space.
PERFORM f_bdc_field USING 'BDC_OKCODE' lv_op space.
PERFORM f_bdc_field USING 'P1000-SHORT' ls_cab-desc_breve space.
PERFORM f_bdc_field USING 'P1000-STEXT' ls_cab-desc space.
PERFORM f_bdc_field USING 'P1000-LANGU' ls_cab-idioma space.
DATA: ctumode LIKE ctu_params-dismode VALUE 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
DATA: cupdate LIKE ctu_params-updmode VALUE 'A'.
"S: synchronously
"A: asynchronously
"L: local
DATA: messtab TYPE STANDARD TABLE OF bdcmsgcoll,
ls_messtab TYPE bdcmsgcoll.
CLEAR messtab.
CALL TRANSACTION 'PP01' USING gt_bdcdata
MODE ctumode
* UPDATE cupdate
MESSAGES INTO messtab.
READ TABLE messtab INTO ls_messtab WITH KEY msgtyp = 'E'.
IF sy-subrc NE 0.
* select single * from HRP1000
* where OTYPE eq 'P0'
* AND OBJID EQ gt_bdcdata-
gs_alv-icon = icon_green_light .
ELSE.
gs_alv-icon = icon_red_light .
ENDIF.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon.
ENDLOOP.
‎2021 Aug 19 7:12 AM
Doh! I did not know if there is an answer the OP cannot edit the question. Makes sense. My fault, then.