Thursday, March 3, 2022

How to call a smartform from a driver program

Below Code Snippet shows how to call a smartform from a driver program. 


DATA:   f_name        TYPE rs38l_fnam,
        gwa_ssfcompop TYPE ssfcompop,
        gwa_control   TYPE ssfctrlop,
        gv_job_output TYPE ssfcrescl,
        gv_devtype    TYPE rspoptype,
        i_otf         TYPE  tsfotf.

* Every Smartform is a function module, generated by SAP. Each time the form is modified a new FM is created. Therefore to get the name of the FM of Smartform we have to use the below FM - SSF_FUNCTION_MODULE_NAME

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname 'SMARTFORM_NAME'
      IMPORTING
        fm_name  f_name.

* Get Device Type 

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
      EXPORTING
        i_language             sy-langu
*       I_APPLICATION          = 'SAPDEFAULT'
      IMPORTING
        e_devtype              gv_devtype
      EXCEPTIONS
        no_language            1
        language_not_installed 2
        no_devtype_found       3
        system_error           4
        OTHERS                 5.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

* Control parameters for print window
    gwa_control-preview 'X'.
    gwa_control-no_dialog 'X'.
    gwa_ssfcompop-tdprinter gv_devtype.
    gwa_ssfcompop-tdcopies 1.
    gwa_control-getotf 'X'.

* Smartform Call 

    CALL FUNCTION f_name
      EXPORTING
*       ARCHIVE_INDEX      =
*       ARCHIVE_INDEX_TAB  =
*       ARCHIVE_PARAMETERS =
        control_parameters gwa_control
*       MAIL_APPL_OBJ      =
*       MAIL_RECIPIENT     =
*       MAIL_SENDER        =
        output_options     gwa_ssfcompop
*       USER_SETTINGS      = 'X'
        itab               tab_name
      IMPORTING
*       DOCUMENT_OUTPUT_INFO       =
        job_output_info    gv_job_output
*       JOB_OUTPUT_OPTIONS =
      EXCEPTIONS
        formatting_error   1
        internal_error     2
        send_error         3
        user_canceled      4
        OTHERS             5.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    APPEND LINES OF gv_job_output-otfdata TO i_otf.

    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
      EXPORTING
        i_otf                    i_otf
      EXCEPTIONS
        convert_otf_to_pdf_error 1
        cntl_error               2
        OTHERS                   3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.



Wednesday, March 2, 2022

How to assign a custom form and driver program to a Standard output for NACE

Let's say, we don't want to use the standard form provided by SAP for our invoice printout. We want to design our own form and program and call it from the invoice-related transaction codes-  VF02, VF03. 

Yes, we are going to use VF02 for this example. 

1. Check the Output Request first. Marked Red in the below image. 




We can see the output type is RD00 


Now Goto Transaction 'NACE'. 

Select V3 - Billing. as we are working with the Invoice output, V3 is the type for this output. And click on Output types. 


It will take us to the output types overview screen. Click on the output type you want to check. In out case it's RD00. and click the processing routines from the dialog structure sidebar.


Here we can see the actual program name and form used for Billing printout. 


We can set our own program and form here. Usually, a new custom type of output is created and mapped to the form and program. 

We already have a few in this demo system. Let's check it. 



Here we have assigned our own custom Z program and form to the output type. 


The output type is custom too. Therefore it needs to be set in the output request as well. This was the first step for this process. 

Finally, we will prepare the Driver program to call it from the standard program with NACE assist using the same Form Routine name.


REPORT zcustom_form.


*All the Includes will go here 

START-OF-SELECTION.
FORM entry USING ent_retco 
             ent_screen 
    CLEAR ent_retco.

*Write your Logic here for the form  
    DATA(i_objkynast-objky.

*nast-objky holds the calling object key - in this case billing number 

    PERFORM fetch_data.  "Fetch the data you want to pass to the form  
    PERFORM call_form.   "Call the Form using FMs. There's already a post about how                             to call an adobe form from the Driver Program 
  
ENDFORM.
 

ENT_RETCO is the return code just like SY-SUBRC.
ENT_SCREEN  is the indicator for print preview. If the print preview is selected, its value is 'X'. Otherwise blank. 

In this way you can use your custom forms for any output types using NACE. 


How to call an Adobe form from Driver program

 Below code snippet shows how an Adobe form is called from a Driver Program. 

DATA  lv_form_name TYPE fpname VALUE 'ZADOBE_FORM',
        wa_otparams  TYPE sfpoutputparams,
        lv_fm        TYPE funcname,
        e_result     TYPE sfpjoboutput.

  "Here goes the code for fetching the data that we want to pass. 

------------------------------------------------------------------
"Every Form is a function module. We don't know the technical name of the FM. So this FM is used to call the actual FM holding the form. 

  CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
    EXPORTING
      i_name     lv_form_name
    IMPORTING
      e_funcname lv_fm.

"These are the output settings to be passed in FP_JOB_OPEN FM 
  wa_otparams-nodialog 'X'.
  wa_otparams-preview 'X'.

"This FM is used to Determine the output settings of the form (Print, Print Preview, Archive settings) 
  CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
      ie_outputparams wa_otparams
    EXCEPTIONS
      cancel          1
      usage_error     2
      system_error    3
      internal_error  4
      OTHERS          5.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

"This will call the ADOBE Form. I stated earlier that every form is an FM. We got the actual FM name from FP_FUNCTION_MODULE_NAME and received it in LV_FM. Now we are calling that directly. 

  CALL FUNCTION lv_fm
    EXPORTING
      ls_tab         table_name 
      ls_var         variable_name
    EXCEPTIONS
      usage_error    1
      system_error   2
      internal_error 3
      OTHERS         4.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
"Every Open Job has to be closed. This will close the output spool and return the result. 

  CALL FUNCTION 'FP_JOB_CLOSE'
    IMPORTING
      e_result       e_result
    EXCEPTIONS
      usage_error    1
      system_error   2
      internal_error 3
      OTHERS         4.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
 

Function Modules to Convert Amount to Words in ABAP

SAP has provided Function Modules to achieve this. 

1. SPELL_AMOUNT - For International Numbering System ( Billions, Millions, Thousand )  

2. HR_IN_CHG_INR_WRDS - For the Indian Numbering system ( Crores, Lakhs )

If you want to convert the amount into Millions and Billions use SPELL_AMOUNT. 

or if you want to convert the amount in Crores and Lakhs then use HR_IN_CHG_INR_WRDS. 


Let's see these FMs in action. 

1. SPELL_AMOUNT-

DATAamnt TYPE DMBTR value '5322478.76' ,
      lv_words TYPE SPELL.

  CALL FUNCTION 'SPELL_AMOUNT'
    EXPORTING
      amount    amnt
      currency  'BDT'
*     FILLER    = ' '
      language  sy-langu
    IMPORTING
      in_words  lv_words
    EXCEPTIONS
      not_found 1
      too_large 2
      OTHERS    3.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

WRITElv_words-wordlv_words-decword.

Output:



Here the output we are receiving from the FM is of type 'SPELL' which is a structure to hold the incoming data. 


Check the structure below. It holds both the word for the amount and decimal places. You can use them as per your requirement. 


2. HR_IN_CHG_INR_WRDS - 

DATAamnt          type PC207-BETRG Value '5322478.76',
      lv_words(100type c.

  CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
    EXPORTING
      amt_in_num               amnt
   IMPORTING
     AMT_IN_WORDS             lv_words
   EXCEPTIONS
     DATA_TYPE_MISMATCH       1
     OTHERS                   2
            .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  WRITElv_words.

Output: 


Here the output we are receiving from the FM is of type 'C'. And the Import parameter is of currency type BETRG. 



One extra feature it provides is the addition of Rupees and Paise. You can replace it with your local currency words with the Replace Keyword in ABAP. 

Replace 'Rupees' with 'TAKA' into lv_words.

I have replaced it with TAKA ( Bangladeshi Currency ). 




Tuesday, March 1, 2022

Tcode List for ABAP

S001 is the Tcode for ABAP Workbench. We can find all the relevant transactions for ABAP through this Tcode.    

SDW0  Provides the same functionality with more features. 

Below is a list of Tcodes that are necessary for an ABAP developer.

ABAPDOCU        ABAP Documentation Library 

ABAPHELP          ABAP Keyword Documentation

AL08      System-Wide List of User sessions in SAP System (Logged Users Information ) 

PFCG     Role Maintenance

SA38      ABAP Reporting

SCMP    View/Table comparison

SCU3     Customized objects and Tables History

SCI          Code Inspector

SE01       Transport Organizer(Extended View)

SE09       Transport organizer

SE10       Transport organizer

SE11       ABAP Dictionary

SE12       ABAP Dictionary display

SE15       Repository Info System

SE16       Display table content

SE16N     General Table Display 

SE17       General table display

SE37       ABAP Function Modules

SE38       ABAP Editor

SE41       Menu Painter

SE51       Screen Painter

SE71       Form Painter

SE80       Object Navigator

SE93       Maintain Transaction

SHDB     Transaction Recorder

SLIN       ABAP Programs Extended Check

SM04     User Sessions

SM21     System Log

SM30     Maintain tables(not all tables can use SM30)

SM31     Maintain tables/Views

SM35     Batch Input Monitoring

SM37     Overview of background jobs

SP00      Spool

SP01      Output controller

SP02      Display output requests

SPAD     Spool administration (printer setup)

SPIC       Spool; installation check

ST01       SAP system trace

ST05       Performance trace

ST07       Application Monitor

ST09       Table call statistics

ST11       Display developer trace

ST12       Application monitor

ST22       Dump Analysis

STAT      Local Transaction statistics

STUN     Performance monitoring

SU01      User maintenance

SU02      Maintain authorization profiles

SU03      Maintain authorizations

SU10      Maintain change to user records

SU12      Delete all users

SU2        Maintain user parameters

SU53      Display Failed authorization check

SM12     Check Lock Entries

SAAB     Checkpoints that Can Be Activated

SALE      ALE customizing transaction

CG3Y     Download File from SAP Application Server to Local machine

CG3Z     Upload File from Local Machine to SAP Application Server

NACE     Output Control - for Mapping standard Tcodes to custom outputs. 

ST05       SQL tracer (for performance tunning)

SE30       ABAP runtime analysis(Performance tuning)

SE61       SAP Documentation

SFP          ADOBE Forms

SMARTFORMS       Smartforms

WE31     Segment creation

WE30    Idoc Type creation

WE81    Creation and assigning of Message type









SAP Standard Program RS_TYPE_WIZARD for Any Data Types

 We can Always go to Tcode SE11 and find out about any specific data type. 

However, there is another way to find data types directly about Tables, structures, or any data type through a standard SAP program named 'RS_TYPE_WIZARD'.

1. Goto transaction se38 or sa38 and in program name field put  'RS_TYPE_WIZARD' and execute. 

2.  It will open the selection screen for the program. 




3. Type any data type you like. Let's check with table VBRK. Press Execute button. 


It's showing us the actual built-in data types that are used to define the table fields. 

4. We can see a hierarchical or XML view of the information as well. Go back and select the hierarchy display from the output options 
    

5.  It will show the types for includes as well. 


    

6. XML view 
    




How to Find Implemented BADIs for a Tcode in SAP

  Simple way to find implemented BADI for a TCode in SAP  First We have to find the Package for the transaction. 1.      Go to that par...