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

ME_PROCESS_REQ_CUST item process problem

Former Member
0 Likes
1,041

Hi,

I'm trying to process user seletion from a popup and insert records on a PR, first selection is OK, problem is second selection (MATNR) still in loop, how could I do for this?

IMPORT totreg  TO totreg  FROM MEMORY ID 'TR'.
  IMPORT tabkind TO tabkind FROM MEMORY ID 'TK'.
  IMPORT vmatnr  TO vmatnr  FROM MEMORY ID 'VM'.
  IMPORT xchoice TO xchoice FROM MEMORY ID 'XC'.


  IF totreg = 1.
    IMPORT vmatnr TO vmatnr FROM MEMORY ID 'VM'.
  ENDIF.

* Getting ITEM
  ls_item = im_item->get_data( ).

  IF ls_item-BNFPO > tabkind AND totreg > 0.
    FREE MEMORY ID 'TR'.
    FREE MEMORY ID 'TK'.
    totreg = 0.
    tabkind = 0.
    EXIT.
  ELSEIF ls_item-BNFPO = 0 AND totreg > 0 AND tabkind > 0 AND totreg = tabkind.
    FREE MEMORY ID 'TR'.
    FREE MEMORY ID 'TK'.
    totreg = 0.
    tabkind = 0.
    EXIT.
  ENDIF.


  IF totreg > 0 AND tabkind > 0.
    IF  totreg = tabkind AND ls_item-BNFPO = 0.
      EXIT.
    ELSEIF totreg = tabkind AND XCHOICE = 1.
      EXIT.
    ENDIF.
  ENDIF.

  IF totreg > 0 AND tabkind > 0 AND totreg = tabkind AND ti_mastb[] IS INITIAL.
    EXIT.
  ENDIF.

  IF totreg = tabkind AND totreg > 0
     AND ( ls_item-BNFPO = tabkind OR ls_item-BNFPO = tabkindb OR ls_item-BNFPO = 0 ).
    EXIT.
  ENDIF.

  IF TOTREG = TABKIND AND totreg > 0.
    tabkindb = tabkind + 1.
  ENDIF.

  IF totreg = tabkind AND totreg > 0 AND ls_item-BNFPO > tabkind.
    FREE MEMORY ID 'TR'.
    FREE MEMORY ID 'TK'.
    totreg = 0.
    tabkind = 0.
  ENDIF.

  IF ls_item-bsart EQ 'ZME' AND ls_item-loekz NE 'X' AND ls_item-afnam EQ 'GB'.

    SELECT MANDT MATNR WERKS STLAN STLNR STLAL
           FROM MAST                                  "#EC CI_SGLSELECT
           INTO TABLE ti_mastb
           WHERE MATNR = ls_item-MATNR .

    CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
      EXPORTING
        ENDPOS_COL   = 75
        ENDPOS_ROW   = 16
        STARTPOS_COL = 3
        STARTPOS_ROW = 5
        TITLETEXT    = 'Seleccione la lista de material'
      IMPORTING
        CHOISE       = xchoice
      TABLES
      VALUETAB     = ti_mastb
      EXCEPTIONS
        BREAK_OFF    = 1
        OTHERS       = 2.

    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    DELETE ti_mastb WHERE STLAL NE XCHOICE.

    SELECT *
           FROM STAS
           INTO TABLE ti_stas
           FOR ALL ENTRIES IN ti_mastb WHERE STLTY = 'M'
                           AND STLAL = ti_mastb-STLAL
                           AND STLNR = ti_mastb-STLNR .

    SELECT *
           FROM STPO
           INTO TABLE ti_stpo
           FOR ALL ENTRIES IN ti_stas WHERE STLTY = 'M'
                           AND STLNR = ti_stas-STLNR
                           AND STLKN = ti_stas-STLKN .

    DESCRIBE TABLE ti_stpo LINES tabkind.
    READ TABLE ti_mastb INTO wa_mastb WITH KEY MATNR = ls_item-matnr.
    menge         = ls_item-menge.
* Se llenan el/los item(s) nuevos
    LOOP AT ti_stpo INTO wa_stpo.

* Se obtiene el objeto cabecera de la solicitud de pedido
      lo_header = im_item->get_requisition( ).

* Se crea una nueva posicion como copia de otra existente
      lo_item = lo_header->create_item( im_item = im_item ).

* Se obtiene el objeto
      ls_item = lo_item->get_data( ).
      ls_itemx = lo_item->get_datax( ).

      ls_item-matnr  = wa_stpo-IDNRK.

      porcentaje    = wa_stpo-AUSCH / 100.
      cantidad      = menge * porcentaje.
      totcant       = cantidad + menge.

      totcant = CEIL( totcant ).
      ls_item-menge = totcant.

      ls_itemx-matnr = 'X'.
      ls_itemx-menge = 'X'.

      IF vmatnr NE ls_item-matnr and totreg >= 0.
        lo_item->set_data( im_data = ls_item ).
        lo_item->set_datax( im_datax = ls_itemx ).
      ENDIF.
      totreg = totreg + 1.
      if totreg = 1.
        vmatnr = wa_mastb-matnr.
        EXPORT vmatnr FROM vmatnr TO MEMORY ID 'VM'.
      endif.
    ENDLOOP.
    EXPORT totreg  FROM totreg  TO MEMORY ID 'TR'.
    EXPORT tabkind FROM tabkind TO MEMORY ID 'TK'.
    EXPORT xchoice FROM xchoice TO MEMORY ID 'XC'.
  ENDIF.

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
926

Hi,

Pls. go thru this link.....

[for better understand of the code you have written|/thread/1319756 [original link is broken];

Thanks,

Sid

7 REPLIES 7
Read only

Former Member
0 Likes
927

Hi,

Pls. go thru this link.....

[for better understand of the code you have written|/thread/1319756 [original link is broken];

Thanks,

Sid

Read only

0 Likes
926

Thanks but how could I do?

Read only

0 Likes
926

break the code into two different messages and then send it across

Read only

0 Likes
926
IMPORT totreg  TO totreg  FROM MEMORY ID 'TR'.
  IMPORT tabkind TO tabkind FROM MEMORY ID 'TK'.
  IMPORT vmatnr  TO vmatnr  FROM MEMORY ID 'VM'.
  IMPORT xchoice TO xchoice FROM MEMORY ID 'XC'.

  IF totreg = 1.
    IMPORT vmatnr TO vmatnr FROM MEMORY ID 'VM'.
  ENDIF.

* Getting Item
  ls_item = im_item->get_data( ).

  IF ls_item-BNFPO > tabkind AND totreg > 0.
    FREE MEMORY ID 'TR'.
    FREE MEMORY ID 'TK'.
    totreg = 0.
    tabkind = 0.
    EXIT.
  ELSEIF ls_item-BNFPO = 0 AND totreg > 0 AND tabkind > 0 AND totreg = tabkind.
    FREE MEMORY ID 'TR'.
    FREE MEMORY ID 'TK'.
    totreg = 0.
    tabkind = 0.
    EXIT.
  ENDIF.


  IF totreg > 0 AND tabkind > 0.
    IF  totreg = tabkind AND ls_item-BNFPO = 0.
      EXIT.
    ELSEIF totreg = tabkind AND XCHOICE = 1.
      EXIT.
    ENDIF.
  ENDIF.

  IF totreg > 0 AND tabkind > 0 AND totreg = tabkind AND ti_mastb[] IS INITIAL.
    EXIT.
  ENDIF.

  IF totreg = tabkind AND totreg > 0
     AND ( ls_item-BNFPO = tabkind OR ls_item-BNFPO = tabkindb OR ls_item-BNFPO = 0 ).
    EXIT.
  ENDIF.

  IF TOTREG = TABKIND AND totreg > 0.
    tabkindb = tabkind + 1.
  ENDIF.

  IF totreg = tabkind AND totreg > 0 AND ls_item-BNFPO > tabkind.
    FREE MEMORY ID 'TR'.
    FREE MEMORY ID 'TK'.
    totreg = 0.
    tabkind = 0.
  ENDIF.

Edited by: mgg on Dec 14, 2009 12:30 PM

Read only

0 Likes
926
IF ls_item-bsart EQ 'ZME' AND ls_item-loekz NE 'X' AND ls_item-afnam EQ 'GB'.

    SELECT MANDT MATNR WERKS STLAN STLNR STLAL
           FROM MAST                                  "#EC CI_SGLSELECT
           INTO TABLE ti_mastb
           WHERE MATNR = ls_item-MATNR
           .

    CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
      EXPORTING
        ENDPOS_COL   = 75
        ENDPOS_ROW   = 16
        STARTPOS_COL = 3
        STARTPOS_ROW = 5
        TITLETEXT    = 'Seleccione la lista de material'
      IMPORTING
        CHOISE       = xchoice
      TABLES
      VALUETAB     = ti_mastb
      EXCEPTIONS
        BREAK_OFF    = 1
        OTHERS       = 2.

    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


    DELETE ti_mastb WHERE STLAL NE XCHOICE.

    SELECT *
           FROM STAS
           INTO TABLE ti_stas
           FOR ALL ENTRIES IN ti_mastb WHERE STLTY = 'M'
                           AND STLAL = ti_mastb-STLAL
                           AND STLNR = ti_mastb-STLNR
           .

    SELECT *
           FROM STPO
           INTO TABLE ti_stpo
           FOR ALL ENTRIES IN ti_stas WHERE STLTY = 'M'
                           AND STLNR = ti_stas-STLNR
                           AND STLKN = ti_stas-STLKN
           .


    DESCRIBE TABLE ti_stpo LINES tabkind.



    READ TABLE ti_mastb INTO wa_mastb WITH KEY MATNR = ls_item-matnr.


    menge         = ls_item-menge.
Read only

0 Likes
926
* Getting item
    LOOP AT ti_stpo INTO wa_stpo.

      lo_header = im_item->get_requisition( ).


      lo_item = lo_header->create_item( im_item = im_item ).


      ls_item = lo_item->get_data( ).
      ls_itemx = lo_item->get_datax( ).


      ls_item-matnr  = wa_stpo-IDNRK.

      porcentaje    = wa_stpo-AUSCH / 100.
      cantidad      = menge * porcentaje.
      totcant       = cantidad + menge.

      totcant = CEIL( totcant ).
      ls_item-menge = totcant.

      ls_itemx-matnr = 'X'.
      ls_itemx-menge = 'X'.

      IF vmatnr NE ls_item-matnr and totreg >= 0.
        lo_item->set_data( im_data = ls_item ).
        lo_item->set_datax( im_datax = ls_itemx ).
      ENDIF.

      totreg = totreg + 1.

      if totreg = 1.
        vmatnr = wa_mastb-matnr.
        EXPORT vmatnr FROM vmatnr TO MEMORY ID 'VM'.
      endif.

    ENDLOOP.

    EXPORT totreg  FROM totreg  TO MEMORY ID 'TR'.
    EXPORT tabkind FROM tabkind TO MEMORY ID 'TK'.
    EXPORT xchoice FROM xchoice TO MEMORY ID 'XC'.

  ENDIF.
Read only

Former Member
0 Likes
926

Solve it!!!

using

PROCESS_HEADER & PROCESS_ITEM