‎2009 Dec 12 6:52 PM
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
‎2009 Dec 12 6:59 PM
Hi,
Pls. go thru this link.....
[for better understand of the code you have written|/thread/1319756 [original link is broken];
Thanks,
Sid
‎2009 Dec 12 6:59 PM
Hi,
Pls. go thru this link.....
[for better understand of the code you have written|/thread/1319756 [original link is broken];
Thanks,
Sid
‎2009 Dec 12 7:04 PM
‎2009 Dec 12 11:27 PM
break the code into two different messages and then send it across
‎2009 Dec 14 11:29 AM
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
‎2009 Dec 14 11:31 AM
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.
‎2009 Dec 14 11:32 AM
* 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.
‎2009 Dec 14 7:38 PM