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

Add EAN problem... And really need help !

Former Member
0 Likes
1,677

Hi all,

I really hope someone will be able to help me, i’m on this program for 4 days and i really want to make it works.

But for the moment, this program is “half-working” !

In fact, I’m trying to write a program which would allow users to add EAN for materials with material transaction MM42.

(Basic Data -> Additional Data -> Additional EANs)

I first try with LSMW, but no batch input is possible because we couldn’t be sure to go to the last line of the list.

So, I decided to go on with a BAPI calling, and that’s what I got now:

(I know, it’s quite simple for you all, but it’s my first one!)

_________________________________________________________

REPORT z_mm_ean_supplem MESSAGE-ID zfi_ap.

***********************************************************************

*******************DECLARATION ET INITIALISATION*********************

***********************************************************************

*----


*

  • Déclaration

*----


*

  • Tables générales

TABLES: mean. " Numéros d'articles européens pour article

  • variables

DATA: v_princ(1) TYPE c, " indicateur d'EAN principal

v_fonct(3) TYPE c VALUE '004'.

  • Zone de réception des erreurs et logs

DATA : bw_return TYPE bapireturn1.

  • Table de recupération du fichier

DATA: BEGIN OF gt_get_fich OCCURS 0,

z_matnr(18),

z_vkorg(4),

z_vtweg(2),

z_fiwrk(4),

z_meinh(3),

z_ean11(13),

z_eantp(2),

END OF gt_get_fich.

DATA: BEGIN OF g_get_fich OCCURS 0,

z_tot(1000),

END OF g_get_fich.

  • Table de reception des lignes existantes et structures associées

DATA : BEGIN OF t_mean OCCURS 0.

INCLUDE STRUCTURE mean.

DATA : END OF t_mean.

DATA : BEGIN OF bt_head OCCURS 0.

INCLUDE STRUCTURE bapie1mathead.

DATA : END OF bt_head.

DATA : BEGIN OF bt_marm OCCURS 0.

INCLUDE STRUCTURE bapie1marmrt.

DATA : END OF bt_marm.

DATA : BEGIN OF bt_marmx OCCURS 0.

INCLUDE STRUCTURE bapie1marmrtx.

DATA : END OF bt_marmx.

DATA : BEGIN OF bt_mean OCCURS 0.

INCLUDE STRUCTURE bapie1meanrt.

DATA : END OF bt_mean.

DATA : BEGIN OF bt_return OCCURS 0.

INCLUDE STRUCTURE bapireturn1.

DATA : END OF bt_return.

*----


*

  • Ecran de sélection

*----


*

SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP.

PARAMETERS: p_file LIKE ibipparms-path OBLIGATORY.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK bl2.

*----


*

  • Initialization

*----


*

INITIALIZATION.

*----


*

  • At selection screen

*----


*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

***********************************************************************

*************************DEBUT DU PROGRAMME**************************

***********************************************************************

*----


*

  • Start of selection

*----


*

START-OF-SELECTION.

PERFORM lecture_du_fichier.

PERFORM traitement.

PERFORM conclusion.

END-OF-SELECTION.

***********************************************************************

*************************FORM ASSOCIES*******************************

***********************************************************************

*&----


*

*& Form lecture_du_fichier

*&----


*

  • Déchargement des fichiers en entrée dans des tables internes

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM lecture_du_fichier.

CALL FUNCTION 'AA_FILE_UPLOAD_EXCEL'

EXPORTING

i_filename = p_file

  • I_TEST =

  • I_UCOMM =

  • I_MAXCOLS =

i_delimiter = '#'

TABLES

et_filecontent = g_get_fich

  • EXCEPTIONS

  • ERROR_ACCESSING_FILE = 1

  • OTHERS = 2

.

LOOP AT g_get_fich.

SPLIT g_get_fich AT '#' INTO gt_get_fich-z_matnr gt_get_fich-z_vkorg

gt_get_fich-z_vtweg gt_get_fich-z_fiwrk gt_get_fich-z_meinh

gt_get_fich-z_ean11 gt_get_fich-z_eantp.

APPEND gt_get_fich.

ENDLOOP.

ENDFORM. " lecture_du_fichier

*&----


*

*& Form traitement

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM traitement.

*Traitement du fichier recupéré

LOOP AT gt_get_fich.

CLEAR v_princ.

CLEAR t_mean.

REFRESH bt_marmx.

REFRESH bt_head.

REFRESH bt_marm.

REFRESH bt_mean.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

EXPORTING

input = gt_get_fich-z_meinh

  • LANGUAGE = SY-LANGU

IMPORTING

output = gt_get_fich-z_meinh

  • EXCEPTIONS

  • UNIT_NOT_FOUND = 1

  • OTHERS = 2

.

SELECT * FROM mean INTO TABLE t_mean

WHERE matnr = gt_get_fich-z_matnr

AND meinh = gt_get_fich-z_meinh.

IF sy-subrc <> 0.

v_princ = 'X'.

ENDIF.

********************ZONE D'APPEL******************

  • Chargt HEAD

bt_head-material = gt_get_fich-z_matnr.

bt_head-basic_view = 'X'.

APPEND bt_head.

  • Chargt MARM

bt_marm-function = v_fonct.

bt_marm-material = gt_get_fich-z_matnr.

bt_marm-alt_unit = gt_get_fich-z_meinh.

bt_marm-ean_upc = gt_get_fich-z_ean11.

bt_marm-ean_cat = gt_get_fich-z_eantp.

bt_marm-SUB_UOM = 'ST'.

bt_marm-NUMERATOR = '10'.

bt_marm-DENOMINATR = '1'.

APPEND bt_marm.

  • Chargt MEAN

bt_mean-function = v_fonct.

bt_mean-material = gt_get_fich-z_matnr.

bt_mean-unit = gt_get_fich-z_meinh.

bt_mean-ean_upc = gt_get_fich-z_ean11.

bt_mean-ean_cat = gt_get_fich-z_eantp.

  • bt_mean-main_ean = v_princ.

APPEND bt_mean.

  • Chargt MARMX

bt_marm-function = v_fonct.

bt_marm-material = gt_get_fich-z_matnr.

bt_marmx-alt_unit = gt_get_fich-z_meinh.

IF v_princ = 'X'.

bt_marmx-ean_upc = v_princ.

bt_marmx-ean_cat = v_princ.

ENDIF.

bt_marmx-SUB_UOM = 'X'.

bt_marmx-NUMERATOR = 'X'.

bt_marmx-DENOMINATR = 'X'.

APPEND bt_marmx.

PERFORM call_bapi.

ENDLOOP.

ENDFORM. " traitement

*&----


*

*& Form call_bapi

*&----


*

  • remplissage des tables concernées MARM-MEAN

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM call_bapi.

IF v_princ = 'X'.

CALL FUNCTION 'BAPI_MATERIAL_MAINTAINDATA_RT'

EXPORTING

headdata = bt_head

IMPORTING

return = bt_return

TABLES

unitsofmeasure = bt_marm

unitsofmeasurex = bt_marmx

  • UNITOFMEASURETEXTS =

  • internationalartnos = bt_mean

.

ELSE.

CALL FUNCTION 'BAPI_MATERIAL_MAINTAINDATA_RT'

EXPORTING

headdata = bt_head

IMPORTING

return = bt_return

TABLES

unitsofmeasure = bt_marm

unitsofmeasurex = bt_marmx

  • UNITOFMEASURETEXTS =

internationalartnos = bt_mean

.

ENDIF.

APPEND bt_return.

ENDFORM. " call_bapi

*&----


*

*& Form conclusion

*&----


*

  • Affichage des resultats

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM conclusion.

LOOP AT bt_return INTO bw_return.

WRITE:/ bw_return-message.

ENDLOOP.

COMMIT WORK.

ENDFORM. " conclusion

_________________________________________________________

Here is my problem:

When I try just to add a new EAN when there is already a main one, it works really well. I can add a second line, three, four, five lines more, no problem. But when I try to add an EAN when there is no previous value, the program doesn’t want to modify anything.

When I give a look at application log, I see exactly the same log for both, with just one difference :

In the first case (already a main EAN) : Material XXXXXX changed.

In the second one (no previous EAN) : No changes made

I tried a lot of things, but nothing works.

I don’t understand why…

I need your help.

Thanks to all answer.

Regards,

R.P.

Message was edited by: Papillon Romain

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,323
  • Chargt MARMX

bt_marm<b>X</b>-function = v_fonct.

bt_marm<b>X</b>-material = gt_get_fich-z_matnr.

bt_marmx-alt_unit = gt_get_fich-z_meinh.

IF v_princ = 'X'.

bt_marmx-ean_upc = v_princ.

bt_marmx-ean_cat = v_princ.

ENDIF.

bt_marmx-SUB_UOM = 'X'.

bt_marmx-NUMERATOR = 'X'.

bt_marmx-DENOMINATR = 'X'.

You forgot the X !!!

5 REPLIES 5
Read only

Former Member
0 Likes
1,323

Is the same BAPI called when you enter a new EAN number manually.

If so, then compare the your input parameters to that.

Read only

0 Likes
1,323

I try to see something different, but i don't know where is the problem coming from...

Read only

Former Member
0 Likes
1,324
  • Chargt MARMX

bt_marm<b>X</b>-function = v_fonct.

bt_marm<b>X</b>-material = gt_get_fich-z_matnr.

bt_marmx-alt_unit = gt_get_fich-z_meinh.

IF v_princ = 'X'.

bt_marmx-ean_upc = v_princ.

bt_marmx-ean_cat = v_princ.

ENDIF.

bt_marmx-SUB_UOM = 'X'.

bt_marmx-NUMERATOR = 'X'.

bt_marmx-DENOMINATR = 'X'.

You forgot the X !!!

Read only

Former Member
0 Likes
1,323

Hi,

I just now saw your post and I believe I'm having a similar problem. Did you solve it? I cannot seem to find a way to set an EAN as main through the BAPI.

Here's the thread I started on this same issue:

Thanks,

Nuno

Read only

0 Likes
1,323

Silly me,

Even though I was quite sure of my code, actually I was also missing some fields in MARM X structure. So this solution also worked for me.

Thanks and sorry for being clumsy.

Nuno