Wednesday 31 January 2024

SAP program to inner join two custom tables

 REPORT zsm_innerjoin.


TYPES: BEGIN OF ty_str,

         id       TYPE int4,

         name     TYPE char20,                                         " Fields

         salary   TYPE int4,

*         location TYPE char20,

       END OF ty_str.                                                    " Creation of  Structure.


DATA: it TYPE STANDARD TABLE OF ty_str,     " Creation of Internal Table.

      wa TYPE ty_str.                                                    " Creation of Work Area


select  zvp_student~id

        zvp_student~name

        zvp_salary~salary

  FROM zvp_student INNER JOIN zvp_salary ON zvp_student~id = zvp_salary~id


  INTO TABLE it.                                                        " Operation for inner join.



LOOP AT it INTO wa.

  WRITE: wa-id, wa-name, wa-salary.

ENDLOOP.                                                                  " Displaying the output of the program.




          O   U   T   P   U   T     :-




                                            

Monday 29 January 2024

SAP Program to insert multiple records into a custom table through selection screen.

 REPORT zsm_data.


TYPESBEGIN OF str,
        id type int4,
         name TYPE char10,
         age TYPE int4,
        adress TYPE char10,
       END OF str.

DATAit TYPE TABLE OF str,
      wa TYPE str.

PARAMETERS:  p_id TYPE int4,
          p_name TYPE char10,
             p_age TYPE int4,
    p_adress TYPE char10.

START-OF-SELECTION.

wa-id p_id.
wa-name p_name.
wa-age p_age.
wa-adress p_adress.

APPEND wa TO it.

LOOP AT it INTO wa.

  WRITE/ wa-idwa-namewa-agewa-adress.
ENDLOOP.

Friday 26 January 2024

SAP program to modify a record in internal table.

REPORT zsm_edit.

TYPES: BEGIN OF str,
         id       TYPE int4,
         name     TYPE char10,
         location TYPE char10,
       END OF str.

DATA: it TYPE STANDARD TABLE OF str,
      wa TYPE str.

wa-id = '1'.
wa-name = 'Suvadeep'.
wa-location = 'Kolkata'.
APPEND wa TO it.

wa-id = '2'.
wa-name = 'Nitai'.
wa-location = 'Bangalore'.
APPEND wa TO it.

wa-id = '3'.
wa-name = 'Chirashree'.
wa-location = 'Pune'.
APPEND wa TO it.

wa-id = '4'.
wa-name = 'Soumyodeep'.
wa-location = 'Hyderabad'.
APPEND wa TO it.

wa-location = 'Kolkata'.
MODIFY it FROM wa TRANSPORTING location WHERE id = '2'.

*clear it.

*FREE it.

loop at it into wa.

  write:/ wa-id, wa-name, wa-location.

  ENDLOOP.

Saturday 20 January 2024

SAP Program to concatenate two strings

 REPORT ZSM_INTERNALCONCAT.


TYPESBEGIN OF str,
         id     TYPE int4,
         first_name   TYPE char10,
         last_name TYPE char10,
         full_name type char20,
       END OF str.

DATAit TYPE STANDARD TABLE OF str,
      wa TYPE str.

wa-id '1'.
wa-first_name 'Suvadeep'.
wa-last_name 'Mondal'.
CONCATENATE wa-first_name wa-last_name into wa-full_name SEPARATED BY ''.
APPEND wa TO it.

wa-id '2'.
wa-first_name 'Nitai'.
wa-last_name 'Mondal'.
CONCATENATE wa-first_name wa-last_name into wa-full_name SEPARATED BY ''.
APPEND wa TO it.

wa-id '3'.
wa-first_name 'Chirashree'.
wa-last_name 'Mondal'.
CONCATENATE wa-first_name wa-last_name into wa-full_name SEPARATED BY ''.
APPEND wa TO it.

wa-id '4'.
wa-first_name 'Soumyodeep'.
wa-last_name 'Mondal'.
CONCATENATE wa-first_name wa-last_name into wa-full_name SEPARATED BY ''.
APPEND wa TO it.


LOOP AT it into wa.

  write/ wa-idwa-first_namewa-last_namewa-full_name.

ENDLOOP.

SAP program to split two strings

 REPORT ZSM_DEMO2.


data: lv_firstname type char10.

data: lv_lastname type char10.

data: lv_fullname type char20.


lv_fullname = 'Suvadeep Mondal'.


 SPLIT lv_fullname at '' INTO lv_firstname lv_lastname.


 write:/ lv_lastname.

Friday 19 January 2024

SAP program to move records from one internal table to another

REPORT ZSM_INTERNAL2.

TYPES: BEGIN OF str,
         id     TYPE int4,
         name   TYPE char10,
         location TYPE char10,
       END OF str.

DATA: it_one TYPE STANDARD TABLE OF str,
      wa TYPE str.

DATA: it_two TYPE STANDARD TABLE OF str.

wa-id = '1'.
wa-name = 'AAA'.
wa-location = 'Kolkata'.
APPEND wa TO it_one.

wa-id = '2'.
wa-name = 'BBB'.
wa-location = 'Chennai'.
APPEND wa TO it_one.

wa-id = '3'.
wa-name = 'CCC'.
wa-location = 'Hyderabad'.
APPEND wa TO it_one.

wa-id = '4'.
wa-name = 'DDD'.
wa-location = 'Lucknow'.
APPEND wa TO it_one.

wa-id = '5'.
wa-name = 'EEE'.
wa-location = 'Pune'.
APPEND wa TO it_one.

wa-id = '6'.
wa-name = 'FFF'.
wa-location = 'Bangalore'.
APPEND wa TO it_one.

wa-id = '7'.
wa-name = 'GGG'.
wa-location = 'Punjab'.
APPEND wa TO it_one.

wa-id = '8'.
wa-name = 'HHH'.
wa-location = 'Haryana'.
APPEND wa TO it_one.

MOVE it_one TO it_two.

LOOP AT it_two into wa.
WRITE:/ wa-id, wa-name, wa-location.
ENDLOOP.

Tuesday 16 January 2024

SAP Calculator Program with if else statement

 REPORT ZSM_DEMO1.


PARAMETERS p_num1 type int4.

PARAMETERS p_num2 type int4.

PARAMETERS operatn type char10.


data: p_result type int4.


if operatn = '+'.

  p_result = p_num1 + p_num2.

  write:/ 'result : ', p_result.


ELSEIF operatn = '-'.

  p_result = p_num1 - p_num2.

  write:/ 'result : ', p_result.


ELSEIF operatn = '*'.

  p_result = p_num1 * p_num2.

  write:/ 'result : ', p_result.


  ELSEIF operatn = '/'.

  p_result = p_num1 / p_num2.

  write:/ 'result : ', p_result.


 ENDIF.

SAP Calculator Program with Switch Case

 REPORT zsm_demo.


PARAMETERS num1 TYPE int4.

PARAMETERS num2 TYPE int4.

PARAMETERS operatn TYPE char10.


DATA: result TYPE int4.


CASE operatn .

  WHEN '+'.

    result = num1 + num2.

    WRITE: / 'Result:', result.

  WHEN '-'.

    result = num1 - num2.

    WRITE: / 'Result:', result.

  WHEN '*'.

    result = num1 * num2.

    WRITE: / 'Result:', result.

  WHEN '/'.

    result = num1 / num2.

    WRITE: / 'Result:', result.


ENDCASE.

Thursday 4 January 2024

SAP Program to inner join between EKKO and EKPO Table

 REPORT ZINNER_JOIN_EKKO_EKPO.


TYPESBEGIN OF ekpo_with_ekko,
         ebeln TYPE ekpo-ebeln,
         bukrs TYPE ekko-bukrs,
         bstyp TYPE ekko-bstyp,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         matkl TYPE ekpo-matkl,
       END OF ekpo_with_ekko.

DATAlt_result TYPE TABLE OF ekpo_with_ekko,
      ls_result TYPE ekpo_with_ekko.

SELECT ekpo~ebeln AS ebeln ekko~bukrs AS bukrs ekko~bstyp AS bstyp ekpo~matnr AS matnr ekpo~werks AS werks ekpo~matkl AS matkl
  FROM ekpo
  INNER JOIN ekko ON ekpo~ebeln ekko~ebeln
  INTO TABLE lt_result.

IF lt_result IS NOT INITIAL.
  LOOP AT lt_result INTO ls_result.
    WRITE'EBELN:'ls_result-ebeln,
            'BUKRS:'ls_result-bukrs,
            'BSTYP:'ls_result-bstyp,
            'MATNR:'ls_result-matnr,
            'WERKS:'ls_result-werks,
            'MATKL:'ls_result-matkl.
  ENDLOOP.
ELSE.
  WRITE'No records found for the specified criteria.'.
ENDIF.