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

Problem with external PERFORM in SAPscripts

Former Member
0 Likes
761

Hi,

In my custom form, i have the following code in MAIN window. This external routine call has to fetch certain fields for each line item.

I do see in my print that each line item carry diff values for RSNUM & RSPOS. For some reason i believe this PERFORM is either executed only once or it is passing the values of item1 and hence its value gets copied on to other items.

Is my routine to be shifted place ? or some other reason......Appreciate help on same.Thanks!

/E POS_ZEILE

/: PERFORM P_GET_QTY IN PROGRAM ZRAM_TEST2

/: USING &MSEG-RSNUM&

/: USING &MSEG-RSPOS&

/: USING &MSEG-MENGE&

/: USING &MSEG-BWART&

/: CHANGING &REQ_QTY&

/: CHANGING &ISD_QTY&

/: CHANGING &OUT_QTY&

/: ENDPERFORM

/: PROTECT

L &MSEG-ZEILE&,,&MSEG-MATNR&,,&MABDR-MAKTX(28)&,,&MSEG-LGORT&/

= &MABDR-LGPBE&,, &MSEG-CHARG& &MSEG-RSNUM& &MSEG-RSPOS&

L3 ,,&REQ_QTY&,,<b>&ISD_QTY&</>,,&OUT_QTY&

/: ENDPROTECT

6 REPLIES 6
Read only

Former Member
0 Likes
711

Hi Ram,

Please do check whether you are correctly clearing the variables being passed after they have been used. There could be a disconnect there.

Regards,

Anand.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
711

Can we see the corresponding code in your ABAP program?

REgards,

Rich Heilman

Read only

Former Member
0 Likes
711

Anand,

Following is my code for the FORM.

FORM p_get_qty TABLES input STRUCTURE itcsy

output STRUCTURE itcsy.

DATA: avlbl TYPE resb-bdmng,

wa_resb TYPE resb,

req(16) TYPE c,

out(16) TYPE c,

isd(16) TYPE c,

c_negative TYPE i VALUE '-1'.

CLEAR wa_resb-rsnum.

READ TABLE input WITH KEY 'MSEG-RSNUM'.

CHECK sy-subrc = 0.

wa_resb-rsnum = input-value.

CLEAR wa_resb-rspos.

READ TABLE input WITH KEY 'MSEG-RSPOS'.

CHECK sy-subrc = 0.

wa_resb-rspos = input-value.

READ TABLE input WITH KEY 'MSEG-MENGE'.

CHECK sy-subrc = 0.

isd_qty = input-value.

READ TABLE input WITH KEY 'MSEG-BWART'.

CHECK sy-subrc = 0.

mvmt = input-value.

IF l_old_rsnum NE wa_resb-rsnum AND l_old_rspos NE wa_resb-rspos.

SELECT SINGLE * INTO wa_resb

FROM resb

WHERE rsnum = wa_resb-rsnum

AND rspos = wa_resb-rspos.

CHECK sy-subrc = 0.

avlbl = wa_resb-bdmng - wa_resb-enmng.

req_qty = avlbl - out_qty.

l_old_rsnum = wa_resb-rsnum.

l_old_rspos = wa_resb-rspos.

ELSE.

req_qty = out_qty.

ENDIF.

out_qty = req_qty - isd_qty.

req = req_qty.

isd = isd_qty.

out = out_qty.

output-name = 'REQ_QTY'.

output-value = req.

MODIFY output INDEX 1.

output-name = 'ISD_QTY'.

output-value = isd.

MODIFY output INDEX 2.

output-name = 'OUT_QTY'.

output-value = out.

MODIFY output INDEX 3.

ENDFORM.

Read only

0 Likes
711

Can we see the code around the WRITE_FORM for the POS_ZEILE element?

Regards,

RIch Heilman

Read only

Former Member
0 Likes
711

Rich,

The print program is standard one. SAPM07DR ->Include M07DRA03->FORM WA03_AUSGABE using lgortsplit.

Regards.

Read only

Former Member
0 Likes
711

Hi,

I got to spend some more time on the code and its now working fine except for couple of issues.

a) when i issue a print the program prints 'N' copies (N = no. of items on the GI).

b) this is my corrected code, here upon on every new rsnum/rspos combination i need to query from resb table. but currently it queries every time. the values in l_old_rsnum and l_old_rspos for some reason is lost when the routine is called the next time.

REPORT zram_test2 .

TABLES resb.

DATA:   mvmt    TYPE mseg-bwart,
        l_rsnum TYPE mseg-rsnum,
        l_rspos TYPE mseg-rspos.

DATA:   req(16) TYPE c,
        out(16) TYPE c,
        isd(16) TYPE c.
*---------------------------------------------------------------------*
*       FORM p_get_qty                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  RSNUM                                                         *
*  -->  RSPOS                                                         *
*---------------------------------------------------------------------*
FORM p_get_qty TABLES input  STRUCTURE itcsy
                      output STRUCTURE itcsy.

  DATA: avlbl TYPE resb-bdmng,
        wa_resb TYPE resb,
        wa_mseg TYPE mseg,
        l_old_rsnum TYPE resb-rsnum,
        l_old_rspos TYPE resb-rspos,
        req_qty TYPE resb-enmng,
        isd_qty TYPE mseg-menge,
        out_qty TYPE resb-enmng,
        c_negative TYPE i VALUE '-1'.

  READ TABLE input WITH KEY 'MSEG-RSNUM'.
  CHECK sy-subrc = 0.
  l_rsnum = input-value.

  READ TABLE input WITH KEY 'MSEG-RSPOS'.
  CHECK sy-subrc = 0.
  l_rspos = input-value.

  CLEAR: isd, req, out.
  READ TABLE input WITH KEY 'MSEG-MENGE'.
  CHECK sy-subrc = 0.
  isd_qty = input-value.

  READ TABLE input WITH KEY 'MSEG-BWART'.
  CHECK sy-subrc = 0.
  mvmt = input-value.


<b>    if ( l_old_rsnum ne l_rsnum  and l_old_rspos ne l_rspos ).
    SELECT SINGLE * INTO wa_resb
                    FROM resb
                    WHERE rsnum = l_rsnum
                    AND   rspos = l_rspos.
    avlbl   = wa_resb-bdmng - wa_resb-enmng.
    req_qty = avlbl - out_qty.
    MOVE l_rsnum TO l_old_rsnum.
    MOVE l_rspos TO l_old_rspos.
  ELSE.
    req_qty = out_qty.
  ENDIF.</b>

  req = req_qty.
  IF ( mvmt = '201' OR mvmt = '261' OR mvmt = '281' ).
* If GOODS ISSUE
* Outstanding qty is diff of Issued qty & Requirements qty
    out_qty = req_qty - isd_qty.
* Issued qty should be shown with a 'minus' sign
    MULTIPLY isd_qty BY c_negative.
  ELSE.
* If GOODS RETURN
* Outstanding qty is sum of Returned qty & Requirements qty
    out_qty = req_qty + isd_qty.
  ENDIF.
  isd = isd_qty.
  out = out_qty.

  output-name = 'REQ_QTY'.
  output-value = req.
  MODIFY output INDEX 1.

  output-name = 'ISD_QTY'.
  output-value = isd.
  MODIFY output INDEX 2.

  output-name = 'OUT_QTY'.
  output-value = out.
  MODIFY output INDEX 3.

Please help