Application Development and Automation 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:Ā 
Read only

Correct Code

former_member381412
Participant
0 Likes
863

Hello All,

We have developed a Z report In MB51.

add some file in mb5b report. my report is working propelly but Rate /KG filed is not

working pls correct my code

Rate /  kg = ( Balance Amount / Closing Qty )

Exp:  Balance Amount          =  100

          Closing Qty          =   50

100 / 50 = 2

2 is rate per kg...

===============================================================================================

DATA: CLS_STK TYPE MSEG-MENGE,

       BAL_AMO TYPE MSEG-DMBTR.

CLEAR: CLS_STK.

CLS_STK = G_S_BESTAND_DETAIL-ANFMENGE.

BAL_AMO = G_S_BESTAND_DETAIL-ANFWERT.

loop at G_T_BELEGE1.

   if G_T_BELEGE1-SHKZG = 'H'.

    G_T_BELEGE1-ZAMOLC    =  G_T_BELEGE1-DMBTR.       " Amount in LC

    G_T_BELEGE1-ZYOUTWORD2 = G_T_BELEGE1-MENGE.       " OutWard qty

    CLS_STK = CLS_STK +  G_T_BELEGE1-ZYOUTWORD2.      " Closing Qty

    BAL_AMO = BAL_AMO + G_T_BELEGE1-DMBTR.            " Balance Amount

    G_T_BELEGE1-ZRATKG1 = BAL_AMO / CLS_STK.           "  Rate / Kg

else.

    G_T_BELEGE1-ZAMOLC    =  G_T_BELEGE1-DMBTR.      "  Amount in LC

    G_T_BELEGE1-ZYINWORD1 = G_T_BELEGE1-menge.       "  Inward Qty

    CLS_STK = CLS_STK +  G_T_BELEGE1-ZYINWORD1.      "  Closing Qty

    BAL_AMO =  BAL_AMO + G_T_BELEGE1-DMBTR.          "  Balance Amount

    G_T_BELEGE1-ZRATKG1 = BAL_AMO / CLS_STK.         "  Rate / Kg

ENDIF.

   IF CLS_STK IS NOT INITIAL.

     G_T_BELEGE1-ZYCLOSE1 =  CLS_STK.

     G_T_BELEGE1-ZAMOUNT1 =  BAL_AMO .

ENDIF.

modify G_T_BELEGE1 TRANSPORTING ZYOUTWORD2 ZYINWORD1

  ZYCLOSE1  ZAMOUNT1 ZAMOLC ZRATKG1.

ENDLOOP.

================================================================================

Thanks in Advance

Richa

1 ACCEPTED SOLUTION
Read only

hendrik_brandes
Contributor
0 Likes
816

Hello Richa,

1) I would suggest, to use field-symbols for the loop at gt_belege1:

LOOP AT GT_BELEGE1 ASSIGNING <BELEG>.

...

ENDLOOP.

Then, you do not need the modify-statement anymore and you have clear structure inside your loop without the header-line.

2) Use variables for CLS_STK and BAL_AMO with a hight precision, so you will not have the rounding problems inside there. For example something with Decimal 17 with 5 decimals.

3) Also check for 0 values inside your calculation, so you cannot have a rate/kg when no stock amount and no quantity is available.

Kind regards,

Hendrik

5 REPLIES 5
Read only

Former Member
0 Likes
816

check data type

G_T_BELEGE1-ZRATKG1

Read only

hendrik_brandes
Contributor
0 Likes
817

Hello Richa,

1) I would suggest, to use field-symbols for the loop at gt_belege1:

LOOP AT GT_BELEGE1 ASSIGNING <BELEG>.

...

ENDLOOP.

Then, you do not need the modify-statement anymore and you have clear structure inside your loop without the header-line.

2) Use variables for CLS_STK and BAL_AMO with a hight precision, so you will not have the rounding problems inside there. For example something with Decimal 17 with 5 decimals.

3) Also check for 0 values inside your calculation, so you cannot have a rate/kg when no stock amount and no quantity is available.

Kind regards,

Hendrik

Read only

0 Likes
816

Dear Hendrik,

Thanks for the response.

My problem is not solve. pls correct my code if you have required all code then use MB5B...

other wise pls give me suitable exp.

Thanks

Message was edited by: Richa Tripathi

Read only

former_member282968
Contributor
0 Likes
816

Hi Richa,

For rate use data element: SNETWR in your internal table  (for G_T_BELEGE1-ZRATKG1.).

ZRATKG1 type SNETWR

With regards,

Read only

RaymondGiuseppi
Active Contributor
0 Likes
816
  • Strange be it credit or debit ("H" or "S") you always add quantity and amount to current quantity and value, or did you lost a minus sign during copy/paste from code ?
  • Also you did not check stock quantity CLS_STK is not zero before divide, currently no problem as you always add a quantity the value is never zero, but after correction, you will get some divide by zero exceptions.

Regards,

Raymond