Friday 17 May 2024

Interactive reporting with VBAK and VBAP tables in SAP

 Program: 


REPORT ZSM_MARA2.

TYPESBEGIN OF str1,
         vbeln TYPE vbeln,
          waerk TYPE waerk,
         netwr TYPE netwr,
         vkorg TYPE vkorg,
       END OF str1.

TYPESBEGIN OF str2,
         vbeln TYPE vbeln,
         posnr TYPE posnr,
         matnr TYPE matnr,
         matkl TYPE matkl,
       END OF str2.

DATAit_one TYPE STANDARD TABLE OF str1,
      wa_one TYPE str1.

DATAit_two TYPE STANDARD TABLE OF str2,
      wa_two TYPE str2.

SELECT vbeln waerk netwr vkorg FROM vbak INTO TABLE it_one.

LOOP AT it_one INTO wa_one.
  WRITE:/ wa_one-vbelnwa_one-waerkwa_one-netwr,  wa_one-vkorg.
  hide wa_one-vbeln.
ENDLOOP.

AT LINE-SELECTION.
  SELECT vbeln posnr matnr matkl
    FROM vbap INTO TABLE it_two WHERE vbeln wa_one-vbeln.
    IF sy-subrc 0.
      loop at it_two INTO wa_two.
        WRITE:/ wa_two-vbelnwa_two-posnrwa_two-matnrwa_two-matkl.
        ENDLOOP.

    ENDIF.


Output: 


             













Tuesday 14 May 2024

Interactive Reporting in SAP

 Program:  


REPORT zsm_interactive.

TYPESBEGIN OF str1,
         matnr TYPE matnr,
         mtart TYPE mtart,
         meins TYPE meins,
       END OF str1.

TYPESBEGIN OF str2,
         matnr TYPE matnr,
         maktx TYPE maktx,
       END OF str2.

DATAit_one TYPE STANDARD TABLE OF str1,
      wa_one TYPE str1.

DATAit_two TYPE STANDARD TABLE OF str2,
      wa_two TYPE str2.

SELECT matnr mtart meins FROM mara INTO TABLE it_one UP TO 10 ROWS.

LOOP AT it_one INTO wa_one.
  WRITE:/ wa_one-matnrwa_one-mtartwa_one-meins.
  hide wa_one-matnr.
ENDLOOP.

AT LINE-SELECTION.
  SELECT matnr maktx
    FROM makt INTO TABLE it_two WHERE matnr wa_one-matnr.
    IF sy-subrc 0.
      loop at it_two INTO wa_two.
        WRITE:/ wa_two-matnrwa_two-maktx.
        ENDLOOP.

ENDIF.



Output: 



                      













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.