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

Modify internal table not working on some field (MATERIAL_EXTERNAL)

pawadee_k
Participant
0 Likes
1,807

I am working on 'BAPI_GOODSMVT_GETDETAIL'.
I want to add material desception to the table ('GOODSMVT_ITEMS') return from this BAPI,

I copy 'BAPI_GOODSMVT_GETDETAIL' to 'ZBAPI_GOODSMVT_GETDETAIL'.
Then added the code below to load material description into the internal table where I want to put the desctiption at 'material_external' field. However when I tested the function, the material_external field in the internal table is not updated. I tried to put in item_text field instead and it works. Why is material_material field not working?

LOOP AT GOODSMVT_ITEMS INTO WA_GOODSMVT_ITEM .
  SELECT MAKTX FROM MAKT INTO MATERIAL_EXTERNAL
    WHERE MATNR = WA_GOODSMVT_ITEM-MATERIAL.
    ENDSELECT.

    WA_GOODSMVT_ITEM-MATERIAL_EXTERNAL = MATERIAL_EXTERNAL.

    MODIFY GOODSMVT_ITEMS FROM WA_GOODSMVT_ITEM INDEX sy-tabix
    TRANSPORTING MATERIAL_EXTERNAL.
  ENDLOOP.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
1,578

A few points.

1. Never copy standard SAP code into your own name space. It is more dangerous than making a modification to the SAP code. Read my comment on this question https://archive.sap.com/discussions/thread/3617361

2. If you're looping through an internal table, don't use MODIFY. Instead using LOOP AT ... ASSIGNING... Search for examples of how this works. Or read the documentation.

3. With select endselect, you are looping through all entries in MAKT that have that particular MATNR, and ending up on the last one. How's that going to work on a multi-language system? Use SELECT SINGLE and specify the full key.


I am working on 'BAPI_GOODSMVT_GETDETAIL'.
I want to add material desception to the table ('GOODSMVT_ITEMS') return from this BAPI,

I copy 'BAPI_GOODSMVT_GETDETAIL' to 'ZBAPI_GOODSMVT_GETDETAIL'.
Then added the code below to load material description into the internal table where I want to put the desctiption at 'material_external' field. However when I tested the function, the material_external field in the internal table is not updated. I tried to put in item_text field instead and it works. Why is material_material field not working?

LOOP AT GOODSMVT_ITEMS INTO WA_GOODSMVT_ITEM .
  SELECT MAKTX FROM MAKT INTO MATERIAL_EXTERNAL
    WHERE MATNR = WA_GOODSMVT_ITEM-MATERIAL.
    ENDSELECT.

    WA_GOODSMVT_ITEM-MATERIAL_EXTERNAL = MATERIAL_EXTERNAL.

    MODIFY GOODSMVT_ITEMS FROM WA_GOODSMVT_ITEM INDEX sy-tabix
    TRANSPORTING MATERIAL_EXTERNAL.
  ENDLOOP.

6 REPLIES 6
Read only

matt
Active Contributor
1,579

A few points.

1. Never copy standard SAP code into your own name space. It is more dangerous than making a modification to the SAP code. Read my comment on this question https://archive.sap.com/discussions/thread/3617361

2. If you're looping through an internal table, don't use MODIFY. Instead using LOOP AT ... ASSIGNING... Search for examples of how this works. Or read the documentation.

3. With select endselect, you are looping through all entries in MAKT that have that particular MATNR, and ending up on the last one. How's that going to work on a multi-language system? Use SELECT SINGLE and specify the full key.


Read only

0 Likes
1,578

Hi Matthew,

Thank you for your comment.

I am actually using my own function group, and I communicated wrongly about coping, I actually called the standard BAPI then loop at the table return from the BAPI not actually coping over the code.

I did changed the copy to select single and LOOP AT... ASSIGNING, however the field material_external remain unchanged.

CALL FUNCTION 'BAPI_GOODSMVT_GETDETAIL'
EXPORTING
  MATERIALDOCUMENT = MATERIALDOCUMENT
  MATDOCUMENTYEAR = MATDOCUMENTYEAR
IMPORTING
  GOODSMVT_HEADER = GOODSMVT_HEADER
TABLES
  GOODSMVT_ITEMS = GOODSMVT_ITEMS
  RETURN = RETURN.

DATA: MATERIAL_EXTERNAL TYPE BAPI2017_GM_ITEM_SHOW-MATERIAL_EXTERNAL.
field-symbols: <fs> TYPE BAPI2017_GM_ITEM_SHOW.

LOOP AT GOODSMVT_ITEMS ASSIGNING <fs>.
  SELECT SINGLE MAKTX FROM MAKT INTO MATERIAL_EXTERNAL
    WHERE MATNR = <fs>-MATERIAL AND SPRAS = 'E'.

  <fs>-MATERIAL_EXTERNAL = MATERIAL_EXTERNAL.
  <fs>-MATERIAL = MATERIAL_EXTERNAL.

ENDLOOP.

In the resulting internal table, field material did changed but not material_external.

Read only

matt
Active Contributor
0 Likes
1,578

You need to run it in debug mode and see how the variables change.

Read only

0 Likes
1,578

Hi Matthew,

In debug mode, I did see the variables, both <fs>-material and <fs>-material_external change.
I also placed a breakpoint after the loop ends, which I see that material_external in the internal table is set.
But when the funcation ends, in the return table the material_external is again empty.

Read only

former_member564522
Active Participant
1,578

Hi Pawadee,

Material External is not the description field. Material has been represented in internal and external format.

When you try to put the material external , it is validating with the existing material.

you can check domain MATNR_EXT for more information on conversion.

Hope you can took advice from Matthew for not copy standard BAPI.

Regards

Himanshu

Read only

0 Likes
1,578

Hi Himanshu,

Thank you for explaining, now I get it.

I was kind of try to sneak in the description into the field so that I don't need to create my own structure with description field since I saw that it have the same length etc.

And yes, I did took Matthew advice 🙂