on 2019 Nov 15 4:56 PM
I`m new to ABAP and I`m trying to create a variance report for order confirmation in Production Planning. The field variance_today is supposed to be updated until variance becomes zero without affecting other field in customised table ZCONFIRMATION(which has to have entries from 1st of the month to sy-datum-1 for all plant). Would you please tell me what is wrong with this program. Either there is no output or it keeps on looping in AUFM. Here`s my report.
TABLES : aufm,afko,zconfirmation.
*Data Declaration
*----------------
TYPES: BEGIN OF gty_plants,
plant TYPE werks,
END OF gty_plants.
DATA: it_plants TYPE TABLE OF gty_plants WITH HEADER LINE WITH KEY plant,"INITIAL SIZE 0
wa_plants LIKE LINE OF it_plants.
wa_plants-plant = 'MNSR'.
INSERT wa_plants INTO TABLE it_plants.
wa_plants-plant = 'TPKR'.
INSERT wa_plants INTO TABLE it_plants.
wa_plants-plant = 'NSPR'.
INSERT wa_plants INTO TABLE it_plants.
wa_plants-plant = 'VTPR'.
INSERT wa_plants INTO TABLE it_plants.
DATA: i_error TYPE string.
DATA: it_aufm TYPE STANDARD TABLE OF aufm ,"INITIAL SIZE 0
wa_aufm LIKE LINE OF it_aufm.
DATA: it_afko TYPE STANDARD TABLE OF afko, "INITIAL SIZE 0,
wa_afko LIKE LINE OF it_afko.
DATA: it_final TYPE STANDARD TABLE OF zconfirmation WITH HEADER LINE WITH KEY plant date1 ,"INITIAL SIZE 0
it_final1 TYPE TABLE OF zconfirmation WITH HEADER LINE WITH KEY plant date1,
it_final2 TYPE TABLE OF zconfirmation WITH HEADER LINE WITH KEY plant date1,
wa_final TYPE zconfirmation,
wa_final1 TYPE zconfirmation,
wa_final2 TYPE zconfirmation.
DATA : it_fcat TYPE slis_t_fieldcat_alv .
DATA : wa_fcat LIKE LINE OF it_fcat .
DATA: aufm_wa TYPE aufm,
r_bwart TYPE RANGE OF aufm-bwart,
r_bwart_line LIKE LINE OF r_bwart,
r_aufnr TYPE RANGE OF aufm-aufnr,
r_aufnr_line LIKE LINE OF r_aufnr.
DATA: date1 LIKE sy-datum,
date2 LIKE sy-datum.
SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_date FOR aufm-budat.
SELECTION-SCREEN:END OF BLOCK b1.
IF s_date IS NOT INITIAL.
date1 = s_date-low.
date2 = s_date-high.
ELSE.
date1 = sy-datum.
date1+6(2) = '01'.
date2 = sy-datum.
ENDIF.
r_bwart_line-sign = 'I'.
r_bwart_line-option = 'BT'.
r_bwart_line-low = '101'.
r_bwart_line-high = '102'.
APPEND r_bwart_line TO r_bwart.
r_aufnr_line-sign = 'I'.
r_aufnr_line-option = 'BT'.
r_aufnr_line-low = '001700000000'.
r_aufnr_line-high = '001799999999'.
APPEND r_aufnr_line TO r_aufnr.
INITIALIZATION.
************************************************************************
* START-OF-SELECTION
START-OF-SELECTION.
WHILE date1 < date2.
LOOP AT it_plants INTO wa_plants.
wa_final-date1 = date1.
wa_final-plant = wa_plants-plant.
PERFORM data_retrieval.
************************************************************************
* END-OF-SELECTION
ENDLOOP.
date1 = date1 + 1.
ENDWHILE.
PERFORM create_fcat.
PERFORM disp_alv.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL_MNSR
*&---------------------------------------------------------------------*
FORM data_retrieval .
CLEAR wa_final.
wa_final-date1 = date1.
SELECT *
FROM aufm
INTO TABLE it_aufm
WHERE werks EQ wa_plants-plant
AND bwart IN r_bwart
AND aufnr IN r_aufnr
AND budat EQ date1.
DESCRIBE TABLE it_aufm LINES wa_final-total.
wa_final-plant = wa_plants-plant.
IF it_aufm[] IS NOT INITIAL.
SELECT *
FROM afko
INTO TABLE it_afko
FOR ALL ENTRIES IN it_aufm
WHERE aufnr EQ it_aufm-aufnr
AND igmng NE 0
AND gstrp EQ date1.
DESCRIBE TABLE it_afko LINES wa_final-viable.
ENDIF.
wa_final-variance_on_date = wa_final-total - wa_final-viable.
wa_final-variance_today = wa_final-variance_on_date.
APPEND wa_final TO it_final.
SELECT * FROM zconfirmation INTO TABLE it_final1.
LOOP AT it_final INTO wa_final .
* CLEAR wa_final1 .
READ TABLE it_final1 INTO wa_final1
WITH TABLE KEY
plant = wa_final-plant
date1 = wa_final-date1 .
* IF sy-subrc IS INITIAL.
* wa_final1-plant = wa_final1-plant.
* wa_final1-date1 = wa_final1-date1.
* wa_final1-total = wa_final1-total.
* wa_final1-viable = wa_final1-viable.
* wa_final1-variance_on_date = wa_final1-variance_on_date.
wa_final1-variance_today = wa_final-variance_today.
* APPEND wa_final1 to it_final2.
MODIFY it_final1 FROM wa_final1 TRANSPORTING variance_today WHERE plant = wa_final1-plant AND date1 = wa_final1-date1.
* ENDIF.
* CLEAR wa_final.
ENDLOOP.
MODIFY zconfirmation FROM it_final1.
COMMIT WORK.
*
* IF sy-subrc EQ 0.
*
* i_error = 'X1'.
* ELSE.
* i_error = 'X2'.
* CLEAR i_error.
* ROLLBACK WORK.
* ENDIF.
* CLEAR wa_final.
ENDFORM. " DATA_RETRIEVAL
Request clarification before answering.
User | Count |
---|---|
96 | |
39 | |
8 | |
6 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.