Skip to Content
0
Aug 13, 2007 at 06:55 AM

LOOP AND APPEND PROBLEM.

60 Views

Hi Folks,

I had highlighted a part of the code down here.

If I use APPEND in that loop it is running indefinitely.

If I use modify it is going to dump.

Due to that I am not getting the BELNR in the where clause of the subsequent loops and thus not able to select the data for some fields.

Kindly help me with this.

REPORT ZMIG

TABLES:MKPF,

MSEG,

EKPO,

RBKP,

RSEG,

LFA1.

TYPE-POOLS:SLIS.

TYPES:BEGIN OF X_MKPF,

MBLNR LIKE MKPF-MBLNR,

MJAHR LIKE MKPF-MJAHR,

BUDAT LIKE MKPF-BUDAT,

XBLNR LIKE MKPF-XBLNR,

END OF X_MKPF.

TYPES:BEGIN OF X_FINAL,

SL_NO LIKE SY-TABIX,

MBLNR LIKE MKPF-MBLNR, "MIGO No.

MJAHR LIKE MKPF-MJAHR,

BUDAT LIKE MKPF-BUDAT, "MIGO DATE

XBLNR LIKE MKPF-XBLNR,

ZEILE LIKE MSEG-ZEILE,

BUKRS LIKE MSEG-BUKRS,

LGORT LIKE MSEG-LGORT,

BWART LIKE MSEG-BWART,

MATNR LIKE MSEG-MATNR,

LIFNR LIKE MSEG-LIFNR,

BWTAR LIKE MSEG-BWTAR,

MENGE LIKE MSEG-MENGE, "Quantity in MSEG

EBELN LIKE MSEG-EBELN,

EBELP LIKE MSEG-EBELP,

WEBRE LIKE EKPO-WEBRE,

AEDAT LIKE EKKO-AEDAT, "PO Date

MENGE1 LIKE EKPO-MENGE, "PO Quantity in EKPO

BELNR LIKE RSEG-BELNR,

GJAHR LIKE RSEG-GJAHR,

MENGE2 LIKE RSEG-MENGE, "Quantity in RSEG

LFBNR LIKE RSEG-LFBNR,

LFGJA LIKE RSEG-LFGJA,

LFPOS LIKE RSEG-LFPOS,

BUDAT1 LIKE RBKP-BUDAT, "MIRO Date

END OF X_FINAL.

*INTERNAL TABLE FOR RBKP AND RSEG.

TYPES:BEGIN OF X_TEMP,

BELNR LIKE RBKP-BELNR,

GJAHR LIKE RBKP-GJAHR,

EBELN LIKE RSEG-EBELN,

EBELP LIKE RSEG-EBELP,

MATNR LIKE RSEG-MATNR,

BUKRS LIKE RSEG-BUKRS,

MENGE LIKE RSEG-MENGE,

XBLNR LIKE RSEG-XBLNR,

LFGJA LIKE RSEG-LFGJA,

LFPOS LIKE RSEG-LFPOS,

LIFNR LIKE RSEG-LIFNR,

END OF X_TEMP.

DATA:ITMKPF TYPE x_MKPF OCCURS 0 WITH HEADER LINE.

DATA:ITTEMP TYPE X_TEMP OCCURS 0 WITH HEADER LINE.

DATA:ITFINAL TYPE X_FINAL OCCURS 0 WITH HEADER LINE.

*Declarations for ALV

DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA:itrepid TYPE sy-repid.

itrepid = sy-repid.

DATA:itevent TYPE slis_t_event.

DATA:itlistheader TYPE slis_t_listheader.

DATA:walistheader LIKE LINE OF itlistheader.

DATA:itlayout TYPE slis_layout_alv.

DATA:top TYPE slis_formname.

DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.

DATA :itsort1 TYPE slis_sortinfo_alv.

DATA:itprintparams TYPE slis_print_alv.

DATA:itvariant TYPE disvariant.

DATA :i(2), "month

y TYPE int4, "year

c(4).

DATA:STRING1(75),STRING2(75),

TITLE1(75),

DATE1(10),

DATE2(10).

SELECTION-SCREEN BEGIN OF SCREEN 100 TITLE MIGO.

PARAMETERS: R1 RADIOBUTTON GROUP G1 USER-COMMAND KK1 DEFAULT 'X',

R2 RADIOBUTTON GROUP G1.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS: S_BUKRS1 FOR MSEG-BUKRS MODIF ID K1,

S_PLANT FOR MSEG-WERKS MODIF ID K1,

S_BUDAT FOR MKPF-BUDAT OBLIGATORY MODIF ID K1,

S_LIFNR1 FOR LFA1-LIFNR MODIF ID K1.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

SELECT-OPTIONS:S_EBELN FOR MSEG-EBELN MODIF ID K2,

S_LIFNR2 FOR LFA1-LIFNR MODIF ID K2,

S_BUKRS2 FOR MSEG-BUKRS MODIF ID K2,

S_WERKS FOR MSEG-WERKS MODIF ID K2.

SELECTION-SCREEN END OF BLOCK B2.

SELECTION-SCREEN END OF SCREEN 100.

CALL SELECTION-SCREEN 100.

AT SELECTION-SCREEN OUTPUT.

IF R1 = 'X'.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'K1'.

SCREEN-ACTIVE = '0'.

SCREEN-INPUT = '0'.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

ENDIF.

IF R2 = 'X'.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'K2'.

SCREEN-ACTIVE = '0'.

SCREEN-INPUT = '0'.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

ENDIF.

start-of-selection.

PERFORM GETDATA.

PERFORM ALV.

*end-of-selection.

&----


*& Form GETDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form GETDATA .

SELECT MBLNR

MJAHR

BUDAT

XBLNR

FROM MKPF INTO CORRESPONDING FIELDS OF TABLE ITMKPF

WHERE BUDAT IN S_BUDAT.

IF sy-subrc NE 0.

MESSAGE 'No Values exist for the Selection.' TYPE 'S'.

ENDIF.

LOOP AT ITMKPF.

MOVE-CORRESPONDING ITMKPF TO ITFINAL.

SELECT MBLNR

MJAHR

ZEILE

BWART

MATNR

WERKS

LGORT

LIFNR

BWTAR

MENGE

EBELN

EBELP

BUKRS

FROM MSEG INTO CORRESPONDING FIELDS OF ITFINAL

WHERE MBLNR = ITMKPF-MBLNR

AND MJAHR = ITMKPF-MJAHR.

*TO GET THE PO QUANTITY AND GR BASED INDICATOR

*SELECT SINGLE MENGE

  • WEBRE

  • FROM EKPO INTO CORRESPONDING FIELDS OF ITFINAL

  • WHERE EBELN = ITFINAL-EBELN

  • AND EBELP = ITFINAL-EBELP.

SELECT SINGLE MENGE

WEBRE

FROM EKPO INTO (ITFINAL-MENGE1,ITFINAL-WEBRE)

WHERE EBELN = ITFINAL-EBELN

AND EBELP = ITFINAL-EBELP.

*TO GET THE PO DATE.

SELECT SINGLE AEDAT

FROM EKKO INTO ITFINAL-AEDAT

WHERE EBELN = ITFINAL-EBELN.

APPEND ITFINAL.

ENDSELECT.

CLEAR ITFINAL.

CLEAR ITMKPF.

ENDLOOP.

LOOP AT ITFINAL.

IF ITFINAL-WEBRE NE 'X'.

DELETE ITFINAL.

ENDIF.

ENDLOOP.

***********12*******

LOOP AT ITFINAL.

SELECT BELNR

GJAHR

FROM RBKP INTO CORRESPONDING FIELDS OF ITTEMP

WHERE XBLNR = ITFINAL-XBLNR

AND LIFNR = ITFINAL-LIFNR

AND BUKRS = ITFINAL-BUKRS. "26

APPEND ITTEMP.

ENDSELECT.

CLEAR ITTEMP.

CLEAR ITFINAL.

ENDLOOP.

LOOP AT ITTEMP.

SELECT EBELN

EBELP

MATNR

BUKRS

MENGE

XBLNR

LFBNR

LFGJA

LFPOS

LIFNR

FROM RSEG INTO CORRESPONDING FIELDS OF ITTEMP

WHERE BELNR = ITTEMP-BELNR

AND GJAHR = ITTEMP-GJAHR.

MODIFY ITTEMP.

ENDSELECT.

ENDLOOP.

<b>LOOP AT ITFINAL.

MOVE-CORRESPONDING ITTEMP TO ITFINAL.

CLEAR ITTEMP.

CLEAR ITFINAL.

ENDLOOP.</b>

************12****************

**TO GET THE MIRO DATE

LOOP AT ITFINAL.

SELECT SINGLE BUDAT

FROM RBKP INTO (ITFINAL-BUDAT1)

WHERE BELNR = ITFINAL-BELNR "XBLNR

AND GJAHR = ITFINAL-GJAHR.

  • AND LIFNR = ITFINAL-LIFNR "26

  • AND BUKRS = ITFINAL-BUKRS. "26

*TO GET THE MIRO QUANTITY

SELECT SINGLE MENGE

FROM RSEG INTO (ITFINAL-MENGE2)

WHERE BELNR = ITFINAL-BELNR

AND GJAHR = ITFINAL-GJAHR.

MODIFY ITFINAL.

ENDLOOP.

endform. " GETDATA

&----


*& Form ALV

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form ALV .

LOOP AT ITFINAL.

ITFINAL-SL_NO = SY-TABIX.

MODIFY ITFINAL.

ENDLOOP.

itlayout-zebra = 'X'.

itlayout-colwidth_optimize = 'X'.

itlayout-no_subtotals = ' '.

IF itfinal[] IS INITIAL.

MESSAGE 'No Values exist for the Selection.' TYPE 'S'.

STOP.

ENDIF.

DEFINE m_fieldcat.

itfieldcat-fieldname = &1.

itfieldcat-col_pos = &2.

itfieldcat-seltext_l = &3.

itfieldcat-do_sum = &4.

itfieldcat-outputlen = &5.

append itfieldcat to itfieldcat.

clear itfieldcat.

END-OF-DEFINITION.

*m_fieldcat 'SL_NO' '' 'SL. NO' '' 03.

*m_fieldcat 'MBLNR' '' 'Materil Doc.No' '' 10.

*m_fieldcat 'MJAHR' '' 'Material Doc.Yr.' '' 04.

*m_fieldcat 'BUDAT' '' 'POSTING DATE' '' 08.

*m_fieldcat 'ZEILE' '' 'Item in Mat.Doc.' '' 04.

**m_fieldcat 'WERKS' '' 'Plant' '' 04 .

*m_fieldcat 'LGORT' '' 'Storage Location' '' 04.

*m_fieldcat 'BWART' '' 'Movement Type' '' 03.

*m_fieldcat 'MATNR' '' 'Material No.' '' 18.

*m_fieldcat 'BWTAR' '' 'Valutaion Type' '' 10.

*m_fieldcat 'LIFNR' '' 'Vendor' '' 10.

*m_fieldcat 'MENGE' '' 'Quantity' '' 13.

*m_fieldcat 'EBELN' '' 'PO.No' '' 10.

*m_fieldcat 'EBELP' '' 'Item No.of PO Doc' '' 05.

*m_fieldcat 'MENGE1' '' 'PO Quantity' '' 13.

*m_fieldcat 'WEBRE' '' 'GR.Indicator' '' 01.

*m_fieldcat 'XBLNR' '' 'Ref.Doc No.' '' 16.

*m_fieldcat 'BELNR' '' 'Accounting Doc.No.' '' 10.

*m_fieldcat 'GJAHR' '' 'Fiscal Yr.' '' 04.

*m_fieldcat 'MENGE2' '' 'MIRO Quantity' '' 13.

m_fieldcat 'SL_NO' '' 'SL. NO' '' 03.

m_fieldcat 'MBLNR' '' 'MIGO.No' '' 10.

m_fieldcat 'BUDAT' '' 'MIGO DATE' '' 08.

m_fieldcat 'MJAHR' '' 'Material Doc.Yr.' '' 04.

m_fieldcat 'XBLNR' '' 'Ref.Doc No.' '' 16.

m_fieldcat 'MENGE' '' 'MIGO Quantity' '' 13.

*****

m_fieldcat 'EBELN' '' 'PO.No' '' 10.

m_fieldcat 'AEDAT' '' 'PO.Date' '' 08.

m_fieldcat 'MENGE1' '' 'PO Quantity' '' 13.

*****

m_fieldcat 'BELNR' '' 'MIRO No.' '' 10.

m_fieldcat 'BUDAT1' '' 'MIRO DATE' '' 08.

m_fieldcat 'MENGE2' '' 'MIRO Quantity' '' 13.

m_fieldcat 'LIFNR' '' 'Vendor' '' 10.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

I_CALLBACK_TOP_OF_PAGE = 'TOP'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = ITLAYOUT

IT_FIELDCAT = ITFIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = ITEVENT[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = ITFINAL

  • EXCEPTIONS

  • PROGRAM_ERROR = 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.

endform. " ALV

FORM TOP.

WRITE: S_BUDAT-LOW TO DATE1,

S_BUDAT-HIGH TO DATE2.

IF R1 = 'X'.

string1 = 'NON GR BASED DOCUMENTS FROM :'.

CONCATENATE string1 date1 'to' date2 INTO title1 SEPARATED BY space.

walistheader-typ = 'H'.

walistheader-info = title1.

APPEND walistheader TO itlistheader.

ELSE.

string2 = 'GR BASED DOCUMENTS FROM :'.

CONCATENATE string2 date1 'to' date2 INTO title1 SEPARATED BY space.

walistheader-typ = 'H'.

walistheader-info = title1.

APPEND walistheader TO itlistheader.

ENDIF.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = ITEVENT

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = ITLISTHEADER

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

CLEAR ITLISTHEADER.

ENDFORM.