Application Development 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: 

comparing with transaction CN52N

former_member185116
Active Participant
0 Kudos

hello all,

we are developing a ZReport similar to transaction CN52N...

in the selection screen we have Material Number..

we need to display quantity for each WBS(whose status is 'APRD') and quantity for each WBS (whose status is "REL')

for status -APRD we are getting correct data similar to CN52N

where as status -REL we are not getting data similar to CN52N.....

what could be the reason,

my code is like below

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

******************sel screen declaration *********************


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

   SELECTION-SCREEN skip 1.

   select-OPTIONS : so_matnr for resb-matnr NO-EXTENSION no INTERVALS OBLIGATORY.

   SELECTION-SCREEN skip 1.

SELECTION-SCREEN END OF BLOCK b1.

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




START-OF-SELECTION.




*********to get APRD records ***

    select rsnum
           rspos
           matnr
           bdmng
           aufnr
           xloek
           xwaok
           kzear
           postp
           FROM resb
           Into CORRESPONDING FIELDS OF TABLE it_resb1
           where matnr in so_matnr
           AND bwart eq '281'
           AND xloek ne 'X'
           AND xwaok ne 'X'
           AND kzear ne 'X'
           AND postp eq 'L'.





  if it_resb1[] is NOT INITIAL.

      select aufnr
             autyp
             pspel
             FROM caufv
             INTO CORRESPONDING FIELDS OF TABLE it_caufv1
             FOR ALL ENTRIES IN it_resb1
             WHERE aufnr eq it_resb1-aufnr
              and autyp eq '20'.    "to get only network orders

  endif.



if it_caufv1[] is NOT INITIAL.

   select pspnr
          posid
          objnr
          FROM prps INTO CORRESPONDING FIELDS OF TABLE it_prps1              "used it_prps1 and it_prps2 for APRD
          FOR ALL ENTRIES IN it_caufv1
          where pspnr eq it_caufv1-pspel.
*         and belkz eq 'X'.
*         and loevm ne 'X'.

endif.




sort it_prps1 by pspnr.


clear : wa_prps1.
REFRESH : it_prps2[].


loop at it_prps1 into wa_prps1.


    CALL FUNCTION 'STATUS_READ'
      EXPORTING
*      CLIENT                 = SY-MANDT
        OBJNR                  = wa_prps1-objnr
        ONLY_ACTIVE            = 'X'
*    IMPORTING
*      OBTYP                  =
*      STSMA                  =
*      STONR                  =
      TABLES
        STATUS                 = it_stat1
*    EXCEPTIONS
*      OBJECT_NOT_FOUND       = 1
*      OTHERS                 = 2
              .



    READ TABLE it_stat1 INTO wa_stat1 with key stat = 'E0008'.         "approved

       if sy-subrc = 0.

          READ TABLE it_stat1 INTO wa_stat1 with key stat = 'I0002'.     "released

             if sy-subrc = 0.

                delete TABLE it_prps1 FROM wa_prps1.

             else.

                APPEND wa_prps1 to it_prps2.

             endif.

        endif.


  endloop.

sort it_prps2 by posid.




loop at it_prps2 INTO wa_prps2.


   READ TABLE it_caufv1 INTO wa_caufv1 with key pspel = wa_prps2-pspnr.

        if sy-subrc = 0.


         loop at it_resb1 INTO wa_resb1 WHERE aufnr = wa_caufv1-aufnr.


            if sy-subrc = 0.


               wa_fin1-matnr = wa_resb1-matnr.
               wa_fin1-abdmng = wa_resb1-bdmng.

               APPEND wa_fin1 to it_fin1.

            endif.

         endloop.

        endif.


endloop.



*loop at it_fin1 INTO wa_fin1.
*
*endloop.


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

*********to get Rel records


    select rsnum
           rspos
           matnr
           bdmng
           aufnr
           xloek
           xwaok
           kzear
           postp
           FROM resb
           Into CORRESPONDING FIELDS OF TABLE it_resb2
           where matnr in so_matnr
           AND bwart eq '281'
           AND postp eq 'L'
           AND xloek ne 'X'.
*         AND xwaok eq 'X'.
*         AND kzear ne 'X'.



  if it_resb2[] is NOT INITIAL.

      select aufnr
             autyp
             pspel
             FROM caufv
             INTO CORRESPONDING FIELDS OF TABLE it_caufv2
             FOR ALL ENTRIES IN it_resb2
             WHERE aufnr eq it_resb2-aufnr
              and autyp eq '20'.    "to get only network orders

  endif.



if it_caufv2[] is NOT INITIAL.

   select pspnr
          posid
          objnr
          FROM prps INTO CORRESPONDING FIELDS OF TABLE it_prps3                                     "used it_prps3 and it_prps4 for REL
          FOR ALL ENTRIES IN it_caufv2
          where pspnr eq it_caufv2-pspel.
*         and belkz eq 'X'.
*         and loevm ne 'X'.

endif.


sort it_prps3 by pspnr.


clear : wa_prps3.
REFRESH : it_prps4[].



loop at it_prps3 INTO wa_prps3.


  CALL FUNCTION 'STATUS_READ'
      EXPORTING
*      CLIENT                 = SY-MANDT
        OBJNR                  = wa_prps3-objnr
        ONLY_ACTIVE            = 'X'
*    IMPORTING
*      OBTYP                  =
*      STSMA                  =
*      STONR                  =
      TABLES
        STATUS                 = it_stat2
*    EXCEPTIONS
*      OBJECT_NOT_FOUND       = 1
*      OTHERS                 = 2
              .



    READ TABLE it_stat2 INTO wa_stat2 with key stat = 'I0002'.         "released

       if sy-subrc = 0.

          APPEND wa_prps3 to it_prps4.

       endif.


endloop.



sort it_prps4 by posid.


loop at it_prps4 INTO wa_prps4.


   READ TABLE it_caufv2 INTO wa_caufv2 with key pspel = wa_prps4-pspnr.

      if sy-subrc = 0.


        loop at it_resb2 INTO wa_resb2 WHERE aufnr = wa_caufv2-aufnr
*                                       AND xloek ne 'X'
*                                        AND xwaok = 'X'
                                        AND postp eq 'L'.


           if sy-subrc = 0.

               wa_fin2-matnr = wa_resb2-matnr.
               wa_fin2-rbdmng = wa_resb2-bdmng.
               wa_fin2-rsnum = wa_resb2-rsnum.

               APPEND wa_fin2 to it_fin2.

            endif.


         endloop.


       endif.


endloop.


*loop at it_fin2 INTO wa_fin2.
*
*endloop.


DESCRIBE TABLE it_fin1.
count1 = sy-tfill.


DESCRIBE TABLE it_fin2.
count2 = sy-tfill.




if count2 > count1.


clear idx.

loop at it_fin2 INTO wa_fin2.


   loop at it_fin1 INTO wa_fin1.

     idx = sy-tabix.

     if sy-subrc = 0.

       wa_fin2-abdmng = wa_fin1-abdmng.

     endif.


      modify it_fin2 FROM wa_fin2 INDEX idx TRANSPORTING abdmng.

     endloop.

     exit.

endloop.


loop at it_fin2 INTO wa_fin2.

   at END OF matnr.
     sum.
     APPEND wa_fin2 to it_final.
   endat.

endloop.


else.


   clear idx.

loop at it_fin1 INTO wa_fin1.


   loop at it_fin2 INTO wa_fin2.

     idx = sy-tabix.

     if sy-subrc = 0.

       wa_fin1-rbdmng = wa_fin2-rbdmng.

     endif.


      modify it_fin1 FROM wa_fin1 INDEX idx TRANSPORTING rbdmng.

     endloop.

     exit.

  endloop.


  loop at it_fin1 INTO wa_fin1.

   at END OF matnr.
     sum.
     APPEND wa_fin1 to it_final.
   endat.

endloop.


endif.







if it_final[] is NOT INITIAL.

   select * FROM makt INTO TABLE it_makt FOR ALL ENTRIES IN it_final
            where matnr eq it_final-matnr.

endif.




loop at it_final INTO wa_final.

   READ TABLE it_makt INTO wa_makt with key matnr = wa_final-matnr.

      if sy-subrc = 0.

         wa_final-maktx = wa_makt-maktx.

         modify it_final FROM wa_final TRANSPORTING maktx.

      endif.

endloop.



PERFORM main_alv_display.




FORM MAIN_ALV_DISPLAY .



REFRESH it_fcat[].

   clear wa_fcat.
   wa_fcat-col_pos = 1.
   wa_fcat-fieldname = 'MATNR'.
   wa_fcat-tabname = 'IT_FINAL'.
   wa_fcat-seltext_l = 'Material No'.
   wa_fcat-outputlen = 25.
   APPEND wa_fcat to it_fcat.
   clear wa_fcat.


   clear wa_fcat.
   wa_fcat-col_pos = 2.
   wa_fcat-fieldname = 'MAKTX'.
   wa_fcat-tabname = 'IT_FINAL'.
   wa_fcat-seltext_m = 'Material Text'.
   wa_fcat-outputlen = 45.
   APPEND wa_fcat to it_fcat.
   clear wa_fcat.


*  clear wa_fcat.
*  wa_fcat-col_pos = 3.
*  wa_fcat-fieldname = 'FBDMNG'.
*  wa_fcat-tabname = 'IT_FINAL'.
*  wa_fcat-seltext_l = 'Stock'.
*  wa_fcat-outputlen = 15.
*  APPEND wa_fcat to it_fcat.
*  clear wa_fcat.


   clear wa_fcat.
   wa_fcat-col_pos = 4.
   wa_fcat-fieldname = 'ABDMNG'.
   wa_fcat-tabname = 'IT_FINAL'.
   wa_fcat-seltext_l = 'Qty In Sanctioned Estimates'.
   wa_fcat-outputlen = 15.
   wa_fcat-emphasize = 'C501'.
   wa_fcat-hotspot = 'X'.
   APPEND wa_fcat to it_fcat.
   clear wa_fcat.


   clear wa_fcat.
   wa_fcat-col_pos = 5.
   wa_fcat-fieldname = 'RBDMNG'.
   wa_fcat-tabname = 'IT_FINAL'.
   wa_fcat-seltext_l = 'Qty In W.O.Issued Estimates'.
   wa_fcat-outputlen = 15.
   wa_fcat-emphasize = 'C501'.
   wa_fcat-hotspot = 'X'.
   APPEND wa_fcat to it_fcat.
   clear wa_fcat.


****** layout declaration ****************************

   wa_layout-zebra = 'X'.
   wa_layout-detail_popup = 'X'.
   wa_layout-colwidth_optimize = 'X'.


   wa_title = 'WBS Material Stock Details'.

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

    v_repid = sy-repid.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     I_CALLBACK_PROGRAM                = v_repid
     I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
*   I_CALLBACK_TOP_OF_PAGE            = ' '
     I_GRID_TITLE                      = wa_title
     IS_LAYOUT                         = wa_layout
     IT_FIELDCAT                       = it_fcat
*   IT_EXCLUDING                      =
*   IT_SORT                           =
*    i_default                         = 'X'
     I_SAVE                            = 'X'
*    is_variant                        = it_variant
*   IT_EVENTS                         =
   TABLES
     T_OUTTAB                          = it_final.



REFRESH it_final[].






ENDFORM.                    " MAIN_ALV_DISPLAY


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

1 REPLY 1

shah_viraj
Active Participant
0 Kudos

Hi Vinay,

I appreciate if you debug the code before posting here. Have you?