Skip to Content

loop and abap code help

i am new in ABAP development. i want to show  tax value instead tax code.I use this Table A003, KONP, EKPO ,RSEG.

Help me READ TABLE inside loop. i use this correct or not. otherwise give me altternate way of this code.

PARAMETERS : P_EBELN TYPE EBELN

.

TYPES : BEGIN OF TY_FINAL,

           EBELN TYPE EBELN,

           EBELP TYPE EBELP,

           MATNR TYPE RSEG-MATNR,

           TXZ01 TYPE EKPO-TXZ01,

           IDLNF TYPE EKPO-IDNLF,

           BPMNG TYPE RSEG-BPMNG,

           MWSKZ TYPE RSEG-MWSKZ,

           VALUE   TYPE KBETR_KOND,

END OF TY_FINAL.


TYPES : BEGIN OF IT_TAX,

         CODE TYPE MWSKZ,

         TAX TYPE KONP-KBETR,

         VALUE TYPE KBETR_KOND,

          END OF IT_TAX.


DATA IT_T TYPE TABLE OF IT_TAX.

DATA WT_T TYPE          IT_TAX.

DATA IT_final TYPE TABLE OF TY_final .

DATA WA_final TYPE          TY_final.


SELECT * FROM A003 INTO TABLE IT_A3.

SELECT * FROM KONP INTO TABLE IT_KP

   FOR ALL ENTRIES IN IT_A3

   WHERE KNUMH = IT_A3-KNUMH.

LOOP AT IT_A3 INTO WT_A3.

    READ TABLE IT_KP INTO WT_KP WITH KEY KNUMH = WT_A3-KNUMH.

    WT_T-CODE = WT_A3-MWSKZ.

    WT_T-TAX = WT_KP-KBETR.

    WT_T-VALUE = WT_KP-KBETR / 10.

    APPEND WT_T TO IT_T.

   ENDLOOP.


SELECT   * FROM EKPO INTO TABLE IT_EKPO

     WHERE EBELN = P_EBELN.

SELECT * FROM RSEG INTO TABLE It_RSEG

      FOR ALL ENTRIES IN IT_EKpO

      WHERE EBELN =  IT_EKpO-EBELN

      AND   EBELP = IT_EKpO-EBELP.

LOOP AT IT_RSEG INTO WA_RSEG.

    READ TABLE IT_EKPO INTO WA_EKPO WITH KEY  EBELN = WA_RSEG-EBELN EBELP = WA_RSEG-EBELP .

    READ TABLE IT_T  INTO WT_T   WITH KEY CODE = WA_RSEG-MWSKZ                                 

    wa_final-ebeln = wa_ekpo-ebeln.

    wa_final-ebelp = wa_ekpo-ebelp.

    wa_final-matnr = wa_rseg-matnr.

    WA_FINAL-TXZ01 = WA_EKPO-TXZ01.

    wa_final-IDLNF = wa_ekpo-IDNLF.

    wa_final-BPMNG = wa_rseg-BPMNG.

    WA_FINAL-MWSKZ = WA_RSEG-MWSKZ.

    WA_FINAL-VALUE = WT_T-VALUE.

APPEND WA_FINAL  TO IT_FINAL.

ENDLOOP.


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Dec 21, 2014 at 10:47 PM

    Do you have an error? Is the code not producing what you expect?

    Can you please formulate a more detailed question.

    Asking us to just read your (completely uncommented) code is not the right way to use this forum.

    cheers

    Paul

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 22, 2014 at 12:54 AM

    Hi Muhammad,

    Always debug your code step by step and check if you want to know if your code is working properly or not. And also follow some coding practices like:

    •    After read statement always check for sy-subrc.
    •    After appending the work area value to the internal table, you should clear the work area value so that the next iteration will not get the previous value again.

    LOOP AT it_a3 INTO wt_a3.

       READ TABLE it_kp INTO wt_kp WITH KEY knumh = wt_a3-knumh.

      IF sy-subrc = 0.

         wt_t-code = wt_a3-mwskz.

         wt_t-tax = wt_kp-kbetr.

         wt_t-value = wt_kp-kbetr / 10.

         APPEND wt_t TO it_t.

         CLEAR wt_t.

       ENDIF.

    ENDLOOP.


    Also for better performance you can use binary search in the read operation after sorting the concerned internal table.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 22, 2014 at 02:10 AM

    Hi,

    For getting the tax details

    Select Query

    KONP-KNUMH    =  EKKO-KNUMV.

    Read Statement.

    Read it_konp with key knumh = wa_ekko-knumv

                                     kopos  = wa_ekpo-ebelp.

    Hope it helpful.

    Regards,

    Venkat.

    Add comment
    10|10000 characters needed characters exceeded