Tuesday, October 27, 2015

Subroutine in SAP Script

Let us go with the existing SAP script. We need to create a subroutine inside this script. As we know the usability of subroutine we want to create a subroutine inside this script. With the help of this subroutine we want to show the Bank details of existing vendor so LFBK table has been used. Now the actual coding part is taken care by SE38 where a subroutine pool program needs to be created. We are calling that program inside this form. To call this program we have to go to Text element with change editor. The steps are as follows.

Step 1: Go to text element change editor. The code can be written there by using '/:' operator.


Step 2: Now create a subroutine pool program in SE38.


Step 3: This program will contain only the form and endform. We can declare nested forms also. The program is as follows.

PROGRAM  zsubroutine_script.

*&---------------------------------------------------------------------*
*&      Form  get_bank
*&---------------------------------------------------------------------*
*       Subroutine by which getting data from vendor bank table LFBK
*----------------------------------------------------------------------*
FORM get_bank TABLES it_input  STRUCTURE itcsy
                     it_output STRUCTURE itcsy.
*-Declaring input table and output table with structure ITCSY
*-ITCSY is a standard structure which holds two fields
*-Name & Value
*-Here the name is field name & value is field value

  "Declaring bank details work area structure
  DATA: BEGIN OF wa_lfbk,
          lifnr TYPE lfbk-lifnr,
          banks TYPE lfbk-banks,
          bankl TYPE lfbk-bankl,
        END OF wa_lfbk.

  DATA: wa_var  TYPE itcsy, "work area for ITCSY
        lv_var  TYPE lifnr. "variable for conversion

  IF it_input IS NOT INITIAL.

    "Reading the input table with key name
    READ TABLE it_input INTO wa_var
    WITH KEY name = 'WA_LFA1-LIFNR'.

    IF sy-subrc = 0.

      "Conversion for vendor account number
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_var-value
        IMPORTING
          output = lv_var.

      "Selecting the bank details
      SELECT SINGLE lifnr banks bankl
        FROM lfbk INTO wa_lfbk
        WHERE lifnr = lv_var.

      IF sy-subrc = 0.

        "Reading the output table with key name - first field
        READ TABLE it_output INTO wa_var
        WITH KEY name = 'WA_LFBK-BANKS'.

        IF sy-subrc = 0.
          wa_var-value = wa_lfbk-banks. "Bank country

          "Modifying the output table with values - bank country
          MODIFY it_output FROM wa_var INDEX sy-tabix.
        ENDIF.

        "Reading the output table with key name - second field
        READ TABLE it_output INTO wa_var
        WITH KEY name = 'WA_LFBK-BANKL'.

        IF sy-subrc = 0.
          wa_var-value = wa_lfbk-bankl. "Bank key

          "Modifying the output table with values - bank key
          MODIFY it_output FROM wa_var INDEX sy-tabix.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    "get_bank

Step 4: Finally in the form we can see the Bank details.


9 comments:

RS Trainings said...

Thanking for given about SAP Info.
For More Details About
SAP ABAP Online Training USA
Online SAP BODS Training USA
Online SAP Hana Training usa
SAP XI/PI online Training usa
SAP BW/BI online Training USA
SAP BO Online Training USA
SAP FICO online Training usa

Rahul said...

Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog on SAP SD.
SAP SD

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...

Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

http://thecreatingexperts.com/sap-mm-training-in-chennai/

simashree said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882
http://thecreatingexperts.com/category/sap-hana-training-in-chennai/

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD