Wednesday 19 June 2013

How to download the source code to local directory in SAP?

SAP has provided a standard report ‘REPTRAN’ using which we can downloads the source code into local directory.

Steps:
  • Execute the program REPTRAN in SE38.
  • In selection screen, give the program name and the directory path to which you wanted to download and execute.

Regards,
Venugopal M N

Monday 17 June 2013

How to get the components of structure i.e. list of fields of a structure in SAP-ABAP?

Sometime it might be required to get the components of the structure i.e. list of fields present in structure.


Use function module GET_COMPONENT_LIST to get the components of the structure.

Example:

REPORT ZVENU_TEST4.

DATA: t_components TYPE STANDARD TABLE OF RSTRUCINFO,
      x_components 
TYPE RSTRUCINFO.

TYPESBEGIN OF ty_tab,
        kunnr 
type kna1-kunnr,
        name1 
type kna1-name1,
       
END OF ty_tab.

DATA: x_kna1 TYPE ty_tab.

*--CAll FM to get hte components of structure
CALL FUNCTION 'GET_COMPONENT_LIST'
  
EXPORTING
    
PROGRAM          = sy-repid
    FIELDNAME        = 
'X_KNA1'
  
TABLES
    COMPONENTS       = t_components.

LOOP AT t_components INTO x_components.
  
WRITE:/  sy-tabix ,' - Field Name : ', x_components-COMPNAME.
ENDLOOP. Output:

Output:


Similarly, using this functional module we can get the components of structure which is present in another program. In such a case pass the program name to PROGRAM field and structure name to FIELDNAME field.

NOTE: This FM give the components of internal table with header line, whereas using this FM we cannot get the component of structure without header line.

Regards,
Venugopal M N

How to get the value of the internal table in F4 help - SAP ABAP?

In this tutorial we will see how to get the value of the internal table in the F4 help.

Case-I:
  • In the above program, we have declared a parameter of type BUKRS (Company Code). Upon pressing the F4 in the selection screen we will get a popup listing all company codes as shown below.
  • This will happen because of the standard Search Help - C_T001 associated with data element BUKRS.



Case-II:
Sometimes the functional requirement will be such that upon pressing the F4, it should display only few company codes (say AC01, AC02, AC03 and US01).

To achieve the above requirement we need to follow below steps.
  • Populate the required values (AC01, AC02, AC03 and US01) of company code into internal table (T_BUKRS)
  • Call FM F4IF_INT_TABLE_VALUE_REQUEST in AT SELECTION-SCREEN ON VALUE-REQUEST section to get the values of internal tables. Refer the below code for the same.
*&---------------------------------------------------------------------*
REPORT ZVENU_TEST3.

*--Declaration of Structures
TYPESBEGIN OF ty_bukrs,
        bukrs TYPE knb1-bukrs,
       END OF ty_bukrs.

*--Declaration of data
DATA: t_bukrs  TYPE STANDARD TABLE OF ty_bukrs,
      x_bukrs  TYPE ty_bukrs,
      t_return TYPE STANDARD TABLE OF ddshretval,
      x_return TYPE ddshretval.

REFRESH: t_bukrs, t_return.
CLEAR:   x_bukrs, x_return.

*--Selecetion Screen Parameter
PARAMETERS: p_bukrs TYPE bukrs.

*--Populatin the values to internal table
INITIALIZATION.
  x_bukrs-bukrs = 'AC01'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.

  x_bukrs-bukrs = 'AC02'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.

  x_bukrs-bukrs = 'AC03'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.

  x_bukrs-bukrs = 'US01'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.
*--Upon pressing the F4 buttion following code will be called
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bukrs.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  EXPORTING
   RETFIELD               = 'BUKRS'   " Field Name Structure
   DYNPPROG               = sy-repid  " Program Name
   DYNPNR                 = sy-dynnr  " Current Screen Number
   DYNPROFIELD            = 'P_BUKRS' " Selection Screen Field
   VALUE_ORG              = 'S'       " Structure
   CALLBACK_PROGRAM       = sy-repid  " Program Name
  TABLES
   VALUE_TAB              = t_bukrs   " Internal table containing values
   RETURN_TAB             = t_return  " Return Table
 EXCEPTIONS
   PARAMETER_ERROR        = 1
   NO_VALUES_FOUND        = 2
   OTHERS                 = 3.
IF SY-SUBRC NE 0.
  MESSAGE 'Error in F4 help.' TYPE 'E'.
ENDIF.
*&---------------------------------------------------------------------*

Upon pressing the F4 in selection screen we'll get below pop-up as below.


Regards,
Venugopal M N


Sunday 16 June 2013

How to find the program name based on the transaction code (T-Code) in SAP?

Sometimes during documentation functional/technical consultants require name of the program associated with T-code.

In SE93 transaction we can find out the program name which is associated with the t-code.

Say, you wanted to find the program associated with transaction code PFAL. Follow below steps to get the program name.

Steps:
  • Go to SE93 and enter T-code (PFAL)
  • Click on display button

Regards,
Venugopal M N



How to write a simple ABAP program in SAP?

In the following post we will see how to write a simple ABAP program.
  • Login to SAP
  • Go to transaction SE38
  • Enter new program name (Say ZTEST1) starting with Y or Z (All custom programs will start with Y or Z in SAP).
  • Enter program name and click on CREATE button.

  • In the next screen, enter the program TITLE and select the type of the program as ‘Executable Program’ and click on SAVE.
  • In the editor screen write the below code.

WRITE in SAP is similar to PRINTF statement in C.
  • Press ‘F8’ for executing the programs. Below is the output of the program.


Refer the below video.


Regards,
Venugopal M N






How to get the list of internal tables, work area & constants details declared in another program in SAP?

We can get the list of internal tables, work area & constants declared in another program in SAP using the standard function module  ‘GET_GLOBAL_SYMBOLS’.


Demo Example:
Let us create a test program ‘ZVENU_TEST1’ having the structure TY_TAB, T_KNA1 AND X_KNA1.



Now, our aim is access the structures & internal tables declared in ‘ZVENU_TEST1’ program from another program ‘ZVENU_TEST2’. This can be achieved by using the FM‘GET_GLOBAL_SYMBOLS’.


Upon executing the above program the internal table T_FIELDLIST will have the required details.

Regards,
Venugopal M N