cancel
Showing results for 
Search instead for 
Did you mean: 

Calling subroutine from SAP script

Former Member
0 Kudos

I am using the below code within my SAP script form that prints GR/GI Slips but its not working. And the only way I can issue the output is from MB02 whcih doesn't seem to allow to call the debuger, so I'm at a lost as to what to do.

Code in SAP script

/:	 	PERFORM GET_BINS IN PROGRAM ZMM_SAPSCRIPT_FORMS                                                                                
USING &MSEG-MATNR&
/:	 	                                                USING &MSEG-LGNUM&
/:	 	                                                CHANGING &MABDR-LGPBE&
/:	 	ENDPERFORM

CODE from my subroutine program:

FORM get_bins TABLES input_table STRUCTURE itcsy
                     output_table STRUCTURE itcsy.

  DATA: lc_matnr    TYPE matnr,
        lc_lgnum    TYPE lgnum,
        lc_lgpla    TYPE lgpla,
        lc_index    TYPE sy-tabix.

* Material no
  READ TABLE input_table WITH KEY name = 'MSEG-MATNR'.
  MOVE input_table-value TO lc_matnr.

* Warehouse number
  READ TABLE input_table WITH KEY name = 'MSEG-LGNUM'.
  MOVE input_table-value TO lc_lgnum.


* Get BIN
  SELECT SINGLE lgpla INTO lc_lgpla
         FROM mlgt
         WHERE matnr = lc_matnr
         AND   lgnum = 'CPT'  "lc_lgnum
         AND   lgtyp = '001'.
  IF sy-subrc = 0.
    READ TABLE output_table WITH KEY name = 'MABDR-LGPBE'.
    lc_index = sy-tabix.
    MOVE lc_lgpla TO output_table-value.
    MODIFY output_table INDEX lc_index.
  ENDIF.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

/: PERFORM GET_BINS IN PROGRAM ZMM_SAPSCRIPT_FORMS

/: USING &MSEG-MATNR&

/: USING &MSEG-LGNUM&

/: CHANGING &MABDR-LGPBE&

/: ENDPERFORM

FORM get_bins TABLES input_table STRUCTURE itcsy

output_table STRUCTURE itcsy.

DATA: lc_matnr TYPE matnr,

lc_lgnum TYPE lgnum,

lc_lgpla TYPE lgpla,

lc_index TYPE sy-tabix.

  • Material no

READ TABLE input_table WITH KEY name = 'MSEG-MATNR'.

MOVE input_table-value TO lc_matnr.

  • Warehouse number

READ TABLE input_table WITH KEY name = 'MSEG-LGNUM'.

MOVE input_table-value TO lc_lgnum.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = lc_matnr

IMPORTING

OUTPUT = lc_matnr .

  • Get BIN

SELECT SINGLE lgpla INTO lc_lgpla

FROM mlgt

WHERE matnr = lc_matnr

AND lgnum = 'CPT' "lc_lgnum

AND lgtyp = '001'.

IF sy-subrc = 0.

READ TABLE output_table WITH KEY name = 'MABDR-LGPBE'.

lc_index = sy-tabix.

MOVE lc_lgpla TO output_table-value.

MODIFY output_table TRANSPORTING VALUE WHERE NAME = 'MABDR-LGPBE'.

ENDIF.

Answers (3)

Answers (3)

Former Member
0 Kudos

Got it. My copy and paste wasn;t very clear but I have the first using parameter on the same line as the Perform, so it didn't work. As soon as I move the USING parameters to new lines it works.

/: PERFORM GET_BINS IN PROGRAM ZMM_SAPSCRIPT_FORMS

/: USING &MSEG-MATNR&

/: USING &MSEG-LGNUM&

/: CHANGING &MABDR-LGPBE&

/: ENDPERFORM

Former Member
0 Kudos

I've tried the below to try and prove that the program is being called but nothing is output, so it looks to me like the subrotuine does not get called. I've treid creating an infinite loop in the subroutine, but it doesn't break so it looks to me like the call within the SAP script doesn't work - any way of proving this?

MOVE 'TEST' TO output_table-value.
*    MODIFY output_table INDEX lc_index.
    MODIFY output_table TRANSPORTING VALUE WHERE NAME = 'MABDR-LGPBE'.

Former Member
0 Kudos

Hi,

don't pass lc_lgpla directly to the output_table-value.

u can another variable type char.

Eg: v_val(30) type c.

v_val = lc_lgpla .

MOVE v_val TO output_table-value.

we must pass character values only to the output_table.