Tuesday 7 May 2024

What is TMG in SAP ?

 TMG is a tool to create table maintenance program by which we can create, edit and delete data in large chunks in a table. The main purpose of the table maintenance generator is to create/change and delete the table entries.

We can transport TMG data by enabling standard recording routine. An end user can access TMG with Tcode

Single Step: Only Overview is created that means the TMG program will have only one screen where we can add, delete or edit records.

Two Step: Two screens namely the overview screen and single screen is created. The user can see the key fields in the first screen and can go on to edit further details.

In this the overview screen contains only the key fields and the single screen contains all the fields. On a single screen we can only maintain the screen. Like delete and insert. We cannot update from a single screen. From the overview screen we can delete and update.

There are 39 events for Table Maintenance Generator.






Program to create a custom screen where in field input it will check whether the number is odd or the number is even

 PROGRAM:  


REPORT ZSM_SCREEN2.

DATAnumber TYPE i.

DATAlv_number TYPE char10.

DATAlv_check TYPE char10.

DATAit_dynpfields TYPE TABLE OF dynpread,
      wa_dynpfields TYPE dynpread.

CALL SCREEN 500.

MODULE user_command_0500 INPUT.

  IF sy-ucomm 'F_CALC'.

    wa_dynpfields-fieldname 'LV_NUMBER'.
    APPEND wa_dynpfields TO it_dynpfields.

    wa_dynpfields-fieldname 'LV_CHECK'.
    APPEND wa_dynpfields TO it_dynpfields.


    CALL FUNCTION 'DYNP_VALUES_READ'
      EXPORTING
        dyname               sy-cprog
        dynumb               sy-dynnr
*       TRANSLATE_TO_UPPER   = ' '
*       REQUEST              = ' '
*       PERFORM_CONVERSION_EXITS             = ' '
*       PERFORM_INPUT_CONVERSION             = ' '
*       DETERMINE_LOOP_INDEX = ' '
*       START_SEARCH_IN_CURRENT_SCREEN       = ' '
*       START_SEARCH_IN_MAIN_SCREEN          = ' '
*       START_SEARCH_IN_STACKED_SCREEN       = ' '
*       START_SEARCH_ON_SCR_STACKPOS         = ' '
*       SEARCH_OWN_SUBSCREENS_FIRST          = ' '
*       SEARCHPATH_OF_SUBSCREEN_AREAS        = ' '
      TABLES
        dynpfields           it_dynpfields
      EXCEPTIONS
        invalid_abapworkarea 1
        invalid_dynprofield  2
        invalid_dynproname   3
        invalid_dynpronummer 4
        invalid_request      5
        no_fielddescription  6
        invalid_parameter    7
        undefind_error       8
        double_conversion    9
        stepl_not_found      10
        OTHERS               11.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    READ TABLE it_dynpfields INTO  DATA(wa_oneWITH KEY fieldname 'LV_NUMBER'.

     IF lv_number 'X'.
      number lv_number.
    IF number MOD 0.
       lv_check 'Even'.
    ELSE.
      lv_check 'Odd'.
    ENDIF.

ENDIF.

ENDIF.

ENDMODULE.

Saturday 4 May 2024

SAP program to innerjoin only four fields from VBAK and VBAP standard tables

 Program: 


REPORT ZSM_INNERJOIN6.

'Creation of structure'


typesBEGIN OF str,
  vbeln type vbeln,
  erdat TYPE erdat,
  matwa TYPE matwa,
  pmatn TYPE pmatn,
  END OF str.

  datait TYPE standard table of str,   
        wa TYPE str.                    'Creation of internal table and work area'

  SELECT vbak~vbeln
         vbak~erdat

         vbap~matwa      'Query to inner join'
         vbap~pmatn

    FROM vbak INNER JOIN vbap ON vbak~vbeln vbap~vbeln INTO TABLE it.

    if sy-subrc 0.     'to check if the select query is correct'
      LOOP at it INTO wa.
        WRITE:/ wa-vbelnwa-erdatwa-matwawa-pmatn.    'Output'
        ENDLOOP.
        ENDIF.



Output: 


                   


                 


SAP Program to add input fields in a custom screen and implementing output

Program: 

 REPORT zsm_screen.


DATAlv_output TYPE char10.

DATAit_dynpfields TYPE TABLE OF dynpread,
      wa_dynpfields TYPE dynpread.

CALL SCREEN 400.

MODULE user_command_0400 INPUT.

  IF sy-ucomm 'F_CALC'.

    wa_dynpfields-fieldname 'LV_ONE'.
    APPEND wa_dynpfields TO it_dynpfields.

    wa_dynpfields-fieldname 'LV_TWO'.
    APPEND wa_dynpfields TO it_dynpfields.

    wa_dynpfields-fieldname 'LV_OUTPUT'.
    APPEND wa_dynpfields TO it_dynpfields.


    CALL FUNCTION 'DYNP_VALUES_READ'
      EXPORTING
        dyname               sy-cprog
        dynumb               sy-dynnr
*       TRANSLATE_TO_UPPER   = ' '
*       REQUEST              = ' '
*       PERFORM_CONVERSION_EXITS             = ' '
*       PERFORM_INPUT_CONVERSION             = ' '
*       DETERMINE_LOOP_INDEX = ' '
*       START_SEARCH_IN_CURRENT_SCREEN       = ' '
*       START_SEARCH_IN_MAIN_SCREEN          = ' '
*       START_SEARCH_IN_STACKED_SCREEN       = ' '
*       START_SEARCH_ON_SCR_STACKPOS         = ' '
*       SEARCH_OWN_SUBSCREENS_FIRST          = ' '
*       SEARCHPATH_OF_SUBSCREEN_AREAS        = ' '
      TABLES
        dynpfields           it_dynpfields
      EXCEPTIONS
        invalid_abapworkarea 1
        invalid_dynprofield  2
        invalid_dynproname   3
        invalid_dynpronummer 4
        invalid_request      5
        no_fielddescription  6
        invalid_parameter    7
        undefind_error       8
        double_conversion    9
        stepl_not_found      10
        OTHERS               11.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    READ TABLE it_dynpfields INTO  DATA(wa_oneWITH KEY fieldname 'LV_ONE'.
    READ TABLE it_dynpfields INTO  DATA(wa_twoWITH KEY fieldname 'LV_TWO'.

    lv_output wa_one-fieldvalue + wa_two-fieldvalue.

  ENDIF.


ENDMODULE.




Output: