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: 

belnr from bseg

Former Member
0 Kudos

Hi experts,

Iam trying to get all the BELNRs from BSEG where equal to MATNR.In the following code iam not able to get all the BELNRs.How can i get all the BELNRs?.Can any one tell me how to do this...


LOOP AT RESULT.
   <b> SELECT SINGLE * FROM BSEG WHERE MATNR = RESULT-MATNR AND
                                    GSBER = '8017' AND
                                    HKONT = '0000150230'.</b>
    IF SY-SUBRC = 0.
      RESULT-BELNR = BSEG-BELNR.
      RESULT-HKONT = BSEG-HKONT.
      RESULT-DMBTR = BSEG-DMBTR.
      RESULT-GSBER = BSEG-GSBER.
      RESULT-SHKZG = BSEG-SHKZG.
      MODIFY RESULT.
    ENDIF.


    TAMT = RESULT-LBKUM * RESULT-VERPR.
    9MTH = RESULT-QTY1 * RESULT-VERPR.
    10MTH = RESULT-QTY2 * RESULT-VERPR.
    13MTH = RESULT-QTY3 * RESULT-VERPR.
    24MTH = RESULT-FBALQTY * RESULT-VERPR.

    MOVE-CORRESPONDING: RESULT TO FINRESULT.
    MOVE: TAMT  TO FINRESULT-FTAMT,
          9MTH  TO FINRESULT-F9MTH,
          10MTH TO FINRESULT-F10MTH,
          13MTH TO FINRESULT-F13MTH,
          24MTH TO FINRESULT-F24MTH.

    APPEND FINRESULT.
    CLEAR FINRESULT.

*    COLLECT FINRESULT.

  ENDLOOP.

8 REPLIES 8

Former Member
0 Kudos
DATA : BEGIN OF itab,
      BELNR LIKE BSEG-BELNR,
      HKONT LIKE BSEG-HKONT,
      DMBTR LIKE BSEG-DMBTR,
      GSBER LIKE BSEG-GSBER,
      SHKZG LIKE BSEG-SHKZG,
            END OF itab.

LOOP AT RESULT.
    SELECT       
      BELNR
      HKONT
      DMBTR
      GSBER
      SHKZG
 FROM BSEG 
 INTO TABLE itab 
 WHERE MATNR = RESULT-MATNR AND
                                    GSBER = '8017' AND
                                    HKONT = '0000150230'.
 
 
    TAMT = RESULT-LBKUM * RESULT-VERPR.
    9MTH = RESULT-QTY1 * RESULT-VERPR.
    10MTH = RESULT-QTY2 * RESULT-VERPR.
    13MTH = RESULT-QTY3 * RESULT-VERPR.
    24MTH = RESULT-FBALQTY * RESULT-VERPR.
 
    MOVE-CORRESPONDING: RESULT TO FINRESULT.
    MOVE: TAMT  TO FINRESULT-FTAMT,
          9MTH  TO FINRESULT-F9MTH,
          10MTH TO FINRESULT-F10MTH,
          13MTH TO FINRESULT-F13MTH,
          24MTH TO FINRESULT-F24MTH.
 
    APPEND FINRESULT.
    CLEAR FINRESULT.
 
*    COLLECT FINRESULT.
 
  ENDLOOP.

0 Kudos

HI Wenceslaus G

Now how to pass all BELNRs into Result ITAB?

thanks

kaki

0 Kudos

The internal table ITAB contains the field BELNR which contains the BELNR values.

Canyou please tell me what is the content of the internal table RESULT.

0 Kudos

DATA: BEGIN OF RESULT OCCURS 0,
      MATNR   LIKE MSEG-MATNR,          "Material Number
      MAKTX   LIKE MAKT-MAKTX,          "Material Description
      WERKS   LIKE MSEG-WERKS,          "Plant
      LGORT   LIKE MSEG-LGORT,          "Storage Location
      LBKUM   LIKE MSEG-LBKUM,          "Total valuated stock qty
      VERPR   LIKE MBEW-VERPR,          "Moving average price
      QTY1    LIKE MSEG-MENGE,          "quantity
      QTY2    LIKE MSEG-MENGE,          "quantity
      QTY3    LIKE MSEG-MENGE,          "quantity
      GSBER   LIKE MSEG-GSBER,          "Business area
      FBALQTY LIKE MSEG-LBKUM,          "lbkum minus menge
      FREMARK(40) TYPE C,
      BELNR   LIKE BSEG-BELNR,         "Doc Number
      HKONT   LIKE BSEG-HKONT,
      DMBTR   LIKE BSEG-DMBTR,
      SHKZG   LIKE BSEG-SHKZG,

      END OF RESULT.

0 Kudos

Is your RESULT internal table populated with all the MATNR values that you wish to retrieve from?

0 Kudos

Yes very much.

0 Kudos

Hope this will be useful...

DATA: BEGIN OF RESULT OCCURS 0,
      MATNR   LIKE MSEG-MATNR,          "Material Number
      MAKTX   LIKE MAKT-MAKTX,          "Material Description
      WERKS   LIKE MSEG-WERKS,          "Plant
      LGORT   LIKE MSEG-LGORT,          "Storage Location
      LBKUM   LIKE MSEG-LBKUM,          "Total valuated stock qty
      VERPR   LIKE MBEW-VERPR,          "Moving average price
      QTY1    LIKE MSEG-MENGE,          "quantity
      QTY2    LIKE MSEG-MENGE,          "quantity
      QTY3    LIKE MSEG-MENGE,          "quantity
      GSBER   LIKE MSEG-GSBER,          "Business area
      FBALQTY LIKE MSEG-LBKUM,          "lbkum minus menge
      FREMARK(40) TYPE C,
      BELNR   LIKE BSEG-BELNR,         "Doc Number
      HKONT   LIKE BSEG-HKONT,
      DMBTR   LIKE BSEG-DMBTR,
      SHKZG   LIKE BSEG-SHKZG,

      END OF RESULT.


DATA : BEGIN OF itab OCCURS 0,
      MATNR LIKE BSEG-MATNR,
      BELNR LIKE BSEG-BELNR,
      HKONT LIKE BSEG-HKONT,
      DMBTR LIKE BSEG-DMBTR,
      GSBER LIKE BSEG-GSBER,
      SHKZG LIKE BSEG-SHKZG,
            END OF itab.

    SELECT
      MATNR
      BELNR
      HKONT
      DMBTR
      GSBER
      SHKZG
 FROM BSEG
 INTO TABLE itab
 FOR ALL ENTRIES IN RESULT
 WHERE MATNR = RESULT-MATNR AND
                                    GSBER = '8017' AND
                                    HKONT = '0000150230'.

SORT itab BY matnr.

LOOP AT result.
  READ TABLE itab WITH KEY matnr = result-matnr BINARY SEARCH.
  IF sy-subrc = 0.
    MOVE-CORRESPONDING itab TO result.
    MODIFY result.
  ENDIF.
ENDLOOP.

LOOP AT result.
    TAMT = RESULT-LBKUM * RESULT-VERPR.
    9MTH = RESULT-QTY1 * RESULT-VERPR.
    10MTH = RESULT-QTY2 * RESULT-VERPR.
    13MTH = RESULT-QTY3 * RESULT-VERPR.
    24MTH = RESULT-FBALQTY * RESULT-VERPR.

    MOVE-CORRESPONDING: RESULT TO FINRESULT.
    MOVE: TAMT  TO FINRESULT-FTAMT,
          9MTH  TO FINRESULT-F9MTH,
          10MTH TO FINRESULT-F10MTH,
          13MTH TO FINRESULT-F13MTH,
          24MTH TO FINRESULT-F24MTH.

    APPEND FINRESULT.
    CLEAR FINRESULT.

    COLLECT FINRESULT.
ENDLOOP.

Former Member
0 Kudos

Kaki - you can't go to BSEG to find out the document number. You have to know the document number (and the company code); otherwise, performance will be so bad that it will take a very long time to do a simple select.

For very large tables, (and BSEG is one of the largest), you must use an index effectively. Since you know the account number, your best bet is probably to go to BSIS and BSAS and get all the documents for HKONT = '0000150230'. Then go to BSEG.

Rob