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

Calling a subroutine form SAPscripts

Former Member
0 Likes
658

Hi,

How to call a subroutine form SAPscripts

Thanks,

1 ACCEPTED SOLUTION
Read only

abapdeveloper20
Contributor
0 Likes
640

Hi,

You can do that by writing perform in SAP SCRIPT window and write the subrouting in one report.

For Eg:

See the sample code in script

/:   IF &PAGE& EQ 1.

/:   DEFINE &STREET&
/:   DEFINE &STR_SUPPL1&
/:   DEFINE &TEMP&
/:   PERFORM GET_DATA_ADRC IN PROGRAM Z_RFFOUS_C
/:   USING &LFA1-ADRNR&
/:   CHANGING &STREET&
/:   CHANGING &STR_SUPPL1&
/:   CHANGING &TEMP&
/:   ENDPERFORM.
/:   ENDIF

and in the program Z_RFFOUS_C.

incorporate your subroutine code.

*---------------------------------------------------------------------*
*       FORM GET_DATA_ADRC                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  IT_USING                                                      *
*  -->  IT_CHANGING                                                   *
*---------------------------------------------------------------------*
FORM GET_DATA_ADRC TABLES IT_USING STRUCTURE ITCSY
                       IT_CHANGING STRUCTURE ITCSY.

  DATA : ADRNR LIKE LFA1-ADRNR.

  DATA : L_STREET LIKE ADRC-STREET,
         L_STR_SUPPL1 LIKE ADRC-STR_SUPPL1,
         L_STR_SUPPL2 LIKE ADRC-STR_SUPPL2,
         L_STR_SUPPL3 LIKE ADRC-STR_SUPPL3,
         L_LOCAT  LIKE ADRC-LOCATION.

  DATA : TEMP(220).

  READ TABLE IT_USING INDEX 1.
  MOVE IT_USING-VALUE TO ADRNR.

  UNPACK ADRNR TO ADRNR.

  SELECT SINGLE STREET
                STR_SUPPL1
                STR_SUPPL2
                STR_SUPPL3
                LOCATION
       FROM   ADRC
       INTO   (L_STREET,
              L_STR_SUPPL1,
              L_STR_SUPPL2,
              L_STR_SUPPL3,
              L_LOCAT)
       WHERE
              ADDRNUMBER = ADRNR.



  READ TABLE IT_CHANGING INDEX 1.
  IT_CHANGING-VALUE = L_STREET.
  MODIFY IT_CHANGING INDEX 1.
*
  READ TABLE IT_CHANGING INDEX 2.
  IT_CHANGING-VALUE = L_STR_SUPPL1.
  MODIFY IT_CHANGING INDEX 2.
*
*  read table it_changing index 3.
*  it_changing-value = l_str_suppl2.
*  modify it_changing index 3.
*
*  read table it_changing index 4.
*  it_changing-value = l_str_suppl3.
*  modify it_changing index 4.
*
*  read table it_changing index 5.
*  it_changing-value = l_locat.
*  modify it_changing index 5.

*  concatenate l_str_suppl2 l_str_suppl3 l_locat into  temp.

  CONCATENATE L_STR_SUPPL2
              ','
              L_STR_SUPPL3
              ','
              L_LOCAT INTO  TEMP.


  WHILE SY-SUBRC = 0.
    REPLACE ',' WITH ' ' INTO TEMP.
  ENDWHILE.

  READ TABLE IT_CHANGING INDEX 3.
  IT_CHANGING-VALUE = TEMP.
  MODIFY IT_CHANGING INDEX 3.


ENDFORM.

revert me back if you face any issues.

Reward points if my answer is helpful.

~Lakshmiraj~

Edited by: LAKSHMIRAJ on Mar 29, 2008 7:22 AM

3 REPLIES 3
Read only

abapdeveloper20
Contributor
0 Likes
641

Hi,

You can do that by writing perform in SAP SCRIPT window and write the subrouting in one report.

For Eg:

See the sample code in script

/:   IF &PAGE& EQ 1.

/:   DEFINE &STREET&
/:   DEFINE &STR_SUPPL1&
/:   DEFINE &TEMP&
/:   PERFORM GET_DATA_ADRC IN PROGRAM Z_RFFOUS_C
/:   USING &LFA1-ADRNR&
/:   CHANGING &STREET&
/:   CHANGING &STR_SUPPL1&
/:   CHANGING &TEMP&
/:   ENDPERFORM.
/:   ENDIF

and in the program Z_RFFOUS_C.

incorporate your subroutine code.

*---------------------------------------------------------------------*
*       FORM GET_DATA_ADRC                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  IT_USING                                                      *
*  -->  IT_CHANGING                                                   *
*---------------------------------------------------------------------*
FORM GET_DATA_ADRC TABLES IT_USING STRUCTURE ITCSY
                       IT_CHANGING STRUCTURE ITCSY.

  DATA : ADRNR LIKE LFA1-ADRNR.

  DATA : L_STREET LIKE ADRC-STREET,
         L_STR_SUPPL1 LIKE ADRC-STR_SUPPL1,
         L_STR_SUPPL2 LIKE ADRC-STR_SUPPL2,
         L_STR_SUPPL3 LIKE ADRC-STR_SUPPL3,
         L_LOCAT  LIKE ADRC-LOCATION.

  DATA : TEMP(220).

  READ TABLE IT_USING INDEX 1.
  MOVE IT_USING-VALUE TO ADRNR.

  UNPACK ADRNR TO ADRNR.

  SELECT SINGLE STREET
                STR_SUPPL1
                STR_SUPPL2
                STR_SUPPL3
                LOCATION
       FROM   ADRC
       INTO   (L_STREET,
              L_STR_SUPPL1,
              L_STR_SUPPL2,
              L_STR_SUPPL3,
              L_LOCAT)
       WHERE
              ADDRNUMBER = ADRNR.



  READ TABLE IT_CHANGING INDEX 1.
  IT_CHANGING-VALUE = L_STREET.
  MODIFY IT_CHANGING INDEX 1.
*
  READ TABLE IT_CHANGING INDEX 2.
  IT_CHANGING-VALUE = L_STR_SUPPL1.
  MODIFY IT_CHANGING INDEX 2.
*
*  read table it_changing index 3.
*  it_changing-value = l_str_suppl2.
*  modify it_changing index 3.
*
*  read table it_changing index 4.
*  it_changing-value = l_str_suppl3.
*  modify it_changing index 4.
*
*  read table it_changing index 5.
*  it_changing-value = l_locat.
*  modify it_changing index 5.

*  concatenate l_str_suppl2 l_str_suppl3 l_locat into  temp.

  CONCATENATE L_STR_SUPPL2
              ','
              L_STR_SUPPL3
              ','
              L_LOCAT INTO  TEMP.


  WHILE SY-SUBRC = 0.
    REPLACE ',' WITH ' ' INTO TEMP.
  ENDWHILE.

  READ TABLE IT_CHANGING INDEX 3.
  IT_CHANGING-VALUE = TEMP.
  MODIFY IT_CHANGING INDEX 3.


ENDFORM.

revert me back if you face any issues.

Reward points if my answer is helpful.

~Lakshmiraj~

Edited by: LAKSHMIRAJ on Mar 29, 2008 7:22 AM

Read only

Former Member
0 Likes
640

Hi,

The Form :

/:PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK

/:USING &EKKO-EBELN&

/:CHANGING &CDECENT&

/:ENDPERFORM

The report :

REPORT zkrpmm_perform_z1medruck .

DATA : BEGIN OF it_input_table OCCURS 10.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_input_table.

  • déclaration de la table output_table contenant les

variables exportées

DATA : BEGIN OF it_output_table OCCURS 0.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_output_table.

DATA : w_ebeln LIKE ekko-ebeln,

  • w_vbeln LIKE vbak-vbeln,

w_zcdffa LIKE vbak-zcdffa.

*----


*

  • FORM CDE_CENT

*

*----


*

FORM cde_cent TABLES input output.

it_input_table[] = input[].

it_output_table[] = output[].

READ TABLE it_input_table INDEX 1.

MOVE it_input_table-value TO w_ebeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = w_ebeln

IMPORTING

output = w_ebeln.

SELECT SINGLE zcdffa FROM ekko

INTO w_zcdffa

WHERE ebeln = w_ebeln.

it_output_table-name = 'CDECENT'.

MOVE w_zcdffa TO it_output_table-value.

MODIFY it_output_table INDEX 1.

output[] = it_output_table[].

ENDFORM.

Reward if helpful...

Sravani.