Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_PR_CREATE EXTENSIONIN

Former Member
0 Likes
29,424

Hello Gurus,

I am creating a PR using BAPI_PR_CREATE, I achieve creating the PR, but I can't save value in the custom fields.

This is my code, would you please help me?

Thanks

DATA: ls_req_item TYPE BAPI_TE_MEREQITEM,

      ls_req_itemx TYPE BAPI_TE_MEREQITEMX,

      ls_extensionin TYPE bapiparex,

      lt_extensionin TYPE STANDARD TABLE OF bapiparex.

           clear ls_extensionin.

        clear ls_req_item.

        ls_req_item-preq_item = wa_gt_data-posic.

        ls_req_item-ZZKOSTL    = wa_praccount-costcenter.

        ls_extensionin-structure = 'BAPI_TE_MEREQITEM'.

        PERFORM transfer_to_extensionin USING ls_req_item CHANGING ls_extensionin.

        APPEND ls_extensionin to lt_extensionin.

        clear ls_extensionin.

        clear ls_req_itemx.

        ls_req_itemx-preq_item = wa_gt_data-posic.

        ls_req_itemx-ZZKOSTL    = 'X'.

        ls_extensionin-structure = 'BAPI_TE_MEREQITEMX'.

        PERFORM transfer_to_extensionin USING ls_req_itemx CHANGING ls_extensionin.

        APPEND ls_extensionin to lt_extensionin.

FORM transfer_to_extensionin

    USING

      is_bapi_extensionin TYPE any

    CHANGING

      cs_bapiparex        TYPE bapiparex.

  DATA l_distance_characters TYPE I.

  FIELD-SYMBOLS <any> TYPE any.

  DESCRIBE DISTANCE BETWEEN cs_bapiparex-structure

            AND cs_bapiparex-valuepart1

            INTO l_distance_characters

            IN CHARACTER MODE.

  ASSIGN cs_bapiparex+l_distance_characters(*) TO <any>

        CASTING LIKE is_bapi_extensionin.

  <any> = is_bapi_extensionin.

ENDFORM.

* Create the PR with the above data's.

  CALL FUNCTION 'BAPI_PR_CREATE'

    EXPORTING

      prheader     = wa_header

      prheaderx    = wa_headerx

    TABLES

      return       = t_return

      pritem       = t_item

      pritemx      = t_itemx

      praccount    = t_praccount

      praccountx   = t_praccountx

      "pritemsource = t_itemsource

      "pritemtext   = t_itext

      EXTENSIONIN  = lt_extensionin

    EXCEPTIONS

      OTHERS       = 1.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
24,522

Hi everyone,

Thank you all for your time and suggestions, I have the answer, because all custom fields of append structure are not CHAR, I can't update customs fields using EXTENSIONIN of BAPI_PR_CREATE.

I think my only solution is to use a simple UPDATE EBAN SET.... WHERE banfn =  ....

Thank you all for your valuable time.

41 REPLIES 41
Read only

Former Member
0 Likes
24,350

- Did you add the custom fields in BAPI_TE_MEREQITEM and BAPI_TE_MEREQITEMX under the append structure CI_EBANDB / CI_EBANDBX or create a new one? Make sure you have used CI_*** append structures;

- Implement the BADI ME_BAPI_PR_CUST put a break in the method MAP2I_EXTENSIONIN and check if IM_CONTAINER is filled.

Regards,

Felipe

Read only

0 Likes
24,350

Hi Felipe,

Yes, I have done that.

The transparent table EBAN has an .INCLUDE begins with CI_***, here are all the custom fields of a PR.

I will take a look at BADI ME_BAPI_PR_CUST, I will debug it.

I'll let you know.

thanks

Read only

Former Member
0 Likes
24,355

Hi Enrique,


please try as a first step to replace

PERFORM transfer_to_extensionin USING ls_req_item CHANGING ls_extensionin.

with

MOVE ls_req_item TO ls_extensionin+30.

and to replace

PERFORM transfer_to_extensionin USING ls_req_itemx CHANGING ls_extensionin.

with

MOVE ls_req_itemx TO ls_extensionin+30.

If this will work, you can improve this code for the code inspector.

Regards,

Klaus

Read only

0 Likes
24,355

Hi Klaus,

It doesn't work, when I write the sentence MOVE......   I have an error , IT SAYS

"LS_EXTENSIONIN+30(960)" and "LS_REQ_ITEM" are not mutually convertible  in a Unicode program. . 

Thanks

Read only

0 Likes
24,355

Hi,

BAPI_TE_MEREQITEM (include CI_EBANDB) should have only char and similar datatypes.

Please read carefully documentation of function BAPI_PR_CREATE parameter EXTENSIONIN and note 509898. Maybe You've to implement BADI described by Felipe.

Regards,

Jarek

Read only

0 Likes
24,355

Hi Jaroslaw,

Thank for answering, I am Reading the note, OK I understand, but still I am figuring out how to solve my problema, I am new at BADI, I am Reading now how to do it.

If you have some lines of code ABAP that can help me please, I will appreciate it. Or Perhaps a Link to read in more detail about this.

Sorry.

Thanks


Read only

0 Likes
24,355

Hi Enrique,


then try the following:  Replace

PERFORM transfer_to_extensionin USING ls_req_item CHANGING ls_extensionin.

with

DESCRIBE  FIELD  ls_req_item LENGTH h_length IN BYTE MODE.

MOVE ls_req_item TO ls_extensionin+30(h_length).

and replace

PERFORM transfer_to_extensionin USING ls_req_itemx CHANGING ls_extensionin.

with

DESCRIBE  FIELD  ls_req_itemx LENGTH h_length IN BYTE MODE.

MOVE ls_req_itemx TO ls_extensionin+30(h_length).

where h_length is defined as

DATA: h_length        TYPE  i.

I've checked this in a small sample report and it worked for me

REPORT  ztest_extensionin.

DATA: ls_req_item     TYPE  bapi_te_mereqitem.

DATA: ls_req_itemx    TYPE  bapi_te_mereqitemx.

DATA: ls_extensionin  TYPE  bapiparex.

DATA: h_length        TYPE  i.

START-OF-SELECTION.

  DESCRIBE  FIELD  ls_req_item LENGTH h_length IN BYTE MODE.

  MOVE ls_req_item TO ls_extensionin+30(h_length).

  DESCRIBE  FIELD  ls_req_itemx LENGTH h_length IN BYTE MODE.

  MOVE ls_req_itemx TO ls_extensionin+30(h_length).

Regards,

Klaus

Read only

0 Likes
24,355

Please try use Klaus code, could help (I didn't try). You can also search SDN with keys: BAPI_PR_CREATE, EXTENSIONIN.

In documentation of EXTENSONIN parametr there is link to SAP help, it' realy useful.

Jarek

Read only

0 Likes
24,354

Hi Klaus,

There must be something different in my report about yours, because I have this error.

I have debug and the line where the report fails is the following:

MOVE ls_req_item TO ls_extensionin+30(h_length).

I have the same declarations lines :

DATA: ls_req_item TYPE BAPI_TE_MEREQITEM,
            ls_req_itemx TYPE BAPI_TE_MEREQITEMX,
            ls_extensionin TYPE bapiparex,
            lt_extensionin TYPE STANDARD TABLE OF bapiparex.

Read only

0 Likes
24,354

The error says that the structure ls_req_item is longer then extensionin.

ls_req_item = 1260 long and extensionin is only 990 long. That is why it dumps.

It is up to you now to check why ls_req_item is that long.

Read only

0 Likes
24,354

Hi,

Thank your for your answer, Yes I understand the error, I know, but I don't how to solve it. this the structure of ls_req_ítem, there are almost 60 fields, the image is only a portion.

Thanks again

Read only

0 Likes
24,354

Can you split up the fields and values ? Extensionin is a table.

Read only

0 Likes
24,354

The BAPI extension can have the maximum length of 960 characteres, you can find SAP documentation below:

Appending Customer Fields - Enhancements, Modifications, ? (CA-BFA) - SAP Library

Seems that your append structure has more than permitted, you can try this way below to try to update the fields up to 960 characteres, sincerly i didn't try and I don't know if it will work, but the fields from character 960 onwards surely cannot be updated by BAPI extension.

MOVE ls_req_item(960) TO ls_extensionin+30(960).

Regards,

Felipe

Read only

0 Likes
24,354

Hi Felipe,

I have this error.

Read only

0 Likes
24,354

If I were you I would go through the link provided by Felippe and see if you followed all the guidelines EXACTLY. Especially concerning the Include and append to be used and the fields in this append structure.

One thing I saw when I read the documentation in the link is:

"Customers can use only fields of data type CHAR and similar data types in BAPI table extensions"

Read only

0 Likes
24,354

You can only use characters fields for BAPI extension, in your append structure you have fields type QUAN, CURR, DEC, this is not supported for extension functionality.

Regards,

Felipe

Read only

0 Likes
24,353

Hi Felipe.

Ok, I got it, Ok that must the error, all the custom fields are not char, perhaps thats because I can't update custom fields using extensión.

Read only

Former Member
0 Likes
24,523

Hi everyone,

Thank you all for your time and suggestions, I have the answer, because all custom fields of append structure are not CHAR, I can't update customs fields using EXTENSIONIN of BAPI_PR_CREATE.

I think my only solution is to use a simple UPDATE EBAN SET.... WHERE banfn =  ....

Thank you all for your valuable time.

Read only

0 Likes
24,353

Hello Enrique,

here is a solution to fill the valuepart1 of the extension structure: you can CAST both source and destination to field symbols of type X to copy a structure with non-character fields (struc) to a character container (dest) in an unicode system. Instead of writing

   DEST = STRUC

use:


  field-symbols: <struc> TYPE X, <dest> TYPE X.

  assign: struc TO <struc>, dest TO <dest>.

  <dest> = <struc>.

Also check class CL_ABAP_CONTAINER_UTILITIES.


regards,


JNN

Read only

0 Likes
24,353

Hi Jacques,

Thank you for your time,

This is my code ABAP now, but it sill doen't work, perhaps it is like Felipe says, only char must declare in APPEND STRUCTURE, but I have different types.

       CLEAR ls_extensionin.
        CLEAR ls_req_item.
        MOVE: wa_gt_data-posic          TO ls_req_item-preq_item.
        MOVE: wa_praccount-costcenter   TO ls_req_item-ZZKOSTL.

              CALL METHOD cl_abap_container_utilities=>fill_container_c
                EXPORTING
                  im_value     = ls_req_item
                IMPORTING
                  ex_container = ls_extensionin+30
                EXCEPTIONS
                  OTHERS       = 0.

              MOVE 'BAPI_TE_MEREQITEM' TO ls_extensionin-structure.
              APPEND ls_extensionin to lt_extensionin.


        CLEAR ls_extensionin.
        CLEAR ls_req_itemx.
        MOVE: wa_gt_data-posic          TO ls_req_itemx-preq_item.
        MOVE: 'X'                       TO ls_req_itemx-ZZKOSTL.

              CALL METHOD cl_abap_container_utilities=>fill_container_c
                EXPORTING
                  im_value     = ls_req_itemx
                IMPORTING
                  ex_container = ls_extensionin+30
                EXCEPTIONS
                  OTHERS       = 0.

              MOVE 'BAPI_TE_MEREQITEMX' TO ls_extensionin-structure.
              APPEND ls_extensionin to lt_extensionin.

Thanks

Read only

0 Likes
24,353

Hello Enrique,

your logic seems correct.

But now you must implement BAdI ME_BAPI_PR_CUST because you have non CLIKE fields in the CI_EBANDB structure. Use the read_container_c( ) in method map2i_extensionin( ). Make sure  OSS Note 1111291 is applied to your system.


best regards,


JNN

Read only

0 Likes
24,353

Hi Enrique,

if you want to update EBAN with

UPDATE EBAN SET

please do this in an update function module with CALL FUNCTION ... IN UPDATE TASK.

First lock the PR (same locks as in ME52N), then get all update values and pass them to the function module in update task, and then finally do a COMMIT to call the function module and release the PR.

Another idea is to shrink BAPI_TE_MEREQITEM to the fiedls you really want to update by BAPI. I don't think you need all custom fields for update here.

Regards,

Klaus

Read only

0 Likes
24,353

Hi Jacques,

I am reading the note but I don't understand the solution., sorry.

I tried to implement the BADI but I have the following message.

Read only

0 Likes
24,353

Hi Klaus,

Thanks so much for your advice.

Best regards.

Read only

0 Likes
24,353

Hi Enrique,

The badi name is ME_BAPI_PR_CUST and not BADI ME_BAPI_PR_CUST. Leave out the BADI part

Read only

0 Likes
24,353

Hi Peter,

It isn't exist either

Thanks


Read only

0 Likes
24,353

Go to transaction SE18 and try again.

Check the enhancement spot ES_BADI_ME_BAPI.

BAdI Definition ME_BAPI_PR_CUST is part of this spot.

JNN

Read only

0 Likes
24,353

You are in the BADI implementation tcode (SE19), you have to go in BADI definition SE18 and then look for ME_BAPI_PR_CUST.

Regards,

Felipe

Read only

0 Likes
24,353

Hi Felipe,

I've read in your first ANSWER that I have to implement the BADI ME_BAPI_PR_CUST.Do I have to go to trx SE18 To implement?

Sorry I am new at implementing BADIs

Best Regards.

Read only

0 Likes
24,353

- Go to SE18 and fill BADI Name with ME_BAPI_PR_CUST then Display;
- On the left side you will find a panel with BAdI definitions click with the right button on ME_BAPI_PR_CUST and then Create BAdI Implementation;

- On new the popscreen, create a new Enhancement implementation.

Regards,

Felipe

Read only

0 Likes
24,353

Enrique, I highly recommend you to read the SAP documentation to get some knowledge about what you're doing.

Business Add-Ins (BAdIs) - Enhancement Framework - SAP Library

Regards,

Felipe

Read only

0 Likes
24,353

Hi Felipe,

I am reading the link now, thanks for the help.

Best Regards.

Read only

0 Likes
24,353

Hi Filipe,

Do you have an example of how to implement it?

Thanks

Read only

0 Likes
24,353

If you don't need to do any validation just put the code below:

ch_struc = im_container.

if you need to do any validation you can follow the example that SAP suggests (your print), in your tests put a break point in the badi and check if im_container is filled with all the values.

Regards,

Felipe

Read only

0 Likes
24,352

The parameter  IM_CONTAINER has the following type.

Is there a quick way to convert this long char VALUEPART1 to the structure

CH_STRUC

Read only

0 Likes
24,352

Hello Enrique,

my proposal: delete lines 13 to 21 from your screenshot and insert your code there.

CASE im_name.

  WHEN 'CI_EBANDB' OR 'CI_EBANDBX'.

    

*  ToDo:   convert im_container to ch_struc.

*    use class CL_ABAP_CONTAINER_UTILITIES

*     method read_container_c( ).

     lf_done = 'X'.    

ENDCASE.

happy coding..

JNN

Read only

0 Likes
24,352

Hi Jacques,

Thank you, I will try to convert using CL_ABAP_CONTAINER_UTILITIES.

Best Regards.

Read only

0 Likes
24,352

Jacques,

It Works, thanks so much.


Read only

Dileep_30
Explorer
0 Likes
16,752

Hi,

I just want to take a moment and request regarding the updating of custom fields, which I am performing, but it is not updating. Could you please share with me the insights related to that, like what shoud I actually need to write in the Mape21 extension method?